diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2020-11-05 21:02:50 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2020-11-09 08:54:00 +0100 |
commit | 4b0be71f49bf874a45d05293968afd0065d26007 (patch) | |
tree | 835cb2d31db7caea29bd3233f88a68eab48333e0 /unittest | |
parent | 5cd91f0bbb547d9890788754d2df8bdc3cc341cd (diff) | |
download | ccache-4b0be71f49bf874a45d05293968afd0065d26007.tar.gz |
Follow symlinks when guessing compiler
This makes ccache able to guess compiler type “GCC” for a common symlink
chain like this:
/usr/bin/cc -> /etc/alternatives/cc -> /usr/bin/gcc
-> gcc-9 -> x86_64-linux-gnu-gcc-9
Closes #718.
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/test_ccache.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/unittest/test_ccache.cpp b/unittest/test_ccache.cpp index ce8b79d4..93d69c5a 100644 --- a/unittest/test_ccache.cpp +++ b/unittest/test_ccache.cpp @@ -30,6 +30,8 @@ # define CCACHE_NAME "ccache" #endif +using TestUtil::TestContext; + TEST_SUITE_BEGIN("ccache"); // Wraps find_compiler in a test friendly interface. @@ -155,6 +157,50 @@ TEST_CASE("find_compiler") } } +TEST_CASE("guess_compiler") +{ + TestContext test_context; + + SUBCASE("Compiler not in file system") + { + CHECK(guess_compiler("/test/prefix/clang") == GuessedCompiler::clang); + CHECK(guess_compiler("/test/prefix/clang-3.8") == GuessedCompiler::clang); + CHECK(guess_compiler("/test/prefix/clang++") == GuessedCompiler::clang); + CHECK(guess_compiler("/test/prefix/clang++-10") == GuessedCompiler::clang); + + CHECK(guess_compiler("/test/prefix/gcc") == GuessedCompiler::gcc); + CHECK(guess_compiler("/test/prefix/gcc-4.8") == GuessedCompiler::gcc); + CHECK(guess_compiler("/test/prefix/g++") == GuessedCompiler::gcc); + CHECK(guess_compiler("/test/prefix/g++-9") == GuessedCompiler::gcc); + CHECK(guess_compiler("/test/prefix/x86_64-w64-mingw32-gcc-posix") + == GuessedCompiler::gcc); + + CHECK(guess_compiler("/test/prefix/nvcc") == GuessedCompiler::nvcc); + CHECK(guess_compiler("/test/prefix/nvcc-10.1.243") + == GuessedCompiler::nvcc); + + CHECK(guess_compiler("/test/prefix/pump") == GuessedCompiler::pump); + CHECK(guess_compiler("/test/prefix/distcc-pump") == GuessedCompiler::pump); + + CHECK(guess_compiler("/test/prefix/x") == GuessedCompiler::unknown); + CHECK(guess_compiler("/test/prefix/cc") == GuessedCompiler::unknown); + CHECK(guess_compiler("/test/prefix/c++") == GuessedCompiler::unknown); + } + +#ifndef _WIN32 + SUBCASE("Follow symlink to actual compiler") + { + const auto cwd = Util::get_actual_cwd(); + Util::write_file(FMT("{}/gcc", cwd), ""); + CHECK(symlink("gcc", FMT("{}/intermediate", cwd).c_str()) == 0); + const auto cc = FMT("{}/cc", cwd); + CHECK(symlink("intermediate", cc.c_str()) == 0); + + CHECK(guess_compiler(cc) == GuessedCompiler::gcc); + } +#endif +} + TEST_CASE("rewrite_dep_file_paths") { Context ctx; |