--- /usr/bin/emerge 2005-04-22 22:08:03.000000000 -0700 +++ emerge 2005-05-16 23:11:15.000000000 -0700 @@ -863,7 +863,7 @@ if "--usepkg" in myopts: portage.db["/"]["bintree"].populate(("--getbinpkg" in myopts), ("--getbinpkgonly" in myopts)) - def create(self,mybigkey,myparent=None,addme=1,myuse=None): + def create(self,mybigkey,myparent=None,addme=1,myuse=None,mylicenses=None): """creates the actual digraph of packages to merge. return 1 on success, 0 on failure mybigkey = specification of package to merge; myparent = parent package (one depending on me); addme = should I be added to the tree? (for the --onlydeps mode)""" @@ -873,6 +873,36 @@ #"no downgrade" emerge #print "mybigkey:",mybigkey + # get ACCEPT_LICENSES from if haven't done so already + # does this code only include make.conf?? + # this gets done multiple times - need to fix + if mylicenses == None: + accept_licenses = string.split(portage.settings['ACCEPT_LICENSE']) + mylicenses = [] + for x in accept_licenses: + if x == "*": + for y in [portage.settings['PORTDIR']+"/licenses", portage.settings["PORTDIR_OVERLAY"]+"/licenses"]: + if os.access(y,os.F_OK): + for z in os.listdir(y): + if z not in mylicenses: + mylicenses.append(z) + if x == "-*": + mylicenses = [] + continue + if x[0] != "+" and x[0] != "-": + add = x + rem = x + elif x[0] == "+": + rem = x[1:] + add = x[1:] + else: + rem = x[1:] + add = "" + while rem in mylicenses: + mylicenses.remove(rem) + if add != "": + mylicenses.append(add) + jbigkey=string.join(mybigkey) if self.digraph.hasnode(jbigkey+" merge") or self.digraph.hasnode(jbigkey+" nomerge"): #this conditional is needed to prevent infinite recursion on already-processed deps @@ -923,6 +953,25 @@ else: #onlydeps mode; don't merge merging=2 + + pkg_licenses = portage.portdb.aux_get(mybigkey[2], ["LICENSE"])[0] + # the assumption here is that | means OR and that AND takes precedence + # i.e. "(foo bar) | license" would be "foo bar | license" + # parenthesis should not be necessary unless + # there is a need for "(foo1 | foo2) (bar1 | bar2)" + for license_group in string.split(pkg_licenses,"|"): + license_accepted = 1 + for license in string.split(license_group): + if license not in mylicenses: + license_accepted = 0 + break + if license_accepted == 1: + break + # if license is missing, do the same as for blockers + if license_accepted == 0: + mybigkey[0]="license" + mybigkey.append(string.replace(pkg_licenses, "|", "OR")) + if merging==1: mybigkey.append("merge") else: @@ -931,6 +980,12 @@ # whatever the case, we need to add the node to our digraph so # that children can depend upon it. self.digraph.addnode(string.join(mybigkey),myparent) + + # return here else get into an infinite loop + # when using --deep or --emptytree + if (mybigkey[0]=="license"): + return 1 + if ("deep" not in myparams) and (not merging): return 1 elif "recurse" not in myparams: @@ -972,20 +1027,20 @@ if myroot=="/": mydep["/"]=edepend["DEPEND"]+" "+edepend["RDEPEND"] - if not self.select_dep("/",mydep["/"],myparent=mp,myuse=myuse): + if not self.select_dep("/",mydep["/"],myparent=mp,myuse=myuse,mylicenses=mylicenses): return 0 else: mydep["/"]=edepend["DEPEND"] mydep[myroot]=edepend["RDEPEND"] - if not self.select_dep("/",mydep["/"],myparent=mp,myuse=myuse): + if not self.select_dep("/",mydep["/"],myparent=mp,myuse=myuse,mylicenses=mylicenses): return 0 - if not self.select_dep(myroot,mydep[myroot],myparent=mp,myuse=myuse): + if not self.select_dep(myroot,mydep[myroot],myparent=mp,myuse=myuse,mylicenses=mylicenses): return 0 if edepend.has_key("PDEPEND") and edepend["PDEPEND"]: # Post Depend -- Add to the list without a parent, as it depends # on a package being present AND must be built after that package. - if not self.select_dep(myroot,edepend["PDEPEND"],myuse=myuse): + if not self.select_dep(myroot,edepend["PDEPEND"],myuse=myuse,mylicenses=mylicenses): return 0 return 1 @@ -1100,7 +1155,7 @@ if curslot == myslot: return match - def select_dep(self,myroot,depstring,myparent=None,arg=None,myuse=None): + def select_dep(self,myroot,depstring,myparent=None,arg=None,myuse=None,mylicenses=None): "given a dependency string, create the appropriate depgraph and return 1 on success and 0 on failure" if "--debug" in myopts: print @@ -1258,12 +1313,12 @@ # myk=["ebuild",myroot,myeb] if myparent: #we are a dependency, so we want to be unconditionally added - if not self.create(myk,myparent,myuse=binpkguseflags): + if not self.create(myk,myparent,myuse=binpkguseflags,mylicenses=mylicenses): return 0 else: #if mysource is not set, then we are a command-line dependency and should not be added #if --onlydeps is specified. - if not self.create(myk,myparent,"--onlydeps" not in myopts,myuse=binpkguseflags): + if not self.create(myk,myparent,"--onlydeps" not in myopts,myuse=binpkguseflags,mylicenses=mylicenses): return 0 if "--debug" in myopts: @@ -1448,6 +1503,13 @@ print red("(is blocking "+x[3]+")") else: print + elif x[0]=="license": + # As "license" is 7 characters, didn't include a symbolic letter + addl=" "+fetch+" " + resolved=portage.db[x[1]]["vartree"].resolve_key(x[2]) + # Is it just me or is there too much red? + print "["+red(x[0]+" "+addl)+"]",red(resolved), + print red("("+x[3]+")") else: if (x[0]!="binary") and ("fetch" in string.split(portage.portdb.aux_get(x[2],["RESTRICT"])[0])): fetch = red("F") @@ -1721,6 +1783,15 @@ print if ("--pretend" not in myopts): sys.exit(1) + + if x[0]=="license": + print "\n!!! Error: License(s) required by " + x[2] + print "!!! Please ensure that ACCEPT_LICENSE contains:" + print "!!! " +x[3] + # Is this necessary? When I emerge with --pretend, it never gets here. + if ("--pretend" not in myopts): + sys.exit(1) + #buildsyspkg: I need mysysdict also on resume (moved from the else block) mysysdict=genericdict(syslist) @@ -2760,7 +2831,7 @@ myvars = ['GENTOO_MIRRORS', 'CONFIG_PROTECT', 'CONFIG_PROTECT_MASK', 'PORTDIR', 'DISTDIR', 'PKGDIR', 'PORTAGE_TMPDIR', 'PORTDIR_OVERLAY', 'USE', 'CHOST', 'CFLAGS', 'CXXFLAGS', - 'ACCEPT_KEYWORDS', 'SYNC', 'FEATURES'] + 'ACCEPT_KEYWORDS', 'SYNC', 'FEATURES','ACCEPT_LICENSE'] myvars.extend(portage_util.grabfile(portage.settings["PORTDIR"]+"/profiles/info_vars"))