]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Look for correct -march=native expansion line on Windows
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 9 Dec 2025 19:14:57 +0000 (20:14 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 9 Dec 2025 20:22:13 +0000 (21:22 +0100)
src/ccache/ccache.cpp
test/fake-compilers/gcc-march-native-win.sh [new file with mode: 0755]
test/suites/base.bash

index 99ccfe49a7c4f040f2b8fa25bb90dfa560c5b2e0..b44296db2d5e939b02f1349c7958abcd6ff862fe 100644 (file)
@@ -2026,7 +2026,11 @@ hash_native_args(Context& ctx, const util::Args& native_args, Hash& hash)
   std::string_view search_string =
     ctx.config.is_compiler_group_clang()
       ? "\"-cc1\"" // "/usr/lib/llvm-18/bin/clang" "-cc1" "-triple" ...
-      : "/cc1 -E"; // /usr/libexec/gcc/x86_64-linux-gnu/13/cc1 -E -quiet ...
+#ifdef _WIN32
+      : "/cc1.exe\" -E"; // "C:/.../cc1.exe" -E -quiet ...
+#else
+      : "/cc1 -E"; // /usr/.../cc1 -E -quiet ...
+#endif
   std::optional<std::string_view> line_to_hash;
   for (const auto line : util::Tokenizer(*output, "\n")) {
     if (line.find(search_string) != std::string_view::npos) {
diff --git a/test/fake-compilers/gcc-march-native-win.sh b/test/fake-compilers/gcc-march-native-win.sh
new file mode 100755 (executable)
index 0000000..7501a82
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+args=("$@")
+
+if [ "$1" = "-###" ]; then
+    cat <<EOF >&2
+Using built-in specs.
+...
+COLLECT_GCC_OPTIONS='-E' ...
+ "/example/cc1.exe" -E -quiet $CC1_ARGS
+COMPILER_PATH=/example
+EOF
+    echo "bin/cc1"
+elif [ "$1" = "-E" ]; then
+    echo preprocessed >"${args[$#-2]}"
+else
+    echo compiled >"${args[$#-2]}"
+fi
index 0074ebf72827fd05527a4241e8e092584ed69e04..cdb7daff6bfe6a4c2104b212b8a626eba80795ba 100644 (file)
@@ -1661,19 +1661,25 @@ EOF
     # -------------------------------------------------------------------------
     TEST "-march=native, GCC"
 
-    CC1_ARGS=one $CCACHE "$TEST_BASE_DIR/fake-compilers/gcc-march-native.sh" -march=native -c test1.c
+    if $HOST_OS_WINDOWS; then
+        compiler="$TEST_BASE_DIR/fake-compilers/gcc-march-native-win.sh"
+    else
+        compiler="$TEST_BASE_DIR/fake-compilers/gcc-march-native.sh"
+    fi
+
+    CC1_ARGS=one $CCACHE "${compiler}" -march=native -c test1.c
     expect_stat preprocessed_cache_hit 0
     expect_stat cache_miss 1
 
-    CC1_ARGS=one $CCACHE "$TEST_BASE_DIR/fake-compilers/gcc-march-native.sh" -march=native -c test1.c
+    CC1_ARGS=one $CCACHE "${compiler}" -march=native -c test1.c
     expect_stat preprocessed_cache_hit 1
     expect_stat cache_miss 1
 
-    CC1_ARGS=two $CCACHE "$TEST_BASE_DIR/fake-compilers/gcc-march-native.sh" -march=native -c test1.c
+    CC1_ARGS=two $CCACHE "${compiler}" -march=native -c test1.c
     expect_stat preprocessed_cache_hit 1
     expect_stat cache_miss 2
 
-    CC1_ARGS=two $CCACHE "$TEST_BASE_DIR/fake-compilers/gcc-march-native.sh" -march=native -c test1.c
+    CC1_ARGS=two $CCACHE "${compiler}" -march=native -c test1.c
     expect_stat preprocessed_cache_hit 2
     expect_stat cache_miss 2