From 066a475e812b8a043439c14fd489a8480994f4da Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 7 Feb 2024 21:09:02 +0100 Subject: [PATCH] chore: Further improve /Tc and /Tp handling - 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 | 3 +++ src/argprocessing.cpp | 4 ++-- src/ccache.cpp | 11 +++++++++-- src/compopt.cpp | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ArgsInfo.hpp b/src/ArgsInfo.hpp index ee78a8357..6fd3f698e 100644 --- a/src/ArgsInfo.hpp +++ b/src/ArgsInfo.hpp @@ -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; diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index b823290d6..719c04348 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -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; } diff --git a/src/ccache.cpp b/src/ccache.cpp index d73f4dec6..3741a8dfe 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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 = diff --git a/src/compopt.cpp b/src/compopt.cpp index 8bac5169c..9f1d603a0 100644 --- a/src/compopt.cpp +++ b/src/compopt.cpp @@ -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}, -- 2.47.2