Add toolchains to dependency error messages in GN

This adds toolchain labels to the error message about depending on generated
files if any of the toolchains are not in the default toolchain. The toolchains
can be confusing (normally they're all in the default one) but for
cross-toolchain dependencies, the error message becomes impossible to
understand without them.

Review URL: https://codereview.chromium.org/1270603004

Cr-Original-Commit-Position: refs/heads/master@{#341221}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 58caeebf366f38af79d90b7d8dcf9dcdf7a6663b
diff --git a/tools/gn/command_gen.cc b/tools/gn/command_gen.cc
index eceb8df..56d3e98 100644
--- a/tools/gn/command_gen.cc
+++ b/tools/gn/command_gen.cc
@@ -71,18 +71,34 @@
                                 const std::vector<const Target*>& targets) {
   std::string err;
 
+  // Only show the toolchain labels (which can be confusing) if something
+  // isn't the default.
+  bool show_toolchains = false;
+  const Label& default_toolchain =
+      targets[0]->settings()->default_toolchain_label();
+  for (const Target* target : targets) {
+    if (target->settings()->toolchain_label() != default_toolchain) {
+      show_toolchains = true;
+      break;
+    }
+  }
+
+  const Target* generator = FindTargetThatGeneratesFile(builder, file);
+  if (generator &&
+      generator->settings()->toolchain_label() != default_toolchain)
+    show_toolchains = true;
+
   const std::string target_str = targets.size() > 1 ? "targets" : "target";
   err += "The file:\n";
   err += "  " + file.value() + "\n";
   err += "is listed as an input or source for the " + target_str + ":\n";
   for (const Target* target : targets)
-    err += "  " + target->label().GetUserVisibleName(false) + "\n";
+    err += "  " + target->label().GetUserVisibleName(show_toolchains) + "\n";
 
-  const Target* generator = FindTargetThatGeneratesFile(builder, file);
   if (generator) {
     err += "but this file was not generated by any dependencies of the " +
         target_str + ". The target\nthat generates the file is:\n  ";
-    err += generator->label().GetUserVisibleName(false);
+    err += generator->label().GetUserVisibleName(show_toolchains);
   } else {
     err += "but no targets in the build generate that file.";
   }