Use a pipe instead of a temp file for the depend phase.
authorZac Medico <zmedico@gentoo.org>
Fri, 22 Dec 2006 22:22:37 +0000 (22:22 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 22 Dec 2006 22:22:37 +0000 (22:22 -0000)
svn path=/main/trunk/; revision=5350

bin/ebuild.sh
pym/portage.py

index 0d26836d93b8dbf33ff62b857f68d766f1415838..92d3bc09d45585885b337c3b8c80353e5e26fcd1 100755 (executable)
@@ -1604,39 +1604,33 @@ for myarg in ${EBUILD_SH_ARGS} ; do
                export SANDBOX_ON="0"
                set -f
 
-               # Handled in portage.py now
-               #dbkey=${PORTAGE_CACHEDIR}/${CATEGORY}/${PF}
-
-               if [ ! -d "${dbkey%/*}" ]; then
-                       install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
+               if [ -n "${dbkey}" ] ; then
+                       if [ ! -d "${dbkey%/*}" ]; then
+                               install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
+                       fi
+                       # Make it group writable. 666&~002==664
+                       umask 002
                fi
 
-               # Make it group writable. 666&~002==664
-               umask 002
+               auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
+                       DESCRIPTION KEYWORDS INHERITED IUSE CDEPEND PDEPEND PROVIDE EAPI
+                       UNUSED_01 UNUSED_02 UNUSED_03 UNUSED_04 UNUSED_05 UNUSED_06
+                       UNUSED_07"
 
                #the extra $(echo) commands remove newlines
-               echo $(echo "$DEPEND")       > $dbkey
-               echo $(echo "$RDEPEND")     >> $dbkey
-               echo $(echo "$SLOT")        >> $dbkey
-               echo $(echo "$SRC_URI")     >> $dbkey
-               echo $(echo "$RESTRICT")    >> $dbkey
-               echo $(echo "$HOMEPAGE")    >> $dbkey
-               echo $(echo "$LICENSE")     >> $dbkey
-               echo $(echo "$DESCRIPTION") >> $dbkey
-               echo $(echo "$KEYWORDS")    >> $dbkey
-               echo $(echo "$INHERITED")   >> $dbkey
-               echo $(echo "$IUSE")        >> $dbkey
-               echo                       >> $dbkey
-               echo $(echo "$PDEPEND")     >> $dbkey
-               echo $(echo "$PROVIDE")     >> $dbkey
-               echo $(echo "${EAPI:-0}")   >> $dbkey
-               echo $(echo "$UNUSED_01")   >> $dbkey
-               echo $(echo "$UNUSED_02")   >> $dbkey
-               echo $(echo "$UNUSED_03")   >> $dbkey
-               echo $(echo "$UNUSED_04")   >> $dbkey
-               echo $(echo "$UNUSED_05")   >> $dbkey
-               echo $(echo "$UNUSED_06")   >> $dbkey
-               echo $(echo "$UNUSED_07")   >> $dbkey
+               unset CDEPEND
+               [ -n "${EAPI}" ] && EAPI=0
+               if [ -n "${dbkey}" ] ; then
+                       > "${dbkey}"
+                       for f in ${auxdbkeys} ; do
+                               echo $(echo ${!f}) >> "${dbkey}" || exit $?
+                       done
+               else
+                       for f in ${auxdbkeys} ; do
+                               echo $(echo ${!f}) 1>&9 || exit $?
+                       done
+                       9>&-
+               fi
                set +f
                #make sure it is writable by our group:
                exit 0
index 991f2b634dfc84a0495980cad683056b40e04252..aef6729e694f3a008e5f02c0af061770b4a5aef0 100644 (file)
@@ -1993,7 +1993,7 @@ class config:
 
 # 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,fd_pipes=None,**keywords):
+def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, **keywords):
        """spawn a subprocess with optional sandbox protection,
        depending on whether sandbox is enabled.  The "free" argument,
        when set to 1, will disable sandboxing.  This allows us to
@@ -3116,7 +3116,32 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
                # get possible slot information from the deps file
                if mydo == "depend":
                        writemsg("!!! DEBUG: dbkey: %s\n" % str(dbkey), 2)
-                       if dbkey:
+                       if isinstance(dbkey, dict):
+                               mysettings["dbkey"] = ""
+                               pr, pw = os.pipe()
+                               fd_pipes = {0:0, 1:1, 2:2, 9:pw}
+                               mypids = spawn(EBUILD_SH_BINARY + " depend", mysettings,
+                                       fd_pipes=fd_pipes, returnpid=True)
+                               os.close(pw) # belongs exclusively to the child process now
+                               maxbytes = 1024
+                               mybytes = []
+                               while True:
+                                       mybytes.append(os.read(pr, maxbytes))
+                                       if not mybytes[-1]:
+                                               break
+                               os.close(pr)
+                               mybytes = "".join(mybytes)
+                               global auxdbkeys
+                               dbkey.update(izip(auxdbkeys, mybytes.split("\n")))
+                               retval = os.waitpid(mypids[0], 0)[1]
+                               # 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_exec.spawn() would do).
+                               if retval & 0xff:
+                                       return (retval & 0xff) << 8
+                               # Otherwise, return its exit code.
+                               return retval >> 8
+                       elif dbkey:
                                mysettings["dbkey"] = dbkey
                        else:
                                mysettings["dbkey"] = \
@@ -5337,55 +5362,13 @@ class portdbapi(dbapi):
                        writemsg("doregen: %s %s\n" % (doregen,mycpv), 2)
                        writemsg("Generating cache entry(0) for: "+str(myebuild)+"\n",1)
 
-                       if self.tmpfs:
-                               mydbkey = self.tmpfs+"/aux_db_key_temp"
-                       else:
-                               mydbkey = self.depcachedir+"/aux_db_key_temp"
-
-                       mylock = None
-                       try:
-                               mylock = portage_locks.lockfile(mydbkey, wantnewlockfile=1)
-                               try:
-                                       os.unlink(mydbkey)
-                               except (IOError, OSError), e:
-                                       if e.errno != errno.ENOENT:
-                                               raise
-                                       del e
-
-                               self.doebuild_settings.reset()
-                               myret = doebuild(myebuild, "depend", "/",
-                                        self.doebuild_settings, dbkey=mydbkey, tree="porttree",
-                                        mydbapi=self)
-                               if myret != os.EX_OK:
-                                       #depend returned non-zero exit code...
-                                       writemsg((red("\naux_get():") + \
-                                               " (0) Error in '%s'. (%s)\n" + \
-                                               "               Check for syntax error or " + \
-                                               "corruption in the ebuild. (--debug)\n\n") % \
-                                               (myebuild, myret), noiselevel=-1)
-                                       raise KeyError(mycpv)
-
-                               try:
-                                       mycent = open(mydbkey, "r")
-                                       os.unlink(mydbkey)
-                                       mylines = mycent.readlines()
-                                       mycent.close()
-                               except (IOError, OSError):
-                                       writemsg((red("\naux_get():") + \
-                                               " (1) Error in '%s' ebuild.\n" + \
-                                               "               Check for syntax error or " + \
-                                               "corruption in the ebuild. (--debug)\n\n") % myebuild,
-                                               noiselevel=-1)
-                                       raise KeyError(mycpv)
-                       finally:
-                               if mylock:
-                                       portage_locks.unlockfile(mylock)
-
+                       self.doebuild_settings.reset()
                        mydata = {}
-                       for x in range(0,len(mylines)):
-                               if mylines[x][-1] == '\n':
-                                       mylines[x] = mylines[x][:-1]
-                               mydata[auxdbkeys[x]] = mylines[x]
+                       myret = doebuild(myebuild, "depend",
+                               self.doebuild_settings["ROOT"], self.doebuild_settings,
+                               dbkey=mydata, tree="porttree", mydbapi=self)
+                       if myret != os.EX_OK:
+                               raise KeyError(mycpv)
 
                        if "EAPI" not in mydata or not mydata["EAPI"].strip():
                                mydata["EAPI"] = "0"