EbuildMetadataPhase: use dynamic pipe fd
authorZac Medico <zmedico@gentoo.org>
Tue, 15 Jan 2013 20:36:02 +0000 (12:36 -0800)
committerZac Medico <zmedico@gentoo.org>
Tue, 15 Jan 2013 20:36:02 +0000 (12:36 -0800)
Also, remove deprecated code from doebuild (with hardcoded pipe fd).

bin/ebuild.sh
pym/_emerge/EbuildMetadataPhase.py
pym/portage/package/ebuild/doebuild.py

index a4be7c0677cfc508dc1056bc1ac4d643b19831b8..2293938bc9f966ef4110f253eb1d8ada82ab7776 100755 (executable)
@@ -696,9 +696,9 @@ if [[ $EBUILD_PHASE = depend ]] ; then
                done
        else
                for f in ${auxdbkeys} ; do
-                       echo $(echo ${!f}) 1>&9 || exit $?
+                       eval "echo \$(echo \${!f}) 1>&${PORTAGE_PIPE_FD}" || exit $?
                done
-               exec 9>&-
+               eval "exec ${PORTAGE_PIPE_FD}>&-"
        fi
        set +f
 else
index 4806f5c2ddc37801e26f6f632b348860109fbc4e..4c7d772d4fa9e3e5748db8a2a31495a1e2a24fe6 100644 (file)
@@ -32,7 +32,6 @@ class EbuildMetadataPhase(SubProcess):
 
        _file_names = ("ebuild",)
        _files_dict = slot_dict_class(_file_names, prefix="")
-       _metadata_fd = 9
 
        def _start(self):
                ebuild_path = self.ebuild_hash.location
@@ -103,7 +102,8 @@ class EbuildMetadataPhase(SubProcess):
                fcntl.fcntl(master_fd, fcntl.F_SETFL,
                        fcntl.fcntl(master_fd, fcntl.F_GETFL) | fcntl_flags)
 
-               fd_pipes[self._metadata_fd] = slave_fd
+               fd_pipes[slave_fd] = slave_fd
+               settings["PORTAGE_PIPE_FD"] = str(slave_fd)
 
                self._raw_metadata = []
                files.ebuild = master_fd
@@ -115,6 +115,7 @@ class EbuildMetadataPhase(SubProcess):
                        settings=settings, debug=debug,
                        mydbapi=self.portdb, tree="porttree",
                        fd_pipes=fd_pipes, returnpid=True)
+               settings.pop("PORTAGE_PIPE_FD", None)
 
                os.close(slave_fd)
                null_input.close()
index e4d3ae4514df591048b16a12c68ba320d0a3650a..a214c39a8ec38a13738c78b92eea61a1ee050290 100644 (file)
@@ -455,7 +455,7 @@ _doebuild_commands_without_builddir = (
 )
 
 def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0,
-       fetchonly=0, cleanup=0, dbkey=None, use_cache=1, fetchall=0, tree=None,
+       fetchonly=0, cleanup=0, dbkey=DeprecationWarning, use_cache=1, fetchall=0, tree=None,
        mydbapi=None, vartree=None, prev_mtimes=None,
        fd_pipes=None, returnpid=False):
        """
@@ -524,6 +524,11 @@ def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0,
                        "settings['ROOT'] instead.",
                        DeprecationWarning, stacklevel=2)
 
+       if dbkey is not DeprecationWarning:
+               warnings.warn("portage.doebuild() called "
+                       "with deprecated dbkey argument.",
+                       DeprecationWarning, stacklevel=2)
+
        if not tree:
                writemsg("Warning: tree not specified to doebuild\n")
                tree = "porttree"
@@ -720,42 +725,7 @@ def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0,
                        if returnpid:
                                return _spawn_phase(mydo, mysettings,
                                        fd_pipes=fd_pipes, returnpid=returnpid)
-                       elif isinstance(dbkey, dict):
-                               warnings.warn("portage.doebuild() called " + \
-                                       "with dict dbkey argument. This usage will " + \
-                                       "not be supported in the future.",
-                                       DeprecationWarning, stacklevel=2)
-                               mysettings["dbkey"] = ""
-                               pr, pw = os.pipe()
-                               fd_pipes = {
-                                       0:portage._get_stdin().fileno(),
-                                       1:sys.__stdout__.fileno(),
-                                       2:sys.__stderr__.fileno(),
-                                       9:pw}
-                               mypids = _spawn_phase(mydo, mysettings, returnpid=True,
-                                       fd_pipes=fd_pipes)
-                               os.close(pw) # belongs exclusively to the child process now
-                               f = os.fdopen(pr, 'rb', 0)
-                               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:
+                       elif dbkey and dbkey is not DeprecationWarning:
                                mysettings["dbkey"] = dbkey
                        else:
                                mysettings["dbkey"] = \