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

Unified 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 side-by-side diff with in-line comments
Download patch
« tools/gn/command_args.cc ('K') | « tools/gn/functions.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/functions.cc
diff --git a/tools/gn/functions.cc b/tools/gn/functions.cc
index d50ccee0d1407a1763cf9dc46f77938c276e38c3..c6deef63d2cd4399c0c07c75a9340cb3c47b4656 100644
--- a/tools/gn/functions.cc
+++ b/tools/gn/functions.cc
@@ -361,6 +361,39 @@ Value RunDefined(Scope* scope,
return Value(function, false);
}
+// getenv ----------------------------------------------------------------------
+
+const char kGetEnv[] = "getenv";
+const char kGetEnv_Help[] =
+ "getenv: Get an environment variable.\n"
+ "\n"
+ " value = getenv(env_var_name)\n"
+ "\n"
+ " Returns the value of the given enironment variable. The case-\n"
+ " sensitivity (or lack thereof) of the lookup will match that of the\n"
+ " underlying operating system.\n"
+ "\n"
+ " If the environment variable is not found, the empty string will be\n"
+ " returned. Note: it might be nice to extend this if we had the concept\n"
+ " of \"none\" in the language to indicate lookup failure.\n"
+ "\n"
+ "Example:\n"
+ "\n"
+ " home_dir = getenv(\"HOME\")\n";
+
+Value RunGetEnv(Scope* scope,
+ const FunctionCallNode* function,
+ const std::vector<Value>& args,
+ Err* err) {
+ if (!EnsureSingleStringArg(function, args, err))
+ return Value();
+
+ 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
+ if (!env_result)
+ return Value(function, ""); // Not found, return empty string.
+ return Value(function, env_result);
+}
+
// import ----------------------------------------------------------------------
const char kImport[] = "import";
@@ -546,6 +579,7 @@ struct FunctionInfoInitializer {
INSERT_FUNCTION(Defined)
INSERT_FUNCTION(ExecScript)
INSERT_FUNCTION(Executable)
+ INSERT_FUNCTION(GetEnv)
INSERT_FUNCTION(Group)
INSERT_FUNCTION(Import)
INSERT_FUNCTION(Print)
« tools/gn/command_args.cc ('K') | « tools/gn/functions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698