Preserve toolchain when generating suggestions in gn check

Record the source target on HeaderChecker::Violation so that CheckPublicHeaders
passes the actual toolchain of the violating target to OutputSuggestions,
preventing incorrect cross-toolchain suggestions.

Change-Id: I7625f30ced367c2f8680e673fc5a5d0b6a6a6964
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/26360
Commit-Queue: Matt Stark <msta@google.com>
Reviewed-by: Takuto Ikuta <tikuta@google.com>
diff --git a/src/gn/command_check.cc b/src/gn/command_check.cc
index dbd322c..f0292a1 100644
--- a/src/gn/command_check.cc
+++ b/src/gn/command_check.cc
@@ -294,9 +294,6 @@
   std::vector<HeaderChecker::Violation> violations;
   header_checker->Run(to_check, force_check, &violations);
 
-  Label default_toolchain = setup ? setup->loader()->default_toolchain_label()
-                                  : Label(SourceDir("//toolchain/"), "default");
-
   bool remaining_violations = false;
   bool needs_separator = false;
   bool has_suggestions = false;
@@ -311,7 +308,8 @@
     if (!violation.source_file.is_null() &&
         !violation.included_file.is_null()) {
       SuggestResult exit_code = OutputSuggestions(
-          all_targets, build_settings, default_toolchain,
+          all_targets, build_settings,
+          violation.source_target->label().GetToolchainLabel(),
           violation.source_file.value(), violation.included_file.value(),
           [&](std::string_view str, TextDecoration dec, HtmlEscaping esc) {
             buf.emplace_back(str, dec, esc);
diff --git a/src/gn/header_checker.cc b/src/gn/header_checker.cc
index f7c7632..93d7b44 100644
--- a/src/gn/header_checker.cc
+++ b/src/gn/header_checker.cc
@@ -517,7 +517,7 @@
                   from_target->label().GetUserVisibleName(false) +
                   "\nhas a source file:\n  " + file.value() +
                   "\nwhich was not found."),
-          file, SourceFile());
+          from_target, file, SourceFile());
     }
     return false;
   }
@@ -564,7 +564,7 @@
                          file.GetType() == SourceFile::SOURCE_H,
                      input_file, included_file, inc.location, &include_errors);
         for (auto& e : include_errors) {
-          violations->emplace_back(std::move(e), file,
+          violations->emplace_back(std::move(e), from_target, file,
                                    std::move(included_file));
         }
       }
diff --git a/src/gn/header_checker.h b/src/gn/header_checker.h
index 17e2afc..6c4561c 100644
--- a/src/gn/header_checker.h
+++ b/src/gn/header_checker.h
@@ -59,6 +59,9 @@
     // The diagnostic error describing the violation.
     Err error;
 
+    // The target whose source file had the violation.
+    const Target* source_target;
+
     // The source file that contained the invalid #include directive.
     SourceFile source_file;