def Merge(args): pb = linker_config_pb2.LinkerConfig() for other in args.input: with open(other, 'rb') as f: pb.MergeFromString(f.read()) with open(args.out, 'wb') as f: f.write(pb.SerializeToString())
def Proto(args): json_content = '' with open(args.source) as f: for line in f: if not line.lstrip().startswith('//'): json_content += line obj = json.loads(json_content, object_pairs_hook=collections.OrderedDict) pb = ParseDict(obj, linker_config_pb2.LinkerConfig()) with open(args.output, 'wb') as f: f.write(pb.SerializeToString())
def Append(args): pb = linker_config_pb2.LinkerConfig() with open(args.source, 'rb') as f: pb.ParseFromString(f.read()) if getattr(type(pb), args.key).DESCRIPTOR.label == FieldDescriptor.LABEL_REPEATED: for value in args.value.split(): getattr(pb, args.key).append(value) else: setattr(pb, args.key, args.value) with open(args.output, 'wb') as f: f.write(pb.SerializeToString())
def SystemProvide(args): pb = linker_config_pb2.LinkerConfig() with open(args.source, 'rb') as f: pb.ParseFromString(f.read()) libraries = args.value.split() def IsInLibPath(lib_name): lib_path = os.path.join(args.system, 'lib', 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) installed_libraries = list(filter(IsInLibPath, libraries)) 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())
def Print(args): with open(args.source, 'rb') as f: pb = linker_config_pb2.LinkerConfig() pb.ParseFromString(f.read()) print(MessageToString(pb))