Correct blacklist entry message
[chromium-blink-merge.git] / tools / gn / function_set_default_toolchain.cc
blobc2b20a5710b01babf87315fd36ea0ad58b372911
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"
12 namespace functions {
14 const char kSetDefaultToolchain[] = "set_default_toolchain";
15 const char kSetDefaultToolchain_Help[] =
16 "set_default_toolchain: Sets the default toolchain name.\n"
17 "\n"
18 " set_default_toolchain(toolchain_label)\n"
19 "\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"
23 "\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"
28 "\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"
34 "\n"
35 "Argument:\n"
36 "\n"
37 " toolchain_label\n"
38 " Toolchain name.\n"
39 "\n"
40 "Example:\n"
41 "\n"
42 " set_default_toolchain(\"//build/config/win:vs32\")";
44 Value RunSetDefaultToolchain(Scope* scope,
45 const FunctionCallNode* function,
46 const std::vector<Value>& args,
47 Err* err) {
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 "
51 "file.");
52 return Value();
55 // Ignore non-default-build-config invocations.
56 if (!scope->IsProcessingDefaultBuildConfig())
57 return Value();
59 const SourceDir& current_dir = scope->GetSourceDir();
60 const Label& default_toolchain = ToolchainLabelForScope(scope);
62 if (!EnsureSingleStringArg(function, args, err))
63 return Value();
64 Label toolchain_label(
65 Label::Resolve(current_dir, default_toolchain, args[0], err));
66 if (toolchain_label.is_null())
67 return Value();
69 ToolchainManager& mgr =
70 scope->settings()->build_settings()->toolchain_manager();
71 mgr.SetDefaultToolchainUnlocked(toolchain_label, function->GetRange(), err);
72 return Value();
75 } // namespace functions