Refactor GN source expansions.

This is in preparation for using {{patterns}} in toolchain definitions. It makes them
more generic and usable for this, without actually implementing any new features or
changing behavior. The only external change should be that the $in variable is used for
actions instead of making a redundant new variable (used to be called $source).

It removes the FileTemplate class and explodes it into several files: the type list and
helpers (substitution_type), a single pattern (substitution_pattern), a list of patterns
(substitution_list), and a class of helper functions for processing templates in various
ways (substitution_writer).

Previously, the things needing substitutions (args, outputs, depfile) were stored as
strings and parsed in to FileTemplates as needed. This new method stores the
SubstitutionList/Pattern directly on the target. This allows it to issue parse errors
(previously such errors were ignored since errors weren't reportable when writing Ninja
files) and cleans up a lot of the code that uses it.

R=scottmg@chromium.org

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

git-svn-id: http://src.chromium.org/svn/trunk/src/tools/gn@287847 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This is an ordered set tailored to GN's (simple) needs.

This vector is now used to store all config lists. Previously the code did a bunch of work to uniquify configs at certain points (in target.cc) but direct_dependent_configs still ended up with lots of duplicates.

Before this patch the chrome/browser target has 41098 direct_dependent_configs, and after this patch it has 7. Apparently we were also spending a lot of time on these. Before this patch Windows wall clock time was 1031ms, and after this patch it's 831ms. Linux was 834ms before and 593ms after.

Also fix minor build issues in base I noticed while working on this.

R=viettrungluu@chromium.org

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

git-svn-id: http://src.chromium.org/svn/trunk/src/tools/gn@287865 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
GN bootstrap.py: fixed cross-compile, etc.

+ Use env var LD (default to CXX)
+ Exclude run_all_unittests.cc from build

NOTRY=true
R=brettw@chromium.org
BUG=

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

git-svn-id: http://src.chromium.org/svn/trunk/src/tools/gn@288001 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
GN: (HeaderChecker) Allow any chain to forward direct dependent configs.

When finding a dependency chain, the header check will now prefer chains which
forward direct-dependent configs if the target which provides a header has
one. Previously an error would be produced because the chain which was found
did not forward configs, even though another chain did.

A breadth-first search is used instead of a depth-first search because short
chains are more likely to be intended by the author, and make for both less
work and clearer diagnostic messages.

This reduces the size of 'gn check' output on the chromium tree and the time
to execute. (Output directed to 'wc -l' and /dev/null, respectively.)

  Before: 104685 lines, 542.36s user, 35.573s total
  After: 36977 lines, 7.10s user, 1.526s total

Manual inspection reveals that the line reduction appears to be from the
removal of spurious errors when IsDependencyOf selected an indirect chain
which does not forward direct-dependent configs, even though a direct
dependency existed. (About 7 cases were examined manually; sheer volume makes
full manual verification infeasible.)

BUG=391505
TEST=HeaderCheckerTest, manual

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

git-svn-id: http://src.chromium.org/svn/trunk/src/tools/gn@288110 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
Improve GN value origins for error messages.

Sets the origin for a value when the value is dereferenced. Previously if you did
  foo = 6
  deps = [ foo ]
You would get the message:
  ERROR at //BUILD.gn:15:9: This is not a string.
    foo = 6
          ^
Which in this case is pretty confusing since that's obviously the case, and you really want to know where it was dereferenced.

With this patch the message is:
  ERROR at //BUILD.gn:21:5: This is not a string.
      foo,
      ^--
  Instead I see a integer = 6
which is more actionable.

R=ajwong@chromium.org

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

git-svn-id: http://src.chromium.org/svn/trunk/src/tools/gn@288131 4ff67af0-8c30-449e-8e8b-ad334ec8d88c