Move environment.bz2 extraction from ebuild.sh to doebuild() on
authorZac Medico <zmedico@gentoo.org>
Thu, 29 Nov 2007 20:24:05 +0000 (20:24 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 29 Nov 2007 20:24:05 +0000 (20:24 -0000)
the python side. The python will be able to use it's awareness
of the ${T}/environment to decide what type of ebuild environment
should be generated. For example, if the ebuild environment
should be able to unset variables that have been inherited from
the calling environment, the existence of ${T}/environment
will indicate that the ebuild environment should be isolated from
the calling environment.

svn path=/main/trunk/; revision=8753

bin/ebuild.sh
bin/isolated-functions.sh
pym/portage/__init__.py

index a5b89c9d4cb7fb2a844770822c7b07737405264a..f8f7377d7f40bbc1976bd59c6ed2265df806bfca 100755 (executable)
@@ -1547,32 +1547,14 @@ if hasq "depend" "${EBUILD_SH_ARGS}"; then
        unset BIN_PATH BIN BODY FUNC_SRC
 fi
 
-# Automatically try to load environment.bz2 whenever
-# "${T}/environment" does not exist, except for phases
-# such as nofetch that do not require ${T} to exist.
-if ! hasq ${EBUILD_SH_ARGS} clean depend nofetch && \
-       [ ! -f "${T}/environment" ] ; then
-       bzip2 -dc "${EBUILD%/*}"/environment.bz2 > \
-               "${T}/environment" 2> /dev/null
-       if [ $? -eq 0 ] && [ -s "${T}/environment" ] ; then
-               preprocess_ebuild_env || \
-                       die "error processing '${EBUILD%/*}/environment.bz2'"
-       else
-               rm -f "${T}/environment"
-       fi
-fi
-
 if hasq ${EBUILD_SH_ARGS} clean ; then
        true
 elif ! hasq ${EBUILD_PHASE} depend && [ -f "${T}"/environment ] ; then
-       if [ "${PN}" == "portage" ] && [ -n "${EBUILD_SH_ARGS}" ] ; then
-               # When portage reinstalls itself, during inst/rm phases, the
-               # environment may have been saved by a different version of ebuild.sh,
-               # so it can't trusted that it's been properly filtered. Therefore,
-               # always preprocess the environment when ${PN} == portage.
-               preprocess_ebuild_env || \
-                       die "error processing environment"
-       fi
+       # The environment may have been extracted from environment.bz2 or
+       # may have come from another version of ebuild.sh or something.
+       # In any case, preprocess it to prevent any potential interference.
+       preprocess_ebuild_env || \
+               die "error processing environment"
        # Colon separated SANDBOX_* variables need to be cumulative.
        for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
                eval PORTAGE_${x}=\${!x}
index 70cae70975c2a4c1188ebbc07eea7caf9423beb0..62824b2bc11e252d332d01fbb70de203d3144f21 100755 (executable)
@@ -423,7 +423,7 @@ save_ebuild_env() {
                        EBUILD_EXIT_STATUS_FILE EBUILD_MASTER_PID \
                        ECLASSDIR ECLASS_DEPTH ENDCOL FAKEROOTKEY FEATURES \
                        GOOD HILITE HOME IMAGE \
-                       KV LAST_E_CMD LAST_E_LEN LD_PRELOAD MOPREFIX \
+                       KV LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
                        NORMAL PATH PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
                        PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC \
                        PORTAGE_BINPKG_TMPFILE PORTAGE_BUILDDIR \
index 8970f476bb1c2e55747922ec3453b161c8b18105..94ab5778092990f10f462907565002feef3e4e7e 100644 (file)
@@ -4302,6 +4302,42 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
                        if logfile and not os.access(os.path.dirname(logfile), os.W_OK):
                                logfile = None
                if have_build_dirs:
+                       env_file = os.path.join(mysettings["T"], "environment")
+                       env_stat = None
+                       saved_env = None
+                       try:
+                               env_stat = os.stat(env_file)
+                       except OSError, e:
+                               if e.errno != errno.ENOENT:
+                                       raise
+                               del e
+                       if not env_stat:
+                               saved_env = os.path.join(
+                                       os.path.dirname(myebuild), "environment.bz2")
+                               if not os.path.isfile(saved_env):
+                                       saved_env = None
+                       if saved_env:
+                               retval = os.system(
+                                       "bzip2 -dc '%s' > '%s'" % (saved_env, env_file))
+                               try:
+                                       env_stat = os.stat(env_file)
+                               except OSError, e:
+                                       if e.errno != errno.ENOENT:
+                                               raise
+                                       del e
+                               if os.WIFEXITED(retval) and \
+                                       os.WEXITSTATUS(retval) == os.EX_OK and \
+                                       env_stat and env_stat.st_size > 0:
+                                       pass
+                               else:
+                                       writemsg("!!! Error extracting saved environment: '%s'" % \
+                                               saved_env, noiselevel=-1)
+                                       try:
+                                               os.unlink(env_file)
+                                       except OSError, e:
+                                               if e.errno != errno.ENOENT:
+                                                       raise
+                                               del e
                        _doebuild_exit_status_unlink(
                                mysettings.get("EBUILD_EXIT_STATUS_FILE"))
                else: