aboutsummaryrefslogtreecommitdiff
path: root/scripts/qemu-plugin-symbols.py
diff options
context:
space:
mode:
authorPierrick Bouvier <pierrick.bouvier@linaro.org>2024-11-21 16:58:03 +0000
committerAlex Bennée <alex.bennee@linaro.org>2024-11-25 10:27:43 +0000
commit1ef08e341f2e134bb06f1a5279032fc44917183b (patch)
treeba79057dd1db21a87443ae67e8e865b932faa1eb /scripts/qemu-plugin-symbols.py
parentcfa3a6c54511374e9ccee26d9c38ac1698fc7af2 (diff)
plugins: detect qemu plugin API symbols from header
Instead of using a static file (error prone and hard to keep in sync), we generate it using a script. Note: if a symbol is not exported, we'll now notice it when linking for Windows/MacOS platforms. Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Message-Id: <20241112212622.3590693-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241121165806.476008-37-alex.bennee@linaro.org>
Diffstat (limited to 'scripts/qemu-plugin-symbols.py')
-rwxr-xr-xscripts/qemu-plugin-symbols.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/qemu-plugin-symbols.py b/scripts/qemu-plugin-symbols.py
new file mode 100755
index 0000000000..e285ebb8f9
--- /dev/null
+++ b/scripts/qemu-plugin-symbols.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Extract QEMU Plugin API symbols from a header file
+#
+# Copyright 2024 Linaro Ltd
+#
+# Author: Pierrick Bouvier <pierrick.bouvier@linaro.org>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import argparse
+import re
+
+def extract_symbols(plugin_header):
+ with open(plugin_header) as file:
+ content = file.read()
+ # Remove QEMU_PLUGIN_API macro definition.
+ content = content.replace('#define QEMU_PLUGIN_API', '')
+ expected = content.count('QEMU_PLUGIN_API')
+ # Find last word between QEMU_PLUGIN_API and (, matching on several lines.
+ # We use *? non-greedy quantifier.
+ syms = re.findall(r'QEMU_PLUGIN_API.*?(\w+)\s*\(', content, re.DOTALL)
+ syms.sort()
+ # Ensure we found as many symbols as API markers.
+ assert len(syms) == expected
+ return syms
+
+def main() -> None:
+ parser = argparse.ArgumentParser(description='Extract QEMU plugin symbols')
+ parser.add_argument('plugin_header', help='Path to QEMU plugin header.')
+ args = parser.parse_args()
+
+ syms = extract_symbols(args.plugin_header)
+
+ print('{')
+ for s in syms:
+ print(" {};".format(s))
+ print('};')
+
+if __name__ == '__main__':
+ main()