xen/scripts: adapt gen_compile_commands.py to Xen

Two changes from the Linux original:

 - Linux's compiler invocations end with the source file
   ("... -c -o foo.o foo.c"), and the script's line pattern relies
   on that; Xen's cmd_cc_o_c places "-c $<" before "-o" and "-MQ",
   so on a Xen object tree the unmodified script matches nothing and
   produces an empty database.  Adjust _LINE_PATTERN to capture the
   command up to and including "-c" plus the source file, dropping
   the remainder, which database consumers do not need.

 - Reword the docstring and help text to refer to Xen.

The support for reading object lists from archives and modules.order
is unused in Xen but retained to minimise divergence from the
original.

Assisted-by: LLM
Signed-off-by: George Dunlap <gwd@xenproject.org>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
This commit is contained in:
George Dunlap authored and Anthony PERARD committed 2026-08-11 11:07:16 +02:00
1 parent 359dae3852
commit 79ea30888d
1 file changed
+8 -4
+8 -4
View File
@@ -5,7 +5,7 @@
#
# Author: Tom Roeder <tmroeder@google.com>
#
"""A tool for generating compile_commands.json in the Linux kernel."""
"""A tool for generating compile_commands.json for the Xen hypervisor."""
import argparse
import json
@@ -19,7 +19,11 @@ _DEFAULT_OUTPUT = 'compile_commands.json'
_DEFAULT_LOG_LEVEL = 'WARNING'
_FILENAME_PATTERN = r'^\..*\.cmd$'
_LINE_PATTERN = r'^(saved)?cmd_[^ ]*\.o := (?P<command_prefix>.* )(?P<file_path>[^ ]*\.[cS]) *(;|$)'
# Capture the command up to and including "-c" plus the source file, and
# drop the remainder: all that follows the source file is the output
# location and dependency-tracking arguments ("-o ...", "-MQ ..."), which
# database consumers do not need.
_LINE_PATTERN = r'^(saved)?cmd_[^ ]*\.o := (?P<command_prefix>.* -c )(?P<file_path>[^ ]*\.[cS])( .*)?$'
_VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
# The tools/ directory adopts a different build system, and produces .cmd
# files in a different format. Do not support it.
@@ -35,10 +39,10 @@ def parse_arguments():
output: Where to write the compile-commands JSON file.
paths: The list of files/directories to handle to find .cmd files.
"""
usage = 'Creates a compile_commands.json database from kernel .cmd files'
usage = 'Creates a compile_commands.json database from Xen .cmd files'
parser = argparse.ArgumentParser(description=usage)
directory_help = ('specify the output directory used for the kernel build '
directory_help = ('specify the output directory used for the Xen build '
'(defaults to the working directory)')
parser.add_argument('-d', '--directory', type=str, default='.',
help=directory_help)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.