]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Use -P -Fi for saving MSVC preprocessor output
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 25 Aug 2022 19:15:01 +0000 (21:15 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 25 Aug 2022 19:43:49 +0000 (21:43 +0200)
Even though MSVC supports "-E" and "-c -o" it apparently doesn't support
"-E -o", so [1] broke MSVC.

[1]: 64fc42ca2c5c9fe60ef4f1dc3882edb5f35579d6

Fixes #1146.

(cherry picked from commit 80a228c3c2014d9953b51ed3ade7ad21f50912f8)

src/ccache.cpp

index 620abb82e825bf0ab1f21854d0b7d3e62e94b799..69f2ce0f858915c5f0f231ab9e64c606978c0eac 100644 (file)
@@ -1134,16 +1134,22 @@ get_result_key_from_cpp(Context& ctx, Args& args, Hash& hash)
     ctx.register_pending_tmp_file(preprocessed_path);
 
     const size_t orig_args_size = args.size();
-    args.push_back("-E");
+
     if (ctx.config.keep_comments_cpp()) {
       args.push_back("-C");
     }
 
-    // Pass -o instead of sending the preprocessor output to stdout to work
-    // around compilers that don't exit with a proper status on write error to
-    // stdout. See also <https://github.com/llvm/llvm-project/issues/56499>.
-    args.push_back("-o");
-    args.push_back(preprocessed_path);
+    // Send preprocessor output to a file instead of stdout to work around
+    // compilers that don't exit with a proper status on write error to stdout.
+    // See also <https://github.com/llvm/llvm-project/issues/56499>.
+    if (ctx.config.is_compiler_group_msvc()) {
+      args.push_back("-P");
+      args.push_back(FMT("-Fi{}", preprocessed_path));
+    } else {
+      args.push_back("-E");
+      args.push_back("-o");
+      args.push_back(preprocessed_path);
+    }
 
     args.push_back(ctx.args_info.input_file);