From nobody Thu Aug 13 09:22:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1786355492; cv=none; d=zohomail.com; s=zohoarc; b=JlmOCPOhikoeh5ZTyMrQvWszbfrTxz4i8s83ctDwUOMHdhhwvcRWD8aQ2EWFI1yu1PDpuz68PxEwnUDvsxR+qR69Wi9lCyefBbixlBAgaad+vQBGDzglM9jUXk8rp7OZppIpx/D5Gm1jziqlSwUZdV7kB+vAUN9xT+fB5ot3qn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786355492; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Lee8YbDbDbQD/PEEAUhgQiCV3VG2M8ylKmtExRHl+xg=; b=T9iUO2fosZuGxzAzhs7tthUToJoP1fZ1FKZkCFFV/fZyYqwKI9XP9QdW6O5Li4pZcRFFABK0GjLpHEoOJ4RgxhgSvEt7lOh1/VnyAF0Yg76eN4Dxv/jClw/eAyUO3iDu7Rn/shJvo6dJqigrEaCqnB+a+Rwro+Iw79iUia5IVIw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1786355492513445.94397586674495; Mon, 10 Aug 2026 02:51:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1387268.1628527 (Exim 4.92) (envelope-from ) id 1wtMeu-0002yt-VZ; Mon, 10 Aug 2026 09:51:04 +0000 Received: by outflank-mailman (output) from mailman id 1387268.1628527; Mon, 10 Aug 2026 09:51:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wtMeu-0002ym-T2; Mon, 10 Aug 2026 09:51:04 +0000 Received: by outflank-mailman (input) for mailman id 1387268; Mon, 10 Aug 2026 09:51:04 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wtMeu-0002yS-46 for xen-devel@lists.xenproject.org; Mon, 10 Aug 2026 09:51:04 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1wtMes-00Ef1R-1B; Mon, 10 Aug 2026 09:51:02 +0000 Received: from [217.155.165.12] (helo=localhost.localdomain) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1wtMer-0066Tx-2V; Mon, 10 Aug 2026 09:51:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xenproject.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From; bh=Lee8YbDbDbQD/PEEAUhgQiCV3VG2M8ylKmtExRHl+xg=; b=rhhNW8QKc6pgPjBx97lRlSd+06 uTwG8e4Wb8L6wbm3TkCTEMvZOmN6xF9jVdobMxidsjyTnfKoEgstkpUj72mdWvMELH50f/XXrq9kF Pt8eIbh/PncyV6spL/WmZBKxElkk072jRANCLK7Rx36w0eOQZe24nLiLjG1Sm6AT3KU0=; From: George Dunlap To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 1/3] xen/scripts: import gen_compile_commands.py from Linux Date: Mon, 10 Aug 2026 10:49:43 +0100 Message-ID: <20260810095056.29884-2-gwd@xenproject.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810095056.29884-1-gwd@xenproject.org> References: <20260810095056.29884-1-gwd@xenproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1786355494632158500 Content-Type: text/plain; charset="utf-8" Xen's Kbuild-derived build system records the exact command line used to compile each object in ..o.cmd files. That is everything needed to produce a compile_commands.json compilation database, the format clangd and other tooling consume to provide accurate cross-referencing (go to definition, find references, call hierarchy) in LSP-capable editors. Import scripts/clang-tools/gen_compile_commands.py from the Linux kernel, unmodified, so that the provenance of the code is easy to verify (commit 90efe2b9119f, Linux v6.16). As-is the script produces an empty database on a Xen tree, since Xen's compile command lines differ slightly from Linux's; the following patch adapts it. Assisted-by: LLM Signed-off-by: George Dunlap Acked-by: Anthony PERARD --- xen/scripts/gen_compile_commands.py | 228 ++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100755 xen/scripts/gen_compile_commands.py diff --git a/xen/scripts/gen_compile_commands.py b/xen/scripts/gen_compile_= commands.py new file mode 100755 index 0000000000..96e6e46ad1 --- /dev/null +++ b/xen/scripts/gen_compile_commands.py @@ -0,0 +1,228 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) Google LLC, 2018 +# +# Author: Tom Roeder +# +"""A tool for generating compile_commands.json in the Linux kernel.""" + +import argparse +import json +import logging +import os +import re +import subprocess +import sys + +_DEFAULT_OUTPUT =3D 'compile_commands.json' +_DEFAULT_LOG_LEVEL =3D 'WARNING' + +_FILENAME_PATTERN =3D r'^\..*\.cmd$' +_LINE_PATTERN =3D r'^(saved)?cmd_[^ ]*\.o :=3D (?P.* )(?P<= file_path>[^ ]*\.[cS]) *(;|$)' +_VALID_LOG_LEVELS =3D ['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. +_EXCLUDE_DIRS =3D ['.git', 'Documentation', 'include', 'tools'] + +def parse_arguments(): + """Sets up and parses command-line arguments. + + Returns: + log_level: A logging level to filter log output. + directory: The work directory where the objects were built. + ar: Command used for parsing .a archives. + output: Where to write the compile-commands JSON file. + paths: The list of files/directories to handle to find .cmd files. + """ + usage =3D 'Creates a compile_commands.json database from kernel .cmd f= iles' + parser =3D argparse.ArgumentParser(description=3Dusage) + + directory_help =3D ('specify the output directory used for the kernel = build ' + '(defaults to the working directory)') + parser.add_argument('-d', '--directory', type=3Dstr, default=3D'.', + help=3Ddirectory_help) + + output_help =3D ('path to the output command database (defaults to ' + + _DEFAULT_OUTPUT + ')') + parser.add_argument('-o', '--output', type=3Dstr, default=3D_DEFAULT_O= UTPUT, + help=3Doutput_help) + + log_level_help =3D ('the level of log messages to produce (defaults to= ' + + _DEFAULT_LOG_LEVEL + ')') + parser.add_argument('--log_level', choices=3D_VALID_LOG_LEVELS, + default=3D_DEFAULT_LOG_LEVEL, help=3Dlog_level_hel= p) + + ar_help =3D 'command used for parsing .a archives' + parser.add_argument('-a', '--ar', type=3Dstr, default=3D'llvm-ar', hel= p=3Dar_help) + + paths_help =3D ('directories to search or files to parse ' + '(files should be *.o, *.a, or modules.order). ' + 'If nothing is specified, the current directory is searc= hed') + parser.add_argument('paths', type=3Dstr, nargs=3D'*', help=3Dpaths_hel= p) + + args =3D parser.parse_args() + + return (args.log_level, + os.path.realpath(args.directory), + args.output, + args.ar, + args.paths if len(args.paths) > 0 else [args.directory]) + + +def cmdfiles_in_dir(directory): + """Generate the iterator of .cmd files found under the directory. + + Walk under the given directory, and yield every .cmd file found. + + Args: + directory: The directory to search for .cmd files. + + Yields: + The path to a .cmd file. + """ + + filename_matcher =3D re.compile(_FILENAME_PATTERN) + exclude_dirs =3D [ os.path.join(directory, d) for d in _EXCLUDE_DIRS ] + + for dirpath, dirnames, filenames in os.walk(directory, topdown=3DTrue): + # Prune unwanted directories. + if dirpath in exclude_dirs: + dirnames[:] =3D [] + continue + + for filename in filenames: + if filename_matcher.match(filename): + yield os.path.join(dirpath, filename) + + +def to_cmdfile(path): + """Return the path of .cmd file used for the given build artifact + + Args: + Path: file path + + Returns: + The path to .cmd file + """ + dir, base =3D os.path.split(path) + return os.path.join(dir, '.' + base + '.cmd') + + +def cmdfiles_for_a(archive, ar): + """Generate the iterator of .cmd files associated with the archive. + + Parse the given archive, and yield every .cmd file used to build it. + + Args: + archive: The archive to parse + + Yields: + The path to every .cmd file found + """ + for obj in subprocess.check_output([ar, '-t', archive]).decode().split= (): + yield to_cmdfile(obj) + + +def cmdfiles_for_modorder(modorder): + """Generate the iterator of .cmd files associated with the modules.ord= er. + + Parse the given modules.order, and yield every .cmd file used to build= the + contained modules. + + Args: + modorder: The modules.order file to parse + + Yields: + The path to every .cmd file found + """ + with open(modorder) as f: + for line in f: + obj =3D line.rstrip() + base, ext =3D os.path.splitext(obj) + if ext !=3D '.o': + sys.exit('{}: module path must end with .o'.format(obj)) + mod =3D base + '.mod' + # Read from *.mod, to get a list of objects that compose the m= odule. + with open(mod) as m: + for mod_line in m: + yield to_cmdfile(mod_line.rstrip()) + + +def process_line(root_directory, command_prefix, file_path): + """Extracts information from a .cmd line and creates an entry from it. + + Args: + root_directory: The directory that was searched for .cmd files. Us= ually + used directly in the "directory" entry in compile_commands.jso= n. + command_prefix: The extracted command line, up to the last element. + file_path: The .c file from the end of the extracted command. + Usually relative to root_directory, but sometimes absolute. + + Returns: + An entry to append to compile_commands. + + Raises: + ValueError: Could not find the extracted file based on file_path a= nd + root_directory or file_directory. + """ + # The .cmd files are intended to be included directly by Make, so they + # escape the pound sign '#' as '$(pound)'. The compile_commands.json f= ile + # is not interepreted by Make, so this code replaces the escaped versi= on + # with '#'. + prefix =3D command_prefix.replace('$(pound)', '#') + + # Return the canonical path, eliminating any symbolic links encountere= d in the path. + abs_path =3D os.path.realpath(os.path.join(root_directory, file_path)) + if not os.path.exists(abs_path): + raise ValueError('File %s not found' % abs_path) + return { + 'directory': root_directory, + 'file': abs_path, + 'command': prefix + file_path, + } + + +def main(): + """Walks through the directory and finds and parses .cmd files.""" + log_level, directory, output, ar, paths =3D parse_arguments() + + level =3D getattr(logging, log_level) + logging.basicConfig(format=3D'%(levelname)s: %(message)s', level=3Dlev= el) + + line_matcher =3D re.compile(_LINE_PATTERN) + + compile_commands =3D [] + + for path in paths: + # If 'path' is a directory, handle all .cmd files under it. + # Otherwise, handle .cmd files associated with the file. + # built-in objects are linked via vmlinux.a + # Modules are listed in modules.order. + if os.path.isdir(path): + cmdfiles =3D cmdfiles_in_dir(path) + elif path.endswith('.a'): + cmdfiles =3D cmdfiles_for_a(path, ar) + elif path.endswith('modules.order'): + cmdfiles =3D cmdfiles_for_modorder(path) + else: + sys.exit('{}: unknown file type'.format(path)) + + for cmdfile in cmdfiles: + with open(cmdfile, 'rt') as f: + result =3D line_matcher.match(f.readline()) + if result: + try: + entry =3D process_line(directory, result.group('co= mmand_prefix'), + result.group('file_path')) + compile_commands.append(entry) + except ValueError as err: + logging.info('Could not add line from %s: %s', + cmdfile, err) + + with open(output, 'wt') as f: + json.dump(sorted(compile_commands, key=3Dlambda x: x["file"]), f, = indent=3D2, sort_keys=3DTrue) + + +if __name__ =3D=3D '__main__': + main() --=20 2.55.0 From nobody Thu Aug 13 09:22:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1786355495; cv=none; d=zohomail.com; s=zohoarc; b=TutVtLqQteGnATOUPIZ4CKaUUqnK+ZZE78ncklAsnymd+YA+Zb/IUVGdlBNwb3IjBHxmitcY2Gsy7XVsBpRFh72vRRlK/lP8Rat9zc6HWwnbG1Jaztdz2sK6xpJutbwKd068Qd/f5u+3sUBx//MRPJ1iEpSpSB2oK6JuasAGfM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786355495; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LeEkJR3wDbFHkguioVrXqEE8FwRBWi05Kbj07PLC7cQ=; b=iV0SFyQYvfJrQKM6t7pmBYOFtqf4NyMWJxxmncVIE+KsY920jGBgVTzHUfZ21o4u/ridgRXUnqv9rzGtwzQgxGLW4skuHx14WkxzKz7sPKx+rRTfDGj3fopCEYq7xIg9T5Yle26ThcSQSDMVhMGxH3gwjKR7oX9Jzon5993lh4c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1786355495837834.8690273812839; Mon, 10 Aug 2026 02:51:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1387269.1628537 (Exim 4.92) (envelope-from ) id 1wtMew-0003Bp-66; Mon, 10 Aug 2026 09:51:06 +0000 Received: by outflank-mailman (output) from mailman id 1387269.1628537; Mon, 10 Aug 2026 09:51:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wtMew-0003Bi-2w; Mon, 10 Aug 2026 09:51:06 +0000 Received: by outflank-mailman (input) for mailman id 1387269; Mon, 10 Aug 2026 09:51:04 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wtMeu-0002ya-H7 for xen-devel@lists.xenproject.org; Mon, 10 Aug 2026 09:51:04 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1wtMet-00Ef1T-21; Mon, 10 Aug 2026 09:51:03 +0000 Received: from [217.155.165.12] (helo=localhost.localdomain) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1wtMet-0066Tx-0J; Mon, 10 Aug 2026 09:51:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xenproject.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From; bh=LeEkJR3wDbFHkguioVrXqEE8FwRBWi05Kbj07PLC7cQ=; b=H0+YJe1MKYv4xfnK6X3L3qR+TV MeoyYG7k9NupZWxt2mQDA9UXMVZbsr5hNkvOw13kPfxWgQfCVHyAXdTLKYIhE37qSoBU+wZ6R1xae ttW/9mrJUlm+dQ3s6vxsvTcQTTgmsAoTGYpGFofRTqcynUf8vI8G9C0XJhqTDptI3AyM=; From: George Dunlap To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 2/3] xen/scripts: adapt gen_compile_commands.py to Xen Date: Mon, 10 Aug 2026 10:49:44 +0100 Message-ID: <20260810095056.29884-3-gwd@xenproject.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810095056.29884-1-gwd@xenproject.org> References: <20260810095056.29884-1-gwd@xenproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1786355496661158500 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Anthony PERARD --- v2: Reword the _LINE_PATTERN comment to describe what the dropped remainder is, rather than commenting on the change relative to Linux. --- xen/scripts/gen_compile_commands.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xen/scripts/gen_compile_commands.py b/xen/scripts/gen_compile_= commands.py index 96e6e46ad1..1c9b05e4dd 100755 --- a/xen/scripts/gen_compile_commands.py +++ b/xen/scripts/gen_compile_commands.py @@ -5,7 +5,7 @@ # # Author: Tom Roeder # -"""A tool for generating compile_commands.json in the Linux kernel.""" +"""A tool for generating compile_commands.json for the Xen hypervisor.""" =20 import argparse import json @@ -19,7 +19,11 @@ _DEFAULT_OUTPUT =3D 'compile_commands.json' _DEFAULT_LOG_LEVEL =3D 'WARNING' =20 _FILENAME_PATTERN =3D r'^\..*\.cmd$' -_LINE_PATTERN =3D r'^(saved)?cmd_[^ ]*\.o :=3D (?P.* )(?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 =3D r'^(saved)?cmd_[^ ]*\.o :=3D (?P.* -c )(= ?P[^ ]*\.[cS])( .*)?$' _VALID_LOG_LEVELS =3D ['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 =3D 'Creates a compile_commands.json database from kernel .cmd f= iles' + usage =3D 'Creates a compile_commands.json database from Xen .cmd file= s' parser =3D argparse.ArgumentParser(description=3Dusage) =20 - directory_help =3D ('specify the output directory used for the kernel = build ' + directory_help =3D ('specify the output directory used for the Xen bui= ld ' '(defaults to the working directory)') parser.add_argument('-d', '--directory', type=3Dstr, default=3D'.', help=3Ddirectory_help) --=20 2.55.0 From nobody Thu Aug 13 09:22:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1786355484; cv=none; d=zohomail.com; s=zohoarc; b=di9WGW+ob2aMTNJLtn1GhWTfm66VESI9x60qkwTK43vTNCIFRRapDDStpK6H8WRNKCqifd6xH3iQ1uD/e64b2GtlHFa3TeK+JZBpC6vEM39ZSsRSDY2ehcL4s1LDd98nVkREWA+MYoZMw0GIDsWpncA46KpKfiHr8cpcFipxoVY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786355484; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sLc17oTn+YSlEdecd+yFeeelQCBxepbt0iFKxuboJsM=; b=IntLsWSRKAnE+WwA6WHFHBqdvxIC4u85dzNdHBWNLEftiktwEKPXqWgHI3hrNF1I98DgGwmKsZdULfokD/hJJc+MTOcuPCSnOFEAx0npD90q36Kqnwhol821KyadpRUgTmg3qUrUNcejcvhLWBhuGPv0c7lX+5+WqnkkcP8GWJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1786355484839628.0615492844719; Mon, 10 Aug 2026 02:51:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1387270.1628546 (Exim 4.92) (envelope-from ) id 1wtMex-0003P1-CP; Mon, 10 Aug 2026 09:51:07 +0000 Received: by outflank-mailman (output) from mailman id 1387270.1628546; Mon, 10 Aug 2026 09:51:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wtMex-0003Oo-92; Mon, 10 Aug 2026 09:51:07 +0000 Received: by outflank-mailman (input) for mailman id 1387270; Mon, 10 Aug 2026 09:51:05 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wtMev-00038U-JV for xen-devel@lists.xenproject.org; Mon, 10 Aug 2026 09:51:05 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1wtMeu-00Ef1f-34; Mon, 10 Aug 2026 09:51:04 +0000 Received: from [217.155.165.12] (helo=localhost.localdomain) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1wtMeu-0066Tx-1O; Mon, 10 Aug 2026 09:51:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xenproject.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From; bh=sLc17oTn+YSlEdecd+yFeeelQCBxepbt0iFKxuboJsM=; b=WdIje4qxZOspjwdk9yTSKiONQ5 /1cO8SG4QFUpLyMuhoijKzQcyjVSaC5D8xbTb60afH0NVTgfPa4s/cYVFq0UqtAPOBetluqSLR6RB sJgiu/YlcF04cRI6fRrXHG16WiSGm4cUFADAXkS4Zj6GspLGlXVfHAo64ovT+eDuAVh4=; From: George Dunlap To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 3/3] build: add compile_commands.json target Date: Mon, 10 Aug 2026 10:49:45 +0100 Message-ID: <20260810095056.29884-4-gwd@xenproject.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260810095056.29884-1-gwd@xenproject.org> References: <20260810095056.29884-1-gwd@xenproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1786355486811158500 Content-Type: text/plain; charset="utf-8" Add a convenience target generating the compilation database from a built object tree, alongside the other developer conveniences (tags, cscope, cloc -- the last of which already walks the same .cmd files): make -C xen compile_commands.json The output lands in the object tree root. For an in-tree build, clangd and other consumers discover it there automatically when opening files; for an out-of-tree build, symlink it into the source tree root (consumers search the ancestors of the file being edited). Note the database records the compiler invocations actually used. With a clang build it is consumable by clangd as-is; for a gcc build, clang-based tools may need a small .clangd configuration (CompileFlags: Remove/Add) dropping gcc-only flags. Also add the generated file to .gitignore. Assisted-by: LLM Signed-off-by: George Dunlap Reviewed-by: Anthony PERARD --- v2: - Make compile_commands.json a file target forced via FORCE rather than declaring it .PHONY, matching the local idiom and Linux's rule for the same target - Commit message: the target is not phony; cover out-of-tree builds --- .gitignore | 1 + xen/Makefile | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index bfc7bdf043..0aa9b801de 100644 --- a/.gitignore +++ b/.gitignore @@ -192,6 +192,7 @@ xen/arch/*/include/generated xen/build-dir-cppcheck/ xen/common/config_data.S xen/common/config.gz +xen/compile_commands.json xen/cppcheck-htmlreport/ xen/cppcheck-report/ xen/cppcheck-misra.* diff --git a/xen/Makefile b/xen/Makefile index d39bdfdd53..d10c29162f 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -685,6 +685,9 @@ cloc: done; \ done | cloc --list-file=3D- =20 +compile_commands.json: FORCE + $(PYTHON) $(srctree)/scripts/gen_compile_commands.py -d $(objtree) + # Target used by xen-analysis.sh script to retrieve Xen build system varia= bles export-variable-%: $(info $*=3D$($*)) --=20 2.55.0