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/parse_tree.h"
8 #include "tools/gn/scope.h"
9 #include "tools/gn/settings.h"
10 #include "tools/gn/toolchain_manager.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 // Ignore non-default-build-config invocations.
56 if (!scope
->IsProcessingDefaultBuildConfig())
59 const SourceDir
& current_dir
= scope
->GetSourceDir();
60 const Label
& default_toolchain
= ToolchainLabelForScope(scope
);
62 if (!EnsureSingleStringArg(function
, args
, err
))
64 Label
toolchain_label(
65 Label::Resolve(current_dir
, default_toolchain
, args
[0], err
));
66 if (toolchain_label
.is_null())
69 ToolchainManager
& mgr
=
70 scope
->settings()->build_settings()->toolchain_manager();
71 mgr
.SetDefaultToolchainUnlocked(toolchain_label
, function
->GetRange(), err
);
75 } // namespace functions