pclouds came up with an interesting patch to support per package environment 
variables. I've updated it a little but it still needs some more work. 
Essentially package.env would be a list of "<atom> <file> [<file> ...]" where 
file is then read using getconfig() from /etc/portage/env/<file>.

Using such an approach would also allow us to knock off bug #55708 
(debug.eclass). Having a file similar to the one attached 
in /etc/portage/env/ by default would allow a user to switch a package to 
debugging quite easily.

With a couple of small modifications to emerge to check FEATURES for 
"buildpkg" after the call to setcpv() is done rather than doing it once 
globally, this would also cover TGL's BUILD_PKGS addition too. Most package.* 
type things should be able to be killed off this way.

Thoughts?

--
Jason Stubbs
Index: pym/portage.py
===================================================================
--- pym/portage.py	(revision 2255)
+++ pym/portage.py	(working copy)
@@ -843,6 +843,7 @@
 		self.locked   = 0
 		self.mycpv    = None
 		self.puse     = []
+		self.penv     = []
 		self.modifiedkeys = []
 
 		self.virtuals = {}
@@ -888,6 +889,7 @@
 			                    "env":       self.configlist[6] }
 			self.profiles = copy.deepcopy(clone.profiles)
 			self.backupenv  = copy.deepcopy(clone.backupenv)
+			self.penvdict   = copy.deepcopy(clone.penvdict)
 			self.pusedict   = copy.deepcopy(clone.pusedict)
 			self.categories = copy.deepcopy(clone.categories)
 			self.pkeywordsdict = copy.deepcopy(clone.pkeywordsdict)
@@ -1054,6 +1056,7 @@
 			if os.environ.get("PORTAGE_CALLER","") == "repoman":
 				# repoman shouldn't use local settings.
 				locations = [self["PORTDIR"] + "/profiles"]
+				self.penvdict = {}
 				self.pusedict = {}
 				self.pkeywordsdict = {}
 				self.punmaskdict = {}
@@ -1064,6 +1067,15 @@
 					if os.path.isdir(ov+"/profiles"):
 						locations.append(ov+"/profiles")
 
+				#package.env
+				penvdict=grabdict_package(USER_CONFIG_PATH+"/package.env")
+				self.penvdict = {}
+				for key in penvdict.keys():
+					cp = dep_getkey(key)
+					if not self.penvdict.has_key(cp):
+						self.penvdict[cp] = {}
+					self.penvdict[cp][key] = penvdict[key]
+
 				pusedict=grabdict_package(USER_CONFIG_PATH+"/package.use")
 				self.pusedict = {}
 				for key in pusedict.keys():
@@ -1258,6 +1270,7 @@
 		self.modifiedkeys = []
 		if not keeping_pkg:
 			self.puse = ""
+			self.penv = ""
 			self.configdict["pkg"].clear()
 		self.regenerate(use_cache=use_cache)
 
@@ -1300,11 +1313,31 @@
 			self.pusekey = best_match_to_list(self.mycpv, self.pusedict[cp].keys())
 			if self.pusekey:
 				newpuse = string.join(self.pusedict[cp][self.pusekey])
-		if newpuse == self.puse:
+		newpenv = ""
+		if self.penvdict.has_key(cp):
+			self.penvkey = best_match_to_list(self.mycpv, self.penvdict[cp].keys())
+			if self.penvkey:
+				newpenv = self.penvdict[cp][self.penvkey]
+		if self.puse == newpuse and self.penv == newpenv:
 			return
 		self.puse = newpuse
+		self.penv = newpenv
 		self.configdict["pkg"]["PKGUSE"] = self.puse[:] # For saving to PUSE file
 		self.configdict["pkg"]["USE"]    = self.puse[:] # this gets appended to USE
+		for envname in self.penv:
+			penvfile = USER_CONFIG_PATH + "/env/" + envname
+			if not os.access(penvfile, os.R_OK):
+				writemsg("!!! Can't access package.env file %s\n" % penvfile)
+			else:
+				penvconfig = getconfig(penvfile)
+				if penvconfig is None:
+					writemsg("!!! Parsing error in %s\n" % penvfile)
+				else:
+					for penv in penvconfig.keys():
+						if penv in self.configdict["pkg"] and penv in INCREMENTALS:
+							self.configdict["pkg"][penv] += " "+penvconfig[penv]
+						else:
+							self.configdict["pkg"][penv] = penvconfig[penv]
 		self.reset(keeping_pkg=1,use_cache=use_cache)
 
 	def setinst(self,mycpv,mydbapi):
CFLAGS="-O1 -g"
CXXFLAGS="${CFLAGS}"
LDFLAGS=""
FEATURES="nostrip"

Reply via email to