Do not allow a module exists both in provideLibs and requireLibs

There was an issue that a library installed in the system with stub is
manually marked as requireLibs, so it created link to the self (system)
namespace from linkerconfig. This change checks from conv_linker_config
if there is any common module in provideLibs and requireLibs before
write result to output path.

Bug: 298333253
Test: Build failed when the common module is not removed.
Change-Id: I855dfc3484bb6c1fec24d498703c4a2a805913c0
This commit is contained in:
Kiyoung Kim 2023-09-27 11:26:58 +09:00
parent 4cbd49810c
commit 3df5f50e1a

View file

@ -62,8 +62,8 @@ def Proto(args):
if args.source:
for input in args.source.split(':'):
pb.MergeFrom(LoadJsonMessage(input))
with open(args.output, 'wb') as f:
f.write(pb.SerializeToString())
ValidateAndWriteAsPbFile(pb, args.output)
def Print(args):
@ -90,8 +90,8 @@ def SystemProvide(args):
for item in installed_libraries:
if item not in getattr(pb, 'provideLibs'):
getattr(pb, 'provideLibs').append(item)
with open(args.output, 'wb') as f:
f.write(pb.SerializeToString())
ValidateAndWriteAsPbFile(pb, args.output)
def Append(args):
@ -106,8 +106,8 @@ def Append(args):
else:
setattr(pb, args.key, args.value)
with open(args.output, 'wb') as f:
f.write(pb.SerializeToString())
ValidateAndWriteAsPbFile(pb, args.output)
def Merge(args):
@ -116,8 +116,7 @@ def Merge(args):
with open(other, 'rb') as f:
pb.MergeFromString(f.read())
with open(args.out, 'wb') as f:
f.write(pb.SerializeToString())
ValidateAndWriteAsPbFile(pb, args.output)
def Validate(args):
@ -151,6 +150,29 @@ def Validate(args):
sys.exit(f'Unknown type: {args.type}')
def ValidateAndWriteAsPbFile(pb, output_path):
ValidateConfiguration(pb)
with open(output_path, 'wb') as f:
f.write(pb.SerializeToString())
def ValidateConfiguration(pb):
"""
Validate if the configuration is valid to be used as linker configuration
"""
# Validate if provideLibs and requireLibs have common module
provideLibs = set(getattr(pb, 'provideLibs'))
requireLibs = set(getattr(pb, 'requireLibs'))
intersectLibs = provideLibs.intersection(requireLibs)
if intersectLibs:
for lib in intersectLibs:
print(f'{lib} exists both in requireLibs and provideLibs', file=sys.stderr)
sys.exit(1)
def GetArgParser():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()