2 # -*- coding: utf-8 -*-
10 def find_command(src, target, compile_commands):
11 for command in compile_commands:
12 if command['file'] != src:
14 if target != '' and command['command'].find(target) == -1:
16 return command['command']
19 def process_command(src, command):
22 for item in shlex.split(command):
26 if item == '-MF' or item == '-MQ' or item == '-o':
33 out.append('-DQEMU_MODINFO')
40 if args[0] == '--target':
43 print("MODINFO_DEBUG target %s" % target)
44 arch = target[:-8] # cut '-softmmu'
45 print("MODINFO_START arch \"%s\" MODINFO_END" % arch)
46 with open('compile_commands.json') as f:
47 compile_commands = json.load(f)
49 if not src.endswith('.c'):
50 print("MODINFO_DEBUG skip %s" % src)
52 print("MODINFO_DEBUG src %s" % src)
53 command = find_command(src, target, compile_commands)
54 cmdline = process_command(src, command)
55 print("MODINFO_DEBUG cmd", cmdline)
56 result = subprocess.run(cmdline, stdout = subprocess.PIPE,
57 universal_newlines = True)
58 if result.returncode != 0:
59 sys.exit(result.returncode)
60 for line in result.stdout.split('\n'):
61 if line.find('MODINFO') != -1:
64 if __name__ == "__main__":