resolve all merge conflicts
authorFabian Groffen <grobian@gentoo.org>
Sat, 27 Feb 2010 18:53:28 +0000 (18:53 -0000)
committerFabian Groffen <grobian@gentoo.org>
Sat, 27 Feb 2010 18:53:28 +0000 (18:53 -0000)
svn path=/main/branches/prefix/; revision=15479

pym/portage/__init__.py
pym/portage/package/ebuild/doebuild.py
pym/portage/package/ebuild/prepare_build_dirs.py

index 207db0bac0eb59fedf8afa5191fafe6c7574ce70..bab3e4ae07a49230687f282f5d846237d5c2561b 100644 (file)
@@ -1017,188 +1017,6 @@ def ExtractKernelVersion(base_dir):
 
        return (version,None)
 
-<<<<<<< .working
-
-
-
-def _can_test_pty_eof():
-       """
-       The _test_pty_eof() function seems to hang on most
-       kernels other than Linux.
-       This was reported for the following kernels which used to work fine
-       without this EOF test: Darwin, AIX, FreeBSD.  They seem to hang on
-       the slave_file.close() call.  Note that Python's implementation of
-       openpty on Solaris already caused random hangs without this EOF test
-       and hence is globally disabled.
-       @rtype: bool
-       @returns: True if _test_pty_eof() won't hang, False otherwise.
-       """
-       return platform.system() in ("Linux",)
-
-def _test_pty_eof():
-       """
-       Returns True if this issues is fixed for the currently
-       running version of python: http://bugs.python.org/issue5380
-       Raises an EnvironmentError from openpty() if it fails.
-       """
-
-       use_fork = False
-
-       import array, fcntl, pty, select, termios
-       test_string = 2 * "blah blah blah\n"
-       test_string = _unicode_decode(test_string,
-               encoding='utf_8', errors='strict')
-
-       # may raise EnvironmentError
-       master_fd, slave_fd = pty.openpty()
-
-       # Non-blocking mode is required for Darwin kernel.
-       fcntl.fcntl(master_fd, fcntl.F_SETFL,
-               fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
-
-       # Disable post-processing of output since otherwise weird
-       # things like \n -> \r\n transformations may occur.
-       mode = termios.tcgetattr(slave_fd)
-       mode[1] &= ~termios.OPOST
-       termios.tcsetattr(slave_fd, termios.TCSANOW, mode)
-
-       # Simulate a subprocess writing some data to the
-       # slave end of the pipe, and then exiting.
-       pid = None
-       if use_fork:
-               pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string,
-                       encoding='utf_8', errors='strict'), env=os.environ,
-                       fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd},
-                       returnpid=True)
-               if isinstance(pids, int):
-                       os.close(master_fd)
-                       os.close(slave_fd)
-                       raise EnvironmentError('spawn failed')
-               pid = pids[0]
-       else:
-               os.write(slave_fd, _unicode_encode(test_string,
-                       encoding='utf_8', errors='strict'))
-       os.close(slave_fd)
-
-       # If using a fork, we must wait for the child here,
-       # in order to avoid a race condition that would
-       # lead to inconsistent results.
-       if pid is not None:
-               os.waitpid(pid, 0)
-
-       master_file = os.fdopen(master_fd, 'rb')
-       eof = False
-       data = []
-       iwtd = [master_file]
-       owtd = []
-       ewtd = []
-
-       while not eof:
-
-               events = select.select(iwtd, owtd, ewtd)
-               if not events[0]:
-                       eof = True
-                       break
-
-               buf = array.array('B')
-               try:
-                       buf.fromfile(master_file, 1024)
-               except EOFError:
-                       eof = True
-               except IOError:
-                       # This is where data loss occurs.
-                       eof = True
-
-               if not buf:
-                       eof = True
-               else:
-                       data.append(_unicode_decode(buf.tostring(),
-                               encoding='utf_8', errors='strict'))
-
-       master_file.close()
-
-       return test_string == ''.join(data)
-
-# If _test_pty_eof() can't be used for runtime detection of
-# http://bugs.python.org/issue5380, openpty can't safely be used
-# unless we can guarantee that the current version of python has
-# been fixed (affects all current versions of python3). When
-# this issue is fixed in python3, we can add another sys.hexversion
-# conditional to enable openpty support in the fixed versions.
-if sys.hexversion >= 0x3000000 and not _can_test_pty_eof():
-       _disable_openpty = True
-else:
-       # Disable the use of openpty on Solaris as it seems Python's openpty
-       # implementation doesn't play nice on Solaris with Portage's
-       # behaviour causing hangs/deadlocks.
-       # Additional note for the future: on Interix, pipes do NOT work, so
-       # _disable_openpty on Interix must *never* be True
-       _disable_openpty = platform.system() in ("SunOS",)
-_tested_pty = False
-
-if not _can_test_pty_eof():
-       # Skip _test_pty_eof() on systems where it hangs.
-       _tested_pty = True
-
-def _create_pty_or_pipe(copy_term_size=None):
-       """
-       Try to create a pty and if then fails then create a normal
-       pipe instead.
-
-       @param copy_term_size: If a tty file descriptor is given
-               then the term size will be copied to the pty.
-       @type copy_term_size: int
-       @rtype: tuple
-       @returns: A tuple of (is_pty, master_fd, slave_fd) where
-               is_pty is True if a pty was successfully allocated, and
-               False if a normal pipe was allocated.
-       """
-
-       got_pty = False
-
-       global _disable_openpty, _tested_pty
-       if not (_tested_pty or _disable_openpty):
-               try:
-                       if not _test_pty_eof():
-                               _disable_openpty = True
-               except EnvironmentError as e:
-                       _disable_openpty = True
-                       writemsg("openpty failed: '%s'\n" % str(e),
-                               noiselevel=-1)
-                       del e
-               _tested_pty = True
-
-       if _disable_openpty:
-               master_fd, slave_fd = os.pipe()
-       else:
-               from pty import openpty
-               try:
-                       master_fd, slave_fd = openpty()
-                       got_pty = True
-               except EnvironmentError as e:
-                       _disable_openpty = True
-                       writemsg("openpty failed: '%s'\n" % str(e),
-                               noiselevel=-1)
-                       del e
-                       master_fd, slave_fd = os.pipe()
-
-       if got_pty:
-               # Disable post-processing of output since otherwise weird
-               # things like \n -> \r\n transformations may occur.
-               import termios
-               mode = termios.tcgetattr(slave_fd)
-               mode[1] &= ~termios.OPOST
-               termios.tcsetattr(slave_fd, termios.TCSANOW, mode)
-
-       if got_pty and \
-               copy_term_size is not None and \
-               os.isatty(copy_term_size):
-               from portage.output import get_term_size, set_term_size
-               rows, columns = get_term_size()
-               set_term_size(rows, columns, slave_fd)
-
-       return (got_pty, master_fd, slave_fd)
-
 # XXX This would be to replace getstatusoutput completely.
 # XXX Issue: cannot block execution. Deadlock condition.
 def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, fakeroot=0, **keywords):
@@ -1810,1335 +1628,6 @@ def _split_ebuild_name_glep55(name):
                return (None, None)
        return (m.group(1), m.group(3))
 
