apex: invoke conv_linker_config validate
as validation
`conv_linker_config validate` command is used to validate the linker configuration embedded in APEX to detect common mistakes. For example, when used in APEX, linker configuration can't set provideLibs/requireLibs. For APEX, there are provideSharedLibs/requireSharedLibs in APEX manifest for that purpose. One might make mistake by setting provideLibs in linker config. Now, when these unsupported properties are set, there'll be build-time error like: // set provideLibs key in com.android.art's linker config. $ m com.android.art ...image.apex/etc/linker.config.pb: provideLibs is set. Use provideSharedLibs in apex_manifest Bug: 264341796 Test: m com.android.art (see above) Change-Id: Ibaf7322616ad333569e6d721680f3d72243402a2
This commit is contained in:
@@ -120,6 +120,37 @@ def Merge(args):
|
||||
f.write(pb.SerializeToString())
|
||||
|
||||
|
||||
def Validate(args):
|
||||
if os.path.isdir(args.input):
|
||||
config_file = os.path.join(args.input, 'etc/linker.config.pb')
|
||||
if os.path.exists(config_file):
|
||||
args.input = config_file
|
||||
Validate(args)
|
||||
# OK if there's no linker config file.
|
||||
return
|
||||
|
||||
if not os.path.isfile(args.input):
|
||||
sys.exit(f"{args.input} is not a file")
|
||||
|
||||
pb = linker_config_pb2.LinkerConfig()
|
||||
with open(args.input, 'rb') as f:
|
||||
pb.ParseFromString(f.read())
|
||||
|
||||
if args.type == 'apex':
|
||||
# Shouldn't use provideLibs/requireLibs in APEX linker.config.pb
|
||||
if getattr(pb, 'provideLibs'):
|
||||
sys.exit(f'{args.input}: provideLibs is set. Use provideSharedLibs in apex_manifest')
|
||||
if getattr(pb, 'requireLibs'):
|
||||
sys.exit(f'{args.input}: requireLibs is set. Use requireSharedLibs in apex_manifest')
|
||||
elif args.type == 'system':
|
||||
if getattr(pb, 'visible'):
|
||||
sys.exit(f'{args.input}: do not use visible, which is for APEX')
|
||||
if getattr(pb, 'permittedPaths'):
|
||||
sys.exit(f'{args.input}: do not use permittedPaths, which is for APEX')
|
||||
else:
|
||||
sys.exit(f'Unknown type: {args.type}')
|
||||
|
||||
|
||||
def GetArgParser():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers()
|
||||
@@ -227,6 +258,18 @@ def GetArgParser():
|
||||
help='Linker configuration files to merge.')
|
||||
append.set_defaults(func=Merge)
|
||||
|
||||
validate = subparsers.add_parser('validate', help='Validate configuration')
|
||||
validate.add_argument(
|
||||
'--type',
|
||||
required=True,
|
||||
choices=['apex', 'system'],
|
||||
help='Type of linker configuration')
|
||||
validate.add_argument(
|
||||
'input',
|
||||
help='Input can be a directory which has etc/linker.config.pb or a path'
|
||||
' to the linker config file')
|
||||
validate.set_defaults(func=Validate)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user