OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/build_settings.h" | 5 #include "tools/gn/build_settings.h" |
6 #include "tools/gn/functions.h" | 6 #include "tools/gn/functions.h" |
| 7 #include "tools/gn/loader.h" |
7 #include "tools/gn/parse_tree.h" | 8 #include "tools/gn/parse_tree.h" |
8 #include "tools/gn/scope.h" | 9 #include "tools/gn/scope.h" |
9 #include "tools/gn/settings.h" | 10 #include "tools/gn/settings.h" |
10 #include "tools/gn/toolchain_manager.h" | |
11 | 11 |
12 namespace functions { | 12 namespace functions { |
13 | 13 |
14 const char kSetDefaultToolchain[] = "set_default_toolchain"; | 14 const char kSetDefaultToolchain[] = "set_default_toolchain"; |
15 const char kSetDefaultToolchain_Help[] = | 15 const char kSetDefaultToolchain_Help[] = |
16 "set_default_toolchain: Sets the default toolchain name.\n" | 16 "set_default_toolchain: Sets the default toolchain name.\n" |
17 "\n" | 17 "\n" |
18 " set_default_toolchain(toolchain_label)\n" | 18 " set_default_toolchain(toolchain_label)\n" |
19 "\n" | 19 "\n" |
20 " The given label should identify a toolchain definition (see\n" | 20 " The given label should identify a toolchain definition (see\n" |
(...skipping 24 matching lines...) Expand all Loading... |
45 const FunctionCallNode* function, | 45 const FunctionCallNode* function, |
46 const std::vector<Value>& args, | 46 const std::vector<Value>& args, |
47 Err* err) { | 47 Err* err) { |
48 if (!scope->IsProcessingBuildConfig()) { | 48 if (!scope->IsProcessingBuildConfig()) { |
49 *err = Err(function->function(), "Must be called from build config.", | 49 *err = Err(function->function(), "Must be called from build config.", |
50 "set_default_toolchain can only be called from the build configuration " | 50 "set_default_toolchain can only be called from the build configuration " |
51 "file."); | 51 "file."); |
52 return Value(); | 52 return Value(); |
53 } | 53 } |
54 | 54 |
55 // Ignore non-default-build-config invocations. | 55 // When the loader is expecting the default toolchain to be set, it will set |
56 if (!scope->IsProcessingDefaultBuildConfig()) | 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) |
57 return Value(); | 60 return Value(); |
58 | 61 |
59 const SourceDir& current_dir = scope->GetSourceDir(); | 62 const SourceDir& current_dir = scope->GetSourceDir(); |
60 const Label& default_toolchain = ToolchainLabelForScope(scope); | 63 const Label& default_toolchain = ToolchainLabelForScope(scope); |
61 | 64 |
62 if (!EnsureSingleStringArg(function, args, err)) | 65 if (!EnsureSingleStringArg(function, args, err)) |
63 return Value(); | 66 return Value(); |
64 Label toolchain_label( | 67 Label toolchain_label( |
65 Label::Resolve(current_dir, default_toolchain, args[0], err)); | 68 Label::Resolve(current_dir, default_toolchain, args[0], err)); |
66 if (toolchain_label.is_null()) | 69 if (toolchain_label.is_null()) |
67 return Value(); | 70 return Value(); |
68 | 71 |
69 ToolchainManager& mgr = | 72 *default_toolchain_dest = toolchain_label; |
70 scope->settings()->build_settings()->toolchain_manager(); | |
71 mgr.SetDefaultToolchainUnlocked(toolchain_label, function->GetRange(), err); | |
72 return Value(); | 73 return Value(); |
73 } | 74 } |
74 | 75 |
75 } // namespace functions | 76 } // namespace functions |
OLD | NEW |