_ARGPARSER.print_usage()
exit(1)
+def print_result(config, res):
+ if res is not None and config not in res:
+ res = {config or '*': res}
+ print(json.dumps(res, indent=4))
+
def do_query(args):
+ if args.arch is None and args.flavour is not None:
+ arg_fail('error: --flavour requires --arch')
a = Annotation(args.file)
for config in (args.config, 'CONFIG_' + args.config if args.config else None):
res = a.search_config(config=config, arch=args.arch, flavour=args.flavour)
if res:
break
- print(json.dumps({config or '*': res}, indent=4))
+ print_result(config, res)
def do_note(args):
if args.config is None:
a.save(args.file)
# Query and print back the value
+ a = Annotation(args.file)
res = a.search_config(config=args.config)
- print(json.dumps(res, indent=4))
+ print_result(args.config, res)
def do_write(args):
if args.config is None:
a.save(args.file)
# Query and print back the value
+ a = Annotation(args.file)
res = a.search_config(config=args.config)
- print(json.dumps(res, indent=4))
+ print_result(args.config, res)
def do_export(args):
if args.arch is None:
c = KConfig(args.update_file)
if args.config is None:
configs = list(set(c.config.keys()) - set(SKIP_CONFIGS))
- a.update(c, arch=args.arch, flavour=args.flavour, configs=configs)
+ if configs:
+ a.update(c, arch=args.arch, flavour=args.flavour, configs=configs)
# Save back to annotations
a.save(args.file)
.config[<CONFIG_OPTION>]
"""
def _parse(self, data: str) -> dict:
- # Parse header
+ self.arch = []
+ self.flavour = []
+ self.flavour_dep = {}
self.header = ''
+ # Parse header
for line in data.splitlines():
if re.match(r'^#.*', line):
m = re.match(r'^# ARCH: (.*)', line)
m = re.match(r'^# FLAVOUR: (.*)', line)
if m:
self.flavour = list(m.group(1).split(' '))
+ m = re.match(r'^# FLAVOUR_DEP: (.*)', line)
+ if m:
+ self.flavour_dep = eval(m.group(1))
self.header += line + "\n"
else:
break
def _compact(self):
# Try to remove redundant settings: if the config value of a flavour is
# the same as the one of the main arch simply drop it.
- for conf in self.config:
+ for conf in self.config.copy():
if 'policy' not in self.config[conf]:
continue
for flavour in self.flavour:
if not m:
continue
arch = m.group(1)
- if arch not in self.config[conf]['policy']:
+ if arch in self.config[conf]['policy']:
+ if self.config[conf]['policy'][flavour] == self.config[conf]['policy'][arch]:
+ del self.config[conf]['policy'][flavour]
+ continue
+ if flavour not in self.flavour_dep:
continue
- if self.config[conf]['policy'][flavour] == self.config[conf]['policy'][arch]:
+ generic = self.flavour_dep[flavour]
+ if generic in self.config[conf]['policy']:
+ if self.config[conf]['policy'][flavour] == self.config[conf]['policy'][generic]:
+ del self.config[conf]['policy'][flavour]
+ continue
+ for flavour in self.config[conf]['policy'].copy():
+ if flavour not in list(set(self.arch + self.flavour)):
del self.config[conf]['policy'][flavour]
+ if not self.config[conf]['policy']:
+ del self.config[conf]
def save(self, fname: str):
""" Save annotations data to the annotation file """
for conf in sorted(self.config):
old_val = tmp_a.config[conf] if conf in tmp_a.config else None
new_val = self.config[conf]
- if old_val != new_val:
- if 'policy' in self.config[conf]:
- val = dict(sorted(self.config[conf]['policy'].items()))
- line = f"{conf : <47} policy<{val}>"
- tmp.write(line + "\n")
- if 'note' in self.config[conf]:
- val = self.config[conf]['note']
+ # If new_val is a subset of old_val, skip it
+ if old_val and 'policy' in old_val and 'policy' in new_val:
+ if old_val['policy'] == old_val['policy'] | new_val['policy']:
+ continue
+ if 'policy' in new_val:
+ val = dict(sorted(new_val['policy'].items()))
+ line = f"{conf : <47} policy<{val}>"
+ tmp.write(line + "\n")
+ if 'note' in new_val:
+ val = new_val['note']
line = f"{conf : <47} note<{val}>"
tmp.write(line + "\n\n")
if flavour is None:
flavour = 'generic'
flavour = f'{arch}-{flavour}'
+ if flavour in self.flavour_dep:
+ generic = self.flavour_dep[flavour]
+ else:
+ generic = flavour
if config is None and arch is None:
# Get all config options for all architectures
return self.config
continue
if flavour in self.config[c]['policy']:
ret[c] = self.config[c]['policy'][flavour]
+ elif generic != flavour and generic in self.config[c]['policy']:
+ ret[c] = self.config[c]['policy'][generic]
elif arch in self.config[c]['policy']:
ret[c] = self.config[c]['policy'][arch]
return ret
if 'policy' in self.config[config]:
if flavour in self.config[config]['policy']:
return {config: self.config[config]['policy'][flavour]}
+ elif generic != flavour and generic in self.config[config]['policy']:
+ return {config: self.config[config]['policy'][generic]}
elif arch in self.config[config]['policy']:
return {config: self.config[config]['policy'][arch]}
return None