Include EPREFIX directories in PATH.
authorZac Medico <zmedico@gentoo.org>
Wed, 9 Nov 2011 00:21:07 +0000 (16:21 -0800)
committerZac Medico <zmedico@gentoo.org>
Wed, 9 Nov 2011 00:21:07 +0000 (16:21 -0800)
This relocates the PATH generation code from ebuild.sh to
doebuild_environment, which helps to eliminate duplicate code.

bin/ebuild.sh
bin/phase-functions.sh
pym/portage/package/ebuild/doebuild.py

index 8ca7a4121d98e28a904da509ddeba69fd89c88e5..226b9f6e5375ff343fff96f94e5d78a18794ea65 100755 (executable)
@@ -5,13 +5,6 @@
 PORTAGE_BIN_PATH="${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"
 PORTAGE_PYM_PATH="${PORTAGE_PYM_PATH:-/usr/lib/portage/pym}"
 
-ROOTPATH=${ROOTPATH##:}
-ROOTPATH=${ROOTPATH%%:}
-PREROOTPATH=${PREROOTPATH##:}
-PREROOTPATH=${PREROOTPATH%%:}
-PATH=$PORTAGE_BIN_PATH/ebuild-helpers:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
-export PATH
-
 # Prevent aliases from causing portage to act inappropriately.
 # Make sure it's before everything so we don't mess aliases that follow.
 unalias -a
@@ -585,18 +578,6 @@ if ! has "$EBUILD_PHASE" clean cleanrm ; then
 
                if [[ $EBUILD_PHASE != depend ]] ; then
 
-                       case "$EAPI" in
-                               0|1|2|3)
-                                       _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers"
-                                       ;;
-                               *)
-                                       _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers/4:$PORTAGE_BIN_PATH/ebuild-helpers"
-                                       ;;
-                       esac
-
-                       PATH=$_ebuild_helpers_path:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
-                       unset _ebuild_helpers_path
-
                        _eprefix=${EPREFIX}
                        case "$EAPI" in 0|1|2) _eprefix= ;; esac
                        # Use default ABI libdir in accordance with bug #355283.
index f46368d688ebf19a195390a4b55f236cbe0d88f3..a686dcdc77c608635763e48de77eba6b4d3fb28f 100644 (file)
@@ -229,6 +229,7 @@ dyn_unpack() {
                return 0
        fi
        if [ ! -d "${WORKDIR}" ]; then
+               echo PATH=$PATH
                install -m${PORTAGE_WORKDIR_MODE:-0700} -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
        fi
        cd "${WORKDIR}" || die "Directory change failed: \`cd '${WORKDIR}'\`"
index cb7da78c74f421ec2167af33cb132302f831d537..da95a63acfafdfa3bf6a01ccfc3a0c47dcc145b7 100644 (file)
@@ -115,6 +115,38 @@ def _spawn_phase(phase, settings, actionmap=None, **kwargs):
        ebuild_phase.wait()
        return ebuild_phase.returncode
 
+def _doebuild_path(settings, eapi=None):
+       """
+       Generate the PATH variable.
+       """
+
+       # Note: PORTAGE_BIN_PATH may differ from the global constant
+       # when portage is reinstalling itself.
+       portage_bin_path = settings["PORTAGE_BIN_PATH"]
+       eprefix = settings["EPREFIX"]
+       prerootpath = [x for x in settings.get("PREROOTPATH", "").split(":") if x]
+       rootpath = [x for x in settings.get("ROOTPATH", "").split(":") if x]
+
+       prefixes = []
+       if eprefix:
+               prefixes.append(eprefix)
+       prefixes.append("/")
+
+       path = []
+
+       if eapi not in (None, "0", "1", "2"):
+               path.append(os.path.join(portage_bin_path, "ebuild-helpers", "4"))
+
+       path.append(os.path.join(portage_bin_path, "ebuild-helpers"))
+       path.extend(prerootpath)
+
+       for prefix in prefixes:
+               for x in ("usr/local/sbin", "usr/local/bin", "usr/sbin", "usr/bin", "sbin", "bin"):
+                       path.append(os.path.join(prefix, x))
+
+       path.extend(rootpath)
+       settings["PATH"] = ":".join(path)
+
 def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
        debug=False, use_cache=None, db=None):
        """
@@ -234,16 +266,6 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
        else:
                mysettings["PVR"]=mysplit[1]+"-"+mysplit[2]
 
-       if "PATH" in mysettings:
-               mysplit=mysettings["PATH"].split(":")
-       else:
-               mysplit=[]
-       # Note: PORTAGE_BIN_PATH may differ from the global constant
-       # when portage is reinstalling itself.
-       portage_bin_path = mysettings["PORTAGE_BIN_PATH"]
-       if portage_bin_path not in mysplit:
-               mysettings["PATH"] = portage_bin_path + ":" + mysettings["PATH"]
-
        # All temporary directories should be subdirectories of
        # $PORTAGE_TMPDIR/portage, since it's common for /tmp and /var/tmp
        # to be mounted with the "noexec" option (see bug #346899).
@@ -311,6 +333,7 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
 
                if eapi is not None:
                        if not eapi_is_supported(eapi):
+                               _doebuild_path(mysettings)
                                raise UnsupportedAPIException(mycpv, eapi)
                        mysettings.configdict['pkg']['EAPI'] = eapi
 
@@ -320,6 +343,7 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
                eapi = mysettings["EAPI"]
                if not eapi_is_supported(eapi):
                        # can't do anything with this.
+                       _doebuild_path(mysettings)
                        raise UnsupportedAPIException(mycpv, eapi)
 
                if hasattr(mydbapi, "getFetchMap") and \
@@ -346,6 +370,8 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None,
                        else:
                                mysettings.configdict["pkg"]["AA"] = " ".join(uri_map)
 
+       _doebuild_path(mysettings, eapi=eapi)
+
        if not eapi_exports_KV(eapi):
                # Discard KV for EAPIs that don't support it. Cache KV is restored
                # from the backupenv whenever config.reset() is called.