]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
chore: Further improve /Tc and /Tp handling
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 7 Feb 2024 20:09:02 +0000 (21:09 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 10 Feb 2024 20:35:05 +0000 (21:35 +0100)
- Remember if /Tc or /Tp was used and prepend it to the source file sent
  to the preprocessor and compiler.
- Mark non-concatenated versions of /Tc and /Tp as too hard for now.

src/ArgsInfo.hpp
src/argprocessing.cpp
src/ccache.cpp
src/compopt.cpp

index ee78a8357b13eaeb9fbe2aba0c58e951c4a87c8f..6fd3f698ebd1e8e62c818a750f3fa1771f247a29 100644 (file)
@@ -34,6 +34,9 @@ struct ArgsInfo
   // The source file path, potentially rewritten into relative.
   std::string input_file;
 
+  // Prefix to the input file when adding it to a command line.
+  std::string input_file_prefix;
+
   // The source file path run through Util::normalize_concrete_absolute_path.
   std::string normalized_input_file;
 
index b823290d6dc8153cb06b4be3e04fd672c96b4948..719c04348d8bd312a1e34d792dd4e1c0feac43ae 100644 (file)
@@ -562,10 +562,10 @@ process_option_arg(const Context& ctx,
       return Statistic::none;
     }
 
-    // MSVC /Tc and /Tp options with no space for specifying input file.
+    // MSVC /Tc and /Tp options in concatenated form for specifying input file.
     if (arg.length() > 3 && util::starts_with(arg, "-T")
         && (arg[2] == 'c' || arg[2] == 'p')) {
-      state.common_args.push_back(args[i]);
+      args_info.input_file_prefix = arg.substr(0, 3);
       state.input_files.emplace_back(arg.substr(3));
       return Statistic::none;
     }
index d73f4dec6a1436cdeb76516630631bdc0add0dce..3741a8dfeb3719c31fc68eacedbd2dfe432c081f 100644 (file)
@@ -1097,7 +1097,8 @@ to_cache(Context& ctx,
   }
 
   if (ctx.config.run_second_cpp()) {
-    args.push_back(ctx.args_info.input_file);
+    args.push_back(
+      FMT("{}{}", ctx.args_info.input_file_prefix, ctx.args_info.input_file));
   } else {
     args.push_back(ctx.i_tmpfile);
   }
@@ -1282,7 +1283,8 @@ get_result_key_from_cpp(Context& ctx, Args& args, Hash& hash)
       args.push_back(preprocessed_path);
     }
 
-    args.push_back(ctx.args_info.input_file);
+    args.push_back(
+      FMT("{}{}", ctx.args_info.input_file_prefix, ctx.args_info.input_file));
 
     add_prefix(args, ctx.config.prefix_command_cpp());
     LOG_RAW("Running preprocessor");
@@ -1870,6 +1872,11 @@ get_manifest_key(Context& ctx, Hash& hash)
   hash.hash_delimiter("inputfile");
   hash.hash(ctx.args_info.input_file);
 
+  if (!ctx.args_info.input_file_prefix.empty()) {
+    hash.hash_delimiter("inputfile prefix");
+    hash.hash(ctx.args_info.input_file_prefix);
+  }
+
   hash.hash_delimiter("sourcecode hash");
   Hash::Digest input_file_digest;
   auto ret =
index 8bac5169c77509dab6d863090eb10d3adf4167c8..9f1d603a04f5f832d8c85f9a4272aebfaea50fbe 100644 (file)
@@ -84,6 +84,8 @@ const CompOpt compopts[] = {
   {"-MM", TOO_HARD},
   {"-MQ", TAKES_ARG},
   {"-MT", TAKES_ARG},
+  {"-Tc", TAKES_ARG | TAKES_PATH | TOO_HARD}, // msvc
+  {"-Tp", TAKES_ARG | TAKES_PATH | TOO_HARD}, // msvc
   {"-U", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG},
   {"-V", TAKES_ARG},
   {"-Wa,", TAKES_CONCAT_ARG | AFFECTS_COMP},