1*2b949d04SAndroid Build Coastguard Worker#!/usr/bin/env python 2*2b949d04SAndroid Build Coastguard Worker 3*2b949d04SAndroid Build Coastguard Worker"""A script to generate MSVC Module-Definition files from version-script 4*2b949d04SAndroid Build Coastguard Workerfiles (which are maintained manually).""" 5*2b949d04SAndroid Build Coastguard Worker 6*2b949d04SAndroid Build Coastguard Workerimport re 7*2b949d04SAndroid Build Coastguard Workerimport sys 8*2b949d04SAndroid Build Coastguard Workerimport pathlib 9*2b949d04SAndroid Build Coastguard Worker 10*2b949d04SAndroid Build Coastguard Worker 11*2b949d04SAndroid Build Coastguard Workerdef symbols_from_map(path): 12*2b949d04SAndroid Build Coastguard Worker return re.findall(r'^\s+(r?xkb_.*);', path.read_text('utf-8'), re.MULTILINE) 13*2b949d04SAndroid Build Coastguard Worker 14*2b949d04SAndroid Build Coastguard Worker 15*2b949d04SAndroid Build Coastguard Workerif 2 > len(sys.argv) > 3: 16*2b949d04SAndroid Build Coastguard Worker raise SystemExit("Usage: {} file.map [file.def]".format(sys.argv[0])) 17*2b949d04SAndroid Build Coastguard Worker 18*2b949d04SAndroid Build Coastguard Worker 19*2b949d04SAndroid Build Coastguard Workermap_file = pathlib.Path(sys.argv[1]) 20*2b949d04SAndroid Build Coastguard Workermap_symbols = set(symbols_from_map(map_file)) 21*2b949d04SAndroid Build Coastguard Worker 22*2b949d04SAndroid Build Coastguard Workerif len(sys.argv) == 3: 23*2b949d04SAndroid Build Coastguard Worker def_file = open(sys.argv[2], "w", encoding="utf-8") 24*2b949d04SAndroid Build Coastguard Workerelse: 25*2b949d04SAndroid Build Coastguard Worker def_file = sys.stdout 26*2b949d04SAndroid Build Coastguard Worker 27*2b949d04SAndroid Build Coastguard Workerdef_file.write("LIBRARY {}\n".format(map_file.stem)) 28*2b949d04SAndroid Build Coastguard Workerdef_file.write("EXPORTS\n") 29*2b949d04SAndroid Build Coastguard Workerfor symbol in sorted(map_symbols): 30*2b949d04SAndroid Build Coastguard Worker def_file.write("\t{}\n".format(symbol)) 31