From a30ef5b3dc58da93de4134c8f2405f55cdea992e Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sun, 23 Jan 2022 17:47:06 -0800 Subject: [PATCH] [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. --- .gitignore | 1 + configs/rules.ninja | 3 +++ scripts/bonnibel/module.py | 6 +++--- scripts/bonnibel/project.py | 10 ++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 29ce563..9d87b33 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ sysroot .peru __pycache__ /venv +compile_commands.json diff --git a/configs/rules.ninja b/configs/rules.ninja index 53f774c..905ba97 100644 --- a/configs/rules.ninja +++ b/configs/rules.ninja @@ -76,3 +76,6 @@ rule strip rule touch command = touch $out + +rule compdb + command = ninja -t compdb > $out diff --git a/scripts/bonnibel/module.py b/scripts/bonnibel/module.py index 458f6cb..4fa6439 100644 --- a/scripts/bonnibel/module.py +++ b/scripts/bonnibel/module.py @@ -141,7 +141,7 @@ class Module: inputs = [] parse_deps = [] - parse_dep = "${module_dir}/.parse_dep.phony" + parse_depfile = "${module_dir}/.parse_dep.phony" for start in self.sources: source = start @@ -150,7 +150,7 @@ class Module: output = source.output if source.action.parse_deps: - oodeps = [parse_dep] + oodeps = [parse_depfile] else: oodeps = [] @@ -177,7 +177,7 @@ class Module: build.newline() build.build( rule = "touch", - outputs = [parse_dep], + outputs = [parse_depfile], implicit = child_deps, order_only = parse_deps, ) diff --git a/scripts/bonnibel/project.py b/scripts/bonnibel/project.py index 42e865c..6a4802c 100644 --- a/scripts/bonnibel/project.py +++ b/scripts/bonnibel/project.py @@ -142,6 +142,8 @@ class Project: build.default([out]) build.newline() + compdb = "${source_root}/compile_commands.json" + build.rule("regen", command = " ".join([str(root / 'configure')] + sys.argv[1:]), description = "Regenerate build files", @@ -156,6 +158,14 @@ class Project: for target in targets: regen_implicits += target.depfiles + build.build( + rule = "compdb", + outputs = [compdb], + implicit = regen_implicits, + ) + build.default([compdb]) + build.newline() + build.build( rule = "regen", outputs = ['build.ninja'],