From 01a6bb2dc23ad83b074b495ef96d9e3c5bb4b35c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 25 Nov 2007 06:33:40 +0000 Subject: [PATCH] Implement loading of environment.bz2 for the pkg_info() phase. 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 | 3 ++- pym/portage.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bin/ebuild.sh b/bin/ebuild.sh index bd01b4750..c28312ec6 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -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 diff --git a/pym/portage.py b/pym/portage.py index 3d5515148..f82074f74 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -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) -- 2.26.2