[pacman-dev] Makepkg should set environment variables of dependencies before continuing build()

Eric Fernandez zeb at zebulon.org.uk
Sun Dec 30 10:48:34 EST 2012


Hi,

I would like to submit a problem regarding environment variables when
installing make dependencies specified in a PKGBUILD. This is a
follow-up of a problem I reported in
https://bbs.archlinux.org/viewtopic.php?pid=1211773.

This happens when a dependency has an /etc/profile.d shell script
which sets one or more environment variables. If this dependency is
installed for the first time on a system, these environment variables
are not available when the build() fonction is run. This is an issue
when these environment variables are required within the PKGBUILD
script. As a workaround, maintainers run the profile script of the
dependencies directly in in build(). However this may be difficult,
especially in case of a meta package with multiple choices. For
instance, if makedepends contains a meta package such as
"java-environment", and Java has never been installed before, the user
will be asked if he wants to install either openjdk6 or jdk7-openjdk.
If the build() fonction requires the JAVA_HOME environment variable,
which contains the path to java, the maintainer has to source the
corresponding /etc/profile.d shell script, but its name is different
in jdk6 and jdk7!

Thus PKGBUILD maintainers have used various "tricks", such as (see
opencascade in AUR):

if [ -z $JAVA_HOME ]; then
    [ -e /etc/profile.d/openjdk6.sh ] && source /etc/profile.d/openjdk6.sh
    [ -e /etc/profile.d/jdk.sh ] && source /etc/profile.d/jdk.sh
fi

or (see java-mecab in AUR):

if [ -f /etc/profile.d/openjdk6.sh ];
  then
    source /etc/profile.d/openjdk6.sh
  elif [ -f /etc/profile.d/jdk.sh ];
  then
    source /etc/profile.d/jdk.sh
fi

As you can see, the goal is the same, but the syntax is different and
awkward. There is no official or normalised way to do this.

I propose to correct this by making the environment variables
immediately available in build() when a package is installed as a
dependency. It would be logical that when makepkg installs
dependencies, the whole package files but also the environment
variables set by this package are available. This would make a
PKGBUILD less error-prone by:
- undifferenciating if a makedepends is installed for the first time or not
- removing the need to source the correct profile shell script, making
the task difficult in case of a meta package
- making the maintenance of the PKGBUILD easier (what happens when
jdk8 is available, and the profile script name has changed again?)

Note that "source /etc/profile" in build() is not a good solution, as
it runs all profile.d scripts and if one script fails, then the build
process is aborted. It is better to fix makepkg upstream. I had a look
at the code, and do not understand why run_pacman does not set the
variables, but maybe it is a problem of variable space?

Eric


More information about the pacman-dev mailing list