diff --git a/scripts/conv_linker_config.py b/scripts/conv_linker_config.py index c6aa3d0dc..c6e6e306f 100644 --- a/scripts/conv_linker_config.py +++ b/scripts/conv_linker_config.py @@ -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()