Apply pylint to conv_linker_config.py
1. Run pyformat scripts/conv_linker_config.py -s 4 --force_quote_type none -i to fix formatting 2. Annotate #pylint: disable=import-error for linker_config_pb2 since it will be provided by soong Test: m conv_linker_config Test: pylint --rcfile tools/repohooks/tools/pylintrc build/soong/scripts/conv_linker_config.py Bug: 195738175 Change-Id: I791576cf65cb053f68c804f8ec5c2fc22976fdb4
This commit is contained in:
@@ -20,7 +20,7 @@ import collections
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import linker_config_pb2
|
import linker_config_pb2 #pylint: disable=import-error
|
||||||
from google.protobuf.descriptor import FieldDescriptor
|
from google.protobuf.descriptor import FieldDescriptor
|
||||||
from google.protobuf.json_format import ParseDict
|
from google.protobuf.json_format import ParseDict
|
||||||
from google.protobuf.text_format import MessageToString
|
from google.protobuf.text_format import MessageToString
|
||||||
@@ -54,9 +54,11 @@ def SystemProvide(args):
|
|||||||
def IsInLibPath(lib_name):
|
def IsInLibPath(lib_name):
|
||||||
lib_path = os.path.join(args.system, 'lib', lib_name)
|
lib_path = os.path.join(args.system, 'lib', lib_name)
|
||||||
lib64_path = os.path.join(args.system, 'lib64', lib_name)
|
lib64_path = os.path.join(args.system, 'lib64', lib_name)
|
||||||
return os.path.exists(lib_path) or os.path.islink(lib_path) or os.path.exists(lib64_path) or os.path.islink(lib64_path)
|
return os.path.exists(lib_path) or os.path.islink(
|
||||||
|
lib_path) or os.path.exists(lib64_path) or os.path.islink(
|
||||||
|
lib64_path)
|
||||||
|
|
||||||
installed_libraries = list(filter(IsInLibPath, libraries))
|
installed_libraries = [lib for lib in libraries if IsInLibPath(lib)]
|
||||||
for item in installed_libraries:
|
for item in installed_libraries:
|
||||||
if item not in getattr(pb, 'provideLibs'):
|
if item not in getattr(pb, 'provideLibs'):
|
||||||
getattr(pb, 'provideLibs').append(item)
|
getattr(pb, 'provideLibs').append(item)
|
||||||
@@ -69,7 +71,8 @@ def Append(args):
|
|||||||
with open(args.source, 'rb') as f:
|
with open(args.source, 'rb') as f:
|
||||||
pb.ParseFromString(f.read())
|
pb.ParseFromString(f.read())
|
||||||
|
|
||||||
if getattr(type(pb), args.key).DESCRIPTOR.label == FieldDescriptor.LABEL_REPEATED:
|
if getattr(type(pb),
|
||||||
|
args.key).DESCRIPTOR.label == FieldDescriptor.LABEL_REPEATED:
|
||||||
for value in args.value.split():
|
for value in args.value.split():
|
||||||
getattr(pb, args.key).append(value)
|
getattr(pb, args.key).append(value)
|
||||||
else:
|
else:
|
||||||
@@ -78,6 +81,7 @@ def Append(args):
|
|||||||
with open(args.output, 'wb') as f:
|
with open(args.output, 'wb') as f:
|
||||||
f.write(pb.SerializeToString())
|
f.write(pb.SerializeToString())
|
||||||
|
|
||||||
|
|
||||||
def Merge(args):
|
def Merge(args):
|
||||||
pb = linker_config_pb2.LinkerConfig()
|
pb = linker_config_pb2.LinkerConfig()
|
||||||
for other in args.input:
|
for other in args.input:
|
||||||
@@ -87,12 +91,14 @@ def Merge(args):
|
|||||||
with open(args.out, 'wb') as f:
|
with open(args.out, 'wb') as f:
|
||||||
f.write(pb.SerializeToString())
|
f.write(pb.SerializeToString())
|
||||||
|
|
||||||
|
|
||||||
def GetArgParser():
|
def GetArgParser():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
|
|
||||||
parser_proto = subparsers.add_parser(
|
parser_proto = subparsers.add_parser(
|
||||||
'proto', help='Convert the input JSON configuration file into protobuf.')
|
'proto',
|
||||||
|
help='Convert the input JSON configuration file into protobuf.')
|
||||||
parser_proto.add_argument(
|
parser_proto.add_argument(
|
||||||
'-s',
|
'-s',
|
||||||
'--source',
|
'--source',
|
||||||
@@ -118,7 +124,8 @@ def GetArgParser():
|
|||||||
print_proto.set_defaults(func=Print)
|
print_proto.set_defaults(func=Print)
|
||||||
|
|
||||||
system_provide_libs = subparsers.add_parser(
|
system_provide_libs = subparsers.add_parser(
|
||||||
'systemprovide', help='Append system provide libraries into the configuration.')
|
'systemprovide',
|
||||||
|
help='Append system provide libraries into the configuration.')
|
||||||
system_provide_libs.add_argument(
|
system_provide_libs.add_argument(
|
||||||
'-s',
|
'-s',
|
||||||
'--source',
|
'--source',
|
||||||
@@ -135,12 +142,11 @@ def GetArgParser():
|
|||||||
'--value',
|
'--value',
|
||||||
required=True,
|
required=True,
|
||||||
type=str,
|
type=str,
|
||||||
help='Values of the libraries to append. If there are more than one it should be separated by empty space')
|
help='Values of the libraries to append. If there are more than one '
|
||||||
|
'it should be separated by empty space'
|
||||||
|
)
|
||||||
system_provide_libs.add_argument(
|
system_provide_libs.add_argument(
|
||||||
'--system',
|
'--system', required=True, type=str, help='Path of the system image.')
|
||||||
required=True,
|
|
||||||
type=str,
|
|
||||||
help='Path of the system image.')
|
|
||||||
system_provide_libs.set_defaults(func=SystemProvide)
|
system_provide_libs.set_defaults(func=SystemProvide)
|
||||||
|
|
||||||
append = subparsers.add_parser(
|
append = subparsers.add_parser(
|
||||||
@@ -157,26 +163,23 @@ def GetArgParser():
|
|||||||
required=True,
|
required=True,
|
||||||
type=str,
|
type=str,
|
||||||
help='Target linker configuration file to write in protobuf.')
|
help='Target linker configuration file to write in protobuf.')
|
||||||
append.add_argument(
|
append.add_argument('--key', required=True, type=str, help='.')
|
||||||
'--key',
|
|
||||||
required=True,
|
|
||||||
type=str,
|
|
||||||
help='.')
|
|
||||||
append.add_argument(
|
append.add_argument(
|
||||||
'--value',
|
'--value',
|
||||||
required=True,
|
required=True,
|
||||||
type=str,
|
type=str,
|
||||||
help='Values of the libraries to append. If there are more than one it should be separated by empty space')
|
help='Values of the libraries to append. If there are more than one'
|
||||||
|
'it should be separated by empty space'
|
||||||
|
)
|
||||||
append.set_defaults(func=Append)
|
append.set_defaults(func=Append)
|
||||||
|
|
||||||
append = subparsers.add_parser(
|
append = subparsers.add_parser('merge', help='Merge configurations')
|
||||||
'merge', help='Merge configurations')
|
|
||||||
append.add_argument(
|
append.add_argument(
|
||||||
'-o',
|
'-o',
|
||||||
'--out',
|
'--out',
|
||||||
required=True,
|
required=True,
|
||||||
type=str,
|
type=str,
|
||||||
help='Ouptut linker configuration file to write in protobuf.')
|
help='Output linker configuration file to write in protobuf.')
|
||||||
append.add_argument(
|
append.add_argument(
|
||||||
'-i',
|
'-i',
|
||||||
'--input',
|
'--input',
|
||||||
|
Reference in New Issue
Block a user