[build] Update compile_commands.json when building

The compile_commands.json database is used by clangd to understand the
compilation settings of the project. Keep this up to date by making
ninja update it as part of the build, and have it depend on all build
and module files.
This commit is contained in:
Justin C. Miller
2022-01-23 17:47:06 -08:00
parent 2750ec8ef9
commit a30ef5b3dc
4 changed files with 17 additions and 3 deletions

1
.gitignore vendored
View File

@@ -12,3 +12,4 @@ sysroot
.peru .peru
__pycache__ __pycache__
/venv /venv
compile_commands.json

View File

@@ -76,3 +76,6 @@ rule strip
rule touch rule touch
command = touch $out command = touch $out
rule compdb
command = ninja -t compdb > $out

View File

@@ -141,7 +141,7 @@ class Module:
inputs = [] inputs = []
parse_deps = [] parse_deps = []
parse_dep = "${module_dir}/.parse_dep.phony" parse_depfile = "${module_dir}/.parse_dep.phony"
for start in self.sources: for start in self.sources:
source = start source = start
@@ -150,7 +150,7 @@ class Module:
output = source.output output = source.output
if source.action.parse_deps: if source.action.parse_deps:
oodeps = [parse_dep] oodeps = [parse_depfile]
else: else:
oodeps = [] oodeps = []
@@ -177,7 +177,7 @@ class Module:
build.newline() build.newline()
build.build( build.build(
rule = "touch", rule = "touch",
outputs = [parse_dep], outputs = [parse_depfile],
implicit = child_deps, implicit = child_deps,
order_only = parse_deps, order_only = parse_deps,
) )

View File

@@ -142,6 +142,8 @@ class Project:
build.default([out]) build.default([out])
build.newline() build.newline()
compdb = "${source_root}/compile_commands.json"
build.rule("regen", build.rule("regen",
command = " ".join([str(root / 'configure')] + sys.argv[1:]), command = " ".join([str(root / 'configure')] + sys.argv[1:]),
description = "Regenerate build files", description = "Regenerate build files",
@@ -156,6 +158,14 @@ class Project:
for target in targets: for target in targets:
regen_implicits += target.depfiles regen_implicits += target.depfiles
build.build(
rule = "compdb",
outputs = [compdb],
implicit = regen_implicits,
)
build.default([compdb])
build.newline()
build.build( build.build(
rule = "regen", rule = "regen",
outputs = ['build.ninja'], outputs = ['build.ninja'],