aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2021-06-24 12:38:04 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2021-07-09 18:20:27 +0200
commitf5723ab66560a10f8461ac223e3d8369c10dc964 (patch)
treedffd7b55455ab1b99d56ed9fc10f3d9e1333f890 /scripts
parent22524c10c489ed7c20be2f5878157a64095e5734 (diff)
modules: collect module meta-data
Add script to collect the module meta-data from the source code, store the results in *.modinfo files. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Jose R. Ziviani <jziviani@suse.de> Message-Id: <20210624103836.2382472-3-kraxel@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/modinfo-collect.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/scripts/modinfo-collect.py b/scripts/modinfo-collect.py
new file mode 100755
index 0000000000..4acb188c3e
--- /dev/null
+++ b/scripts/modinfo-collect.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+import json
+import shlex
+import subprocess
+
+def find_command(src, target, compile_commands):
+ for command in compile_commands:
+ if command['file'] != src:
+ continue
+ if target != '' and command['command'].find(target) == -1:
+ continue
+ return command['command']
+ return 'false'
+
+def process_command(src, command):
+ skip = False
+ arg = False
+ out = []
+ for item in shlex.split(command):
+ if arg:
+ out.append(x)
+ arg = False
+ continue
+ if skip:
+ skip = False
+ continue
+ if item == '-MF' or item == '-MQ' or item == '-o':
+ skip = True
+ continue
+ if item == '-c':
+ skip = True
+ continue
+ out.append(item)
+ out.append('-DQEMU_MODINFO')
+ out.append('-E')
+ out.append(src)
+ return out
+
+def main(args):
+ target = ''
+ if args[0] == '--target':
+ args.pop(0)
+ target = args.pop(0)
+ print("MODINFO_DEBUG target %s" % target)
+ arch = target[:-8] # cut '-softmmu'
+ print("MODINFO_START arch \"%s\" MODINFO_END" % arch)
+ with open('compile_commands.json') as f:
+ compile_commands = json.load(f)
+ for src in args:
+ print("MODINFO_DEBUG src %s" % src)
+ command = find_command(src, target, compile_commands)
+ cmdline = process_command(src, command)
+ print("MODINFO_DEBUG cmd", cmdline)
+ result = subprocess.run(cmdline, stdout = subprocess.PIPE,
+ universal_newlines = True)
+ if result.returncode != 0:
+ sys.exit(result.returncode)
+ for line in result.stdout.split('\n'):
+ if line.find('MODINFO') != -1:
+ print(line)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])