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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 Err* err) { | 54 Err* err) { |
55 if (!block) { | 55 if (!block) { |
56 FillNeedsBlockError(function, err); | 56 FillNeedsBlockError(function, err); |
57 return false; | 57 return false; |
58 } | 58 } |
59 | 59 |
60 // Copy the target defaults, if any, into the scope we're going to execute | 60 // Copy the target defaults, if any, into the scope we're going to execute |
61 // the block in. | 61 // the block in. |
62 const Scope* default_scope = scope->GetTargetDefaults(target_type); | 62 const Scope* default_scope = scope->GetTargetDefaults(target_type); |
63 if (default_scope) { | 63 if (default_scope) { |
64 if (!default_scope->NonRecursiveMergeTo(block_scope, false, function, | 64 Scope::MergeOptions merge_options; |
65 "target defaults", err)) | 65 merge_options.skip_private_vars = true; |
| 66 if (!default_scope->NonRecursiveMergeTo(block_scope, merge_options, |
| 67 function, "target defaults", err)) |
66 return false; | 68 return false; |
67 } | 69 } |
68 | 70 |
69 // The name is the single argument to the target function. | 71 // The name is the single argument to the target function. |
70 if (!EnsureSingleStringArg(function, args, err)) | 72 if (!EnsureSingleStringArg(function, args, err)) |
71 return false; | 73 return false; |
72 | 74 |
73 // Set the target name variable to the current target, and mark it used | 75 // Set the target name variable to the current target, and mark it used |
74 // because we don't want to issue an error if the script ignores it. | 76 // because we don't want to issue an error if the script ignores it. |
75 const base::StringPiece target_name("target_name"); | 77 const base::StringPiece target_name("target_name"); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 " Note that you can not import a BUILD.gn file that's otherwise used\n" | 441 " Note that you can not import a BUILD.gn file that's otherwise used\n" |
440 " in the build. Files must either be imported or implicitly loaded as\n" | 442 " in the build. Files must either be imported or implicitly loaded as\n" |
441 " a result of deps rules, but not both.\n" | 443 " a result of deps rules, but not both.\n" |
442 "\n" | 444 "\n" |
443 " The imported file's scope will be merged with the scope at the point\n" | 445 " The imported file's scope will be merged with the scope at the point\n" |
444 " import was called. If there is a conflict (both the current scope and\n" | 446 " import was called. If there is a conflict (both the current scope and\n" |
445 " the imported file define some variable or rule with the same name but\n" | 447 " the imported file define some variable or rule with the same name but\n" |
446 " different value), a runtime error will be thrown. Therefore, it's good\n" | 448 " different value), a runtime error will be thrown. Therefore, it's good\n" |
447 " practice to minimize the stuff that an imported file defines.\n" | 449 " practice to minimize the stuff that an imported file defines.\n" |
448 "\n" | 450 "\n" |
| 451 " Variables and templates beginning with an underscore '_' are\n" |
| 452 " considered private and will not be imported. Imported files can use\n" |
| 453 " such variables for internal computation without affecting other files.\n" |
| 454 "\n" |
449 "Examples:\n" | 455 "Examples:\n" |
450 "\n" | 456 "\n" |
451 " import(\"//build/rules/idl_compilation_rule.gni\")\n" | 457 " import(\"//build/rules/idl_compilation_rule.gni\")\n" |
452 "\n" | 458 "\n" |
453 " # Looks in the current directory.\n" | 459 " # Looks in the current directory.\n" |
454 " import(\"my_vars.gni\")\n"; | 460 " import(\"my_vars.gni\")\n"; |
455 | 461 |
456 Value RunImport(Scope* scope, | 462 Value RunImport(Scope* scope, |
457 const FunctionCallNode* function, | 463 const FunctionCallNode* function, |
458 const std::vector<Value>& args, | 464 const std::vector<Value>& args, |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 return found_function->second.executed_block_runner( | 741 return found_function->second.executed_block_runner( |
736 function, args.list_value(), &block_scope, err); | 742 function, args.list_value(), &block_scope, err); |
737 } | 743 } |
738 | 744 |
739 // Otherwise it's a no-block function. | 745 // Otherwise it's a no-block function. |
740 return found_function->second.no_block_runner(scope, function, | 746 return found_function->second.no_block_runner(scope, function, |
741 args.list_value(), err); | 747 args.list_value(), err); |
742 } | 748 } |
743 | 749 |
744 } // namespace functions | 750 } // namespace functions |
OLD | NEW |