Add support for snapshot testing.

User macro files passed on the command line allow a user to
override the defaults in configuration files to test new changes
in pending releases.

Fix macros issues with keys with more than one map.
This commit is contained in:
Chris Johns 2013-04-13 18:29:30 +10:00
parent 667255cb77
commit 0565e1fa4b
3 changed files with 62 additions and 43 deletions

View File

@ -239,8 +239,6 @@ class build:
# sources as these may be overridden by user loaded macros. # sources as these may be overridden by user loaded macros.
# #
sources = package.sources() sources = package.sources()
for sm in self.macros.find('source[0-9]*'):
sources[sm] = [self.macros[sm]]
url = None url = None
for s in sources: for s in sources:
tag = s[len('source'):] tag = s[len('source'):]

View File

@ -103,42 +103,40 @@ class package:
self.config.macros[info] = '\n'.join(self.infos[info]) self.config.macros[info] = '\n'.join(self.infos[info])
def get_info(self, info, expand = True): def get_info(self, info, expand = True):
if info in self.infos: if info in self.config.macros:
_info = self.config.macros[info].split('\n')
if expand: if expand:
return self.config.expand(self.infos[info]) return self.config.expand(_info)
else: else:
return self.infos[info] return _info
return None return None
def extract_info(self, label, expand = True): def extract_info(self, label, expand = True):
ll = label.lower()
infos = {} infos = {}
for i in self.infos: keys = self.config.macros.find('%s.*' % (ll))
il = i.lower() for k in keys:
if il.startswith(label): if k == ll:
if il == label: k = '%s0' % (ll)
il = label + '0' elif not k[len(ll):].isdigit():
elif not il[len(label):].isdigit(): continue
continue infos[k] = [self.config.expand(self.config.macros[k])]
infos[il] = self.config.expand(self.infos[i])
return infos return infos
def find_info(self, label, expand = True): def _find_macro(self, label, expand = True):
for i in self.infos: if label in self.config.macros:
if i.lower() == label: macro = self.config.macros[label].split('\n')
if expand: if expand:
return self.config.expand(self.infos[i]) return self.config.expand(macro)
else: else:
return self.infos[i] return macro
return None return None
def find_info(self, label, expand = True):
return self._find_macro(label, expand)
def find_directive(self, label, expand = True): def find_directive(self, label, expand = True):
for d in self.directives: return self._find_macro(label, expand)
if d.lower() == label:
if expand:
return self.config.expand(self.directives[d])
else:
return self.directives[d]
return None
def name(self): def name(self):
info = self.find_info('name') info = self.find_info('name')

View File

@ -118,11 +118,11 @@ class macros:
return text return text
def __iter__(self): def __iter__(self):
return macros.macro_iterator(self.macros[self.read_map].keys()) return macros.macro_iterator(self.keys())
def __getitem__(self, key): def __getitem__(self, key):
macro = self.get(key) macro = self.get(key)
if macro is None: if macro is None or macro[1] == 'undefine':
raise IndexError('key: %s' % (key)) raise IndexError('key: %s' % (key))
return macro[2] return macro[2]
@ -143,7 +143,7 @@ class macros:
raise TypeError('bad value tuple value field: %s' % (type(value[2]))) raise TypeError('bad value tuple value field: %s' % (type(value[2])))
if value[0] not in ['none', 'triplet', 'dir', 'file', 'exe']: if value[0] not in ['none', 'triplet', 'dir', 'file', 'exe']:
raise TypeError('bad value tuple (type field): %s' % (value[0])) raise TypeError('bad value tuple (type field): %s' % (value[0]))
if value[1] not in ['none', 'optional', 'required', 'override']: if value[1] not in ['none', 'optional', 'required', 'override', 'undefine']:
raise TypeError('bad value tuple (attrib field): %s' % (value[1])) raise TypeError('bad value tuple (attrib field): %s' % (value[1]))
self.macros[self.write_map][self.key_filter(key)] = value self.macros[self.write_map][self.key_filter(key)] = value
@ -157,18 +157,31 @@ class macros:
return len(self.keys()) return len(self.keys())
def keys(self): def keys(self):
k = self.macros[self.read_map].keys()
def _map_keys(_map):
u = []
k = []
for mk in _map:
if _map[mk][1] == 'undefine':
u += [mk]
else:
k += [mk]
return k, u
keys, undefined = _map_keys(self.macros[self.read_map])
if map is not 'global': if map is not 'global':
k += self.macros['global'].keys() gk, u = _map_keys(self.macros['global'])
return sorted(set(k)) undefined = set(undefined + u)
for k in gk:
if k not in undefined:
keys += [k]
return sorted(set(keys))
def has_key(self, key): def has_key(self, key):
if type(key) is not str: if type(key) is not str:
raise TypeError('bad key type (want str): %s' % (type(key))) raise TypeError('bad key type (want str): %s' % (type(key)))
key = self.key_filter(key) if self.key_filter(key) not in self.keys():
if key not in self.macros[self.read_map].keys(): return False
if key not in self.macros['global'].keys():
return False
return True return True
def maps(self): def maps(self):
@ -277,7 +290,11 @@ class macros:
macro = [] macro = []
token = '' token = ''
state = 'key' state = 'key'
return macros for m in macros:
if m not in self.macros:
self.macros[m] = {}
for mm in macros[m]:
self.macros[m][mm] = macros[m][mm]
def load(self, name): def load(self, name):
try: try:
@ -287,11 +304,6 @@ class macros:
raise error.general('opening macro file: %s' % (path.host(name))) raise error.general('opening macro file: %s' % (path.host(name)))
macros = self.parse(mc) macros = self.parse(mc)
mc.close() mc.close()
for m in macros:
if m not in self.macros:
self.macros[m] = {}
for mm in macros[m]:
self.macros[m][mm] = macros[m][mm]
self.files += [name] self.files += [name]
def get(self, key): def get(self, key):
@ -376,4 +388,15 @@ if __name__ == "__main__":
if d.has_key('test1'): if d.has_key('test1'):
print 'error: copy failed.' print 'error: copy failed.'
sys.exit(1) sys.exit(1)
m.parse("[test]\n" \
"test1: none, undefine, ''\n" \
"name: none, override, 'pink'\n")
m.set_read_map('test')
if m['name'] != 'pink':
print 'error: override failed. name is %s' % (m['name'])
sys.exit(1)
if m.has_key('test1'):
print 'error: map undefine failed.'
sys.exit(1)
print m print m
print m.keys()