From: Joel Rosdahl Date: Sat, 7 Jun 2025 19:16:30 +0000 (+0200) Subject: fix: Detect cc/c++ hard link to clang/clang++ before gcc/g++ X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9c51f45f34ec0d09d292870e399e47f4c9bb784b;p=thirdparty%2Fccache.git fix: Detect cc/c++ hard link to clang/clang++ before gcc/g++ Apparently clang/clang++ can be gcc/g++ in addition to cc/c++, at least on some macOS versions, so detect clang hard link before gcc since the other way around (gcc installed as an alias of clang) seems less likely. Fixes #1597. --- diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 8c0bce3b..d727ba81 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -295,7 +295,7 @@ probe_generic_compiler(const fs::path& path) // link to a compiler with a more specific name. std::string name = util::pstr(path.filename()).str(); if (name == "cc" || name == "c++") { - static const char* candidate_names[] = {"gcc", "g++", "clang", "clang++"}; + static const char* candidate_names[] = {"clang", "clang++", "gcc", "g++"}; for (const char* candidate_name : candidate_names) { fs::path candidate = path.parent_path() / candidate_name; if (fs::equivalent(candidate, path)) { diff --git a/unittest/test_ccache.cpp b/unittest/test_ccache.cpp index 69770cb2..fcf7326e 100644 --- a/unittest/test_ccache.cpp +++ b/unittest/test_ccache.cpp @@ -223,15 +223,40 @@ TEST_CASE("guess_compiler") CHECK(guess_compiler(clang_cl) == CompilerType::clang_cl); } - SUBCASE("Probe hardlink for actual compiler") + SUBCASE("Probe hardlink for actual compiler, gcc") { const auto cwd = *fs::current_path(); - util::write_file(cwd / "gcc", ""); const auto cc = cwd / "cc"; - CHECK(fs::create_hard_link("gcc", cc)); + const auto gcc = cwd / "gcc"; + util::write_file(cwd / "cc", ""); + CHECK(fs::create_hard_link(cc, gcc)); CHECK(guess_compiler(cc) == CompilerType::gcc); } + + SUBCASE("Probe hardlink for actual compiler, clang") + { + const auto cwd = *fs::current_path(); + const auto cc = cwd / "cc"; + const auto clang = cwd / "clang"; + util::write_file(cwd / "cc", ""); + CHECK(fs::create_hard_link(cc, clang)); + + CHECK(guess_compiler(cc) == CompilerType::clang); + } + + SUBCASE("Probe hardlink for actual compiler, gcc+clang") + { + const auto cwd = *fs::current_path(); + const auto cc = cwd / "cc"; + const auto gcc = cwd / "gcc"; + const auto clang = cwd / "clang"; + util::write_file(cwd / "cc", ""); + CHECK(fs::create_hard_link(cc, gcc)); + CHECK(fs::create_hard_link(cc, clang)); + + CHECK(guess_compiler(cc) == CompilerType::clang); + } #endif }