As noted in a comment to #592.
// Is the compiler being asked to output dependencies?
bool generating_dependencies = false;
- // Option MD/MMD
+ // Seen -MD or -MMD?
bool seen_MD_MMD = false;
- // Change target of dependency file
- bool change_dep_file = false;
-
// Is the dependency makefile target name specified with -MT or -MQ?
bool dependency_target_specified = false;
using Result::FileType;
using string_view = nonstd::string_view;
-ResultRetriever::ResultRetriever(Context& ctx) : m_ctx(ctx)
+ResultRetriever::ResultRetriever(Context& ctx, bool rewrite_dependency_target)
+ : m_ctx(ctx), m_rewrite_dependency_target(rewrite_dependency_target)
{
}
if (m_dest_file_type == FileType::stderr_output) {
m_stderr_text.append(reinterpret_cast<const char*>(data), size);
} else if (m_dest_file_type == FileType::dependency && m_first
- && m_ctx.args_info.change_dep_file) {
+ && m_rewrite_dependency_target) {
// Write the object file name
if (!write_fd(*m_dest_fd,
m_ctx.args_info.output_obj.data(),
class ResultRetriever : public Result::Reader::Consumer
{
public:
- ResultRetriever(Context& ctx);
+ ResultRetriever(Context& ctx, bool rewrite_dependency_target);
virtual void on_header(CacheEntryReader& cache_entry_reader);
virtual void on_entry_start(uint32_t entry_number,
std::string m_dest_path;
std::string m_stderr_text;
bool m_first;
+ bool m_rewrite_dependency_target;
};
}
}
- if (!ctx.args_info.dependency_target_specified && ctx.args_info.seen_MD_MMD) {
- ctx.args_info.change_dep_file = true;
- }
-
if (state.generating_debuginfo_level_3 && !config.run_second_cpp()) {
cc_log("Generating debug info level 3; not compiling preprocessed code");
config.set_run_second_cpp(true);
}
}
-// Update a hash with information common for the direct and preprocessor modes.
+static bool
+should_rewrite_dependency_target(const ArgsInfo& args_info)
+{
+ return !args_info.dependency_target_specified && args_info.seen_MD_MMD;
+}
+
+// update a hash with information common for the direct and preprocessor modes.
static void
hash_common_info(const Context& ctx,
const Args& args,
hash.hash(dir_to_hash);
}
- if ((!ctx.args_info.change_dep_file && ctx.args_info.generating_dependencies)
+ if ((!should_rewrite_dependency_target(ctx.args_info)
+ && ctx.args_info.generating_dependencies)
|| ctx.args_info.seen_split_dwarf) {
// The output object file name is part of the .d file, so include the path
// in the hash if generating dependencies.
// Get result from cache.
Result::Reader result_reader(ctx.result_path());
- ResultRetriever result_retriever(ctx);
+ ResultRetriever result_retriever(
+ ctx, should_rewrite_dependency_target(ctx.args_info));
auto error = result_reader.read(result_retriever);
if (error) {