Commits

Michał Górny committed 7f315f3

Support reading USE_EXPAND variables.

  • Participants
  • Parent commits 1f0288b

Comments (0)

Files changed (2)

File lib/flaggie/cli.py

 	mkconf = MakeConf(
 		(os.path.join(confroot, MAKE_CONF_FILE),
 			os.path.join(usercpath, 'make.conf')),
-		porttree)
+		porttree, cache)
 	pfiles = PackageFiles(usercpath, porttree, mkconf)
 
 	for actset in act:

File lib/flaggie/makeconf.py

 				self._modifier = val
 				self.modified = True
 
-			def toString(self):
+			def toString(self, raw = False):
 				if not self.modified:
 					return self._origs
 				else:
 					return PackageFileSet.PackageFile.PackageEntry.PackageFlag.toString(self)
 
+		class ExpandedFlag(MakeConfFlag):
+			def __init__(self, s, use_expanded_from):
+				self.prefix = '%s_' % use_expanded_from
+				MakeConfVariable.FlattenedToken.MakeConfFlag.__init__(
+						self, self.prefix + s)
+
+			def toString(self, raw = False):
+				ret = MakeConfVariable.FlattenedToken.MakeConfFlag.toString(self)
+				if raw:
+					ret = ret.replace(self.prefix, '', 1)
+				return ret
+
 		class Whitespace(object):
 			def __init__(self, s):
 				self.s = s
 
-			def toString(self):
+			def toString(self, raw = False):
 				return self.s
 
 			@property
 					raise NotImplementedError('Disabling modified for PartialFlag is not supported.')
 
 		def __init__(self, token):
+			self.use_expanded = False
 			self._token = token
 			token.flags = []
 
 		self._tokens = tokens
 		self._flattokens = flattentokens(tokens)
 		self._parsed = False
+		self._useexpanded = []
 
 	def parseflags(self):
 		if self._parsed:
 				for i, e in enumerate(sl):
 					if i%2 == 0:
 						if e:
-							if lta and i == lasti:
+							strippedtoken = e.lstrip('+-')
+							if t.use_expanded:
+								assert(not lta or i != lasti)
+								t.flags.append(self.FlattenedToken.ExpandedFlag(e, t.use_expanded))
+							elif [x for x in self._useexpanded if strippedtoken.startswith(x)]:
+								# inactive due to USE_EXPAND
+								t.flags.append(self.FlattenedToken.PartialFlag(e))
+							elif lta and i == lasti:
 								t.flags.append(self.FlattenedToken.MakeConfFlag(e, lta))
 							else:
 								t.flags.append(self.FlattenedToken.MakeConfFlag(e))
 
 		self._parsed = True
 
+	def append(self, var):
+		if self._parsed:
+			raise NotImplementedError('Appending to a parsed variable not supported')
+
+		key = var._key.lower()
+		self._useexpanded.append(key)
+
+		newtokens = []
+		for t in var._flattokens:
+			t.use_expanded = key
+			newtokens.append(t)
+		newtokens.append(self.FlattenedToken(MakeConf.MakeConfFile.Whitespace(' ')))
+		newtokens.extend(self._flattokens)
+		self._flattokens = newtokens
+
 	def __iter__(self):
 		self.parseflags()
 
 			@property
 			def data(self):
 				if self.modified:
-					return ''.join([f.toString() for f in self.flags])
+					return ''.join([f.toString(True) for f in self.flags])
 				else:
 					return self.s
 
 
 			f.close()
 
-	def __init__(self, paths, dbapi):
+	def __init__(self, paths, dbapi, caches = None):
 		self.files = {}
 		self.variables = {}
 		self.newvars = []
 		self.masterfile = None
+		
+		use_expand_vars = frozenset(caches['use'].use_expand_vars)
 
 		for path in paths:
 			if os.path.exists(path):
 			self.files[path] = mf
 			self.masterfile = mf
 
+		for key in use_expand_vars:
+			if key in self.variables:
+				self.variables['USE'].append(self.variables[key])
+
 	def parse(self, mf, path):
 		# 1) group tokens in lines
 		lines = []