Chromium Code Reviews| 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) |