Add ICU message format support
[chromium-blink-merge.git] / tools / gn / function_set_default_toolchain.cc
blobcc5929e6686a4d1de95cc2494738d40f6ea8f6f9
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"
12 namespace functions {
14 const char kSetDefaultToolchain[] = "set_default_toolchain";
15 const char kSetDefaultToolchain_HelpShort[] =
16 "set_default_toolchain: Sets the default toolchain name.";
17 const char kSetDefaultToolchain_Help[] =
18 "set_default_toolchain: Sets the default toolchain name.\n"
19 "\n"
20 " set_default_toolchain(toolchain_label)\n"
21 "\n"
22 " The given label should identify a toolchain definition (see\n"
23 " \"help toolchain\"). This toolchain will be used for all targets\n"
24 " unless otherwise specified.\n"
25 "\n"
26 " This function is only valid to call during the processing of the build\n"
27 " configuration file. Since the build configuration file is processed\n"
28 " separately for each toolchain, this function will be a no-op when\n"
29 " called under any non-default toolchains.\n"
30 "\n"
31 " For example, the default toolchain should be appropriate for the\n"
32 " current environment. If the current environment is 32-bit and \n"
33 " somebody references a target with a 64-bit toolchain, we wouldn't\n"
34 " want processing of the build config file for the 64-bit toolchain to\n"
35 " reset the default toolchain to 64-bit, we want to keep it 32-bits.\n"
36 "\n"
37 "Argument:\n"
38 "\n"
39 " toolchain_label\n"
40 " Toolchain name.\n"
41 "\n"
42 "Example:\n"
43 "\n"
44 " set_default_toolchain(\"//build/config/win:vs32\")";
46 Value RunSetDefaultToolchain(Scope* scope,
47 const FunctionCallNode* function,
48 const std::vector<Value>& args,
49 Err* err) {
50 if (!scope->IsProcessingBuildConfig()) {
51 *err = Err(function->function(), "Must be called from build config.",
52 "set_default_toolchain can only be called from the build configuration "
53 "file.");
54 return Value();
57 // When the loader is expecting the default toolchain to be set, it will set
58 // this key on the scope to point to the destination.
59 Label* default_toolchain_dest = static_cast<Label*>(
60 scope->GetProperty(Loader::kDefaultToolchainKey, nullptr));
61 if (!default_toolchain_dest)
62 return Value();
64 const SourceDir& current_dir = scope->GetSourceDir();
65 const Label& default_toolchain = ToolchainLabelForScope(scope);
67 if (!EnsureSingleStringArg(function, args, err))
68 return Value();
69 Label toolchain_label(
70 Label::Resolve(current_dir, default_toolchain, args[0], err));
71 if (toolchain_label.is_null())
72 return Value();
74 *default_toolchain_dest = toolchain_label;
75 return Value();
78 } // namespace functions