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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "tools/gn/config.h" | 10 #include "tools/gn/config.h" |
11 #include "tools/gn/config_values_generator.h" | 11 #include "tools/gn/config_values_generator.h" |
12 #include "tools/gn/err.h" | 12 #include "tools/gn/err.h" |
13 #include "tools/gn/input_file.h" | 13 #include "tools/gn/input_file.h" |
14 #include "tools/gn/item_tree.h" | |
15 #include "tools/gn/parse_tree.h" | 14 #include "tools/gn/parse_tree.h" |
16 #include "tools/gn/scheduler.h" | 15 #include "tools/gn/scheduler.h" |
17 #include "tools/gn/scope.h" | 16 #include "tools/gn/scope.h" |
18 #include "tools/gn/settings.h" | 17 #include "tools/gn/settings.h" |
19 #include "tools/gn/target_manager.h" | |
20 #include "tools/gn/token.h" | 18 #include "tools/gn/token.h" |
21 #include "tools/gn/value.h" | 19 #include "tools/gn/value.h" |
22 | 20 |
23 namespace { | 21 namespace { |
24 | 22 |
25 // This is called when a template is invoked. When we see a template | 23 // This is called when a template is invoked. When we see a template |
26 // declaration, that funciton is RunTemplate. | 24 // declaration, that funciton is RunTemplate. |
27 Value RunTemplateInvocation(Scope* scope, | 25 Value RunTemplateInvocation(Scope* scope, |
28 const FunctionCallNode* invocation, | 26 const FunctionCallNode* invocation, |
29 const std::vector<Value>& args, | 27 const std::vector<Value>& args, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 const std::vector<Value>& args, | 252 const std::vector<Value>& args, |
255 Scope* scope, | 253 Scope* scope, |
256 Err* err) { | 254 Err* err) { |
257 if (!EnsureSingleStringArg(function, args, err) || | 255 if (!EnsureSingleStringArg(function, args, err) || |
258 !EnsureNotProcessingImport(function, scope, err)) | 256 !EnsureNotProcessingImport(function, scope, err)) |
259 return Value(); | 257 return Value(); |
260 | 258 |
261 Label label(MakeLabelForScope(scope, function, args[0].string_value())); | 259 Label label(MakeLabelForScope(scope, function, args[0].string_value())); |
262 | 260 |
263 if (g_scheduler->verbose_logging()) | 261 if (g_scheduler->verbose_logging()) |
264 g_scheduler->Log("Generating config", label.GetUserVisibleName(true)); | 262 g_scheduler->Log("Defining config", label.GetUserVisibleName(true)); |
265 | 263 |
266 // Create the empty config object. | 264 // Create the new config. |
267 ItemTree* tree = &scope->settings()->build_settings()->item_tree(); | 265 scoped_ptr<Config> config(new Config(scope->settings(), label)); |
268 Config* config = Config::GetConfig(scope->settings(), function->GetRange(), | 266 config->set_defined_from(function); |
269 label, NULL, err); | |
270 if (err->has_error()) | |
271 return Value(); | |
272 | 267 |
273 // Fill it. | 268 // Fill it. |
274 const SourceDir& input_dir = scope->GetSourceDir(); | 269 const SourceDir& input_dir = scope->GetSourceDir(); |
275 ConfigValuesGenerator gen(&config->config_values(), scope, | 270 ConfigValuesGenerator gen(&config->config_values(), scope, input_dir, err); |
276 function->function(), input_dir, err); | |
277 gen.Run(); | 271 gen.Run(); |
278 if (err->has_error()) | 272 if (err->has_error()) |
279 return Value(); | 273 return Value(); |
280 | 274 |
281 // Mark as complete. | 275 // Mark as complete. |
282 { | 276 scope->settings()->build_settings()->ItemDefined(config.PassAs<Item>()); |
283 base::AutoLock lock(tree->lock()); | |
284 tree->MarkItemDefinedLocked(scope->settings()->build_settings(), label, | |
285 err); | |
286 } | |
287 return Value(); | 277 return Value(); |
288 } | 278 } |
289 | 279 |
290 // declare_args ---------------------------------------------------------------- | 280 // declare_args ---------------------------------------------------------------- |
291 | 281 |
292 const char kDeclareArgs[] = "declare_args"; | 282 const char kDeclareArgs[] = "declare_args"; |
293 const char kDeclareArgs_Help[] = | 283 const char kDeclareArgs_Help[] = |
294 "declare_args: Declare build arguments used by this file.\n" | 284 "declare_args: Declare build arguments used by this file.\n" |
295 "\n" | 285 "\n" |
296 " Introduces the given arguments into the current scope. If they are\n" | 286 " Introduces the given arguments into the current scope. If they are\n" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 return found_function->second.executed_block_runner( | 633 return found_function->second.executed_block_runner( |
644 function, args.list_value(), &block_scope, err); | 634 function, args.list_value(), &block_scope, err); |
645 } | 635 } |
646 | 636 |
647 // Otherwise it's a no-block function. | 637 // Otherwise it's a no-block function. |
648 return found_function->second.no_block_runner(scope, function, | 638 return found_function->second.no_block_runner(scope, function, |
649 args.list_value(), err); | 639 args.list_value(), err); |
650 } | 640 } |
651 | 641 |
652 } // namespace functions | 642 } // namespace functions |
OLD | NEW |