Chromium Code Reviews| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 *err = Err(function, "Bad argument to defined().", | 354 *err = Err(function, "Bad argument to defined().", |
| 355 "defined() takes one argument which should be an identifier."); | 355 "defined() takes one argument which should be an identifier."); |
| 356 return Value(); | 356 return Value(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 if (scope->GetValue(identifier->value().value())) | 359 if (scope->GetValue(identifier->value().value())) |
| 360 return Value(function, true); | 360 return Value(function, true); |
| 361 return Value(function, false); | 361 return Value(function, false); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // getenv ---------------------------------------------------------------------- | |
| 365 | |
| 366 const char kGetEnv[] = "getenv"; | |
| 367 const char kGetEnv_Help[] = | |
| 368 "getenv: Get an environment variable.\n" | |
| 369 "\n" | |
| 370 " value = getenv(env_var_name)\n" | |
| 371 "\n" | |
| 372 " Returns the value of the given enironment variable. The case-\n" | |
| 373 " sensitivity (or lack thereof) of the lookup will match that of the\n" | |
| 374 " underlying operating system.\n" | |
| 375 "\n" | |
| 376 " If the environment variable is not found, the empty string will be\n" | |
| 377 " returned. Note: it might be nice to extend this if we had the concept\n" | |
| 378 " of \"none\" in the language to indicate lookup failure.\n" | |
| 379 "\n" | |
| 380 "Example:\n" | |
| 381 "\n" | |
| 382 " home_dir = getenv(\"HOME\")\n"; | |
| 383 | |
| 384 Value RunGetEnv(Scope* scope, | |
| 385 const FunctionCallNode* function, | |
| 386 const std::vector<Value>& args, | |
| 387 Err* err) { | |
| 388 if (!EnsureSingleStringArg(function, args, err)) | |
| 389 return Value(); | |
| 390 | |
| 391 const char* env_result = getenv(args[0].string_value().c_str()); | |
|
viettrungluu
2014/02/12 23:09:35
Does this work properly on Windows?
(You could us
| |
| 392 if (!env_result) | |
| 393 return Value(function, ""); // Not found, return empty string. | |
| 394 return Value(function, env_result); | |
| 395 } | |
| 396 | |
| 364 // import ---------------------------------------------------------------------- | 397 // import ---------------------------------------------------------------------- |
| 365 | 398 |
| 366 const char kImport[] = "import"; | 399 const char kImport[] = "import"; |
| 367 const char kImport_Help[] = | 400 const char kImport_Help[] = |
| 368 "import: Import a file into the current scope.\n" | 401 "import: Import a file into the current scope.\n" |
| 369 "\n" | 402 "\n" |
| 370 " The import command loads the rules and variables resulting from\n" | 403 " The import command loads the rules and variables resulting from\n" |
| 371 " executing the given file into the current scope.\n" | 404 " executing the given file into the current scope.\n" |
| 372 "\n" | 405 "\n" |
| 373 " By convention, imported files are named with a .gni extension.\n" | 406 " By convention, imported files are named with a .gni extension.\n" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 | 572 |
| 540 INSERT_FUNCTION(Assert) | 573 INSERT_FUNCTION(Assert) |
| 541 INSERT_FUNCTION(Component) | 574 INSERT_FUNCTION(Component) |
| 542 INSERT_FUNCTION(Config) | 575 INSERT_FUNCTION(Config) |
| 543 INSERT_FUNCTION(Copy) | 576 INSERT_FUNCTION(Copy) |
| 544 INSERT_FUNCTION(Custom) | 577 INSERT_FUNCTION(Custom) |
| 545 INSERT_FUNCTION(DeclareArgs) | 578 INSERT_FUNCTION(DeclareArgs) |
| 546 INSERT_FUNCTION(Defined) | 579 INSERT_FUNCTION(Defined) |
| 547 INSERT_FUNCTION(ExecScript) | 580 INSERT_FUNCTION(ExecScript) |
| 548 INSERT_FUNCTION(Executable) | 581 INSERT_FUNCTION(Executable) |
| 582 INSERT_FUNCTION(GetEnv) | |
| 549 INSERT_FUNCTION(Group) | 583 INSERT_FUNCTION(Group) |
| 550 INSERT_FUNCTION(Import) | 584 INSERT_FUNCTION(Import) |
| 551 INSERT_FUNCTION(Print) | 585 INSERT_FUNCTION(Print) |
| 552 INSERT_FUNCTION(ProcessFileTemplate) | 586 INSERT_FUNCTION(ProcessFileTemplate) |
| 553 INSERT_FUNCTION(ReadFile) | 587 INSERT_FUNCTION(ReadFile) |
| 554 INSERT_FUNCTION(RebasePath) | 588 INSERT_FUNCTION(RebasePath) |
| 555 INSERT_FUNCTION(SetDefaults) | 589 INSERT_FUNCTION(SetDefaults) |
| 556 INSERT_FUNCTION(SetDefaultToolchain) | 590 INSERT_FUNCTION(SetDefaultToolchain) |
| 557 INSERT_FUNCTION(SetSourcesAssignmentFilter) | 591 INSERT_FUNCTION(SetSourcesAssignmentFilter) |
| 558 INSERT_FUNCTION(SharedLibrary) | 592 INSERT_FUNCTION(SharedLibrary) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 return found_function->second.executed_block_runner( | 666 return found_function->second.executed_block_runner( |
| 633 function, args.list_value(), &block_scope, err); | 667 function, args.list_value(), &block_scope, err); |
| 634 } | 668 } |
| 635 | 669 |
| 636 // Otherwise it's a no-block function. | 670 // Otherwise it's a no-block function. |
| 637 return found_function->second.no_block_runner(scope, function, | 671 return found_function->second.no_block_runner(scope, function, |
| 638 args.list_value(), err); | 672 args.list_value(), err); |
| 639 } | 673 } |
| 640 | 674 |
| 641 } // namespace functions | 675 } // namespace functions |
| OLD | NEW |