Skip to content

Commit 8881d16

Browse files
authored
Merge pull request #7840 from The-OpenROAD-Project-staging/run-clang-tidy-compile-json
run-clang-tidy-cached.cc now take COMPILE_JSON envar
2 parents 2e35f60 + ac829bd commit 8881d16

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

etc/run-clang-tidy-cached.cc

Lines changed: 14 additions & 9 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>
@@ -282,7 +284,8 @@ class ClangTidyRunner
282284
// Given a work-queue in/out-file, process it. Using system() for portability.
283285
// Empties work_queue.
284286
void RunClangTidyOn(ContentAddressedStore& output_store,
285-
std::list<filepath_contenthash_t>* work_queue)
287+
std::list<filepath_contenthash_t>* work_queue,
288+
std::string_view compile_json_str)
286289
{
287290
if (work_queue->empty()) {
288291
return;
@@ -319,9 +322,10 @@ class ClangTidyRunner
319322
const std::string tmp_out = final_out.string() + uniquifier + ".tmp";
320323
// Putting the file to clang-tidy early in the command line so that
321324
// it is easy to find with `ps` or `top`.
322-
const std::string command = clang_tidy_ + " '" + work.first.string()
323-
+ "'" + clang_tidy_args_ + "> '" + tmp_out
324-
+ "' 2>/dev/null";
325+
const std::string command
326+
= clang_tidy_ + " -p " + std::string(compile_json_str) + " '"
327+
+ work.first.string() + "'" + clang_tidy_args_ + "> '" + tmp_out
328+
+ "' 2>/dev/null";
325329
const int r = system(command.c_str());
326330
#ifdef WIFSIGNALED
327331
// NOLINTBEGIN
@@ -629,14 +633,15 @@ int main(int argc, char* argv[])
629633
return EXIT_FAILURE;
630634
}
631635

632-
auto compdb_ts = fs::last_write_time("compile_commands.json", ec);
636+
std::string_view compile_json_str
637+
= EnvWithFallback("COMPILE_JSON", "build/compile_commands.json");
638+
auto compdb_ts = fs::last_write_time(compile_json_str, ec);
633639
if (ec.value() != 0) {
634640
compdb_ts = fs::last_write_time("compile_flags.txt", ec);
635641
}
636642
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";
643+
std::cerr << "No compilation db " << compile_json_str
644+
<< " found; create that first.\n";
640645
return EXIT_FAILURE;
641646
}
642647

@@ -655,7 +660,7 @@ int main(int argc, char* argv[])
655660
auto work_list = cc_file_gatherer.BuildWorkList(build_env_latest_change);
656661

657662
// Now the expensive part...
658-
runner.RunClangTidyOn(store, &work_list);
663+
runner.RunClangTidyOn(store, &work_list, compile_json_str);
659664

660665
const std::string detailed_report = cache_prefix + "clang-tidy.out";
661666
const std::string summary = cache_prefix + "clang-tidy.summary";

0 commit comments

Comments
 (0)