1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "tools/gn/build_settings.h"
6 #include "tools/gn/functions.h"
7 #include "tools/gn/loader.h"
8 #include "tools/gn/parse_tree.h"
9 #include "tools/gn/scope.h"
10 #include "tools/gn/settings.h"
14 const char kSetDefaultToolchain[] = "set_default_toolchain";
15 const char kSetDefaultToolchain_Help[] =
16 "set_default_toolchain: Sets the default toolchain name.\n"
18 " set_default_toolchain(toolchain_label)\n"
20 " The given label should identify a toolchain definition (see\n"
21 " \"help toolchain\"). This toolchain will be used for all targets\n"
22 " unless otherwise specified.\n"
24 " This function is only valid to call during the processing of the build\n"
25 " configuration file. Since the build configuration file is processed\n"
26 " separately for each toolchain, this function will be a no-op when\n"
27 " called under any non-default toolchains.\n"
29 " For example, the default toolchain should be appropriate for the\n"
30 " current environment. If the current environment is 32-bit and \n"
31 " somebody references a target with a 64-bit toolchain, we wouldn't\n"
32 " want processing of the build config file for the 64-bit toolchain to\n"
33 " reset the default toolchain to 64-bit, we want to keep it 32-bits.\n"
42 " set_default_toolchain(\"//build/config/win:vs32\")";
44 Value RunSetDefaultToolchain(Scope* scope,
45 const FunctionCallNode* function,
46 const std::vector<Value>& args,
48 if (!scope->IsProcessingBuildConfig()) {
49 *err = Err(function->function(), "Must be called from build config.",
50 "set_default_toolchain can only be called from the build configuration "
55 // When the loader is expecting the default toolchain to be set, it will set
56 // this key on the scope to point to the destination.
57 Label* default_toolchain_dest = static_cast<Label*>(
58 scope->GetProperty(Loader::kDefaultToolchainKey, NULL));
59 if (!default_toolchain_dest)
62 const SourceDir& current_dir = scope->GetSourceDir();
63 const Label& default_toolchain = ToolchainLabelForScope(scope);
65 if (!EnsureSingleStringArg(function, args, err))
67 Label toolchain_label(
68 Label::Resolve(current_dir, default_toolchain, args[0], err));
69 if (toolchain_label.is_null())
72 *default_toolchain_dest = toolchain_label;
76 } // namespace functions