[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 3/3] build: add compile_commands.json target



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 <gwd@xxxxxxxxxxxxxx>
---
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=-
 
+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 variables
 export-variable-%:
        $(info $*=$($*))
-- 
2.55.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.