Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: tools/gn/functions.cc

Issue 161783002: Remove default value checking in GN, adds getenv function, reorders parameters to rebase_path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/functions.h ('k') | tools/gn/value.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "tools/gn/config.h" 11 #include "tools/gn/config.h"
11 #include "tools/gn/config_values_generator.h" 12 #include "tools/gn/config_values_generator.h"
12 #include "tools/gn/err.h" 13 #include "tools/gn/err.h"
13 #include "tools/gn/input_file.h" 14 #include "tools/gn/input_file.h"
14 #include "tools/gn/parse_tree.h" 15 #include "tools/gn/parse_tree.h"
15 #include "tools/gn/scheduler.h" 16 #include "tools/gn/scheduler.h"
16 #include "tools/gn/scope.h" 17 #include "tools/gn/scope.h"
17 #include "tools/gn/settings.h" 18 #include "tools/gn/settings.h"
18 #include "tools/gn/token.h" 19 #include "tools/gn/token.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 *err = Err(function, "Bad argument to defined().", 355 *err = Err(function, "Bad argument to defined().",
355 "defined() takes one argument which should be an identifier."); 356 "defined() takes one argument which should be an identifier.");
356 return Value(); 357 return Value();
357 } 358 }
358 359
359 if (scope->GetValue(identifier->value().value())) 360 if (scope->GetValue(identifier->value().value()))
360 return Value(function, true); 361 return Value(function, true);
361 return Value(function, false); 362 return Value(function, false);
362 } 363 }
363 364
365 // getenv ----------------------------------------------------------------------
366
367 const char kGetEnv[] = "getenv";
368 const char kGetEnv_Help[] =
369 "getenv: Get an environment variable.\n"
370 "\n"
371 " value = getenv(env_var_name)\n"
372 "\n"
373 " Returns the value of the given enironment variable. If the value is\n"
374 " not found, it will try to look up the variable with the \"opposite\"\n"
375 " case (based on the case of the first letter of the variable), but\n"
376 " is otherwise case-sensitive.\n"
377 "\n"
378 " If the environment variable is not found, the empty string will be\n"
379 " returned. Note: it might be nice to extend this if we had the concept\n"
380 " of \"none\" in the language to indicate lookup failure.\n"
381 "\n"
382 "Example:\n"
383 "\n"
384 " home_dir = getenv(\"HOME\")\n";
385
386 Value RunGetEnv(Scope* scope,
387 const FunctionCallNode* function,
388 const std::vector<Value>& args,
389 Err* err) {
390 if (!EnsureSingleStringArg(function, args, err))
391 return Value();
392
393 scoped_ptr<base::Environment> env(base::Environment::Create());
394
395 std::string result;
396 if (!env->GetVar(args[0].string_value().c_str(), &result))
397 return Value(function, ""); // Not found, return empty string.
398 return Value(function, result);
399 }
400
364 // import ---------------------------------------------------------------------- 401 // import ----------------------------------------------------------------------
365 402
366 const char kImport[] = "import"; 403 const char kImport[] = "import";
367 const char kImport_Help[] = 404 const char kImport_Help[] =
368 "import: Import a file into the current scope.\n" 405 "import: Import a file into the current scope.\n"
369 "\n" 406 "\n"
370 " The import command loads the rules and variables resulting from\n" 407 " The import command loads the rules and variables resulting from\n"
371 " executing the given file into the current scope.\n" 408 " executing the given file into the current scope.\n"
372 "\n" 409 "\n"
373 " By convention, imported files are named with a .gni extension.\n" 410 " By convention, imported files are named with a .gni extension.\n"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 576
540 INSERT_FUNCTION(Assert) 577 INSERT_FUNCTION(Assert)
541 INSERT_FUNCTION(Component) 578 INSERT_FUNCTION(Component)
542 INSERT_FUNCTION(Config) 579 INSERT_FUNCTION(Config)
543 INSERT_FUNCTION(Copy) 580 INSERT_FUNCTION(Copy)
544 INSERT_FUNCTION(Custom) 581 INSERT_FUNCTION(Custom)
545 INSERT_FUNCTION(DeclareArgs) 582 INSERT_FUNCTION(DeclareArgs)
546 INSERT_FUNCTION(Defined) 583 INSERT_FUNCTION(Defined)
547 INSERT_FUNCTION(ExecScript) 584 INSERT_FUNCTION(ExecScript)
548 INSERT_FUNCTION(Executable) 585 INSERT_FUNCTION(Executable)
586 INSERT_FUNCTION(GetEnv)
549 INSERT_FUNCTION(Group) 587 INSERT_FUNCTION(Group)
550 INSERT_FUNCTION(Import) 588 INSERT_FUNCTION(Import)
551 INSERT_FUNCTION(Print) 589 INSERT_FUNCTION(Print)
552 INSERT_FUNCTION(ProcessFileTemplate) 590 INSERT_FUNCTION(ProcessFileTemplate)
553 INSERT_FUNCTION(ReadFile) 591 INSERT_FUNCTION(ReadFile)
554 INSERT_FUNCTION(RebasePath) 592 INSERT_FUNCTION(RebasePath)
555 INSERT_FUNCTION(SetDefaults) 593 INSERT_FUNCTION(SetDefaults)
556 INSERT_FUNCTION(SetDefaultToolchain) 594 INSERT_FUNCTION(SetDefaultToolchain)
557 INSERT_FUNCTION(SetSourcesAssignmentFilter) 595 INSERT_FUNCTION(SetSourcesAssignmentFilter)
558 INSERT_FUNCTION(SharedLibrary) 596 INSERT_FUNCTION(SharedLibrary)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 return found_function->second.executed_block_runner( 670 return found_function->second.executed_block_runner(
633 function, args.list_value(), &block_scope, err); 671 function, args.list_value(), &block_scope, err);
634 } 672 }
635 673
636 // Otherwise it's a no-block function. 674 // Otherwise it's a no-block function.
637 return found_function->second.no_block_runner(scope, function, 675 return found_function->second.no_block_runner(scope, function,
638 args.list_value(), err); 676 args.list_value(), err);
639 } 677 }
640 678
641 } // namespace functions 679 } // namespace functions
OLDNEW
« no previous file with comments | « tools/gn/functions.h ('k') | tools/gn/value.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698