Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: tools/gn/target.cc

Issue 2394163004: GN: Check if targets with precompiled headers use unsupported toolchains. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/target.h ('k') | tools/gn/target_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+}
« no previous file with comments | « tools/gn/target.h ('k') | tools/gn/target_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698