Index: tools/gn/target.cc |
diff --git a/tools/gn/target.cc b/tools/gn/target.cc |
index aafdc4fedce82579452e522357e17519127e483e..9eff72fcbd93a8a156640853a56d30dcd4474b1a 100644 |
--- a/tools/gn/target.cc |
+++ b/tools/gn/target.cc |
@@ -308,6 +308,9 @@ bool Target::OnResolved(Err* err) { |
if (!CheckAssertNoDeps(err)) |
return false; |
CheckSourcesGenerated(); |
+ if (config_values_.has_precompiled_headers() && |
+ !CheckPrecompiledHeaders(err)) |
+ return false; |
} |
if (!write_runtime_deps_output_.value().empty()) |
@@ -777,3 +780,45 @@ void Target::CheckSourceGenerated(const SourceFile& source) const { |
g_scheduler->AddUnknownGeneratedInput(this, source); |
} |
} |
+ |
+bool Target::CheckPrecompiledHeaders(Err* err) const { |
+ // Figure out what source types are needed. |
+ SourceFileTypeSet used_types; |
+ for (const auto& source : sources_) |
+ used_types.Set(GetSourceFileType(source)); |
+ |
+ // Not all source types support precompiled precompiled headers. |
+ static const SourceFileType kSourceTypesToCheck[] = { |
+ SOURCE_C, SOURCE_CPP, SOURCE_M, SOURCE_MM, |
+ }; |
+ |
+ bool is_valid = true; |
+ for (auto type : kSourceTypesToCheck) { |
+ if (!used_types.Get(type)) |
+ continue; |
+ |
+ const Toolchain::ToolType toolType = |
+ Toolchain::GetToolTypeForSourceType(type); |
+ const Tool* tool = toolchain_->GetTool(toolType); |
+ |
+ if (!tool || tool->precompiled_header_type() != Tool::PCH_NONE) |
+ continue; |
+ |
+ // Make a generic error first and then append a list of "broken" tool()s. |
+ if (!err->has_error()) { |
+ *err = Err(defined_from(), |
+ "Toolchain (" + toolchain_->label().GetUserVisibleName(false) + |
+ ") used by target (" + label().GetUserVisibleName(false) + |
+ ") doesn't support precompiled headers.", |
+ "Either remove the precompiled header from the target or add " |
+ "support to the toolchain."); |
+ is_valid = false; |
+ } |
+ |
+ err->AppendSubErr(Err(tool->defined_from(), |
+ "Tool \"" + Toolchain::ToolTypeToName(toolType) + |
+ "\" doesn't set precompiled_header_type.")); |
+ } |
+ |
+ return is_valid; |
+} |