Check headers as well as sources for generated files.

Previously, gn only required that your dependencies generate any
required generated files used in your sources. Now they also require
that your dependencies generate any required header files.

Bug: 556959580
Change-Id: I5181217b94e6eca50a1ffee43d6ca1a56a6a6964
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/28781
Commit-Queue: Matt Stark <msta@google.com>
Reviewed-by: Takuto Ikuta <tikuta@google.com>
diff --git a/src/gn/command_gen.cc b/src/gn/command_gen.cc
index 704e504..15937af 100644
--- a/src/gn/command_gen.cc
+++ b/src/gn/command_gen.cc
@@ -152,6 +152,14 @@
   }
 }
 
+bool HasDirectPrivateDep(const Target* target, const Target* dep) {
+  for (const auto& pair : target->private_deps()) {
+    if (pair.ptr == dep)
+      return true;
+  }
+  return false;
+}
+
 struct CompareTargets {
   bool operator()(const Target* lhs, const Target* rhs) const {
     if (!lhs)
@@ -170,42 +178,96 @@
 
 template <typename T>
 using OrderedTargetMap = std::map<const Target*, T, CompareTargets>;
+using TargetFilesMap = OrderedTargetMap<std::set<SourceFile>>;
+
+struct MissingSourceFiles {
+  TargetFilesMap needs_private_dep;
+  TargetFilesMap needs_public_dep;
+  TargetFilesMap should_be_public;
+};
 
 // Returns an error for a target that declared source or input files in the
 // output directory without the required dependency on the generating target.
-Err CreateInvalidGeneratedInputError(
-    const Target* target,
-    const OrderedTargetMap<std::set<SourceFile>>& missing_files) {
+Err CreateInvalidGeneratedInputError(const Target* target,
+                                     const MissingSourceFiles& missing) {
   const Label& default_toolchain =
       target->settings()->default_toolchain_label();
 
   std::string err = "The target:\n  " +
                     target->label().GetUserVisibleName(default_toolchain) +
                     "\n";
-  size_t file_count = 0;
-  for (const auto& [generator, files] : missing_files)
-    file_count += files.size();
-  err += file_count > 1
-             ? "has inputs or sources not generated by any dependencies:\n"
-             : "has an input or source not generated by any dependencies:\n";
+  bool has_section = false;
 
-  std::string deps_str;
-  for (const auto& [generator, files] : missing_files) {
-    std::string suffix;
-    if (generator) {
-      std::string gen_name = generator->label().AsRelative(target->label());
-      suffix = " (generated by " + gen_name + ")\n";
-      deps_str += " " + gen_name;
-    } else {
-      suffix = " (not generated by any target)\n";
+  auto append_section = [&](const TargetFilesMap& targets,
+                            std::string_view singular,
+                            std::string_view plural) {
+    if (targets.empty())
+      return;
+    if (has_section)
+      err += "and ";
+    has_section = true;
+    size_t file_count = 0;
+    for (const auto& [generator, files] : targets)
+      file_count += files.size();
+    err += file_count > 1 ? plural : singular;
+    for (const auto& [generator, files] : targets) {
+      std::string suffix;
+      if (generator) {
+        suffix = " (generated by " +
+                 generator->label().AsRelative(target->label()) + ")\n";
+      } else {
+        suffix = " (not generated by any target)\n";
+      }
+      for (const SourceFile& file : files)
+        err += "  " + file.value() + suffix;
     }
-    for (const SourceFile& file : files)
-      err += "  " + file.value() + suffix;
+  };
+
+  append_section(missing.should_be_public,
+                 "has a public header generated by a private dependency:\n",
+                 "has public headers generated by private dependencies:\n");
+  append_section(missing.needs_public_dep,
+                 "has a public header not generated by any public_deps:\n",
+                 "has public headers not generated by any public_deps:\n");
+  append_section(missing.needs_private_dep,
+                 "has an input or source not generated by any dependencies:\n",
+                 "has inputs or sources not generated by any dependencies:\n");
+
+  if (!missing.should_be_public.empty()) {
+    err +=
+        "Strict include checking requires public headers to be generated "
+        "by\npublic_deps rather than deps.\n";
   }
 
-  if (!deps_str.empty()) {
-    err += "\nTo fix this, run:\n  gn edit \"add deps" + deps_str + "\" " +
-           target->label().GetUserVisibleName(false);
+  std::string edit_cmds;
+  auto append_edit = [&](std::string_view command,
+                         const TargetFilesMap& targets, auto should_include) {
+    std::string deps_str;
+    for (const auto& [generator, files] : targets) {
+      if (generator && should_include(generator)) {
+        deps_str += " " + generator->label().AsRelative(target->label());
+      }
+    }
+    if (!deps_str.empty()) {
+      edit_cmds += "\n  gn edit \"";
+      edit_cmds += command;
+      edit_cmds += deps_str;
+      edit_cmds += "\" " + target->label().GetUserVisibleName(false);
+    }
+  };
+
+  auto include_all = [](const Target*) { return true; };
+  // Promoting or adding a dependency to public_deps satisfies private deps too,
+  // so avoid suggesting adding the same dependency to deps as well.
+  append_edit("add deps", missing.needs_private_dep, [&](const Target* gen) {
+    return !missing.should_be_public.contains(gen) &&
+           !missing.needs_public_dep.contains(gen);
+  });
+  append_edit("move deps public_deps", missing.should_be_public, include_all);
+  append_edit("add public_deps", missing.needs_public_dep, include_all);
+
+  if (!edit_cmds.empty()) {
+    err += "\nTo fix this, run:" + edit_cmds;
   } else if (!err.empty() && err.back() == '\n') {
     err.pop_back();
   }
@@ -213,7 +275,8 @@
   return Err(Location(), "Input to target not generated by a dependency.", err);
 }
 
-using UnknownGeneratedInputs = std::multimap<SourceFile, const Target*>;
+using UnknownGeneratedInputs =
+    std::multimap<SourceFile, std::pair<const Target*, Scheduler::DepType>>;
 
 std::vector<Err> ComputeInvalidGeneratedInputErrors(
     const UnknownGeneratedInputs& unknown_inputs,
@@ -227,13 +290,21 @@
       generators.emplace(output, target);
   }
 
-  // Map from Target with missing inputs to target generating a set of inputs.
-  OrderedTargetMap<OrderedTargetMap<std::set<SourceFile>>> by_target;
-  for (const auto& [file, target] : unknown_inputs) {
+  OrderedTargetMap<MissingSourceFiles> by_target;
+  for (const auto& [file, entry] : unknown_inputs) {
+    auto [target, dep_type] = entry;
     auto it =
         generators.find(OutputFile(target->settings()->build_settings(), file));
     const Target* generator = it != generators.end() ? it->second : nullptr;
-    by_target[target][generator].insert(file);
+    MissingSourceFiles& missing = by_target[target];
+    if (dep_type == Scheduler::PUBLIC_DEP) {
+      if (generator && HasDirectPrivateDep(target, generator))
+        missing.should_be_public[generator].insert(file);
+      else
+        missing.needs_public_dep[generator].insert(file);
+    } else {
+      missing.needs_private_dep[generator].insert(file);
+    }
   }
 
   std::vector<Err> errors;
diff --git a/src/gn/commands_unittest.cc b/src/gn/commands_unittest.cc
index b1abd5d..1116669 100644
--- a/src/gn/commands_unittest.cc
+++ b/src/gn/commands_unittest.cc
@@ -257,14 +257,19 @@
 
   TestTarget gen_alpha(setup, "//gen:alpha", Target::ACTION);
   gen_alpha.action_values().outputs() =
-      SubstitutionList::MakeForTest("//out/Debug/z.cc");
+      SubstitutionList::MakeForTest("//out/Debug/z.h", "//out/Debug/z.cc");
   ASSERT_TRUE(gen_alpha.OnResolved(&err));
 
   TestTarget gen_beta(setup, "//gen:beta", Target::ACTION);
-  gen_beta.action_values().outputs() =
-      SubstitutionList::MakeForTest("//out/Debug/b.cc", "//out/Debug/a.cc");
+  gen_beta.action_values().outputs() = SubstitutionList::MakeForTest(
+      "//out/Debug/b.cc", "//out/Debug/a.cc", "//out/Debug/a.h");
   ASSERT_TRUE(gen_beta.OnResolved(&err));
 
+  TestTarget gen_gamma(setup, "//gen:gamma", Target::ACTION);
+  gen_gamma.action_values().outputs() =
+      SubstitutionList::MakeForTest("//out/Debug/priv.cc");
+  ASSERT_TRUE(gen_gamma.OnResolved(&err));
+
   Target alt_gen(&alt_settings, Label(SourceDir("//gen/"), "alt_gen",
                                       alt_toolchain.label().dir(),
                                       alt_toolchain.label().name()));
@@ -272,7 +277,7 @@
   alt_gen.set_output_type(Target::ACTION);
   ASSERT_TRUE(alt_gen.SetToolchain(&alt_toolchain, &err));
   alt_gen.action_values().outputs() =
-      SubstitutionList::MakeForTest("//out/Debug/alt/alt.cc");
+      SubstitutionList::MakeForTest("//out/Debug/alt/alt.h");
   ASSERT_TRUE(alt_gen.OnResolved(&err));
 
   TestTarget single_missing(setup, "//a:single_missing", Target::SOURCE_SET);
@@ -286,6 +291,18 @@
   grouped_by_gen.sources().emplace_back("//out/Debug/a.cc");
   ASSERT_TRUE(grouped_by_gen.OnResolved(&err));
 
+  TestTarget combined(setup, "//c:combined", Target::SOURCE_SET);
+  combined.set_check_includes_strict(true);
+  combined.set_all_headers_public(false);
+  combined.public_headers().emplace_back("//out/Debug/missing.h");
+  combined.public_headers().emplace_back("//out/Debug/z.h");
+  combined.public_headers().emplace_back("//out/Debug/a.h");
+  combined.private_deps().push_back(LabelTargetPair(&gen_beta));
+  combined.sources().emplace_back("//out/Debug/missing.cc");
+  combined.sources().emplace_back("//out/Debug/priv.cc");
+  combined.sources().emplace_back("//out/Debug/z.cc");
+  ASSERT_TRUE(combined.OnResolved(&err));
+
   Target multi_tc_alt(&alt_settings, Label(SourceDir("//e/"), "multi_tc",
                                            alt_toolchain.label().dir(),
                                            alt_toolchain.label().name()));
@@ -296,7 +313,8 @@
   ASSERT_TRUE(multi_tc_alt.OnResolved(&err));
 
   TestTarget multi_tc_default(setup, "//e:multi_tc", Target::SOURCE_SET);
-  multi_tc_default.sources().emplace_back("//out/Debug/alt/alt.cc");
+  multi_tc_default.set_check_includes_strict(true);
+  multi_tc_default.sources().emplace_back("//out/Debug/alt/alt.h");
   ASSERT_TRUE(multi_tc_default.OnResolved(&err));
 
   Target alt_only(&alt_settings, Label(SourceDir("//f/"), "alt_only",
@@ -313,13 +331,15 @@
       &alt_only,
       &multi_tc_default,
       &multi_tc_alt,
+      &combined,
       &grouped_by_gen,
       &single_missing,
       &alt_gen,
+      &gen_gamma,
       &gen_beta,
       &gen_alpha,
   });
-  ASSERT_EQ(4u, errors.size());
+  ASSERT_EQ(5u, errors.size());
 
   // Single missing file uses singular phrasing.
   EXPECT_EQ("Input to target not generated by a dependency.",
@@ -351,26 +371,50 @@
       "  gn edit \"add deps //gen:alpha //gen:beta\" //b:grouped_by_gen",
       errors[1].help_text());
 
-  // Toolchain deduplication prefers default toolchain and prints dep toolchain.
+  // Combined public_deps, private_deps, and add deps deduplication.
   EXPECT_EQ("Input to target not generated by a dependency.",
             errors[2].message());
   EXPECT_EQ(
       "The target:\n"
-      "  //e:multi_tc\n"
-      "has an input or source not generated by any dependencies:\n"
-      "  //out/Debug/alt/alt.cc (generated by //gen:alt_gen(//aaa:alt))\n"
+      "  //c:combined\n"
+      "has a public header generated by a private dependency:\n"
+      "  //out/Debug/a.h (generated by //gen:beta)\n"
+      "and has public headers not generated by any public_deps:\n"
+      "  //out/Debug/z.h (generated by //gen:alpha)\n"
+      "  //out/Debug/missing.h (not generated by any target)\n"
+      "and has inputs or sources not generated by any dependencies:\n"
+      "  //out/Debug/z.cc (generated by //gen:alpha)\n"
+      "  //out/Debug/priv.cc (generated by //gen:gamma)\n"
+      "  //out/Debug/missing.cc (not generated by any target)\n"
+      "Strict include checking requires public headers to be generated by\n"
+      "public_deps rather than deps.\n"
       "\n"
       "To fix this, run:\n"
-      "  gn edit \"add deps //gen:alt_gen(//aaa:alt)\" //e:multi_tc",
+      "  gn edit \"add deps //gen:gamma\" //c:combined\n"
+      "  gn edit \"move deps public_deps //gen:beta\" //c:combined\n"
+      "  gn edit \"add public_deps //gen:alpha\" //c:combined",
       errors[2].help_text());
 
+  // Toolchain deduplication prefers default toolchain and prints dep toolchain.
+  EXPECT_EQ("Input to target not generated by a dependency.",
+            errors[3].message());
+  EXPECT_EQ(
+      "The target:\n"
+      "  //e:multi_tc\n"
+      "has a public header not generated by any public_deps:\n"
+      "  //out/Debug/alt/alt.h (generated by //gen:alt_gen(//aaa:alt))\n"
+      "\n"
+      "To fix this, run:\n"
+      "  gn edit \"add public_deps //gen:alt_gen(//aaa:alt)\" //e:multi_tc",
+      errors[3].help_text());
+
   // Non-default target with only ungenerated inputs omits gn edit instructions.
   EXPECT_EQ("Input to target not generated by a dependency.",
-            errors[3].message());
+            errors[4].message());
   EXPECT_EQ(
       "The target:\n"
       "  //f:alt_only(//aaa:alt)\n"
       "has an input or source not generated by any dependencies:\n"
       "  //out/Debug/alt/missing.cc (not generated by any target)",
-      errors[3].help_text());
+      errors[4].help_text());
 }
diff --git a/src/gn/scheduler.cc b/src/gn/scheduler.cc
index c6de66e..b4d2a56 100644
--- a/src/gn/scheduler.cc
+++ b/src/gn/scheduler.cc
@@ -5,6 +5,7 @@
 #include "gn/scheduler.h"
 
 #include <algorithm>
+#include <utility>
 
 #include "gn/standard_out.h"
 #include "gn/target.h"
@@ -106,9 +107,10 @@
 }
 
 void Scheduler::AddUnknownGeneratedInput(const Target* target,
-                                         const SourceFile& file) {
+                                         const SourceFile& file,
+                                         DepType dep_type) {
   std::lock_guard<std::mutex> lock(lock_);
-  unknown_generated_inputs_.insert(std::make_pair(file, target));
+  unknown_generated_inputs_.emplace(file, std::make_pair(target, dep_type));
 }
 
 void Scheduler::AddWriteRuntimeDepsTarget(const Target* target) {
@@ -143,8 +145,8 @@
   return generated_files_.find(file) != generated_files_.end();
 }
 
-std::multimap<SourceFile, const Target*> Scheduler::GetUnknownGeneratedInputs()
-    const {
+std::multimap<SourceFile, std::pair<const Target*, Scheduler::DepType>>
+Scheduler::GetUnknownGeneratedInputs() const {
   std::lock_guard<std::mutex> lock(lock_);
 
   // Remove all unknown inputs that were written files. These are OK as inputs
@@ -152,7 +154,8 @@
   //
   // It's assumed that this function is called once during cleanup to check for
   // errors, so performing this work in the lock doesn't matter.
-  std::multimap<SourceFile, const Target*> filtered = unknown_generated_inputs_;
+  std::multimap<SourceFile, std::pair<const Target*, DepType>> filtered =
+      unknown_generated_inputs_;
   for (const SourceFile& file : written_files_)
     filtered.erase(file);
 
diff --git a/src/gn/scheduler.h b/src/gn/scheduler.h
index 0db3726..ffe15ce 100644
--- a/src/gn/scheduler.h
+++ b/src/gn/scheduler.h
@@ -9,6 +9,8 @@
 #include <functional>
 #include <map>
 #include <mutex>
+#include <utility>
+#include <vector>
 
 #include "base/atomic_ref_count.h"
 #include "base/files/file_path.h"
@@ -24,6 +26,11 @@
 // Maintains the thread pool and error state.
 class Scheduler {
  public:
+  enum DepType {
+    PRIVATE_DEP,
+    PUBLIC_DEP,
+  };
+
   Scheduler();
   ~Scheduler();
 
@@ -90,8 +97,11 @@
   //
   // The result returned by GetUnknownGeneratedInputs will not count any files
   // that were written by write_file during execution.
-  void AddUnknownGeneratedInput(const Target* target, const SourceFile& file);
-  std::multimap<SourceFile, const Target*> GetUnknownGeneratedInputs() const;
+  void AddUnknownGeneratedInput(const Target* target,
+                                const SourceFile& file,
+                                DepType dep_type);
+  std::multimap<SourceFile, std::pair<const Target*, DepType>>
+  GetUnknownGeneratedInputs() const;
   void ClearUnknownGeneratedInputsAndWrittenFiles();  // For testing.
 
   // We maintain a count of the things we need to do that works like a
@@ -149,7 +159,8 @@
   std::vector<base::FilePath> gen_dependencies_;
   std::vector<SourceFile> written_files_;
   std::vector<const Target*> write_runtime_deps_targets_;
-  std::multimap<SourceFile, const Target*> unknown_generated_inputs_;
+  std::multimap<SourceFile, std::pair<const Target*, DepType>>
+      unknown_generated_inputs_;
   std::map<SourceFile, bool> generated_files_;
 
   Scheduler(const Scheduler&) = delete;
diff --git a/src/gn/target.cc b/src/gn/target.cc
index f1cef5f..39856c3 100644
--- a/src/gn/target.cc
+++ b/src/gn/target.cc
@@ -179,6 +179,7 @@
 
 void CheckSourceGenerated(const Target* source_target,
                           const SourceFile& source,
+                          bool check_private_deps,
                           CheckSourceGeneratedCursor* cursor) {
   const auto& build_settings = source_target->settings()->build_settings();
   if (!IsStringInOutputDir(build_settings->build_dir(), source.value()))
@@ -195,14 +196,13 @@
   // If this is not the first file, start by looking where the last one was
   // found.
   if (cursor->target) {
-    bool check_private_deps = cursor->target == source_target;
     if (EnsureFileIsGeneratedByDependency(
-            cursor->target, out_file, check_private_deps, consider_object_files,
-            check_data_deps, &seen_targets, cursor))
+            cursor->target, out_file,
+            check_private_deps && cursor->target == source_target,
+            consider_object_files, check_data_deps, &seen_targets, cursor))
       return;
   }
 
-  bool check_private_deps = true;
   if (!EnsureFileIsGeneratedByDependency(
           source_target, out_file, check_private_deps, consider_object_files,
           check_data_deps, &seen_targets, cursor)) {
@@ -217,7 +217,9 @@
     if (!EnsureFileIsGeneratedByDependency(
             source_target, out_file, check_private_deps, consider_object_files,
             check_data_deps, &seen_targets, cursor))
-      g_scheduler->AddUnknownGeneratedInput(source_target, source);
+      g_scheduler->AddUnknownGeneratedInput(
+          source_target, source,
+          check_private_deps ? Scheduler::PRIVATE_DEP : Scheduler::PUBLIC_DEP);
   }
 }
 
@@ -1260,20 +1262,38 @@
 }
 
 void Target::CheckSourcesGenerated() const {
-  // Checks that any inputs or sources to this target that are in the build
-  // directory are generated by a target that this one transitively depends on
-  // in some way. We already guarantee that all generated files are written
-  // to the build dir.
+  // Checks that any inputs, sources, or public headers for this target that
+  // are in the build directory are generated by a target that this one
+  // transitively depends on in some way. We already guarantee that all
+  // generated files are written to the build dir.
   //
   // See Scheduler::AddUnknownGeneratedInput's declaration for more.
   CheckSourceGeneratedCursor cursor;
-  for (const SourceFile& file : sources_)
-    CheckSourceGenerated(this, file, &cursor);
+  bool check_private_deps = !check_includes_strict_;
+  // Cursor could be pointing to a private dep, in which case if you attempt to
+  // call it with check_private_deps=false, it would still try to take the
+  // shortcut and check the private dep.
+  // So we have a separate cursor we use when check_private_deps=false.
+  CheckSourceGeneratedCursor public_cursor;
+  CheckSourceGeneratedCursor* header_cursor =
+      check_private_deps ? &cursor : &public_cursor;
+  for (const SourceFile& file : public_headers_) {
+    CheckSourceGenerated(this, file, check_private_deps, header_cursor);
+  }
+
+  for (const SourceFile& file : sources_) {
+    if (IsBinary() && all_headers_public_ &&
+        file.GetType() == SourceFile::SOURCE_H) {
+      CheckSourceGenerated(this, file, check_private_deps, header_cursor);
+    } else {
+      CheckSourceGenerated(this, file, /*check_private_deps=*/true, &cursor);
+    }
+  }
 
   cursor.target = nullptr;
   for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) {
     for (const SourceFile& file : iter.cur().inputs())
-      CheckSourceGenerated(this, file, &cursor);
+      CheckSourceGenerated(this, file, /*check_private_deps=*/true, &cursor);
   }
   // TODO(agrieve): Check all_libs_ here as well (those that are source files).
   // http://crbug.com/571731
diff --git a/src/gn/target_unittest.cc b/src/gn/target_unittest.cc
index f36f7f2..e8b751f 100644
--- a/src/gn/target_unittest.cc
+++ b/src/gn/target_unittest.cc
@@ -21,16 +21,21 @@
 
 // Asserts that the current global scheduler has a single unknown generated
 // file with the given name from the given target.
-void AssertSchedulerHasOneUnknownFileMatching(const Target* target,
-                                              const SourceFile& file) {
+void AssertSchedulerHasOneUnknownFileMatching(
+    const Target* target,
+    const SourceFile& file,
+    bool requires_public_dep = false) {
   auto unknown = g_scheduler->GetUnknownGeneratedInputs();
-  ASSERT_EQ(1u, unknown.size());  // Should be one unknown file.
-  auto found = unknown.find(file);
-  ASSERT_TRUE(found != unknown.end()) << file.value();
-  EXPECT_TRUE(target == found->second)
-      << "Target doesn't match. Expected\n  "
-      << target->label().GetUserVisibleName(false) << "\nBut got\n  "
-      << found->second->label().GetUserVisibleName(false);
+  ASSERT_EQ(1u, unknown.size());  // Should be one unknown value.
+  auto first = unknown.begin();
+  EXPECT_EQ(file, first->first);
+  EXPECT_EQ(target, first->second.first)
+      << "Target doesn't match: expected "
+      << target->label().GetUserVisibleName(false) << ", got "
+      << first->second.first->label().GetUserVisibleName(false);
+  Scheduler::DepType expected_dep =
+      requires_public_dep ? Scheduler::PUBLIC_DEP : Scheduler::PRIVATE_DEP;
+  EXPECT_EQ(expected_dep, first->second.second);
 }
 
 }  // namespace
@@ -914,6 +919,7 @@
   Err err;
 
   SourceFile generated_file("//out/Debug/generated.cc");
+  SourceFile generated_header("//out/Debug/generated.h");
 
   // This target has a generated input and no dependency makes it.
   TestTarget non_existent_generator(setup, "//foo:non_existent_generator",
@@ -926,8 +932,8 @@
 
   // Make a target that generates the file.
   TestTarget generator(setup, "//foo:generator", Target::ACTION);
-  generator.action_values().outputs() =
-      SubstitutionList::MakeForTest(generated_file.value().c_str());
+  generator.action_values().outputs() = SubstitutionList::MakeForTest(
+      "//out/Debug/generated.cc", "//out/Debug/generated.h");
   err = Err();
   EXPECT_TRUE(generator.OnResolved(&err)) << err.message();
 
@@ -960,10 +966,60 @@
   EXPECT_TRUE(existent_public.OnResolved(&err)) << err.message();
   TestTarget indirect_public(setup, "//foo:indirect_public",
                              Target::EXECUTABLE);
+  indirect_public.set_check_includes_strict(true);
+  indirect_public.public_headers().push_back(generated_header);
   indirect_public.sources().push_back(generated_file);
   indirect_public.public_deps().push_back(LabelTargetPair(&existent_public));
   EXPECT_TRUE(indirect_public.OnResolved(&err)) << err.message();
   EXPECT_TRUE(scheduler().GetUnknownGeneratedInputs().empty());
+
+  // Under check_includes_strict, private headers (all_headers_public = false)
+  // are allowed via private deps, while public_headers and public headers in
+  // sources require public_deps (using a separate cursor from .cc sources).
+  TestTarget strict_priv_header(setup, "//foo:strict_priv_header",
+                                Target::SOURCE_SET);
+  strict_priv_header.set_check_includes_strict(true);
+  strict_priv_header.set_all_headers_public(false);
+  strict_priv_header.sources().push_back(generated_header);
+  strict_priv_header.private_deps().push_back(LabelTargetPair(&generator));
+  EXPECT_TRUE(strict_priv_header.OnResolved(&err)) << err.message();
+  EXPECT_TRUE(scheduler().GetUnknownGeneratedInputs().empty());
+
+  TestTarget strict_public_header(setup, "//foo:strict_public_header",
+                                  Target::SOURCE_SET);
+  strict_public_header.set_check_includes_strict(true);
+  strict_public_header.set_all_headers_public(false);
+  strict_public_header.public_headers().push_back(generated_header);
+  strict_public_header.private_deps().push_back(LabelTargetPair(&generator));
+  EXPECT_TRUE(strict_public_header.OnResolved(&err)) << err.message();
+  AssertSchedulerHasOneUnknownFileMatching(&strict_public_header,
+                                           generated_header,
+                                           /*requires_public_dep=*/true);
+  scheduler().ClearUnknownGeneratedInputsAndWrittenFiles();
+
+  TestTarget strict_cursor(setup, "//foo:strict_cursor", Target::SOURCE_SET);
+  strict_cursor.set_check_includes_strict(true);
+  strict_cursor.sources().push_back(generated_file);
+  strict_cursor.sources().push_back(generated_header);
+  strict_cursor.private_deps().push_back(LabelTargetPair(&generator));
+  EXPECT_TRUE(strict_cursor.OnResolved(&err)) << err.message();
+  AssertSchedulerHasOneUnknownFileMatching(&strict_cursor, generated_header,
+                                           /*requires_public_dep=*/true);
+  scheduler().ClearUnknownGeneratedInputsAndWrittenFiles();
+
+  TestTarget non_strict(setup, "//foo:non_strict", Target::SOURCE_SET);
+  non_strict.set_check_includes_strict(false);
+  non_strict.public_headers().push_back(generated_header);
+  non_strict.private_deps().push_back(LabelTargetPair(&generator));
+  EXPECT_TRUE(non_strict.OnResolved(&err)) << err.message();
+  EXPECT_TRUE(scheduler().GetUnknownGeneratedInputs().empty());
+
+  TestTarget copy_target(setup, "//foo:copy_target", Target::COPY_FILES);
+  copy_target.set_check_includes_strict(true);
+  copy_target.sources().push_back(generated_header);
+  copy_target.private_deps().push_back(LabelTargetPair(&generator));
+  EXPECT_TRUE(copy_target.OnResolved(&err)) << err.message();
+  EXPECT_TRUE(scheduler().GetUnknownGeneratedInputs().empty());
 }
 
 // This is sort of a Scheduler test, but is related to the above test more.