Implement loading of environment.bz2 for the pkg_info() phase.
authorZac Medico <zmedico@gentoo.org>
Sun, 25 Nov 2007 06:26:29 +0000 (06:26 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 25 Nov 2007 06:26:29 +0000 (06:26 -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.

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

bin/ebuild.sh
pym/portage/__init__.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 e3f2dd2c62cced78a7036e7b1816972656d0f145..c496b32cfd1de1bd5d73e9ad513acffe721ea497 100644 (file)
@@ -3594,6 +3594,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
@@ -3603,6 +3607,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())
@@ -4048,12 +4056,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)
 
@@ -4145,13 +4165,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)
@@ -4411,6 +4433,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)