Mark build arguments implicitly used in GN.

This regressed in https://codereview.chromium.org/2092623002 which caused a revert of the GN roll. The particular issue is that a build argument in a BUILD.gn file was used in only one of the toolchains, so the other toolchains were giving unused variable errors on it.

Build variables kept at their default values already are marked implicitly used, and anything in a .gni file is the same. The remaining cases are pretty confusing so it seems better to not warn in this case instead of requiring the author to wrap the build variable in a condition based on the usage.

TBR=dpranke

Review-Url: https://codereview.chromium.org/2151633002
Cr-Original-Commit-Position: refs/heads/master@{#405291}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 8b05f575431f4854163470695cf1a6f6495263ce
diff --git a/tools/gn/args.cc b/tools/gn/args.cc
index accdf7e..823a8cc 100644
--- a/tools/gn/args.cc
+++ b/tools/gn/args.cc
@@ -184,6 +184,12 @@
       declared_arguments.insert(arg);
     }
 
+    // In all the cases below, mark the variable used. If a variable is set
+    // that's only used in one toolchain, we don't want to report unused
+    // variable errors in other toolchains. Also, in some cases it's reasonable
+    // for the build file to overwrite the value with a different value based
+    // on some other condition without dereferencing the value first.
+
     // Check whether this argument has been overridden on the toolchain level
     // and use the override instead.
     Scope::KeyValueMap::const_iterator toolchain_override =
@@ -192,6 +198,7 @@
       scope_to_set->SetValue(toolchain_override->first,
                              toolchain_override->second,
                              toolchain_override->second.origin());
+      scope_to_set->MarkUsed(arg.first);
       continue;
     }
 
@@ -201,11 +208,10 @@
     if (override != overrides_.end()) {
       scope_to_set->SetValue(override->first, override->second,
                              override->second.origin());
+      scope_to_set->MarkUsed(override->first);
       continue;
     }
 
-    // Mark the variable used so the build script can override it in
-    // certain cases without getting unused value errors.
     scope_to_set->SetValue(arg.first, arg.second, arg.second.origin());
     scope_to_set->MarkUsed(arg.first);
   }