Enable check_includes_strict by default. Note that this change is backwards-incompatible and will require downstream projects to explicitly disable check_includes_strict in their BUILDCONFIG.gn. Bug: 555455099 Change-Id: Ie05cd7f182053355cba533a3c18ea0d06a6a6964 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/27240 Reviewed-by: Takuto Ikuta <tikuta@google.com> Commit-Queue: Matt Stark <msta@google.com>
diff --git a/src/gn/target_generator.cc b/src/gn/target_generator.cc index 85ddf6e..b58b37a 100644 --- a/src/gn/target_generator.cc +++ b/src/gn/target_generator.cc
@@ -69,9 +69,6 @@ if (!FillAssertNoDeps()) return; - if (!FillCheckIncludesStrict()) - return; - if (!Visibility::FillItemVisibility(target_, scope_, err_)) return; @@ -80,6 +77,14 @@ // Do type-specific generation. DoRun(); + + if (err_->has_error()) + return; + + // FillCheckIncludesStrict requires public and sources to be set. + // This only occurs during DoRun, so it needs to go after it + if (!FillCheckIncludesStrict()) + return; } // static @@ -399,8 +404,17 @@ bool TargetGenerator::FillCheckIncludesStrict() { const Value* value = scope_->GetValue(variables::kCheckIncludesStrict, true); - if (!value) + if (!value) { + // We want to enable check_includes_strict by default *where it makes + // sense*. If there were no header files used, there was no `public`, and + // thus `public_deps` doesn't make any sense except to intentionally + // re-export dependencies. + target_->set_check_includes_strict( + target_->all_headers_public() + ? target_->source_types_used().Get(SourceFile::SOURCE_H) + : !target_->public_headers().empty()); return true; + } if (!value->VerifyTypeIs(Value::BOOLEAN, err_)) return false; target_->set_check_includes_strict(value->boolean_value());