Allow converting logtags to java without merged logtags file

Most logtags files only have entries with hardcoded numbers.
Allow these files to be converted to java without needing the
merged logtags file.

Test: m checkbuild
Change-Id: I4cd38aa502fc9b8e50af92ff8296d3ad6abfb56e
This commit is contained in:
Colin Cross 2017-11-15 21:34:32 -08:00
parent e89df93231
commit 0bb782bd4e
1 changed files with 25 additions and 18 deletions

View File

@ -51,30 +51,37 @@ for o, a in opts:
print >> sys.stderr, "unhandled option %s" % (o,)
sys.exit(1)
if len(args) != 2:
print "need exactly two input files, not %d" % (len(args),)
if len(args) != 1 and len(args) != 2:
print "need one or two input files, not %d" % (len(args),)
print __doc__
sys.exit(1)
fn = args[0]
tagfile = event_log_tags.TagFile(fn)
# Load the merged tag file (which should have numbers assigned for all
# tags. Use the numbers from the merged file to fill in any missing
# numbers from the input file.
merged_fn = args[1]
merged_tagfile = event_log_tags.TagFile(merged_fn)
merged_by_name = dict([(t.tagname, t) for t in merged_tagfile.tags])
for t in tagfile.tags:
if t.tagnum is None:
if t.tagname in merged_by_name:
t.tagnum = merged_by_name[t.tagname].tagnum
else:
# We're building something that's not being included in the
# product, so its tags don't appear in the merged file. Assign
# them all an arbitrary number so we can emit the java and
# compile the (unused) package.
t.tagnum = 999999
if len(args) > 1:
# Load the merged tag file (which should have numbers assigned for all
# tags. Use the numbers from the merged file to fill in any missing
# numbers from the input file.
merged_fn = args[1]
merged_tagfile = event_log_tags.TagFile(merged_fn)
merged_by_name = dict([(t.tagname, t) for t in merged_tagfile.tags])
for t in tagfile.tags:
if t.tagnum is None:
if t.tagname in merged_by_name:
t.tagnum = merged_by_name[t.tagname].tagnum
else:
# We're building something that's not being included in the
# product, so its tags don't appear in the merged file. Assign
# them all an arbitrary number so we can emit the java and
# compile the (unused) package.
t.tagnum = 999999
else:
# Not using the merged tag file, so all tags must have manually assigned
# numbers
for t in tagfile.tags:
if t.tagnum is None:
tagfilef.AddError("tag \"%s\" has no number" % (tagname,), tag.linenum)
if "java_package" not in tagfile.options:
tagfile.AddError("java_package option not specified", linenum=0)