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/functions.h" | 5 #include "tools/gn/functions.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "tools/gn/config.h" | 11 #include "tools/gn/config.h" |
12 #include "tools/gn/config_values_generator.h" | 12 #include "tools/gn/config_values_generator.h" |
13 #include "tools/gn/err.h" | 13 #include "tools/gn/err.h" |
14 #include "tools/gn/input_file.h" | 14 #include "tools/gn/input_file.h" |
15 #include "tools/gn/parse_tree.h" | 15 #include "tools/gn/parse_tree.h" |
16 #include "tools/gn/scheduler.h" | 16 #include "tools/gn/scheduler.h" |
17 #include "tools/gn/scope.h" | 17 #include "tools/gn/scope.h" |
18 #include "tools/gn/settings.h" | 18 #include "tools/gn/settings.h" |
19 #include "tools/gn/template.h" | 19 #include "tools/gn/template.h" |
20 #include "tools/gn/token.h" | 20 #include "tools/gn/token.h" |
21 #include "tools/gn/value.h" | 21 #include "tools/gn/value.h" |
| 22 #include "tools/gn/value_extractors.h" |
| 23 #include "tools/gn/variables.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // Some functions take a {} following them, and some don't. For the ones that | 27 // Some functions take a {} following them, and some don't. For the ones that |
26 // don't, this is used to verify that the given block node is null and will | 28 // don't, this is used to verify that the given block node is null and will |
27 // set the error accordingly if it's not. Returns true if the block is null. | 29 // set the error accordingly if it's not. Returns true if the block is null. |
28 bool VerifyNoBlockForFunctionCall(const FunctionCallNode* function, | 30 bool VerifyNoBlockForFunctionCall(const FunctionCallNode* function, |
29 const BlockNode* block, | 31 const BlockNode* block, |
30 Err* err) { | 32 Err* err) { |
31 if (!block) | 33 if (!block) |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 294 |
293 if (g_scheduler->verbose_logging()) | 295 if (g_scheduler->verbose_logging()) |
294 g_scheduler->Log("Defining config", label.GetUserVisibleName(true)); | 296 g_scheduler->Log("Defining config", label.GetUserVisibleName(true)); |
295 | 297 |
296 // Create the new config. | 298 // Create the new config. |
297 scoped_ptr<Config> config(new Config(scope->settings(), label)); | 299 scoped_ptr<Config> config(new Config(scope->settings(), label)); |
298 config->set_defined_from(function); | 300 config->set_defined_from(function); |
299 if (!Visibility::FillItemVisibility(config.get(), scope, err)) | 301 if (!Visibility::FillItemVisibility(config.get(), scope, err)) |
300 return Value(); | 302 return Value(); |
301 | 303 |
302 // Fill it. | 304 // Fill the flags and such. |
303 const SourceDir& input_dir = scope->GetSourceDir(); | 305 const SourceDir& input_dir = scope->GetSourceDir(); |
304 ConfigValuesGenerator gen(&config->config_values(), scope, input_dir, err); | 306 ConfigValuesGenerator gen(&config->own_values(), scope, input_dir, err); |
305 gen.Run(); | 307 gen.Run(); |
306 if (err->has_error()) | 308 if (err->has_error()) |
307 return Value(); | 309 return Value(); |
308 | 310 |
| 311 // Read sub-configs. |
| 312 const Value* configs_value = scope->GetValue(variables::kConfigs, true); |
| 313 if (configs_value) { |
| 314 ExtractListOfUniqueLabels(*configs_value, scope->GetSourceDir(), |
| 315 ToolchainLabelForScope(scope), |
| 316 &config->configs(), err); |
| 317 } |
| 318 if (err->has_error()) |
| 319 return Value(); |
| 320 |
309 // Save the generated item. | 321 // Save the generated item. |
310 Scope::ItemVector* collector = scope->GetItemCollector(); | 322 Scope::ItemVector* collector = scope->GetItemCollector(); |
311 if (!collector) { | 323 if (!collector) { |
312 *err = Err(function, "Can't define a config in this context."); | 324 *err = Err(function, "Can't define a config in this context."); |
313 return Value(); | 325 return Value(); |
314 } | 326 } |
315 collector->push_back(config.release()); | 327 collector->push_back(config.release()); |
316 | 328 |
317 return Value(); | 329 return Value(); |
318 } | 330 } |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 } | 874 } |
863 | 875 |
864 // Otherwise it's a no-block function. | 876 // Otherwise it's a no-block function. |
865 if (!VerifyNoBlockForFunctionCall(function, block, err)) | 877 if (!VerifyNoBlockForFunctionCall(function, block, err)) |
866 return Value(); | 878 return Value(); |
867 return found_function->second.no_block_runner(scope, function, | 879 return found_function->second.no_block_runner(scope, function, |
868 args.list_value(), err); | 880 args.list_value(), err); |
869 } | 881 } |
870 | 882 |
871 } // namespace functions | 883 } // namespace functions |
OLD | NEW |