Handle new filetype 'linker_config'

Handle new filetype 'linker_config' which is configuration for
linkerconfig in json type and convert into protobuf in build time.

Bug: 169634881
Test: Build succeeded and cuttlefish boot succeeded
Change-Id: I56555fc738e6d6600d15a191a24f79a2ee747f52
This commit is contained in:
Kiyoung Kim
2020-10-06 17:16:44 +09:00
parent 6ddb81b0db
commit 62abd12ba5
9 changed files with 415 additions and 0 deletions

View File

@@ -206,3 +206,22 @@ python_binary_host {
"ninja_rsp.py",
],
}
python_binary_host {
name: "conv_linker_config",
srcs: [
"conv_linker_config.py",
],
version: {
py2: {
enabled: false,
},
py3: {
enabled: true,
embedded_launcher: true,
},
},
libs: [
"linker_config_proto",
],
}

View File

@@ -2,3 +2,4 @@ per-file system-clang-format,system-clang-format-2 = enh@google.com,smoreland@go
per-file build-mainline-modules.sh = ngeoffray@google.com,paulduffin@google.com,mast@google.com
per-file build-aml-prebuilts.sh = ngeoffray@google.com,paulduffin@google.com,mast@google.com
per-file construct_context.py = ngeoffray@google.com,calin@google.com,mathieuc@google.com,skvadrik@google.com
per-file conv_linker_config.py = kiyoungkim@google.com, jiyong@google.com, jooyung@google.com

View File

@@ -0,0 +1,81 @@
#!/usr/bin/env python
#
# Copyright (C) 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" A tool to convert json file into pb with linker config format."""
import argparse
import collections
import json
import linker_config_pb2
from google.protobuf.json_format import ParseDict
from google.protobuf.text_format import MessageToString
def Proto(args):
with open(args.source) as f:
obj = json.load(f, object_pairs_hook=collections.OrderedDict)
pb = ParseDict(obj, linker_config_pb2.LinkerConfig())
with open(args.output, 'wb') as f:
f.write(pb.SerializeToString())
def Print(args):
with open(args.source, 'rb') as f:
pb = linker_config_pb2.LinkerConfig()
pb.ParseFromString(f.read())
print(MessageToString(pb))
def GetArgParser():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
parser_proto = subparsers.add_parser(
'proto', help='Convert the input JSON configuration file into protobuf.')
parser_proto.add_argument(
'-s',
'--source',
required=True,
type=str,
help='Source linker configuration file in JSON.')
parser_proto.add_argument(
'-o',
'--output',
required=True,
type=str,
help='Target path to create protobuf file.')
parser_proto.set_defaults(func=Proto)
print_proto = subparsers.add_parser(
'print', help='Print configuration in human-readable text format.')
print_proto.add_argument(
'-s',
'--source',
required=True,
type=str,
help='Source linker configuration file in protobuf.')
print_proto.set_defaults(func=Print)
return parser
def main():
args = GetArgParser().parse_args()
args.func(args)
if __name__ == '__main__':
main()