Implement per-package default USE flags at the ebuild and profile levels for bug...
authorZac Medico <zmedico@gentoo.org>
Sat, 14 Oct 2006 04:07:49 +0000 (04:07 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 14 Oct 2006 04:07:49 +0000 (04:07 -0000)
svn path=/main/trunk/; revision=4679

bin/ebuild.sh
bin/emerge
bin/repoman
cnf/make.globals
pym/portage.py

index e3935e5936bef319bef98f411d820e2810c88eea..48a457a8f768df0a48bf66a08e51b95296e3e0b8 100755 (executable)
@@ -1514,6 +1514,17 @@ PDEPEND="$PDEPEND $E_PDEPEND"
 unset E_IUSE E_DEPEND E_RDEPEND E_PDEPEND
 
 if [ "${EBUILD_PHASE}" != "depend" ]; then
+       # Make IUSE defaults backward compatible with all the old shell code.
+       iuse_temp=""
+       for x in ${IUSE} ; do
+               if [[ ${x} == +* ]]; then
+                       iuse_temp="${iuse_temp} ${x:1}"
+               else
+                       iuse_temp="${iuse_temp} ${x}"
+               fi
+       done
+       export IUSE=${iuse_temp}
+       unset iuse_temp
        # Lock the dbkey variables after the global phase
        declare -r DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE DESCRIPTION
        declare -r KEYWORDS INHERITED IUSE PDEPEND PROVIDE
index cd03a3df78be6e74c099beea4d312bf489185b92..e167ba7c1f508b782716a52eecf773d872544f1d 100755 (executable)
@@ -622,6 +622,13 @@ def genericdict(mylist):
                mynewdict[portage.dep_getkey(x)]=x
        return mynewdict
 
+def filter_iuse_defaults(iuse):
+       for flag in iuse:
+               if flag.startswith("+"):
+                       yield flag[1:]
+               else:
+                       yield flag
+
 class depgraph:
 
        pkg_tree_map = {
@@ -737,7 +744,7 @@ class depgraph:
                mydbapi = self.trees[myroot][self.pkg_tree_map[mytype]].dbapi
 
                if myuse is None:
-                       self.pkgsettings[myroot].setcpv(mykey)
+                       self.pkgsettings[myroot].setcpv(mykey, mydb=portdb)
                        myuse = self.pkgsettings[myroot]["USE"].split()
                self.useFlags[myroot][mykey] = myuse
 
@@ -755,15 +762,17 @@ class depgraph:
                            --newuse is specified, we need to merge the package. """
                        if merging==0 and "--newuse" in self.myopts and \
                                vardbapi.cpv_exists(mykey):
-                               pkgsettings.setcpv(mykey)
+                               pkgsettings.setcpv(mykey, mydb=portdb)
                                forced_flags = set()
                                forced_flags.update(pkgsettings.useforce)
                                forced_flags.update(pkgsettings.puseforce)
                                forced_flags.update(pkgsettings.usemask)
                                forced_flags.update(pkgsettings.pusemask)
                                old_use = vardbapi.aux_get(mykey, ["USE"])[0].split()
-                               iuses = set(mydbapi.aux_get(mykey, ["IUSE"])[0].split())
-                               old_iuse = set(vardbapi.aux_get(mykey, ["IUSE"])[0].split())
+                               iuses = set(filter_iuse_defaults(
+                                       mydbapi.aux_get(mykey, ["IUSE"])[0].split()))
+                               old_iuse = set(filter_iuse_defaults(
+                                       vardbapi.aux_get(mykey, ["IUSE"])[0].split()))
                                if iuses.symmetric_difference(
                                        old_iuse).difference(forced_flags):
                                        merging = 1
@@ -1158,9 +1167,10 @@ class depgraph:
                                                myeb_pkg = portage.best(myeb_pkg_matches)
 
                                if myeb_pkg and "--newuse" in self.myopts:
-                                       iuses = set(bindb.aux_get(myeb_pkg, ["IUSE"])[0].split())
+                                       iuses = set(filter_iuse_defaults(
+                                               bindb.aux_get(myeb_pkg, ["IUSE"])[0].split()))
                                        old_use = bindb.aux_get(myeb_pkg, ["USE"])[0].split()
-                                       pkgsettings.setcpv(myeb_pkg)
+                                       pkgsettings.setcpv(myeb_pkg, mydb=portdb)
                                        now_use = pkgsettings["USE"].split()
                                        forced_flags = set()
                                        forced_flags.update(pkgsettings.useforce)
@@ -1169,7 +1179,8 @@ class depgraph:
                                        forced_flags.update(pkgsettings.pusemask)
                                        cur_iuse = iuses
                                        if "--usepkgonly" not in self.myopts and myeb:
-                                               cur_iuse = set(portdb.aux_get(myeb, ["IUSE"])[0].split())
+                                               cur_iuse = set(filter_iuse_defaults(
+                                                       portdb.aux_get(myeb, ["IUSE"])[0].split()))
                                        if iuses.symmetric_difference(
                                                cur_iuse).difference(forced_flags):
                                                myeb_pkg = None
@@ -1613,7 +1624,7 @@ class depgraph:
                        bindb  = self.trees[myroot]["bintree"].dbapi
                        vartree = self.trees[myroot]["vartree"]
                        pkgsettings = self.pkgsettings[myroot]
-                       pkgsettings.setcpv(pkg_key)
+                       pkgsettings.setcpv(pkg_key, mydb=portdb)
                        if pkg_key not in self.useFlags[myroot]:
                                if "binary" == pkg_type:
                                        self.useFlags[myroot][pkg_key] = bindb.aux_get(
@@ -1683,7 +1694,8 @@ class depgraph:
                                
                                if pkg_key in self.useFlags[myroot]:
                                        # USE flag display
-                                       cur_iuse = mydbapi.aux_get(pkg_key, ["IUSE"])[0].split()
+                                       cur_iuse = list(filter_iuse_defaults(
+                                               mydbapi.aux_get(pkg_key, ["IUSE"])[0].split()))
 
                                        forced_flags = set()
                                        forced_flags.update(pkgsettings.useforce)
@@ -1704,7 +1716,8 @@ class depgraph:
                                                old_iuse, old_use = \
                                                        self.trees[x[1]]["vartree"].dbapi.aux_get(
                                                                pkg, ["IUSE", "USE"])
-                                               old_iuse = portage.unique_array(old_iuse.split())
+                                               old_iuse = list(set(
+                                                       filter_iuse_defaults(old_iuse.split())))
                                                old_iuse.sort()
                                                old_use = old_use.split()
                                                is_new = False
@@ -3382,6 +3395,7 @@ def action_info(settings, trees, myopts, myfiles):
        # passed on the command line
        mypkgs = []
        vardb = trees[settings["ROOT"]]["vartree"].dbapi
+       portdb = trees[settings["ROOT"]]["porttree"].dbapi
        for x in myfiles:
                mypkgs.extend(vardb.match(x))
 
@@ -3413,9 +3427,10 @@ def action_info(settings, trees, myopts, myfiles):
                                # so set diff_found so we know to print
                                if valuesmap[myvar] != global_vals[myvar]:
                                        diff_values[myvar] = valuesmap[myvar]
+                       valuesmap["IUSE"] = set(filter_iuse_defaults(valuesmap["IUSE"]))
                        valuesmap["USE"] = valuesmap["USE"].intersection(valuesmap["IUSE"])
                        pkgsettings.reset()
-                       pkgsettings.setcpv(pkg)
+                       pkgsettings.setcpv(pkg, mydb=portdb)
                        if valuesmap["IUSE"].intersection(pkgsettings["USE"].split()) != \
                                valuesmap["USE"]:
                                diff_values["USE"] = valuesmap["USE"]
index b8ab7312fac4f2e03afcab0f193e7b1707027f13..7b0a0fe6777d179ec48bff96cf91e84b92b24403 100755 (executable)
@@ -1059,7 +1059,12 @@ for x in scanlist:
                badlicsyntax = False
                badprovsyntax = False
                catpkg = catdir+"/"+y
-               myiuse = myaux["IUSE"].split() + repoman_settings.archlist()
+               myiuse = set(repoman_settings.archlist())
+               for myflag in myaux["IUSE"].split():
+                       if myflag.startswith("+"):
+                               myflag = myflag[1:]
+                       myiuse.add(myflag)
+
                type_list, badsyntax = [], []
                for mytype in ("DEPEND", "RDEPEND", "PDEPEND", "LICENSE", "PROVIDE"):
                        mydepstr = myaux[mytype]
@@ -1214,7 +1219,13 @@ for x in scanlist:
                        stats["ebuild.nesteddie"]=stats["ebuild.nesteddie"]+1
                        fails["ebuild.nesteddie"].append(x+"/"+y+".ebuild")
                # uselist checks - global
-               myuse = myaux["IUSE"].split()
+               myuse = []
+               default_use = []
+               for myflag in myaux["IUSE"].split():
+                       if myflag.startswith("+"):
+                               default_use.append(myflag)
+                               myflag = myflag[1:]
+                       myuse.append(myflag)
                for mypos in range(len(myuse)-1,-1,-1):
                        if myuse[mypos] and (myuse[mypos] in uselist):
                                del myuse[mypos]
@@ -1224,6 +1235,8 @@ for x in scanlist:
                        for mypos in range(len(myuse)-1,-1,-1):
                                if myuse[mypos] and (myuse[mypos] in luselist[mykey]):
                                        del myuse[mypos]
+               if default_use and myaux["EAPI"] == "0":
+                       myuse += default_use
                for mypos in range(len(myuse)):
                        stats["IUSE.invalid"]=stats["IUSE.invalid"]+1
                        fails["IUSE.invalid"].append(x+"/"+y+".ebuild: %s" % myuse[mypos])      
index a8bfa55aade0c1060c824f16ce1e45f4c62bb7db..96f3a5b36830abee0542cf4660b21a4fadb585e8 100644 (file)
@@ -61,7 +61,7 @@ CONFIG_PROTECT="/etc"
 CONFIG_PROTECT_MASK="/etc/env.d"
 
 # Disable auto-use
-USE_ORDER="env:pkg:conf:defaults"
+USE_ORDER="env:pkg:conf:pkgprofile:defaults:pkginternal"
 
 # Default ownership of installed files.
 PORTAGE_INST_UID="0"
index 71a582a6acbdfe2fb60ac4d603e840d1664c6f3a..eae73be78f47de5a54afd29618c01ae7155c32f8 100644 (file)
@@ -898,6 +898,7 @@ class config:
                        self.puseforcedict = copy.deepcopy(clone.puseforcedict)
                        self.puseforce     = copy.deepcopy(clone.puseforce)
                        self.puse     = copy.deepcopy(clone.puse)
+                       self.pkgprofileuse = copy.deepcopy(clone.pkgprofileuse)
                        self.mycpv    = copy.deepcopy(clone.mycpv)
 
                        self.configlist = copy.deepcopy(clone.configlist)
@@ -905,13 +906,15 @@ class config:
                        self.lookuplist.reverse()
                        self.configdict = {
                                "env.d":     self.configlist[0],
-                               "globals":   self.configlist[1],
-                               "defaults":  self.configlist[2],
-                               "conf":      self.configlist[3],
-                               "pkg":       self.configlist[4],
-                               "auto":      self.configlist[5],
-                               "backupenv": self.configlist[6],
-                               "env":       self.configlist[7] }
+                               "pkginternal": self.configlist[1],
+                               "globals":     self.configlist[2],
+                               "defaults":    self.configlist[3],
+                               "pkgprofile":  self.configlist[4],
+                               "conf":        self.configlist[5],
+                               "pkg":         self.configlist[6],
+                               "auto":        self.configlist[7],
+                               "backupenv":   self.configlist[8],
+                               "env":         self.configlist[9] }
                        self.profiles = copy.deepcopy(clone.profiles)
                        self.backupenv  = self.configdict["backupenv"]
                        self.pusedict   = copy.deepcopy(clone.pusedict)
@@ -979,6 +982,9 @@ class config:
                        self.configlist.append({})
                        self.configdict["env.d"] = self.configlist[-1]
 
+                       self.configlist.append({})
+                       self.configdict["pkginternal"] = self.configlist[-1]
+
                        # The symlink might not exist or might not be a symlink.
                        if self.profile_path is None:
                                self.profiles = []
@@ -1043,6 +1049,17 @@ class config:
                                self.pusemaskdict[cp][k] = v
                        del rawpusemask
 
+                       self.pkgprofileuse = {}
+                       rawprofileuse = [grabdict_package(
+                               os.path.join(x, "package.use"), juststrings=True) \
+                               for x in self.profiles]
+                       rawprofileuse = stack_dicts(rawprofileuse, incremental=True)
+                       for k, v in rawprofileuse.iteritems():
+                               cp = dep_getkey(k)
+                               self.pkgprofileuse.setdefault(cp, {})
+                               self.pkgprofileuse[cp][k] = v
+                       del rawprofileuse
+
                        self.useforce = stack_lists(
                                [grabfile(os.path.join(x, "use.force")) \
                                for x in self.profiles], incremental=True)
@@ -1097,6 +1114,9 @@ class config:
                        self.configlist.append(self.mygcfg)
                        self.configdict["defaults"]=self.configlist[-1]
 
+                       self.configlist.append({})
+                       self.configdict["pkgprofile"] = self.configlist[-1]
+
                        try:
                                self.mygcfg = getconfig(
                                        os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)),
@@ -1278,7 +1298,7 @@ class config:
                        # reasonable defaults; this is important as without USE_ORDER,
                        # USE will always be "" (nothing set)!
                        if "USE_ORDER" not in self:
-                               self.backupenv["USE_ORDER"] = "env:pkg:conf:defaults"
+                               self.backupenv["USE_ORDER"] = "env:pkg:conf:pkgprofile:defaults:pkginternal"
 
                        self["PORTAGE_GID"] = str(portage_gid)
                        self.backup_changes("PORTAGE_GID")
@@ -1441,6 +1461,8 @@ class config:
                        self.pusemask = []
                        self.puseforce = []
                        self.configdict["pkg"].clear()
+                       self.configdict["pkginternal"].clear()
+                       self.configdict["pkgprofile"].clear()
                self.regenerate(use_cache=use_cache)
 
        def load_infodir(self,infodir):
@@ -1484,12 +1506,25 @@ class config:
                        return 1
                return 0
 
-       def setcpv(self,mycpv,use_cache=1):
+       def setcpv(self, mycpv, use_cache=1, mydb=None):
                self.modifying()
                if self.mycpv == mycpv:
                        return
                self.mycpv = mycpv
                cp = dep_getkey(mycpv)
+               pkginternaluse = ""
+               if mydb:
+                       pkginternaluse = " ".join([x[1:] \
+                               for x in mydb.aux_get(mycpv, ["IUSE"])[0].split() \
+                               if x.startswith("+")])
+               self.configdict["pkginternal"]["USE"] = pkginternaluse
+               pkgprofileuse = ""
+               if cp in self.pkgprofileuse:
+                       best_match = best_match_to_list(
+                               self.mycpv, self.pkgprofileuse[cp].keys())
+                       if best_match:
+                               pkgprofileuse = self.pkgprofileuse[cp][best_match]
+               self.configdict["pkgprofile"]["USE"] = pkgprofileuse
                self.puse = ""
                if self.pusedict.has_key(cp):
                        self.pusekey = best_match_to_list(self.mycpv, self.pusedict[cp].keys())
@@ -2536,7 +2571,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m
                # 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)
+               mysettings.setcpv(mycpv, use_cache=use_cache, mydb=mydbapi)
 
        mysettings["EBUILD_PHASE"] = mydo