Don't use a nested scope for BUILDCONFIG.

The change bac5bd0 ("Do not use the root scope for BUILDCONFIG.gn.")
introducted a nested scope into BUILDCONFIG.gn processing. But this
means that the build config file can't modify the default scope which is
its whole purpose.

This removes the nested scope and modifies the directory during
execution of the build config file which was the goal of the above
change.

Change-Id: I0790fae81d52554f9a80f0721aa9ae899a21c446
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/5880
Reviewed-by: Petr Hosek <phosek@google.com>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/tools/gn/loader.cc b/tools/gn/loader.cc
index b53b094..d1a2953 100644
--- a/tools/gn/loader.cc
+++ b/tools/gn/loader.cc
@@ -309,11 +309,18 @@
                     settings->build_settings()->build_config_file().value());
   trace.SetToolchain(settings->toolchain_label());
 
-  Err err;
-  Scope our_scope(base_config);
-  our_scope.set_source_dir(
+  // Run the BUILDCONFIG with its directory as the current one. We want
+  // BUILDCONFIG to modify the base_config so can't make a copy or a nested one.
+  base_config->set_source_dir(
       settings->build_settings()->build_config_file().GetDir());
-  root->Execute(&our_scope, &err);
+
+  Err err;
+  root->Execute(base_config, &err);
+
+  // Put back the root as the default source dir. This probably isn't necessary
+  // as other scopes will set their directories to their own path, but it's a
+  // better default than the build config's directory.
+  base_config->set_source_dir(SourceDir("//"));
 
   // Clear all private variables left in the scope. We want the root build
   // config to be like a .gni file in that variables beginning with an