summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-11-25 06:26:29 +0000
committerZac Medico <zmedico@gentoo.org>2007-11-25 06:26:29 +0000
commitb13416933b67988130b92f0a554e639cbf03e493 (patch)
tree2afead2349baa833f3c7f6b5463a168939cb06c6
parent8415bbc1e05e67f03ae9fa8155a2a7a0142ad136 (diff)
downloadportage-b13416933b67988130b92f0a554e639cbf03e493.tar.gz
portage-b13416933b67988130b92f0a554e639cbf03e493.tar.bz2
portage-b13416933b67988130b92f0a554e639cbf03e493.zip
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. svn path=/main/trunk/; revision=8649
-rwxr-xr-xbin/ebuild.sh3
-rw-r--r--pym/portage/__init__.py29
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/__init__.py b/pym/portage/__init__.py
index e3f2dd2c6..c496b32cf 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -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)