gn: Use .obj extension for pch objects on Windows.
Fixes a cosmetic regression from https://codereview.chromium.org/1292983004
BUG=603902
Review URL: https://codereview.chromium.org/1893933002
Cr-Original-Commit-Position: refs/heads/master@{#387893}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: c065bd83a55626de81db52aca9bf88dbb425e904
diff --git a/tools/gn/ninja_binary_target_writer.cc b/tools/gn/ninja_binary_target_writer.cc
index a62f872..4a923c3 100644
--- a/tools/gn/ninja_binary_target_writer.cc
+++ b/tools/gn/ninja_binary_target_writer.cc
@@ -103,14 +103,15 @@
}
}
-std::string GetWindowsPCHObjectExtension(Toolchain::ToolType tool_type) {
+std::string GetWindowsPCHObjectExtension(Toolchain::ToolType tool_type,
+ const std::string& obj_extension) {
const char* lang_suffix = GetPCHLangSuffixForToolType(tool_type);
std::string result = ".";
// For MSVC, annotate the obj files with the language type. For example:
- // obj/foo/target_name.precompile.o ->
- // obj/foo/target_name.precompile.cc.o
+ // obj/foo/target_name.precompile.obj ->
+ // obj/foo/target_name.precompile.cc.obj
result += lang_suffix;
- result += ".o";
+ result += obj_extension;
return result;
}
@@ -182,7 +183,8 @@
Tool::PrecompiledHeaderType header_type = tool->precompiled_header_type();
switch (header_type) {
case Tool::PCH_MSVC:
- output_extension = GetWindowsPCHObjectExtension(tool_type);
+ output_extension = GetWindowsPCHObjectExtension(
+ tool_type, output_value.substr(extension_offset - 1));
break;
case Tool::PCH_GCC:
output_extension = GetGCCPCHOutputExtension(tool_type);
@@ -621,7 +623,7 @@
if (tool_type != Toolchain::TYPE_NONE) {
// Only include PCH deps that correspond to the tool type, for instance,
- // do not specify target_name.precompile.cc.o (a CXX PCH file) as a dep
+ // do not specify target_name.precompile.cc.obj (a CXX PCH file) as a dep
// for the output of a C tool type.
//
// This makes the assumption that pch_deps only contains pch output files
@@ -631,9 +633,13 @@
if (tool->precompiled_header_type() != Tool::PCH_NONE) {
for (const auto& dep : pch_deps) {
const std::string& output_value = dep.value();
+ size_t extension_offset = FindExtensionOffset(output_value);
+ if (extension_offset == std::string::npos)
+ continue;
std::string output_extension;
if (tool->precompiled_header_type() == Tool::PCH_MSVC) {
- output_extension = GetWindowsPCHObjectExtension(tool_type);
+ output_extension = GetWindowsPCHObjectExtension(
+ tool_type, output_value.substr(extension_offset - 1));
} else if (tool->precompiled_header_type() == Tool::PCH_GCC) {
output_extension = GetGCCPCHOutputExtension(tool_type);
}