| 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" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 365 |
| 366 const char kImport[] = "import"; | 366 const char kImport[] = "import"; |
| 367 const char kImport_Help[] = | 367 const char kImport_Help[] = |
| 368 "import: Import a file into the current scope.\n" | 368 "import: Import a file into the current scope.\n" |
| 369 "\n" | 369 "\n" |
| 370 " The import command loads the rules and variables resulting from\n" | 370 " The import command loads the rules and variables resulting from\n" |
| 371 " executing the given file into the current scope.\n" | 371 " executing the given file into the current scope.\n" |
| 372 "\n" | 372 "\n" |
| 373 " By convention, imported files are named with a .gni extension.\n" | 373 " By convention, imported files are named with a .gni extension.\n" |
| 374 "\n" | 374 "\n" |
| 375 " It does not do an \"include\". The imported file is executed in a\n" | 375 " An import is different than a C++ \"include\". The imported file is\n" |
| 376 " standalone environment from the caller of the import command. The\n" | 376 " executed in a standalone environment from the caller of the import\n" |
| 377 " results of this execution are cached for other files that import the\n" | 377 " command. The results of this execution are cached for other files that\n" |
| 378 " same .gni file.\n" | 378 " import the same .gni file.\n" |
| 379 "\n" | 379 "\n" |
| 380 " Note that you can not import a BUILD.gn file that's otherwise used\n" | 380 " Note that you can not import a BUILD.gn file that's otherwise used\n" |
| 381 " in the build. Files must either be imported or implicitly loaded as\n" | 381 " in the build. Files must either be imported or implicitly loaded as\n" |
| 382 " a result of deps rules, but not both.\n" | 382 " a result of deps rules, but not both.\n" |
| 383 "\n" | 383 "\n" |
| 384 " The imported file's scope will be merged with the scope at the point\n" | 384 " The imported file's scope will be merged with the scope at the point\n" |
| 385 " import was called. If there is a conflict (both the current scope and\n" | 385 " import was called. If there is a conflict (both the current scope and\n" |
| 386 " the imported file define some variable or rule with the same name)\n" | 386 " the imported file define some variable or rule with the same name but\n" |
| 387 " a runtime error will be thrown. Therefore, it's good practice to\n" | 387 " different value), a runtime error will be thrown. Therefore, it's good\n" |
| 388 " minimize the stuff that an imported file defines.\n" | 388 " practice to minimize the stuff that an imported file defines.\n" |
| 389 "\n" | 389 "\n" |
| 390 "Examples:\n" | 390 "Examples:\n" |
| 391 "\n" | 391 "\n" |
| 392 " import(\"//build/rules/idl_compilation_rule.gni\")\n" | 392 " import(\"//build/rules/idl_compilation_rule.gni\")\n" |
| 393 "\n" | 393 "\n" |
| 394 " # Looks in the current directory.\n" | 394 " # Looks in the current directory.\n" |
| 395 " import(\"my_vars.gni\")\n"; | 395 " import(\"my_vars.gni\")\n"; |
| 396 | 396 |
| 397 Value RunImport(Scope* scope, | 397 Value RunImport(Scope* scope, |
| 398 const FunctionCallNode* function, | 398 const FunctionCallNode* function, |
| 399 const std::vector<Value>& args, | 399 const std::vector<Value>& args, |
| 400 Err* err) { | 400 Err* err) { |
| 401 if (!EnsureSingleStringArg(function, args, err) || | 401 if (!EnsureSingleStringArg(function, args, err)) |
| 402 !EnsureNotProcessingImport(function, scope, err)) | |
| 403 return Value(); | 402 return Value(); |
| 404 | 403 |
| 405 const SourceDir& input_dir = scope->GetSourceDir(); | 404 const SourceDir& input_dir = scope->GetSourceDir(); |
| 406 SourceFile import_file = | 405 SourceFile import_file = |
| 407 input_dir.ResolveRelativeFile(args[0].string_value()); | 406 input_dir.ResolveRelativeFile(args[0].string_value()); |
| 408 scope->settings()->import_manager().DoImport(import_file, function, | 407 scope->settings()->import_manager().DoImport(import_file, function, |
| 409 scope, err); | 408 scope, err); |
| 410 return Value(); | 409 return Value(); |
| 411 } | 410 } |
| 412 | 411 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return found_function->second.executed_block_runner( | 632 return found_function->second.executed_block_runner( |
| 634 function, args.list_value(), &block_scope, err); | 633 function, args.list_value(), &block_scope, err); |
| 635 } | 634 } |
| 636 | 635 |
| 637 // Otherwise it's a no-block function. | 636 // Otherwise it's a no-block function. |
| 638 return found_function->second.no_block_runner(scope, function, | 637 return found_function->second.no_block_runner(scope, function, |
| 639 args.list_value(), err); | 638 args.list_value(), err); |
| 640 } | 639 } |
| 641 | 640 |
| 642 } // namespace functions | 641 } // namespace functions |
| OLD | NEW |