Skip to content

Commit 82e53e7

Browse files
committed
run-clang-tidy-cached.cc now take COMPILE_JSON envar
This defaults to build/compile_commands.json to avoid the need for a symlink while still preserving the ability to use an abitrary input. Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent bf4f697 commit 82e53e7

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

etc/run-clang-tidy-cached.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ B=${0%%.cc}; [ "$B" -nt "$0" ] || c++ -std=c++17 -o"$B" "$0" && exec "$B" "$@";
3232
// CLANG_TIDY_CONFIG = override configuration file in kConfig.clang_tidy_file
3333
// CACHE_DIR = where to put the cached content; default ~/.cache
3434
// CLANG_TIDY_JOBS = Number of tasks to run in parallel.
35+
// COMPILE_JSON = where to find cmake compile commands;
36+
// default build/compile_commands.json
3537

3638
// This file shall be c++17 self-contained; not using any re2 or absl niceties.
3739
#include <unistd.h>
@@ -629,14 +631,15 @@ int main(int argc, char* argv[])
629631
return EXIT_FAILURE;
630632
}
631633

632-
auto compdb_ts = fs::last_write_time("compile_commands.json", ec);
634+
std::string_view compile_json_str
635+
= EnvWithFallback("COMPILE_JSON", "build/compile_commands.json");
636+
auto compdb_ts = fs::last_write_time(compile_json_str, ec);
633637
if (ec.value() != 0) {
634638
compdb_ts = fs::last_write_time("compile_flags.txt", ec);
635639
}
636640
if (ec.value() != 0) {
637-
std::cerr << "No compilation db compile_commands.json or compile_flags.txt "
638-
<< "found; create that first. For cmake projects, often simply\n"
639-
<< "\tln -s build/compile_commands.json .\n";
641+
std::cerr << "No compilation db " << compile_json_str
642+
<< " found; create that first.\n";
640643
return EXIT_FAILURE;
641644
}
642645

0 commit comments

Comments
 (0)