Implement loading of environment.bz2 for the pkg_info() phase.
authorZac Medico <zmedico@gentoo.org>
Sun, 25 Nov 2007 06:33:40 +0000 (06:33 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 25 Nov 2007 06:33:40 +0000 (06:33 -0000)
Since a temporary directory is required for processing of
${T}/environment, and we want a user who's not in the portage
group to be able to run the pkg_info() phase, PORTAGE_TMPDIR
is temporarily overridden with a directory created by mkdtemp.
To make this work, doebuild() creates the tempdir and cleans
it up in a finally block. (trunk r8649)

svn path=/main/branches/2.1.2/; revision=8650

bin/ebuild.sh
pym/portage.py

index bd01b47500b2bdacef6aa30078eed714610dce1f..c28312ec6f35768fe96e3055a284aedba0cae48f 100755 (executable)
@@ -1601,7 +1601,8 @@ if hasq "depend" "${EBUILD_SH_ARGS}"; then
        unset BIN_PATH BIN BODY FUNC_SRC
 fi
 
-if hasq ${EBUILD_PHASE} setup prerm && [ ! -f "${T}/environment" ]; then
+if hasq ${EBUILD_PHASE} info prerm setup \
+       && [ ! -f "${T}/environment" ] ; then
        bzip2 -dc "${EBUILD%/*}"/environment.bz2 > \
                "${T}/environment" 2> /dev/null
        if [ -s "${T}/environment" ] ; then
index 3d55151480b88eed6dad01123a5668eda80773d6..f82074f74c413033d080e546e3223a89f610f149 100644 (file)
@@ -3544,6 +3544,10 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m
                raise portage_exception.IncorrectParameter(
                        "Invalid ebuild path: '%s'" % myebuild)
 
+       # Make a backup of PORTAGE_TMPDIR prior to calling config.reset()
+       # so that the caller can override it.
+       tmpdir = mysettings["PORTAGE_TMPDIR"]
+
        if mydo != "depend":
                """For performance reasons, setcpv only triggers reset when it
                detects a package-specific change in config.  For the ebuild
@@ -3552,6 +3556,10 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m
                mysettings.reset(use_cache=use_cache)
                mysettings.setcpv(mycpv, use_cache=use_cache, mydb=mydbapi)
 
+       # config.reset() might have reverted a change made by the caller,
+       # so restore it to it's original value.
+       mysettings["PORTAGE_TMPDIR"] = tmpdir
+
        mysettings["EBUILD_PHASE"] = mydo
 
        mysettings["PORTAGE_MASTER_PID"] = str(os.getpid())
@@ -3997,12 +4005,24 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
 
        logfile=None
        builddir_lock = None
+       tmpdir = None
+       tmpdir_orig = None
        try:
                if mydo in ("digest", "manifest", "help"):
                        # Temporarily exempt the depend phase from manifest checks, in case
                        # aux_get calls trigger cache generation.
                        _doebuild_manifest_exempt_depend += 1
 
+               # If we don't need much space and we don't need a constant location,
+               # we can temporarily override PORTAGE_TMPDIR with a random temp dir
+               # so that there's no need for locking and it can be used even if the
+               # user isn't in the portage group.
+               if mydo in ("info",):
+                       from tempfile import mkdtemp
+                       tmpdir = mkdtemp()
+                       tmpdir_orig = mysettings["PORTAGE_TMPDIR"]
+                       mysettings["PORTAGE_TMPDIR"] = tmpdir
+
                doebuild_environment(myebuild, mydo, myroot, mysettings, debug,
                        use_cache, mydbapi)
 
@@ -4094,13 +4114,15 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
 
                # Build directory creation isn't required for any of these.
                have_build_dirs = False
-               if mydo not in ("digest", "fetch", "help", "info", "manifest"):
+               if mydo not in ("digest", "fetch", "help", "manifest"):
                        mystatus = prepare_build_dirs(myroot, mysettings, cleanup)
                        if mystatus:
                                return mystatus
                        have_build_dirs = True
                        # PORTAGE_LOG_FILE is set above by the prepare_build_dirs() call.
-                       logfile = mysettings.get("PORTAGE_LOG_FILE", None)
+                       logfile = mysettings.get("PORTAGE_LOG_FILE")
+                       if logfile and not os.access(os.path.dirname(logfile), os.W_OK):
+                               logfile = None
                if mydo == "unmerge":
                        return unmerge(mysettings["CATEGORY"],
                                mysettings["PF"], myroot, mysettings, vartree=vartree)
@@ -4363,6 +4385,9 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
                return retval
 
        finally:
+               if tmpdir:
+                       mysettings["PORTAGE_TMPDIR"] = tmpdir_orig
+                       shutil.rmtree(tmpdir)
                if builddir_lock:
                        portage_locks.unlockdir(builddir_lock)