-<<<<<<< .working
-def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, mydbapi):
-
-       ebuild_path = os.path.abspath(myebuild)
-       pkg_dir     = os.path.dirname(ebuild_path)
-
-       if "CATEGORY" in mysettings.configdict["pkg"]:
-               cat = mysettings.configdict["pkg"]["CATEGORY"]
-       else:
-               cat = os.path.basename(normalize_path(os.path.join(pkg_dir, "..")))
-
-       eapi = None
-       if 'parse-eapi-glep-55' in mysettings.features:
-               mypv, eapi = portage._split_ebuild_name_glep55(
-                       os.path.basename(myebuild))
-       else:
-               mypv = os.path.basename(ebuild_path)[:-7]
-
-       mycpv = cat+"/"+mypv
-       mysplit = versions._pkgsplit(mypv)
-       if mysplit is None:
-               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':
-               if mycpv != mysettings.mycpv:
-                       # Don't pass in mydbapi here since the resulting aux_get
-                       # call would lead to infinite 'depend' phase recursion.
-                       mysettings.setcpv(mycpv)
-       else:
-               # If IUSE isn't in configdict['pkg'], it means that setcpv()
-               # hasn't been called with the mydb argument, so we have to
-               # call it here (portage code always calls setcpv properly,
-               # but api consumers might not).
-               if mycpv != mysettings.mycpv or \
-                       'IUSE' not in mysettings.configdict['pkg']:
-                       # Reload env.d variables and reset any previous settings.
-                       mysettings.reload()
-                       mysettings.reset()
-                       mysettings.setcpv(mycpv, 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.pop("EBUILD_PHASE", None) # remove from backupenv
-       mysettings["EBUILD_PHASE"] = mydo
-
-       mysettings["PORTAGE_MASTER_PID"] = str(os.getpid())
-
-       # We are disabling user-specific bashrc files.
-       mysettings["BASH_ENV"] = INVALID_ENV_FILE
-
-       if debug: # Otherwise it overrides emerge's settings.
-               # We have no other way to set debug... debug can't be passed in
-               # due to how it's coded... Don't overwrite this so we can use it.
-               mysettings["PORTAGE_DEBUG"] = "1"
-
-       mysettings["EPREFIX"]  = EPREFIX.rstrip(os.path.sep)
-       mysettings["EBUILD"]   = ebuild_path
-       mysettings["O"]        = pkg_dir
-       mysettings.configdict["pkg"]["CATEGORY"] = cat
-       mysettings["FILESDIR"] = os.path.join(pkg_dir, "files")
-       mysettings["PF"]       = mypv
-
-       if hasattr(mydbapi, '_repo_info'):
-               mytree = os.path.dirname(os.path.dirname(pkg_dir))
-               repo_info = mydbapi._repo_info[mytree]
-               mysettings['PORTDIR'] = repo_info.portdir
-               mysettings['PORTDIR_OVERLAY'] = repo_info.portdir_overlay
-
-       mysettings["PORTDIR"] = os.path.realpath(mysettings["PORTDIR"])
-       mysettings["DISTDIR"] = os.path.realpath(mysettings["DISTDIR"])
-       mysettings["RPMDIR"]  = os.path.realpath(mysettings["RPMDIR"])
-
-       mysettings["ECLASSDIR"]   = mysettings["PORTDIR"]+"/eclass"
-       mysettings["SANDBOX_LOG"] = mycpv.replace("/", "_-_")
-
-       mysettings["PROFILE_PATHS"] = "\n".join(mysettings.profiles)
-       mysettings["P"]  = mysplit[0]+"-"+mysplit[1]
-       mysettings["PN"] = mysplit[0]
-       mysettings["PV"] = mysplit[1]
-       mysettings["PR"] = mysplit[2]
-
-       if portage.util.noiselimit < 0:
-               mysettings["PORTAGE_QUIET"] = "1"
-
-       if mydo == 'depend' and \
-               'EAPI' not in mysettings.configdict['pkg']:
-
-               if eapi is not None:
-                       # From parse-eapi-glep-55 above.
-                       pass
-               elif 'parse-eapi-ebuild-head' in mysettings.features:
-                       eapi = _parse_eapi_ebuild_head(
-                               codecs.open(_unicode_encode(ebuild_path,
-                               encoding=_encodings['fs'], errors='strict'),
-                               mode='r', encoding=_encodings['content'], errors='replace'))
-
-               if eapi is not None:
-                       if not eapi_is_supported(eapi):
-                               raise portage.exception.UnsupportedAPIException(mycpv, eapi)
-                       mysettings.configdict['pkg']['EAPI'] = eapi
-
-       if mydo != "depend":
-               # Metadata vars such as EAPI and RESTRICT are
-               # set by the above config.setcpv() call.
-               eapi = mysettings["EAPI"]
-               if not eapi_is_supported(eapi):
-                       # can't do anything with this.
-                       raise portage.exception.UnsupportedAPIException(mycpv, eapi)
-
-       if mysplit[2] == "r0":
-               mysettings["PVR"]=mysplit[1]
-       else:
-               mysettings["PVR"]=mysplit[1]+"-"+mysplit[2]
-
-       if "PATH" in mysettings:
-               mysplit=mysettings["PATH"].split(":")
-       else:
-               mysplit=[]
-       # Note: PORTAGE_BIN_PATH may differ from the global constant
-       # when portage is reinstalling itself.
-       portage_bin_path = mysettings["PORTAGE_BIN_PATH"]
-       if portage_bin_path not in mysplit:
-               mysettings["PATH"] = portage_bin_path + ":" + mysettings["PATH"]
-
-       # Sandbox needs cannonical paths.
-       mysettings["PORTAGE_TMPDIR"] = os.path.realpath(
-               mysettings["PORTAGE_TMPDIR"])
-       mysettings["BUILD_PREFIX"] = os.path.join(mysettings["PORTAGE_TMPDIR"], "portage")
-       mysettings["PKG_TMPDIR"]   = os.path.join(mysettings["PORTAGE_TMPDIR"], "binpkgs")
-       
-       # Package {pre,post}inst and {pre,post}rm may overlap, so they must have separate
-       # locations in order to prevent interference.
-       if mydo in ("unmerge", "prerm", "postrm", "cleanrm"):
-               mysettings["PORTAGE_BUILDDIR"] = os.path.join(
-                       mysettings["PKG_TMPDIR"],
-                       mysettings["CATEGORY"], mysettings["PF"])
-       else:
-               mysettings["PORTAGE_BUILDDIR"] = os.path.join(
-                       mysettings["BUILD_PREFIX"],
-                       mysettings["CATEGORY"], mysettings["PF"])
-
-       mysettings["HOME"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "homedir")
-       mysettings["WORKDIR"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "work")
-       mysettings["D"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image") + os.sep
-       mysettings["ED"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image" + mysettings["EPREFIX"]) + os.sep
-       mysettings["T"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "temp")
-
-       mysettings["PORTAGE_BASHRC"] = os.path.join(
-               mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_FILE)
-       mysettings["EBUILD_EXIT_STATUS_FILE"] = os.path.join(
-               mysettings["PORTAGE_BUILDDIR"], ".exit_status")
-
-       #set up KV variable -- DEP SPEEDUP :: Don't waste time. Keep var persistent.
-       if eapi not in ('0', '1', '2', '3', '3_pre2'):
-               # Discard KV for EAPIs that don't support it. Cache KV is restored
-               # from the backupenv whenever config.reset() is called.
-               mysettings.pop('KV', None)
-       elif mydo != 'depend' and 'KV' not in mysettings and \
-               mydo in ('compile', 'config', 'configure', 'info',
-               'install', 'nofetch', 'postinst', 'postrm', 'preinst',
-               'prepare', 'prerm', 'setup', 'test', 'unpack'):
-               mykv,err1=ExtractKernelVersion(os.path.join(myroot, EPREFIX_LSTRIP, "usr/src/linux"))
-               if mykv:
-                       # Regular source tree
-                       mysettings["KV"]=mykv
-               else:
-                       mysettings["KV"]=""
-               mysettings.backup_changes("KV")
-
-       # Allow color.map to control colors associated with einfo, ewarn, etc...
-       mycolors = []
-       for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET"):
-               mycolors.append("%s=$'%s'" % \
-                       (c, portage.output.style_to_ansi_code(c)))
-       mysettings["PORTAGE_COLORMAP"] = "\n".join(mycolors)
-
-def prepare_build_dirs(myroot, mysettings, cleanup):
-
-       clean_dirs = [mysettings["HOME"]]
-
-       # We enable cleanup when we want to make sure old cruft (such as the old
-       # environment) doesn't interfere with the current phase.
-       if cleanup:
-               clean_dirs.append(mysettings["T"])
-
-       for clean_dir in clean_dirs:
-               try:
-                       shutil.rmtree(clean_dir)
-               except OSError as oe:
-                       if errno.ENOENT == oe.errno:
-                               pass
-                       elif errno.EPERM == oe.errno:
-                               writemsg("%s\n" % oe, noiselevel=-1)
-                               writemsg(_("Operation Not Permitted: rmtree('%s')\n") % \
-                                       clean_dir, noiselevel=-1)
-                               return 1
-                       else:
-                               raise
-
-       def makedirs(dir_path):
-               try:
-                       os.makedirs(dir_path)
-               except OSError as oe:
-                       if errno.EEXIST == oe.errno:
-                               pass
-                       elif errno.EPERM == oe.errno:
-                               writemsg("%s\n" % oe, noiselevel=-1)
-                               writemsg(_("Operation Not Permitted: makedirs('%s')\n") % \
-                                       dir_path, noiselevel=-1)
-                               return False
-                       else:
-                               raise
-               return True
-
-       mysettings["PKG_LOGDIR"] = os.path.join(mysettings["T"], "logging")
-
-       mydirs = [os.path.dirname(mysettings["PORTAGE_BUILDDIR"])]
-       mydirs.append(os.path.dirname(mydirs[-1]))
-
-       try:
-               for mydir in mydirs:
-                       portage.util.ensure_dirs(mydir)
-                       portage.util.apply_secpass_permissions(mydir,
-                               gid=portage_gid, uid=portage_uid, mode=0o70, mask=0)
-               for dir_key in ("PORTAGE_BUILDDIR", "HOME", "PKG_LOGDIR", "T"):
-                       """These directories don't necessarily need to be group writable.
-                       However, the setup phase is commonly run as a privileged user prior
-                       to the other phases being run by an unprivileged user.  Currently,
-                       we use the portage group to ensure that the unprivleged user still
-                       has write access to these directories in any case."""
-                       portage.util.ensure_dirs(mysettings[dir_key], mode=0o775)
-                       portage.util.apply_secpass_permissions(mysettings[dir_key],
-                               uid=portage_uid, gid=portage_gid)
-       except portage.exception.PermissionDenied as e:
-               writemsg(_("Permission Denied: %s\n") % str(e), noiselevel=-1)
-               return 1
-       except portage.exception.OperationNotPermitted as e:
-               writemsg(_("Operation Not Permitted: %s\n") % str(e), noiselevel=-1)
-               return 1
-       except portage.exception.FileNotFound as e:
-               writemsg(_("File Not Found: '%s'\n") % str(e), noiselevel=-1)
-               return 1
-
-       # Reset state for things like noauto and keepwork in FEATURES.
-       for x in ('.die_hooks',):
-               try:
-                       os.unlink(os.path.join(mysettings['PORTAGE_BUILDDIR'], x))
-               except OSError:
-                       pass
-
-       _prepare_workdir(mysettings)
-       if mysettings.get('EBUILD_PHASE') != 'fetch':
-               # Avoid spurious permissions adjustments when fetching with
-               # a temporary PORTAGE_TMPDIR setting (for fetchonly).
-               _prepare_features_dirs(mysettings)
-
-def _adjust_perms_msg(settings, msg):
-
-       def write(msg):
-               writemsg(msg, noiselevel=-1)
-
-       background = settings.get("PORTAGE_BACKGROUND") == "1"
-       log_path = settings.get("PORTAGE_LOG_FILE")
-       log_file = None
-
-       if background and log_path is not None:
-               try:
-                       log_file = codecs.open(_unicode_encode(log_path,
-                               encoding=_encodings['fs'], errors='strict'),
-                               mode='a', encoding=_encodings['content'], errors='replace')
-               except IOError:
-                       def write(msg):
-                               pass
-               else:
-                       def write(msg):
-                               log_file.write(_unicode_decode(msg))
-                               log_file.flush()
-
-       try:
-               write(msg)
-       finally:
-               if log_file is not None:
-                       log_file.close()
-
-def _prepare_features_dirs(mysettings):
-
-       features_dirs = {
-               "ccache":{
-                       "path_dir": EPREFIX+"/usr/lib/ccache/bin",
-                       "basedir_var":"CCACHE_DIR",
-                       "default_dir":os.path.join(mysettings["PORTAGE_TMPDIR"], "ccache"),
-                       "always_recurse":False},
-               "distcc":{
-                       "path_dir": EPREFIX+"/usr/lib/distcc/bin",
-                       "basedir_var":"DISTCC_DIR",
-                       "default_dir":os.path.join(mysettings["BUILD_PREFIX"], ".distcc"),
-                       "subdirs":("lock", "state"),
-                       "always_recurse":True}
-       }
-       dirmode  = 0o2070
-       filemode =   0o60
-       modemask =    0o2
-       restrict = mysettings.get("PORTAGE_RESTRICT","").split()
-       from portage.data import secpass
-       droppriv = secpass >= 2 and \
-               "userpriv" in mysettings.features and \
-               "userpriv" not in restrict
-       for myfeature, kwargs in features_dirs.items():
-               if myfeature in mysettings.features:
-                       failure = False
-                       basedir = mysettings.get(kwargs["basedir_var"])
-                       if basedir is None or not basedir.strip():
-                               basedir = kwargs["default_dir"]
-                               mysettings[kwargs["basedir_var"]] = basedir
-                       try:
-                               path_dir = kwargs["path_dir"]
-                               if not os.path.isdir(path_dir):
-                                       raise portage.exception.DirectoryNotFound(path_dir)
-
-                               mydirs = [mysettings[kwargs["basedir_var"]]]
-                               if "subdirs" in kwargs:
-                                       for subdir in kwargs["subdirs"]:
-                                               mydirs.append(os.path.join(basedir, subdir))
-                               for mydir in mydirs:
-                                       modified = portage.util.ensure_dirs(mydir)
-                                       # Generally, we only want to apply permissions for
-                                       # initial creation.  Otherwise, we don't know exactly what
-                                       # permissions the user wants, so should leave them as-is.
-                                       droppriv_fix = False
-                                       if droppriv:
-                                               st = os.stat(mydir)
-                                               if st.st_gid != portage_gid or \
-                                                       not dirmode == (stat.S_IMODE(st.st_mode) & dirmode):
-                                                       droppriv_fix = True
-                                               if not droppriv_fix:
-                                                       # Check permissions of files in the directory.
-                                                       for filename in os.listdir(mydir):
-                                                               try:
-                                                                       subdir_st = os.lstat(
-                                                                               os.path.join(mydir, filename))
-                                                               except OSError:
-                                                                       continue
-                                                               if subdir_st.st_gid != portage_gid or \
-                                                                       ((stat.S_ISDIR(subdir_st.st_mode) and \
-                                                                       not dirmode == (stat.S_IMODE(subdir_st.st_mode) & dirmode))):
-                                                                       droppriv_fix = True
-                                                                       break
-
-                                       if droppriv_fix:
-                                               _adjust_perms_msg(mysettings,
-                                                       colorize("WARN", " * ") + \
-                                                       _("Adjusting permissions "
-                                                       "for FEATURES=userpriv: '%s'\n") % mydir)
-                                       elif modified:
-                                               _adjust_perms_msg(mysettings,
-                                                       colorize("WARN", " * ") + \
-                                                       _("Adjusting permissions "
-                                                       "for FEATURES=%s: '%s'\n") % (myfeature, mydir))
-
-                                       if modified or kwargs["always_recurse"] or droppriv_fix:
-                                               def onerror(e):
-                                                       raise   # The feature is disabled if a single error
-                                                                       # occurs during permissions adjustment.
-                                               if not apply_recursive_permissions(mydir,
-                                               gid=portage_gid, dirmode=dirmode, dirmask=modemask,
-                                               filemode=filemode, filemask=modemask, onerror=onerror):
-                                                       raise portage.exception.OperationNotPermitted(
-                                                               _("Failed to apply recursive permissions for the portage group."))
-
-                       except portage.exception.DirectoryNotFound as e:
-                               failure = True
-                               writemsg(_("\n!!! Directory does not exist: '%s'\n") % \
-                                       (e,), noiselevel=-1)
-                               writemsg(_("!!! Disabled FEATURES='%s'\n") % myfeature,
-                                       noiselevel=-1)
-
-                       except portage.exception.PortageException as e:
-                               failure = True
-                               writemsg("\n!!! %s\n" % str(e), noiselevel=-1)
-                               writemsg(_("!!! Failed resetting perms on %s='%s'\n") % \
-                                       (kwargs["basedir_var"], basedir), noiselevel=-1)
-                               writemsg(_("!!! Disabled FEATURES='%s'\n") % myfeature,
-                                       noiselevel=-1)
-
-                       if failure:
-                               mysettings.features.remove(myfeature)
-                               mysettings['FEATURES'] = ' '.join(sorted(mysettings.features))
-                               time.sleep(5)
-
-def _prepare_workdir(mysettings):
-       workdir_mode = 0o700
-       try:
-               mode = mysettings["PORTAGE_WORKDIR_MODE"]
-               if mode.isdigit():
-                       parsed_mode = int(mode, 8)
-               elif mode == "":
-                       raise KeyError()
-               else:
-                       raise ValueError()
-               if parsed_mode & 0o7777 != parsed_mode:
-                       raise ValueError("Invalid file mode: %s" % mode)
-               else:
-                       workdir_mode = parsed_mode
-       except KeyError as e:
-               writemsg(_("!!! PORTAGE_WORKDIR_MODE is unset, using %s.\n") % oct(workdir_mode))
-       except ValueError as e:
-               if len(str(e)) > 0:
-                       writemsg("%s\n" % e)
-               writemsg(_("!!! Unable to parse PORTAGE_WORKDIR_MODE='%s', using %s.\n") % \
-               (mysettings["PORTAGE_WORKDIR_MODE"], oct(workdir_mode)))
-       mysettings["PORTAGE_WORKDIR_MODE"] = oct(workdir_mode).replace('o', '')
-       try:
-               apply_secpass_permissions(mysettings["WORKDIR"],
-               uid=portage_uid, gid=portage_gid, mode=workdir_mode)
-       except portage.exception.FileNotFound:
-               pass # ebuild.sh will create it
-
-       if mysettings.get("PORT_LOGDIR", "") == "":
-               while "PORT_LOGDIR" in mysettings:
-                       del mysettings["PORT_LOGDIR"]
-       if "PORT_LOGDIR" in mysettings:
-               try:
-                       modified = portage.util.ensure_dirs(mysettings["PORT_LOGDIR"])
-                       if modified:
-                               apply_secpass_permissions(mysettings["PORT_LOGDIR"],
-                                       uid=portage_uid, gid=portage_gid, mode=0o2770)
-               except portage.exception.PortageException as e:
-                       writemsg("!!! %s\n" % str(e), noiselevel=-1)
-                       writemsg(_("!!! Permission issues with PORT_LOGDIR='%s'\n") % \
-                               mysettings["PORT_LOGDIR"], noiselevel=-1)
-                       writemsg(_("!!! Disabling logging.\n"), noiselevel=-1)
-                       while "PORT_LOGDIR" in mysettings:
-                               del mysettings["PORT_LOGDIR"]
-       if "PORT_LOGDIR" in mysettings and \
-               os.access(mysettings["PORT_LOGDIR"], os.W_OK):
-               logid_path = os.path.join(mysettings["PORTAGE_BUILDDIR"], ".logid")
-               if not os.path.exists(logid_path):
-                       open(_unicode_encode(logid_path), 'w')
-               logid_time = _unicode_decode(time.strftime("%Y%m%d-%H%M%S",
-                       time.gmtime(os.stat(logid_path).st_mtime)),
-                       encoding=_encodings['content'], errors='replace')
-
-               if "split-log" in mysettings.features:
-                       mysettings["PORTAGE_LOG_FILE"] = os.path.join(
-                               mysettings["PORT_LOGDIR"], "build", "%s/%s:%s.log" % \
-                               (mysettings["CATEGORY"], mysettings["PF"], logid_time))
-               else:
-                       mysettings["PORTAGE_LOG_FILE"] = os.path.join(
-                               mysettings["PORT_LOGDIR"], "%s:%s:%s.log" % \
-                               (mysettings["CATEGORY"], mysettings["PF"], logid_time))
-
-               util.ensure_dirs(os.path.dirname(mysettings["PORTAGE_LOG_FILE"]))
-
-       else:
-               # NOTE: When sesandbox is enabled, the local SELinux security policies
-               # may not allow output to be piped out of the sesandbox domain. The
-               # current policy will allow it to work when a pty is available, but
-               # not through a normal pipe. See bug #162404.
-               mysettings["PORTAGE_LOG_FILE"] = os.path.join(
-                       mysettings["T"], "build.log")
-
-def _doebuild_exit_status_check(mydo, settings):
-       """
-       Returns an error string if the shell appeared
-       to exit unsuccessfully, None otherwise.
-       """
-       exit_status_file = settings.get("EBUILD_EXIT_STATUS_FILE")
-       if not exit_status_file or \
-               os.path.exists(exit_status_file):
-               return None
-       msg = _("The ebuild phase '%s' has exited "
-       "unexpectedly. This type of behavior "
-       "is known to be triggered "
-       "by things such as failed variable "
-       "assignments (bug #190128) or bad substitution "
-       "errors (bug #200313). Normally, before exiting, bash should "
-       "have displayed an error message above. If bash did not "
-       "produce an error message above, it's possible "
-       "that the ebuild has called `exit` when it "
-       "should have called `die` instead. This behavior may also "
-       "be triggered by a corrupt bash binary or a hardware "
-       "problem such as memory or cpu malfunction. If the problem is not "
-       "reproducible or it appears to occur randomly, then it is likely "
-       "to be triggered by a hardware problem. "
-       "If you suspect a hardware problem then you should "
-       "try some basic hardware diagnostics such as memtest. "
-       "Please do not report this as a bug unless it is consistently "
-       "reproducible and you are sure that your bash binary and hardware "
-       "are functioning properly.") % mydo
-       return msg
-
-def _doebuild_exit_status_check_and_log(settings, mydo, retval):
-       msg = _doebuild_exit_status_check(mydo, settings)
-       if msg:
-               if retval == os.EX_OK:
-                       retval = 1
-               from textwrap import wrap
-               from portage.elog.messages import eerror
-               for l in wrap(msg, 72):
-                       eerror(l, phase=mydo, key=settings.mycpv)
-       return retval
-
-def _doebuild_exit_status_unlink(exit_status_file):
-       """
-       Double check to make sure it really doesn't exist
-       and raise an OSError if it still does (it shouldn't).
-       OSError if necessary.
-       """
-       if not exit_status_file:
-               return
-       try:
-               os.unlink(exit_status_file)
-       except OSError:
-               pass
-       if os.path.exists(exit_status_file):
-               os.unlink(exit_status_file)
-
-_doebuild_manifest_exempt_depend = 0
-_doebuild_manifest_cache = None
-_doebuild_broken_ebuilds = set()
-_doebuild_broken_manifests = set()
-
-def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
-       fetchonly=0, cleanup=0, dbkey=None, use_cache=1, fetchall=0, tree=None,
-       mydbapi=None, vartree=None, prev_mtimes=None,
-       fd_pipes=None, returnpid=False):
-
-       """
-       Wrapper function that invokes specific ebuild phases through the spawning
-       of ebuild.sh
-       
-       @param myebuild: name of the ebuild to invoke the phase on (CPV)
-       @type myebuild: String
-       @param mydo: Phase to run
-       @type mydo: String
-       @param myroot: $ROOT (usually '/', see man make.conf)
-       @type myroot: String
-       @param mysettings: Portage Configuration
-       @type mysettings: instance of portage.config
-       @param debug: Turns on various debug information (eg, debug for spawn)
-       @type debug: Boolean
-       @param listonly: Used to wrap fetch(); passed such that fetch only lists files required.
-       @type listonly: Boolean
-       @param fetchonly: Used to wrap fetch(); passed such that files are only fetched (no other actions)
-       @type fetchonly: Boolean
-       @param cleanup: Passed to prepare_build_dirs (TODO: what does it do?)
-       @type cleanup: Boolean
-       @param dbkey: A dict (usually keys and values from the depend phase, such as KEYWORDS, USE, etc..)
-       @type dbkey: Dict or String
-       @param use_cache: Enables the cache
-       @type use_cache: Boolean
-       @param fetchall: Used to wrap fetch(), fetches all URIs (even ones invalid due to USE conditionals)
-       @type fetchall: Boolean
-       @param tree: Which tree to use ('vartree','porttree','bintree', etc..), defaults to 'porttree'
-       @type tree: String
-       @param mydbapi: a dbapi instance to pass to various functions; this should be a portdbapi instance.
-       @type mydbapi: portdbapi instance
-       @param vartree: A instance of vartree; used for aux_get calls, defaults to db[myroot]['vartree']
-       @type vartree: vartree instance
-       @param prev_mtimes: A dict of { filename:mtime } keys used by merge() to do config_protection
-       @type prev_mtimes: dictionary
-       @param fd_pipes: A dict of mapping for pipes, { '0': stdin, '1': stdout }
-               for example.
-       @type fd_pipes: Dictionary
-       @param returnpid: Return a list of process IDs for a successful spawn, or
-               an integer value if spawn is unsuccessful. NOTE: This requires the
-               caller clean up all returned PIDs.
-       @type returnpid: Boolean
-       @rtype: Boolean
-       @returns:
-       1. 0 for success
-       2. 1 for error
-       
-       Most errors have an accompanying error message.
-       
-       listonly and fetchonly are only really necessary for operations involving 'fetch'
-       prev_mtimes are only necessary for merge operations.
-       Other variables may not be strictly required, many have defaults that are set inside of doebuild.
-       
-       """
-       
-       if not tree:
-               writemsg("Warning: tree not specified to doebuild\n")
-               tree = "porttree"
-       global db
-       
-       # chunked out deps for each phase, so that ebuild binary can use it 
-       # to collapse targets down.
-       actionmap_deps={
-       "setup":  [],
-       "unpack": ["setup"],
-       "prepare": ["unpack"],
-       "configure": ["prepare"],
-       "compile":["configure"],
-       "test":   ["compile"],
-       "install":["test"],
-       "rpm":    ["install"],
-       "package":["install"],
-       }
-       
-       if mydbapi is None:
-               mydbapi = db[myroot][tree].dbapi
-
-       if vartree is None and mydo in ("merge", "qmerge", "unmerge"):
-               vartree = db[myroot]["vartree"]
-
-       features = mysettings.features
-       noauto = "noauto" in features
-       from portage.data import secpass
-
-       clean_phases = ("clean", "cleanrm")
-       validcommands = ["help","clean","prerm","postrm","cleanrm","preinst","postinst",
-                       "config", "info", "setup", "depend", "pretend",
-                       "fetch", "fetchall", "digest",
-                       "unpack", "prepare", "configure", "compile", "test",
-                       "install", "rpm", "qmerge", "merge",
-                       "package","unmerge", "manifest"]
-
-       if mydo not in validcommands:
-               validcommands.sort()
-               writemsg("!!! doebuild: '%s' is not one of the following valid commands:" % mydo,
-                       noiselevel=-1)
-               for vcount in range(len(validcommands)):
-                       if vcount%6 == 0:
-                               writemsg("\n!!! ", noiselevel=-1)
-                       writemsg(validcommands[vcount].ljust(11), noiselevel=-1)
-               writemsg("\n", noiselevel=-1)
-               return 1
-
-       if mydo == "fetchall":
-               fetchall = 1
-               mydo = "fetch"
-
-       parallel_fetchonly = mydo in ("fetch", "fetchall") and \
-               "PORTAGE_PARALLEL_FETCHONLY" in mysettings
-
-       if mydo not in clean_phases and not os.path.exists(myebuild):
-               writemsg("!!! doebuild: %s not found for %s\n" % (myebuild, mydo),
-                       noiselevel=-1)
-               return 1
-
-       global _doebuild_manifest_exempt_depend
-
-       if "strict" in features and \
-               "digest" not in features and \
-               tree == "porttree" and \
-               mydo not in ("digest", "manifest", "help") and \
-               not _doebuild_manifest_exempt_depend:
-               # Always verify the ebuild checksums before executing it.
-               global _doebuild_manifest_cache, _doebuild_broken_ebuilds, \
-                       _doebuild_broken_ebuilds
-
-               if myebuild in _doebuild_broken_ebuilds:
-                       return 1
-
-               pkgdir = os.path.dirname(myebuild)
-               manifest_path = os.path.join(pkgdir, "Manifest")
-
-               # Avoid checking the same Manifest several times in a row during a
-               # regen with an empty cache.
-               if _doebuild_manifest_cache is None or \
-                       _doebuild_manifest_cache.getFullname() != manifest_path:
-                       _doebuild_manifest_cache = None
-                       if not os.path.exists(manifest_path):
-                               out = portage.output.EOutput()
-                               out.eerror(_("Manifest not found for '%s'") % (myebuild,))
-                               _doebuild_broken_ebuilds.add(myebuild)
-                               return 1
-                       mf = Manifest(pkgdir, mysettings["DISTDIR"])
-
-               else:
-                       mf = _doebuild_manifest_cache
-
-               try:
-                       mf.checkFileHashes("EBUILD", os.path.basename(myebuild))
-               except KeyError:
-                       out = portage.output.EOutput()
-                       out.eerror(_("Missing digest for '%s'") % (myebuild,))
-                       _doebuild_broken_ebuilds.add(myebuild)
-                       return 1
-               except portage.exception.FileNotFound:
-                       out = portage.output.EOutput()
-                       out.eerror(_("A file listed in the Manifest "
-                               "could not be found: '%s'") % (myebuild,))
-                       _doebuild_broken_ebuilds.add(myebuild)
-                       return 1
-               except portage.exception.DigestException as e:
-                       out = portage.output.EOutput()
-                       out.eerror(_("Digest verification failed:"))
-                       out.eerror("%s" % e.value[0])
-                       out.eerror(_("Reason: %s") % e.value[1])
-                       out.eerror(_("Got: %s") % e.value[2])
-                       out.eerror(_("Expected: %s") % e.value[3])
-                       _doebuild_broken_ebuilds.add(myebuild)
-                       return 1
-
-               if mf.getFullname() in _doebuild_broken_manifests:
-                       return 1
-
-               if mf is not _doebuild_manifest_cache:
-
-                       # Make sure that all of the ebuilds are
-                       # actually listed in the Manifest.
-                       glep55 = 'parse-eapi-glep-55' in mysettings.features
-                       for f in os.listdir(pkgdir):
-                               pf = None
-                               if glep55:
-                                       pf, eapi = _split_ebuild_name_glep55(f)
-                               elif f[-7:] == '.ebuild':
-                                       pf = f[:-7]
-                               if pf is not None and not mf.hasFile("EBUILD", f):
-                                       f = os.path.join(pkgdir, f)
-                                       if f not in _doebuild_broken_ebuilds:
-                                               out = portage.output.EOutput()
-                                               out.eerror(_("A file is not listed in the "
-                                                       "Manifest: '%s'") % (f,))
-                                       _doebuild_broken_manifests.add(manifest_path)
-                                       return 1
-
-                       # Only cache it if the above stray files test succeeds.
-                       _doebuild_manifest_cache = mf
-
-       def exit_status_check(retval):
-               msg = _doebuild_exit_status_check(mydo, mysettings)
-               if msg:
-                       if retval == os.EX_OK:
-                               retval = 1
-                       from textwrap import wrap
-                       from portage.elog.messages import eerror
-                       for l in wrap(msg, 72):
-                               eerror(l, phase=mydo, key=mysettings.mycpv)
-               return retval
-
-       # Note: PORTAGE_BIN_PATH may differ from the global
-       # constant when portage is reinstalling itself.
-       portage_bin_path = mysettings["PORTAGE_BIN_PATH"]
-       ebuild_sh_binary = os.path.join(portage_bin_path,
-               os.path.basename(EBUILD_SH_BINARY))
-       misc_sh_binary = os.path.join(portage_bin_path,
-               os.path.basename(MISC_SH_BINARY))
-
-       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)
-
-               if mydo in clean_phases:
-                       retval = spawn(_shell_quote(ebuild_sh_binary) + " clean",
-                               mysettings, debug=debug, fd_pipes=fd_pipes, free=1,
-                               logfile=None, returnpid=returnpid)
-                       return retval
-
-               restrict = set(mysettings.get('PORTAGE_RESTRICT', '').split())
-               # get possible slot information from the deps file
-               if mydo == "depend":
-                       writemsg("!!! DEBUG: dbkey: %s\n" % str(dbkey), 2)
-                       droppriv = "userpriv" in mysettings.features
-                       if returnpid:
-                               mypids = spawn(_shell_quote(ebuild_sh_binary) + " depend",
-                                       mysettings, fd_pipes=fd_pipes, returnpid=True,
-                                       droppriv=droppriv)
-                               return mypids
-                       elif isinstance(dbkey, dict):
-                               mysettings["dbkey"] = ""
-                               pr, pw = os.pipe()
-                               fd_pipes = {
-                                       0:sys.stdin.fileno(),
-                                       1:sys.stdout.fileno(),
-                                       2:sys.stderr.fileno(),
-                                       9:pw}
-                               mypids = spawn(_shell_quote(ebuild_sh_binary) + " depend",
-                                       mysettings,
-                                       fd_pipes=fd_pipes, returnpid=True, droppriv=droppriv)
-                               os.close(pw) # belongs exclusively to the child process now
-                               f = os.fdopen(pr, 'rb')
-                               for k, v in zip(auxdbkeys,
-                                       (_unicode_decode(line).rstrip('\n') for line in f)):
-                                       dbkey[k] = v
-                               f.close()
-                               retval = os.waitpid(mypids[0], 0)[1]
-                               portage.process.spawned_pids.remove(mypids[0])
-                               # If it got a signal, return the signal that was sent, but
-                               # shift in order to distinguish it from a return value. (just
-                               # like portage.process.spawn() would do).
-                               if retval & 0xff:
-                                       retval = (retval & 0xff) << 8
-                               else:
-                                       # Otherwise, return its exit code.
-                                       retval = retval >> 8
-                               if retval == os.EX_OK and len(dbkey) != len(auxdbkeys):
-                                       # Don't trust bash's returncode if the
-                                       # number of lines is incorrect.
-                                       retval = 1
-                               return retval
-                       elif dbkey:
-                               mysettings["dbkey"] = dbkey
-                       else:
-                               mysettings["dbkey"] = \
-                                       os.path.join(mysettings.depcachedir, "aux_db_key_temp")
-
-                       return spawn(_shell_quote(ebuild_sh_binary) + " depend",
-                               mysettings,
-                               droppriv=droppriv)
-
-               # Validate dependency metadata here to ensure that ebuilds with invalid
-               # data are never installed via the ebuild command. Don't bother when
-               # returnpid == True since there's no need to do this every time emerge
-               # executes a phase.
-               if not returnpid:
-                       rval = _validate_deps(mysettings, myroot, mydo, mydbapi)
-                       if rval != os.EX_OK:
-                               return rval
-
-               if "PORTAGE_TMPDIR" not in mysettings or \
-                       not os.path.isdir(mysettings["PORTAGE_TMPDIR"]):
-                       writemsg(_("The directory specified in your "
-                               "PORTAGE_TMPDIR variable, '%s',\n"
-                               "does not exist.  Please create this directory or "
-                               "correct your PORTAGE_TMPDIR setting.\n") % mysettings.get("PORTAGE_TMPDIR", ""), noiselevel=-1)
-                       return 1
-               
-               # as some people use a separate PORTAGE_TMPDIR mount
-               # we prefer that as the checks below would otherwise be pointless
-               # for those people.
-               if os.path.exists(os.path.join(mysettings["PORTAGE_TMPDIR"], "portage")):
-                       checkdir = os.path.join(mysettings["PORTAGE_TMPDIR"], "portage")
-               else:
-                       checkdir = mysettings["PORTAGE_TMPDIR"]
-
-               if not os.access(checkdir, os.W_OK):
-                       writemsg(_("%s is not writable.\n"
-                               "Likely cause is that you've mounted it as readonly.\n") % checkdir,
-                               noiselevel=-1)
-                       return 1
-               else:
-                       from tempfile import NamedTemporaryFile
-                       fd = NamedTemporaryFile(prefix="exectest-", dir=checkdir)
-                       os.chmod(fd.name, 0o755)
-                       if not os.access(fd.name, os.X_OK):
-                               writemsg(_("Can not execute files in %s\n"
-                                       "Likely cause is that you've mounted it with one of the\n"
-                                       "following mount options: 'noexec', 'user', 'users'\n\n"
-                                       "Please make sure that portage can execute files in this directory.\n") % checkdir,
-                                       noiselevel=-1)
-                               fd.close()
-                               return 1
-                       fd.close()
-               del checkdir
-
-               if mydo == "unmerge":
-                       return unmerge(mysettings["CATEGORY"],
-                               mysettings["PF"], myroot, mysettings, vartree=vartree)
-
-               # Build directory creation isn't required for any of these.
-               # In the fetch phase, the directory is needed only for RESTRICT=fetch
-               # in order to satisfy the sane $PWD requirement (from bug #239560)
-               # when pkg_nofetch is spawned.
-               have_build_dirs = False
-               if not parallel_fetchonly and \
-                       mydo not in ('digest', 'help', 'manifest') and \
-                       not (mydo == 'fetch' and 'fetch' not in restrict):
-                       mystatus = prepare_build_dirs(myroot, mysettings, cleanup)
-                       if mystatus:
-                               return mystatus
-                       have_build_dirs = True
-
-                       # emerge handles logging externally
-                       if not returnpid:
-                               # PORTAGE_LOG_FILE is set by the
-                               # above prepare_build_dirs() call.
-                               logfile = mysettings.get("PORTAGE_LOG_FILE")
-
-               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 as 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" % \
-                                       (_shell_quote(saved_env),
-                                       _shell_quote(env_file)))
-                               try:
-                                       env_stat = os.stat(env_file)
-                               except OSError as 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:
-                                       # This is a signal to ebuild.sh, so that it knows to filter
-                                       # out things like SANDBOX_{DENY,PREDICT,READ,WRITE} that
-                                       # would be preserved between normal phases.
-                                       open(_unicode_encode(env_file + '.raw'), 'w')
-                               else:
-                                       writemsg(_("!!! Error extracting saved "
-                                               "environment: '%s'\n") % \
-                                               saved_env, noiselevel=-1)
-                                       try:
-                                               os.unlink(env_file)
-                                       except OSError as e:
-                                               if e.errno != errno.ENOENT:
-                                                       raise
-                                               del e
-                                       env_stat = None
-                       if env_stat:
-                               pass
-                       else:
-                               for var in ("ARCH", ):
-                                       value = mysettings.get(var)
-                                       if value and value.strip():
-                                               continue
-                                       msg = _("%(var)s is not set... "
-                                               "Are you missing the '%(configroot)setc/make.profile' symlink? "
-                                               "Is the symlink correct? "
-                                               "Is your portage tree complete?") % \
-                                               {"var": var, "configroot": mysettings["PORTAGE_CONFIGROOT"]}
-                                       from portage.elog.messages import eerror
-                                       from textwrap import wrap
-                                       for line in wrap(msg, 70):
-                                               eerror(line, phase="setup", key=mysettings.mycpv)
-                                       from portage.elog import elog_process
-                                       elog_process(mysettings.mycpv, mysettings)
-                                       return 1
-                       del env_file, env_stat, saved_env
-                       _doebuild_exit_status_unlink(
-                               mysettings.get("EBUILD_EXIT_STATUS_FILE"))
-               else:
-                       mysettings.pop("EBUILD_EXIT_STATUS_FILE", None)
-
-               # if any of these are being called, handle them -- running them out of
-               # the sandbox -- and stop now.
-               if mydo == "help":
-                       return spawn(_shell_quote(ebuild_sh_binary) + " " + mydo,
-                               mysettings, debug=debug, free=1, logfile=logfile)
-               elif mydo == "setup":
-                       retval = spawn(
-                               _shell_quote(ebuild_sh_binary) + " " + mydo, mysettings,
-                               debug=debug, free=1, logfile=logfile, fd_pipes=fd_pipes,
-                               returnpid=returnpid)
-                       if returnpid:
-                               return retval
-                       retval = exit_status_check(retval)
-                       if secpass >= 2:
-                               """ Privileged phases may have left files that need to be made
-                               writable to a less privileged user."""
-                               apply_recursive_permissions(mysettings["T"],
-                                       uid=portage_uid, gid=portage_gid, dirmode=0o70, dirmask=0,
-                                       filemode=0o60, filemask=0)
-                       return retval
-               elif mydo == "preinst":
-                       phase_retval = spawn(
-                               _shell_quote(ebuild_sh_binary) + " " + mydo,
-                               mysettings, debug=debug, free=1, logfile=logfile,
-                               fd_pipes=fd_pipes, returnpid=returnpid)
-
-                       if returnpid:
-                               return phase_retval
-
-                       phase_retval = exit_status_check(phase_retval)
-                       if phase_retval == os.EX_OK:
-                               _doebuild_exit_status_unlink(
-                                       mysettings.get("EBUILD_EXIT_STATUS_FILE"))
-                               mysettings.pop("EBUILD_PHASE", None)
-                               phase_retval = spawn(
-                                       " ".join(_post_pkg_preinst_cmd(mysettings)),
-                                       mysettings, debug=debug, free=1, logfile=logfile)
-                               phase_retval = exit_status_check(phase_retval)
-                               if phase_retval != os.EX_OK:
-                                       writemsg(_("!!! post preinst failed; exiting.\n"),
-                                               noiselevel=-1)
-                       return phase_retval
-               elif mydo == "postinst":
-                       phase_retval = spawn(
-                               _shell_quote(ebuild_sh_binary) + " " + mydo,
-                               mysettings, debug=debug, free=1, logfile=logfile,
-                               fd_pipes=fd_pipes, returnpid=returnpid)
-
-                       if returnpid:
-                               return phase_retval
-
-                       phase_retval = exit_status_check(phase_retval)
-                       if phase_retval == os.EX_OK:
-                               _doebuild_exit_status_unlink(
-                                       mysettings.get("EBUILD_EXIT_STATUS_FILE"))
-                               mysettings.pop("EBUILD_PHASE", None)
-                               phase_retval = spawn(" ".join(_post_pkg_postinst_cmd(mysettings)),
-                                       mysettings, debug=debug, free=1, logfile=logfile)
-                               phase_retval = exit_status_check(phase_retval)
-                               if phase_retval != os.EX_OK:
-                                       writemsg(_("!!! post postinst failed; exiting.\n"),
-                                               noiselevel=-1)
-                       return phase_retval
-               elif mydo in ("prerm", "postrm", "config", "info"):
-                       retval =  spawn(
-                               _shell_quote(ebuild_sh_binary) + " " + mydo,
-                               mysettings, debug=debug, free=1, logfile=logfile,
-                               fd_pipes=fd_pipes, returnpid=returnpid)
-
-                       if returnpid:
-                               return retval
-
-                       retval = exit_status_check(retval)
-                       return retval
-
-               mycpv = "/".join((mysettings["CATEGORY"], mysettings["PF"]))
-
-               emerge_skip_distfiles = returnpid
-               emerge_skip_digest = returnpid
-               # Only try and fetch the files if we are going to need them ...
-               # otherwise, if user has FEATURES=noauto and they run `ebuild clean
-               # unpack compile install`, we will try and fetch 4 times :/
-               need_distfiles = not emerge_skip_distfiles and \
-                       (mydo in ("fetch", "unpack") or \
-                       mydo not in ("digest", "manifest") and "noauto" not in features)
-               alist = mysettings.configdict["pkg"].get("A")
-               aalist = mysettings.configdict["pkg"].get("AA")
-               if alist is None or aalist is None:
-                       # Make sure we get the correct tree in case there are overlays.
-                       mytree = os.path.realpath(
-                               os.path.dirname(os.path.dirname(mysettings["O"])))
-                       useflags = mysettings["PORTAGE_USE"].split()
-                       try:
-                               alist = mydbapi.getFetchMap(mycpv, useflags=useflags,
-                                       mytree=mytree)
-                               aalist = mydbapi.getFetchMap(mycpv, mytree=mytree)
-                       except portage.exception.InvalidDependString as e:
-                               writemsg("!!! %s\n" % str(e), noiselevel=-1)
-                               writemsg(_("!!! Invalid SRC_URI for '%s'.\n") % mycpv,
-                                       noiselevel=-1)
-                               del e
-                               return 1
-                       mysettings.configdict["pkg"]["A"] = " ".join(alist)
-                       mysettings.configdict["pkg"]["AA"] = " ".join(aalist)
-               else:
-                       alist = set(alist.split())
-                       aalist = set(aalist.split())
-               if ("mirror" in features) or fetchall:
-                       fetchme = aalist
-                       checkme = aalist
-               else:
-                       fetchme = alist
-                       checkme = alist
-
-               if mydo == "fetch":
-                       # Files are already checked inside fetch(),
-                       # so do not check them again.
-                       checkme = []
-
-               if not emerge_skip_distfiles and \
-                       need_distfiles and not fetch(
-                       fetchme, mysettings, listonly=listonly, fetchonly=fetchonly):
-                       return 1
-
-               if mydo == "fetch" and listonly:
-                       return 0
-
-               try:
-                       if mydo == "manifest":
-                               return not digestgen(mysettings=mysettings, myportdb=mydbapi)
-                       elif mydo == "digest":
-                               return not digestgen(mysettings=mysettings, myportdb=mydbapi)
-                       elif mydo != 'fetch' and not emerge_skip_digest and \
-                               "digest" in mysettings.features:
-                               # Don't do this when called by emerge or when called just
-                               # for fetch (especially parallel-fetch) since it's not needed
-                               # and it can interfere with parallel tasks.
-                               digestgen(mysettings=mysettings, myportdb=mydbapi)
-               except portage.exception.PermissionDenied as e:
-                       writemsg(_("!!! Permission Denied: %s\n") % (e,), noiselevel=-1)
-                       if mydo in ("digest", "manifest"):
-                               return 1
-
-               # See above comment about fetching only when needed
-               if not emerge_skip_distfiles and \
-                       not digestcheck(checkme, mysettings, "strict" in features):
-                       return 1
-
-               if mydo == "fetch":
-                       return 0
-
-               # remove PORTAGE_ACTUAL_DISTDIR once cvs/svn is supported via SRC_URI
-               if (mydo != "setup" and "noauto" not in features) or mydo == "unpack":
-                       orig_distdir = mysettings["DISTDIR"]
-                       mysettings["PORTAGE_ACTUAL_DISTDIR"] = orig_distdir
-                       edpath = mysettings["DISTDIR"] = \
-                               os.path.join(mysettings["PORTAGE_BUILDDIR"], "distdir")
-                       portage.util.ensure_dirs(edpath, gid=portage_gid, mode=0o755)
-
-                       # Remove any unexpected files or directories.
-                       for x in os.listdir(edpath):
-                               symlink_path = os.path.join(edpath, x)
-                               st = os.lstat(symlink_path)
-                               if x in alist and stat.S_ISLNK(st.st_mode):
-                                       continue
-                               if stat.S_ISDIR(st.st_mode):
-                                       shutil.rmtree(symlink_path)
-                               else:
-                                       os.unlink(symlink_path)
-
-                       # Check for existing symlinks and recreate if necessary.
-                       for x in alist:
-                               symlink_path = os.path.join(edpath, x)
-                               target = os.path.join(orig_distdir, x)
-                               try:
-                                       link_target = os.readlink(symlink_path)
-                               except OSError:
-                                       os.symlink(target, symlink_path)
-                               else:
-                                       if link_target != target:
-                                               os.unlink(symlink_path)
-                                               os.symlink(target, symlink_path)
-
-               #initial dep checks complete; time to process main commands
-
-               restrict = mysettings["PORTAGE_RESTRICT"].split()
-               nosandbox = (("userpriv" in features) and \
-                       ("usersandbox" not in features) and \
-                       "userpriv" not in restrict and \
-                       "nouserpriv" not in restrict)
-               if nosandbox and ("userpriv" not in features or \
-                       "userpriv" in restrict or \
-                       "nouserpriv" in restrict):
-                       nosandbox = ("sandbox" not in features and \
-                               "usersandbox" not in features)
-
-               if not process.sandbox_capable:
-                       nosandbox = True
-
-               sesandbox = mysettings.selinux_enabled() and \
-                       "sesandbox" in mysettings.features
-
-               droppriv = "userpriv" in mysettings.features and \
-                       "userpriv" not in restrict and \
-                       secpass >= 2
-
-               fakeroot = "fakeroot" in mysettings.features
-
-               ebuild_sh = _shell_quote(ebuild_sh_binary) + " %s"
-               misc_sh = _shell_quote(misc_sh_binary) + " dyn_%s"
-
-               # args are for the to spawn function
-               actionmap = {
-"pretend":  {"cmd":ebuild_sh, "args":{"droppriv":0,        "free":1,         "sesandbox":0,         "fakeroot":0}},
-"setup":    {"cmd":ebuild_sh, "args":{"droppriv":0,        "free":1,         "sesandbox":0,         "fakeroot":0}},
-"unpack":   {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":0,         "sesandbox":sesandbox, "fakeroot":0}},
-"prepare":  {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":0,         "sesandbox":sesandbox, "fakeroot":0}},
-"configure":{"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":nosandbox, "sesandbox":sesandbox, "fakeroot":0}},
-"compile":  {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":nosandbox, "sesandbox":sesandbox, "fakeroot":0}},
-"test":     {"cmd":ebuild_sh, "args":{"droppriv":droppriv, "free":nosandbox, "sesandbox":sesandbox, "fakeroot":0}},
-"install":  {"cmd":ebuild_sh, "args":{"droppriv":0,        "free":0,         "sesandbox":sesandbox, "fakeroot":fakeroot}},
-"rpm":      {"cmd":misc_sh,   "args":{"droppriv":0,        "free":0,         "sesandbox":0,         "fakeroot":fakeroot}},
-"package":  {"cmd":misc_sh,   "args":{"droppriv":0,        "free":0,         "sesandbox":0,         "fakeroot":fakeroot}},
-               }
-
-               # merge the deps in so we have again a 'full' actionmap
-               # be glad when this can die.
-               for x in actionmap:
-                       if len(actionmap_deps.get(x, [])):
-                               actionmap[x]["dep"] = ' '.join(actionmap_deps[x])
-
-               if mydo in actionmap:
-                       if mydo == "package":
-                               # Make sure the package directory exists before executing
-                               # this phase. This can raise PermissionDenied if
-                               # the current user doesn't have write access to $PKGDIR.
-                               parent_dir = os.path.join(mysettings["PKGDIR"],
-                                       mysettings["CATEGORY"])
-                               portage.util.ensure_dirs(parent_dir)
-                               if not os.access(parent_dir, os.W_OK):
-                                       raise portage.exception.PermissionDenied(
-                                               "access('%s', os.W_OK)" % parent_dir)
-                       retval = spawnebuild(mydo,
-                               actionmap, mysettings, debug, logfile=logfile,
-                               fd_pipes=fd_pipes, returnpid=returnpid)
-               elif mydo=="qmerge":
-                       # check to ensure install was run.  this *only* pops up when users
-                       # forget it and are using ebuild
-                       if not os.path.exists(
-                               os.path.join(mysettings["PORTAGE_BUILDDIR"], ".installed")):
-                               writemsg(_("!!! mydo=qmerge, but the install phase has not been run\n"),
-                                       noiselevel=-1)
-                               return 1
-                       # qmerge is a special phase that implies noclean.
-                       if "noclean" not in mysettings.features:
-                               mysettings.features.add("noclean")
-                       #qmerge is specifically not supposed to do a runtime dep check
-                       retval = merge(
-                               mysettings["CATEGORY"], mysettings["PF"], mysettings["D"],
-                               os.path.join(mysettings["PORTAGE_BUILDDIR"], "build-info"),
-                               myroot, mysettings, myebuild=mysettings["EBUILD"], mytree=tree,
-                               mydbapi=mydbapi, vartree=vartree, prev_mtimes=prev_mtimes)
-               elif mydo=="merge":
-                       retval = spawnebuild("install", actionmap, mysettings, debug,
-                               alwaysdep=1, logfile=logfile, fd_pipes=fd_pipes,
-                               returnpid=returnpid)
-                       retval = exit_status_check(retval)
-                       if retval != os.EX_OK:
-                               # The merge phase handles this already.  Callers don't know how
-                               # far this function got, so we have to call elog_process() here
-                               # so that it's only called once.
-                               from portage.elog import elog_process
-                               elog_process(mysettings.mycpv, mysettings)
-                       if retval == os.EX_OK:
-                               retval = merge(mysettings["CATEGORY"], mysettings["PF"],
-                                       mysettings["D"], os.path.join(mysettings["PORTAGE_BUILDDIR"],
-                                       "build-info"), myroot, mysettings,
-                                       myebuild=mysettings["EBUILD"], mytree=tree, mydbapi=mydbapi,
-                                       vartree=vartree, prev_mtimes=prev_mtimes)
-               else:
-                       print(_("!!! Unknown mydo: %s") % mydo)
-                       return 1
-
-               return retval
-
-       finally:
-
-               if tmpdir:
-                       mysettings["PORTAGE_TMPDIR"] = tmpdir_orig
-                       shutil.rmtree(tmpdir)
-               if builddir_lock:
-                       portage.locks.unlockdir(builddir_lock)
-
-               # Make sure that DISTDIR is restored to it's normal value before we return!
-               if "PORTAGE_ACTUAL_DISTDIR" in mysettings:
-                       mysettings["DISTDIR"] = mysettings["PORTAGE_ACTUAL_DISTDIR"]
-                       del mysettings["PORTAGE_ACTUAL_DISTDIR"]
-
-               if logfile:
-                       try:
-                               if os.stat(logfile).st_size == 0:
-                                       os.unlink(logfile)
-                       except OSError:
-                               pass
-
-               if mydo in ("digest", "manifest", "help"):
-                       # If necessary, depend phase has been triggered by aux_get calls
-                       # and the exemption is no longer needed.
-                       _doebuild_manifest_exempt_depend -= 1
-
-def _validate_deps(mysettings, myroot, mydo, mydbapi):
-
-       invalid_dep_exempt_phases = \
-               set(["clean", "cleanrm", "help", "prerm", "postrm"])
-       dep_keys = ["DEPEND", "RDEPEND", "PDEPEND"]
-       misc_keys = ["LICENSE", "PROPERTIES", "PROVIDE", "RESTRICT", "SRC_URI"]
-       other_keys = ["SLOT"]
-       all_keys = dep_keys + misc_keys + other_keys
-       metadata = dict(zip(all_keys,
-               mydbapi.aux_get(mysettings.mycpv, all_keys)))
-
-       class FakeTree(object):
-               def __init__(self, mydb):
-                       self.dbapi = mydb
-       dep_check_trees = {myroot:{}}
-       dep_check_trees[myroot]["porttree"] = \
-               FakeTree(fakedbapi(settings=mysettings))
-
-       msgs = []
-       for dep_type in dep_keys:
-               mycheck = dep_check(metadata[dep_type], None, mysettings,
-                       myuse="all", myroot=myroot, trees=dep_check_trees)
-               if not mycheck[0]:
-                       msgs.append("  %s: %s\n    %s\n" % (
-                               dep_type, metadata[dep_type], mycheck[1]))
-
-       for k in misc_keys:
-               try:
-                       portage.dep.use_reduce(
-                               portage.dep.paren_reduce(metadata[k]), matchall=True)
-               except portage.exception.InvalidDependString as e:
-                       msgs.append("  %s: %s\n    %s\n" % (
-                               k, metadata[k], str(e)))
-
-       if not metadata["SLOT"]:
-               msgs.append(_("  SLOT is undefined\n"))
-
-       if msgs:
-               portage.util.writemsg_level(_("Error(s) in metadata for '%s':\n") % \
-                       (mysettings.mycpv,), level=logging.ERROR, noiselevel=-1)
-               for x in msgs:
-                       portage.util.writemsg_level(x,
-                               level=logging.ERROR, noiselevel=-1)
-               if mydo not in invalid_dep_exempt_phases:
-                       return 1
-
-       return os.EX_OK
-
-expandcache={}
-
-=======
->>>>>>> .merge-right.r15449
 def _movefile(src, dest, **kwargs):
        """Calls movefile and raises a PortageException if an error occurs."""
        if movefile(src, dest, **kwargs) is None:
index d1595b1fff8958742f162290edcbc9637554a7ba..d7259b4699833f4343701707356fe73eb01680c7 100644 (file)
@@ -102,6 +102,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings,
                # due to how it's coded... Don't overwrite this so we can use it.
                mysettings["PORTAGE_DEBUG"] = "1"
 
+       mysettings["EPREFIX"]  = EPREFIX.rstrip(os.path.sep)
        mysettings["EBUILD"]   = ebuild_path
        mysettings["O"]        = pkg_dir
        mysettings.configdict["pkg"]["CATEGORY"] = cat
@@ -192,8 +193,9 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings,
        mysettings["D"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image") + os.sep
        mysettings["T"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "temp")
 
-       # Prefix forward compatability
-       mysettings["ED"] = mysettings["D"]
+       ## Prefix forward compatability
+       #mysettings["ED"] = mysettings["D"]
+       mysettings["ED"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "image" + mysettings["EPREFIX"]) + os.sep
 
        mysettings["PORTAGE_BASHRC"] = os.path.join(
                mysettings["PORTAGE_CONFIGROOT"], EBUILD_SH_ENV_FILE)
@@ -209,7 +211,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings,
                mydo in ('compile', 'config', 'configure', 'info',
                'install', 'nofetch', 'postinst', 'postrm', 'preinst',
                'prepare', 'prerm', 'setup', 'test', 'unpack'):
-               mykv,err1=ExtractKernelVersion(os.path.join(myroot, "usr/src/linux"))
+               mykv,err1=ExtractKernelVersion(os.path.join(myroot, EPREFIX_LSTRIP, "usr/src/linux"))
                if mykv:
                        # Regular source tree
                        mysettings["KV"]=mykv
index 83031d689e73503b08e3eefbdf9a8dc939ef35c9..e7ef42598811af5e0893c6c44ed32a845579374a 100644 (file)
@@ -131,12 +131,12 @@ def _prepare_features_dirs(mysettings):
 
        features_dirs = {
                "ccache":{
-                       "path_dir": "/usr/lib/ccache/bin",
+                       "path_dir": EPREFIX+"/usr/lib/ccache/bin",
                        "basedir_var":"CCACHE_DIR",
                        "default_dir":os.path.join(mysettings["PORTAGE_TMPDIR"], "ccache"),
                        "always_recurse":False},
                "distcc":{
-                       "path_dir": "/usr/lib/distcc/bin",
+                       "path_dir": EPREFIX+"/usr/lib/distcc/bin",
                        "basedir_var":"DISTCC_DIR",
                        "default_dir":os.path.join(mysettings["BUILD_PREFIX"], ".distcc"),
                        "subdirs":("lock", "state"),