def unlockfile(mytuple): import fcntl #XXX: Compatability hack. if len(mytuple) == 3: lockfilename,myfd,unlinkfile = mytuple locking_method = fcntl.flock verbosity=0 elif len(mytuple) == 4: lockfilename,myfd,unlinkfile,locking_method = mytuple verbosity=0 elif len(mytuple) == 5: lockfilename,myfd,unlinkfile,locking_method,verbosity = mytuple else: raise if(myfd == HARDLINK_FD): unhardlink_lockfile(lockfilename) return True if type(lockfilename) == types.StringType and not os.path.exists(lockfilename): portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1) if (myfd != None) and type(lockfilename) == types.StringType: os.close(myfd) return False try: if myfd == None: myfd = os.open(lockfilename, os.O_WRONLY,0660) unlinkfile = 1 locking_method(myfd,fcntl.LOCK_UN) except SystemExit, e: raise
def environ(self): "return our locally-maintained environment" mydict = {} for x in self.keys(): mydict[x] = self[x] if not mydict.has_key("HOME") and mydict.has_key("BUILD_PREFIX"): writemsg("*** HOME not set. Setting to " + mydict["BUILD_PREFIX"] + "\n") mydict["HOME"] = mydict["BUILD_PREFIX"][:] return mydict
def perform_checksum(filename, hash_function=md5hash, calc_prelink=0): myfilename = filename[:] prelink_tmpfile = PRIVATE_PATH + "/prelink-checksum.tmp." + str( os.getpid()) mylock = None if calc_prelink and prelink_capable: mylock = portage_locks.lockfile(prelink_tmpfile, wantnewlockfile=1) # Create non-prelinked temporary file to md5sum. # Raw data is returned on stdout, errors on stderr. # Non-prelinks are just returned. try: shutil.copy2(filename, prelink_tmpfile) except SystemExit, e: raise except Exception, e: portage_util.writemsg("!!! Unable to copy file '" + str(filename) + "'.\n") portage_util.writemsg("!!! " + str(e) + "\n") sys.exit(1)
def __getitem__(self, mykey): match = '' for x in self.lookuplist: if x == None: writemsg("!!! lookuplist is null.\n") elif x.has_key(mykey): match = x[mykey] break if 0 and match and mykey in ["PORTAGE_BINHOST"]: # These require HTTP Encoding try: import urllib if urllib.unquote(match) != match: writemsg("Note: %s already contains escape codes." % (mykey)) else: match = urllib.quote(match) except SystemExit, e: raise except:
def lockfile(mypath,wantnewlockfile=0,unlinkfile=0,verbosity=0): """Creates all dirs upto, the given dir. Creates a lockfile for the given directory as the file: directoryname+'.portage_lockfile'.""" import fcntl if not mypath: raise portage_exception.InvalidData, "Empty path given" if type(mypath) == types.StringType and mypath[-1] == '/': mypath = mypath[:-1] if type(mypath) == types.FileType: mypath = mypath.fileno() if type(mypath) == types.IntType: lockfilename = mypath wantnewlockfile = 0 unlinkfile = 0 elif wantnewlockfile: lockfilename = mypath+".portage_lockfile" unlinkfile = 1 else: lockfilename = mypath if type(mypath) == types.StringType: if not os.path.exists(os.path.dirname(mypath)): raise portage_exception.DirectoryNotFound, os.path.dirname(mypath) if not os.path.exists(lockfilename): old_mask=os.umask(000) myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660) try: if os.stat(lockfilename).st_gid != portage_data.portage_gid: os.chown(lockfilename,os.getuid(),portage_data.portage_gid) except SystemExit, e: raise except OSError, e: if e[0] == 2: #XXX: No such file or directory return lockfile(mypath,wantnewlockfile,unlinkfile) else: portage_util.writemsg("Cannot chown a lockfile. This could cause inconvenience later.\n",verbosity) os.umask(old_mask)
def load_infodir(self, infodir): if self.configdict.has_key("pkg"): self.configdict["pkg"].clear() else: writemsg("No pkg setup for settings instance?\n") sys.exit(17) if os.path.exists(infodir): if os.path.exists(infodir + "/environment"): self.configdict["pkg"][ "PORT_ENV_FILE"] = infodir + "/environment" elif os.path.exists(infodir + "/environment.bz2"): self.configdict["pkg"][ "PORT_ENV_FILE"] = infodir + "/environment.bz2" # else: # print "wth, no env found in the infodir, '%s'" % infodir # import traceback # traceback.print_stack() # sys.exit(15) myre = re.compile('^[A-Z]+$') for filename in listdir(infodir, filesonly=1): if myre.match(filename): try: mydata = open(infodir + "/" + filename).read().strip() if len(mydata) < 2048: if filename == "USE": self.configdict["pkg"][ filename] = "-* " + mydata else: self.configdict["pkg"][filename] = mydata except SystemExit, e: raise except: writemsg("!!! Unable to read file: %s\n" % infodir + "/" + filename) pass
from output import green, red ostype = os.uname()[0] lchown = None if ostype == "Linux": userland = "GNU" os.environ["XARGS"] = "xargs -r" elif ostype in ["Darwin", "FreeBSD", "OpenBSD"]: if ostype == "Darwin": lchown = os.chown userland = "BSD" os.environ["XARGS"] = "xargs" else: writemsg( red("Operating system") + " \"" + ostype + "\" " + red("currently unsupported. Exiting.") + "\n") sys.exit(1) if not lchown: if "lchown" in dir(os): # Included in python-2.3 lchown = os.lchown else: import missingos lchown = missingos.lchown os.environ["USERLAND"] = userland #Secpass will be set to 1 if the user is root or in the portage group. secpass = 0
def regenerate(self, useonly=0, use_cache=1): if self.already_in_regenerate: # XXX: THIS REALLY NEEDS TO GET FIXED. autouse() loops. writemsg("!!! Looping in regenerate.\n", 1) return else: self.already_in_regenerate = 1 if useonly: myincrementals = ["USE"] else: myincrementals = self.incrementals[:] # XXX HACK, harring # this is a design flaw of the code. from portage import db, root rootdb = db.get(root) for mykey in myincrementals: if mykey == "USE": mydbs = self.uvlist # XXX Global usage of db... Needs to go away somehow. if rootdb and "vartree" in rootdb: _use = self.autouse(rootdb["vartree"], use_cache=use_cache) else: _use = "" self.configdict["auto"]["USE"] = _use else: mydbs = self.configlist[:-1] myflags = [] for curdb in mydbs: if mykey not in curdb: continue #variables are already expanded mysplit = curdb[mykey].split() for x in mysplit: if x == "-*": # "-*" is a special "minus" var that means "unset all settings". # so USE="-* gnome" will have *just* gnome enabled. myflags = [] continue if x[0] == "+": # Not legal. People assume too much. Complain. writemsg( red("USE flags should not start with a '+': %s\n" % x)) x = x[1:] if x[0] == "-": if x[1:] in myflags: # Unset/Remove it. myflags.remove(x[1:]) continue # We got here, so add it now. if x not in myflags: myflags.append(x) myflags.sort() #store setting in last element of configlist, the original environment: self.configlist[-1][mykey] = " ".join(myflags) del myflags #cache split-up USE var in a global usesplit = [] for x in self.configlist[-1]["USE"].split(): if x not in self.usemask: usesplit.append(x) if self.has_key("USE_EXPAND"): for var in self["USE_EXPAND"].split(): if self.has_key(var): for x in self[var].split(): mystr = var.lower() + "_" + x if mystr not in usesplit: usesplit.append(mystr) # Pre-Pend ARCH variable to USE settings so '-*' in env doesn't kill arch. # XXX: harring wonders why profiledir is checked here... from portage import profiledir if profiledir: if self.configdict["defaults"].has_key("ARCH"): if self.configdict["defaults"]["ARCH"]: if self.configdict["defaults"]["ARCH"] not in usesplit: usesplit.insert(0, self.configdict["defaults"]["ARCH"]) self.configlist[-1]["USE"] = " ".join(usesplit) self.already_in_regenerate = 0
def __init__(self, clone=None, mycpv=None, config_profile_path=portage_const.PROFILE_PATH, config_incrementals=None): self.already_in_regenerate = 0 self.locked = 0 self.mycpv = None self.puse = [] self.modifiedkeys = [] self.virtuals = {} self.v_count = 0 if clone: self.clone(clone) else: self.depcachedir = portage_const.DEPCACHE_PATH if not os.path.exists(config_profile_path): writemsg("config_profile_path not specified to class config\n") sys.exit(1) self.profile_path = config_profile_path if not config_incrementals: import traceback traceback.print_stack() writemsg("incrementals not specified to class config\n") writemsg("sayonara, sucker.\n") sys.exit(1) self.incrementals = copy.deepcopy(config_incrementals) self.module_priority = ["user", "default"] self.modules = {} self.modules["user"] = getconfig(portage_const.MODULES_FILE_PATH) if self.modules["user"] == None: self.modules["user"] = {} self.modules["default"] = { "portdbapi.metadbmodule": "cache.metadata.database", "portdbapi.auxdbmodule": "cache.flat_list.database", } self.usemask = [] self.configlist = [] self.backupenv = {} # back up our incremental variables: self.configdict = {} # configlist will contain: [ globals, defaults, conf, pkg, auto, backupenv (incrementals), origenv ] # The symlink might not exist or might not be a symlink. try: self.profiles = [abssymlink(self.profile_path)] except (OSError, IOError): self.profiles = [self.profile_path] mypath = self.profiles[0] while os.path.exists(mypath + "/parent"): mypath = os.path.normpath(mypath + "///" + grabfile(mypath + "/parent")[0]) if os.path.exists(mypath): self.profiles.insert(0, mypath) if os.environ.get("PORTAGE_CALLER", '') == "repoman": pass else: # XXX: This should depend on ROOT? if os.path.exists("/" + portage_const.CUSTOM_PROFILE_PATH): self.profiles.append("/" + portage_const.CUSTOM_PROFILE_PATH) self.packages_list = grab_multiple("packages", self.profiles, grabfile_package) self.packages = stack_lists(self.packages_list, incremental=1) del self.packages_list #self.packages = grab_stacked("packages", self.profiles, grabfile, incremental_lines=1) # revmaskdict self.prevmaskdict = {} for x in self.packages: mycatpkg = portage_dep.dep_getkey(x) if not self.prevmaskdict.has_key(mycatpkg): self.prevmaskdict[mycatpkg] = [x] else: self.prevmaskdict[mycatpkg].append(x) # get profile-masked use flags -- INCREMENTAL Child over parent usemask_lists = grab_multiple("use.mask", self.profiles, grabfile) self.usemask = stack_lists(usemask_lists, incremental=True) del usemask_lists use_defs_lists = grab_multiple("use.defaults", self.profiles, grabdict) self.use_defs = stack_dictlist(use_defs_lists, incremental=True) del use_defs_lists try: mygcfg_dlists = grab_multiple("make.globals", self.profiles + ["/etc"], getconfig) self.mygcfg = stack_dicts( mygcfg_dlists, incrementals=portage_const.INCREMENTALS, ignore_none=1) if self.mygcfg == None: self.mygcfg = {} except SystemExit, e: raise except Exception, e: writemsg("!!! %s\n" % (e)) writemsg( "!!! Incorrect multiline literals can cause this. Do not use them.\n" ) writemsg( "!!! Errors in this file should be reported on bugs.gentoo.org.\n" ) sys.exit(1)
"!!! not then please report this to bugs.gentoo.org and, if possible, a dev\n" ) writemsg("!!! on #gentoo (irc.freenode.org)\n") sys.exit(1) self.configlist.append(self.mygcfg) self.configdict["defaults"] = self.configlist[-1] try: # XXX: Should depend on root? self.mygcfg = getconfig("/" + portage_const.MAKE_CONF_FILE) if self.mygcfg == None: self.mygcfg = {} except SystemExit, e: raise except Exception, e: writemsg("!!! %s\n" % (e)) writemsg( "!!! Incorrect multiline literals can cause this. Do not use them.\n" ) sys.exit(1) self.configlist.append(self.mygcfg) self.configdict["conf"] = self.configlist[-1] self.configlist.append({}) self.configdict["pkg"] = self.configlist[-1] #auto-use: self.configlist.append({}) self.configdict["auto"] = self.configlist[-1]
# try for a non-blocking lock, if it's held, throw a message # we're waiting on lockfile and use a blocking attempt. locking_method = None link_success=False for locking_method in (fcntl.flock, fcntl.lockf): try: locking_method(myfd,fcntl.LOCK_EX|fcntl.LOCK_NB) link_success=True break except IOError, e: if "errno" not in dir(e): raise if e.errno == errno.EAGAIN: # resource temp unavailable; eg, someone beat us to the lock. if type(mypath) == types.IntType: portage_util.writemsg("waiting for lock on fd %i\n" % myfd,verbosity) else: portage_util.writemsg("waiting for lock on %s\n" % lockfilename,verbosity) # try for the exclusive lock now. locking_method(myfd,fcntl.LOCK_EX) elif e.errno == errno.ENOLCK: pass else: raise if not link_success: # We're not allowed to lock on this FS. os.close(myfd) link_success = False if lockfilename == str(lockfilename):
ftype = [] for x in list: try: pathstat = os.lstat(mypath + "/" + x) if stat.S_ISREG(pathstat[stat.ST_MODE]): ftype.append(0) elif stat.S_ISDIR(pathstat[stat.ST_MODE]): ftype.append(1) elif stat.S_ISLNK(pathstat[stat.ST_MODE]): pathstat = os.stat(mypath + "/" + x) if stat.S_ISREG(pathstat[stat.ST_MODE]): ftype.append(2) elif stat.S_ISDIR(pathstat[stat.ST_MODE]): ftype.append(3) else: ftype.append(4) except SystemExit, e: raise except: ftype.append(3) dircache[mypath] = mtime, list, ftype return list[:], ftype[:] portage_util.writemsg( "cacheddirStats: H:%d/M:%d/S:%d\n" % (cacheHit, cacheMiss, cacheStale), 10) return ret_list, ret_ftype
def process_phase(self,phase,mysettings,myebuild,myroot,allstages=False,**keywords): """the public 'doebuild' interface- all phases are called here, along w/ a valid config allstages is the equivalent of 'do merge, and all needed phases to get to it' **keywords is options passed on to __adjust_env. It will be removed as __adjust_env is digested""" from portage import merge,unmerge,features validcommands = ["help","clean","prerm","postrm","preinst","postinst", "config","setup","depend","fetch","digest", "unpack","compile","test","install","rpm","qmerge","merge", "package","unmerge", "manifest"] if phase not in validcommands: validcommands.sort() writemsg("!!! doebuild: '%s' is not one of the following valid commands:" % phase) for vcount in range(len(validcommands)): if vcount%6 == 0: writemsg("\n!!! ") writemsg(string.ljust(validcommands[vcount], 11)) writemsg("\n") return 1 retval=self.__adjust_env(phase,mysettings,myebuild,myroot,**keywords) if retval: return retval if "userpriv" in features: sandbox = ("usersandbox" in features) else: sandbox = ("sandbox" in features) droppriv=(("userpriv" in features) and \ ("nouserpriv" not in string.split(mysettings["PORTAGE_RESTRICT"])) and portage_exec.userpriv_capable) use_fakeroot=(("userpriv_fakeroot" in features) and droppriv and portage_exec.fakeroot_capable) # basically a nasty graph of 'w/ this phase, have it userprived/sandboxed/fakeroot', and run # these phases prior actionmap={ "depend": { "sandbox":False, "userpriv":True, "fakeroot":False}, "setup": { "sandbox":True, "userpriv":False, "fakeroot":False}, "unpack": {"dep":"setup", "sandbox":sandbox, "userpriv":True, "fakeroot":False}, "compile": {"dep":"unpack", "sandbox":sandbox,"userpriv":True, "fakeroot":False}, "test": {"dep":"compile","sandbox":sandbox,"userpriv":True, "fakeroot":False}, "install": {"dep":"test", "sandbox":(not use_fakeroot or (not use_fakeroot and sandbox)), "userpriv":use_fakeroot,"fakeroot":use_fakeroot}, "rpm": {"dep":"install","sandbox":False, "userpriv":use_fakeroot, "fakeroot":use_fakeroot}, "package": {"dep":"install", "sandbox":False, "userpriv":use_fakeroot, "fakeroot":use_fakeroot}, "merge" : {"dep":"install", "sandbox":True, "userpriv":False, "fakeroot":False} } merging=False # this shouldn't technically ever be called, get_keys exists for this. # left in for compatability while portage.doebuild still exists if phase=="depend": return retval elif phase=="unmerge": return unmerge(mysettings["CATEGORY"],mysettings["PF"],myroot,mysettings) elif phase in ["fetch","digest","manifest","clean"]: return retval elif phase=="merge": merging=True elif phase=="qmerge": #no phases ran. phase="merge" merging=True # return merge(mysettings["CATEGORY"],mysettings["PF"],mysettings["D"],mysettings["PORTAGE_BUILDDIR"]+"/build-info",myroot,\ # mysettings) elif phase in ["help","clean","prerm","postrm","preinst","postinst","config"]: self.__ebp = request_ebuild_processor(userpriv=False) self.__ebp.write("process_ebuild %s" % phase) self.__ebp.send_env(mysettings) self.__ebp.set_sandbox_state(phase in ["help","clean"]) self.__ebp.write("start_processing") retval = self.__generic_phase([],mysettings) release_ebuild_processor(self.__ebp) self.__ebp = None return not retval k=phase # represent the phases to run, grouping each phase based upon if it's sandboxed, fakerooted, and userpriv'd # ugly at a glance, but remember a processor can run multiple phases now. # best to not be wasteful in terms of env saving/restoring, and just run all applicable phases in one shot phases=[[[phase]]] sandboxed=[[actionmap[phase]["sandbox"]]] privs=[(actionmap[phase]["userpriv"],actionmap[phase]["fakeroot"])] if allstages: while actionmap[k].has_key("dep"): k=actionmap[k]["dep"] if actionmap[k]["userpriv"] != privs[-1][0] or actionmap[k]["fakeroot"] != privs[-1][1]: phases.append([[k]]) sandboxed.append([actionmap[k]["sandbox"]]) privs.append((actionmap[k]["userpriv"],actionmap[k]["fakeroot"])) elif actionmap[k]["sandbox"] != sandboxed[-1][-1]: phases[-1].append([k]) sandboxed[-1].extend([actionmap[k]["sandbox"]]) else: phases[-1][-1].append(k) privs.reverse() phases.reverse() sandboxed.reverse() for x in phases: for y in x: y.reverse() x.reverse() # and now we have our phases grouped in parallel to the sandbox/userpriv/fakeroot state. all_phases = portage_util.flatten(phases) # print "all_phases=",all_phases # print "phases=",phases # print "sandbox=",sandboxed # print "privs=",privs # sys.exit(1) # print "\n\ndroppriv=",droppriv,"use_fakeroot=",use_fakeroot,"\n\n" #temporary hack until sandbox + fakeroot (if ever) play nice. while privs: if self.__ebp == None or (droppriv and self.__ebp.userprived() != privs[0][0]) or \ (use_fakeroot and self.__ebp.fakerooted() != privs[0][1]): if self.__ebp != None: print "swapping processors for",phases[0][0] release_ebuild_processor(self.__ebp) self.__ebp = None opts={} #only engage fakeroot when userpriv'd if use_fakeroot and privs[0][1]: opts["save_file"] = mysettings["T"]+"/fakeroot_db" self.__ebp = request_ebuild_processor(userpriv=(privs[0][0] and droppriv), \ fakeroot=(privs[0][1] and use_fakeroot), \ sandbox=(not (privs[0][1] and use_fakeroot) and portage_exec.sandbox_capable),**opts) #loop through the instances where the processor must have the same sandboxed state- #note a sandbox'd process can have it's sandbox disabled. #this seperation is needed since you can't mix sandbox and fakeroot atm. for sandbox in sandboxed[0]: if "merge" in phases[0][0]: if len(phases[0][0]) == 1: print "skipping this phase, it's just merge" continue phases[0][0].remove("merge") self.__ebp.write("process_ebuild %s" % string.join(phases[0][0]," ")) self.__ebp.send_env(mysettings) self.__ebp.set_sandbox_state(sandbox) self.__ebp.write("start_processing") phases[0].pop(0) retval = not self.__generic_phase([],mysettings) if retval: release_ebuild_processor(self.__ebp) self.__ebp = None return retval sandboxed.pop(0) privs.pop(0) phases.pop(0) # hey hey. we're done. Now give it back. release_ebuild_processor(self.__ebp) self.__ebp = None # packaging moved out of ebuild.sh, and into this code. # makes it so ebuild.sh no longer must run as root for the package phase. if "package" in all_phases: print "processing package" #mv "${PF}.tbz2" "${PKGDIR}/All" if not os.path.exists(mysettings["PKGDIR"]+"/All"): os.makedirs(mysettings["PKGDIR"]+"/All") if not os.path.exists(mysettings["PKGDIR"]+"/"+mysettings["CATEGORY"]): os.makedirs(mysettings["PKGDIR"]+"/"+mysettings["CATEGORY"]) if os.path.exists("%s/All/%s.tbz2" % (mysettings["PKGDIR"],mysettings["PF"])): os.remove("%s/All/%s.tbz2" % (mysettings["PKGDIR"],mysettings["PF"])) retval = not portage_util.movefile("%s/%s.tbz2" % (mysettings["PORTAGE_BUILDDIR"],mysettings["PF"]), mysettings["PKGDIR"]+"/All/"+mysettings["PF"]+".tbz2") > 0 if retval: return False if os.path.exists("%s/%s/%s.tbz2" % (mysettings["PKGDIR"],mysettings["CATEGORY"],mysettings["PF"])): os.remove("%s/%s/%s.tbz2" % (mysettings["PKGDIR"],mysettings["CATEGORY"],mysettings["PF"])) os.symlink("%s/All/%s.tbz2" % (mysettings["PKGDIR"],mysettings["PF"]), "%s/%s/%s.tbz2" % (mysettings["PKGDIR"],mysettings["CATEGORY"],mysettings["PF"])) #same as the package phase above, removes the root requirement for the rpm phase. if "rpm" in all_phases: rpm_name="%s-%s-%s" % (mysettings["PN"],mysettings["PV"],mysettings["PR"]) retval = not portage_util.movefile("%s/%s.tar.gz" % (mysettings["T"],mysettings["PF"]), "/usr/src/redhat/SOURCES/%s.tar.gz" % mysettings["PF"]) > 0 if retval: print "moving src for rpm failed, retval=",retval return False retval=portage_exec.spawn(("rpmbuild","-bb","%s/%s.spec" % \ (mysettings["PORTAGE_BUILDDIR"],mysettings["PF"]))) if retval: print "Failed to integrate rpm spec file" return retval if not os.path.exists(mysettings["RPMDIR"]+"/"+mysettings["CATEGORY"]): os.makedirs(mysettings["RPMDIR"]+"/"+mysettings["CATEGORY"]) retval = not portage_util.movefile("/usr/src/redhat/RPMS/i386/%s.i386.rpm" % rpm_name, "%s/%s/%s.rpm" % (mysettings["RPMDIR"],mysettings["CATEGORY"],rpm_name)) > 0 if retval: print "rpm failed" return retval # not great check, but it works. # basically, if FEATURES="-buildpkg" emerge package was called, the files in the current # image directory don't have their actual perms. so we use an ugly bit of bash # to make the fakeroot (claimed) permissions/owners a reality. if use_fakeroot and os.path.exists(mysettings["T"]+"/fakeroot_db") and merging: print "correcting fakeroot privs" retval=portage_exec.spawn(("/usr/lib/portage/bin/affect-fakeroot-perms.sh", \ mysettings["T"]+"/fakeroot_db", \ mysettings["D"]),env={"BASHRC":portage_const.INVALID_ENV_FILE}) if retval or retval == None: print red("!!!")+"affecting fakeroot perms after the fact failed" return retval if merging: print "processing merge" retval = merge(mysettings["CATEGORY"],mysettings["PF"],mysettings["D"],mysettings["PORTAGE_BUILDDIR"]+"/build-info",myroot,\ mysettings,myebuild=mysettings["EBUILD"]) return retval
def __adjust_env(self,mydo,mysettings,myebuild,myroot,debug=0,listonly=0,fetchonly=0,cleanup=0,dbkey=None,\ use_cache=1,fetchall=0,tree="porttree",use_info_env=True,verbosity=0): """formerly portage.doebuild, since it's specific to ebuilds, it's now a method of ebuild handling. severely gutted, and in need of cleansing/exorcism""" from portage import db,ExtractKernelVersion,fetch,features, \ digestgen,digestcheck,root,flatten, digestParseFile from portage_data import portage_uid,portage_gid,secpass import portage_dep from portage_util import writemsg ebuild_path = os.path.abspath(myebuild) pkg_dir = os.path.dirname(ebuild_path) if mysettings.configdict["pkg"].has_key("CATEGORY"): cat = mysettings.configdict["pkg"]["CATEGORY"] else: cat = os.path.basename(os.path.normpath(pkg_dir+"/..")) mypv = os.path.basename(ebuild_path)[:-7] mycpv = cat+"/"+mypv mysplit=portage_versions.pkgsplit(mypv,silent=0) if mysplit==None: writemsg("!!! Error: PF is null '%s'; exiting.\n" % mypv) return 1 if mydo == "clean": cleanup=True if mydo != "depend": # XXX: We're doing a little hack here to curtain the gvisible locking # XXX: that creates a deadlock... Really need to isolate that. mysettings.reset(use_cache=use_cache) mysettings.setcpv(mycpv,use_cache=use_cache) if not os.path.exists(myebuild): writemsg("!!! doebuild: "+str(myebuild)+" not found for "+str(mydo)+"\n") return 1 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"]=str(debug) mysettings["ROOT"] = myroot mysettings["EBUILD"] = ebuild_path mysettings["O"] = pkg_dir mysettings["CATEGORY"] = cat mysettings["FILESDIR"] = pkg_dir+"/files" mysettings["PF"] = mypv mysettings["ECLASSDIR"] = mysettings["PORTDIR"]+"/eclass" mysettings["PROFILE_PATHS"] = PROFILE_PATH+"\n"+CUSTOM_PROFILE_PATH mysettings["P"] = mysplit[0]+"-"+mysplit[1] mysettings["PN"] = mysplit[0] mysettings["PV"] = mysplit[1] mysettings["PR"] = mysplit[2] # ensure this is set for all phases, setup included. # Should be ok again to set $T, as sandbox does not depend on it mysettings["BUILD_PREFIX"] = mysettings["PORTAGE_TMPDIR"]+"/portage" mysettings["PORTAGE_BUILDDIR"] = mysettings["BUILD_PREFIX"]+"/"+mysettings["PF"] mysettings["T"] = mysettings["PORTAGE_BUILDDIR"]+"/temp" mysettings["WORKDIR"] = mysettings["PORTAGE_BUILDDIR"]+"/work" mysettings["D"] = mysettings["PORTAGE_BUILDDIR"]+"/image/" # bailing now, probably horks a few things up, but neh. # got to break a few eggs to make an omelot after all (spelling is wrong, too) :) if mydo=="unmerge": return 0 if mydo!="depend": try: mysettings["INHERITED"],mysettings["RESTRICT"] = db[root][tree].dbapi.aux_get( mycpv,["INHERITED","RESTRICT"]) mysettings["PORTAGE_RESTRICT"]=string.join(flatten(portage_dep.use_reduce( portage_dep.paren_reduce(mysettings["RESTRICT"]), uselist=mysettings["USE"].split() )),' ') except SystemExit, e: raise except Exception, e: print "caught exception %s in ebd_proc:doebuild" % str(e) mysettings["RESTRICT"] = mysettings["PORTAGE_RESTRICT"] = "" pass
mysettings["KV"]=mykv else: mysettings["KV"]="" if (mydo!="depend") or not mysettings.has_key("KVERS"): myso=os.uname()[2] mysettings["KVERS"]=myso[1] # get possible slot information from the deps file if mydo=="depend": if mysettings.has_key("PORTAGE_DEBUG") and mysettings["PORTAGE_DEBUG"]=="1": # XXX: This needs to use a FD for saving the output into a file. # XXX: Set this up through spawn pass writemsg("!!! DEBUG: dbkey: %s\n" % str(dbkey),2) if dbkey: mysettings["dbkey"] = dbkey else: mysettings["dbkey"] = mysettings.depcachedir+"/aux_db_key_temp" return 0 mysettings["PORTAGE_LOGFILE"]='' logfile=None #fetch/digest crap if mydo not in ["prerm","postrm","preinst","postinst","config","help","setup","unmerge"]: newuris, alist = db["/"]["porttree"].dbapi.getfetchlist(mycpv,mysettings=mysettings)