[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/48] modules: collect module meta-data
From: |
Paolo Bonzini |
Subject: |
[PULL 06/48] modules: collect module meta-data |
Date: |
Thu, 8 Jul 2021 17:17:06 +0200 |
From: Gerd Hoffmann <kraxel@redhat.com>
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>
---
meson.build | 16 +++++++++
scripts/modinfo-collect.py | 67 ++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+)
create mode 100755 scripts/modinfo-collect.py
diff --git a/meson.build b/meson.build
index 9cd966a86b..ff580f1f80 100644
--- a/meson.build
+++ b/meson.build
@@ -2241,6 +2241,9 @@ subdir('tests/qtest/fuzz')
# Library dependencies #
########################
+modinfo_collect = find_program('scripts/modinfo-collect.py')
+modinfo_files = []
+
block_mods = []
softmmu_mods = []
foreach d, list : modules
@@ -2254,6 +2257,19 @@ foreach d, list : modules
else
softmmu_mods += sl
endif
+ if module_ss.sources() != []
+ # FIXME: Should use sl.extract_all_objects(recursive: true) as
+ # input. Sources can be used multiple times but objects are
+ # unique when it comes to lookup in compile_commands.json.
+ # Depnds on a mesion version with
+ # https://github.com/mesonbuild/meson/pull/8900
+ modinfo_files += custom_target(d + '-' + m + '.modinfo',
+ output: d + '-' + m + '.modinfo',
+ input: module_ss.sources(),
+ capture: true,
+ build_by_default: true, # to be removed
when added to a target
+ command: [modinfo_collect, '@INPUT@'])
+ endif
else
if d == 'block'
block_ss.add_all(module_ss)
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:])
--
2.31.1
- [PULL 00/48] Misc patches for QEMU 6.1 soft freeze, Paolo Bonzini, 2021/07/08
- [PULL 01/48] configure: fix libdaxctl options, Paolo Bonzini, 2021/07/08
- [PULL 03/48] meson: fix missing preprocessor symbols, Paolo Bonzini, 2021/07/08
- [PULL 06/48] modules: collect module meta-data,
Paolo Bonzini <=
- [PULL 02/48] configure: fix libpmem configuration option, Paolo Bonzini, 2021/07/08
- [PULL 04/48] osdep: fix HAVE_BROKEN_SIZE_MAX case, Paolo Bonzini, 2021/07/08
- [PULL 05/48] modules: add modinfo macros, Paolo Bonzini, 2021/07/08
- [PULL 10/48] modules: add virtio-gpu module annotations, Paolo Bonzini, 2021/07/08
- [PULL 12/48] modules: add audio module annotations, Paolo Bonzini, 2021/07/08
- [PULL 07/48] modules: generate modinfo.c, Paolo Bonzini, 2021/07/08
- [PULL 09/48] modules: add qxl module annotations, Paolo Bonzini, 2021/07/08
- [PULL 13/48] modules: add usb-redir module annotations, Paolo Bonzini, 2021/07/08
- [PULL 14/48] modules: add ccid module annotations, Paolo Bonzini, 2021/07/08
- [PULL 08/48] modules: check if all dependencies can be satisfied, Paolo Bonzini, 2021/07/08