conv_linker_config proto supports multiple input json files

conv_linker_config proto -s input1.json:input2.json generates a merged
proto output file.

Bug: 264330513
Test: conv_linker_config proto -s input1.json:input2.json
Change-Id: I4806fc606d115c42a1c745fba67960ce6db8c8d7
This commit is contained in:
Jooyung Han
2023-01-09 16:23:14 +09:00
parent 939673bf6b
commit 014ccd4ef0

View File

@@ -27,13 +27,15 @@ from google.protobuf.text_format import MessageToString
def Proto(args): def Proto(args):
pb = linker_config_pb2.LinkerConfig()
for input in args.source.split(':'):
json_content = '' json_content = ''
with open(args.source) as f: with open(input) as f:
for line in f: for line in f:
if not line.lstrip().startswith('//'): if not line.lstrip().startswith('//'):
json_content += line json_content += line
obj = json.loads(json_content, object_pairs_hook=collections.OrderedDict) obj = json.loads(json_content, object_pairs_hook=collections.OrderedDict)
pb = ParseDict(obj, linker_config_pb2.LinkerConfig()) ParseDict(obj, pb)
with open(args.output, 'wb') as f: with open(args.output, 'wb') as f:
f.write(pb.SerializeToString()) f.write(pb.SerializeToString())
@@ -104,7 +106,7 @@ def GetArgParser():
'--source', '--source',
required=True, required=True,
type=str, type=str,
help='Source linker configuration file in JSON.') help='Colon-separated list of linker configuration files in JSON.')
parser_proto.add_argument( parser_proto.add_argument(
'-o', '-o',
'--output', '--output',