Include parent environment by default, add option to not, for Process.
BUG=https://code.google.com/p/dart/issues/detail?id=9294,https://code.google.com/p/dart/issues/detail?id=9295 R=sgjesse@google.com Review URL: https://codereview.chromium.org//17261026 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@24262 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -20,11 +20,13 @@ patch class Process {
|
||||
List<String> arguments,
|
||||
{String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
bool runInShell}) {
|
||||
bool includeParentEnvironment: true,
|
||||
bool runInShell: false}) {
|
||||
_ProcessImpl process = new _ProcessImpl(executable,
|
||||
arguments,
|
||||
workingDirectory,
|
||||
environment,
|
||||
includeParentEnvironment,
|
||||
runInShell);
|
||||
return process._start();
|
||||
}
|
||||
@@ -34,13 +36,15 @@ patch class Process {
|
||||
List<String> arguments,
|
||||
{String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
bool runInShell,
|
||||
bool includeParentEnvironment: true,
|
||||
bool runInShell: false,
|
||||
Encoding stdoutEncoding: Encoding.SYSTEM,
|
||||
Encoding stderrEncoding: Encoding.SYSTEM}) {
|
||||
return _runNonInteractiveProcess(executable,
|
||||
arguments,
|
||||
workingDirectory,
|
||||
environment,
|
||||
includeParentEnvironment,
|
||||
runInShell,
|
||||
stdoutEncoding,
|
||||
stderrEncoding);
|
||||
@@ -68,6 +72,7 @@ class _ProcessImpl extends NativeFieldWrapperClass1 implements Process {
|
||||
List<String> arguments,
|
||||
String this._workingDirectory,
|
||||
Map<String, String> environment,
|
||||
bool includeParentEnvironment,
|
||||
bool runInShell) {
|
||||
runInShell = identical(runInShell, true);
|
||||
if (runInShell) {
|
||||
@@ -101,20 +106,23 @@ class _ProcessImpl extends NativeFieldWrapperClass1 implements Process {
|
||||
"WorkingDirectory is not a String: $_workingDirectory");
|
||||
}
|
||||
|
||||
if (environment != null) {
|
||||
var env = environment;
|
||||
if (env is !Map) {
|
||||
throw new ArgumentError("Environment is not a map: $env");
|
||||
}
|
||||
_environment = [];
|
||||
env.forEach((key, value) {
|
||||
if (key is !String || value is !String) {
|
||||
throw new ArgumentError(
|
||||
"Environment key or value is not a string: ($key, $value)");
|
||||
}
|
||||
_environment.add('$key=$value');
|
||||
});
|
||||
_environment = [];
|
||||
if (environment == null) {
|
||||
environment = {};
|
||||
}
|
||||
if (environment is !Map) {
|
||||
throw new ArgumentError("Environment is not a map: $environment");
|
||||
}
|
||||
if (identical(true, includeParentEnvironment)) {
|
||||
environment = Platform.environment..addAll(environment);
|
||||
}
|
||||
environment.forEach((key, value) {
|
||||
if (key is !String || value is !String) {
|
||||
throw new ArgumentError(
|
||||
"Environment key or value is not a string: ($key, $value)");
|
||||
}
|
||||
_environment.add('$key=$value');
|
||||
});
|
||||
|
||||
// stdin going to process.
|
||||
_stdin = new _StdSink(new _Socket._writePipe());
|
||||
@@ -331,6 +339,7 @@ Future<ProcessResult> _runNonInteractiveProcess(String path,
|
||||
List<String> arguments,
|
||||
String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
bool includeParentEnvironment,
|
||||
bool runInShell,
|
||||
Encoding stdoutEncoding,
|
||||
Encoding stderrEncoding) {
|
||||
@@ -339,6 +348,7 @@ Future<ProcessResult> _runNonInteractiveProcess(String path,
|
||||
arguments,
|
||||
workingDirectory: workingDirectory,
|
||||
environment: environment,
|
||||
includeParentEnvironment: includeParentEnvironment,
|
||||
runInShell: runInShell).then((Process p) {
|
||||
int pid = p.pid;
|
||||
|
||||
|
||||
@@ -591,19 +591,12 @@ Future _doProcess(Function fn, String executable, List<String> args,
|
||||
executable = "cmd";
|
||||
}
|
||||
|
||||
var env = null;
|
||||
if (environment != null) {
|
||||
env = new Map.from(Platform.environment);
|
||||
environment.forEach((key, value) => env[key] = value);
|
||||
}
|
||||
|
||||
|
||||
log.process(executable, args);
|
||||
|
||||
return fn(executable,
|
||||
args,
|
||||
workingDirectory: workingDir,
|
||||
environment: env);
|
||||
environment: environment);
|
||||
}
|
||||
|
||||
/// Wraps [input] to provide a timeout. If [input] completes before
|
||||
|
||||
@@ -453,8 +453,7 @@ ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) {
|
||||
|
||||
if (tokenEndpoint == null) tokenEndpoint = new Future.value();
|
||||
var environmentFuture = tokenEndpoint.then((tokenEndpoint) {
|
||||
// TODO(nweiz): remove this when issue 9294 is fixed.
|
||||
var environment = new Map.from(Platform.environment);
|
||||
var environment = {};
|
||||
environment['_PUB_TESTING'] = 'true';
|
||||
environment['PUB_CACHE'] = pathInSandbox(cachePath);
|
||||
environment['DART_SDK'] = pathInSandbox(sdkPath);
|
||||
|
||||
@@ -83,6 +83,10 @@ abstract class Process {
|
||||
* if an environment variable with code-points outside the US-ASCII range is
|
||||
* passed in.
|
||||
*
|
||||
* If [includeParentEnvironment] is `true`, the process's environment will
|
||||
* include the parent process's environment, with [environment] taking
|
||||
* precedence. Default is `true`.
|
||||
*
|
||||
* If [runInShell] is true, the process will be spawned through a system
|
||||
* shell. On Linux and Mac OS, [:/bin/sh:] is used, while
|
||||
* [:%WINDIR%\system32\cmd.exe:] is used on Windows.
|
||||
@@ -97,6 +101,7 @@ abstract class Process {
|
||||
List<String> arguments,
|
||||
{String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
bool includeParentEnvironment: true,
|
||||
bool runInShell: false});
|
||||
|
||||
/**
|
||||
@@ -114,6 +119,10 @@ abstract class Process {
|
||||
* if an environment variable with code-points outside the US-ASCII range is
|
||||
* passed in.
|
||||
*
|
||||
* If [includeParentEnvironment] is `true`, the process's environment will
|
||||
* include the parent process's environment, with [environment] taking
|
||||
* precedence. Default is `true`.
|
||||
*
|
||||
* If [runInShell] is true, the process will be spawned through a system
|
||||
* shell. On Linux and Mac OS, `/bin/sh` is used, while
|
||||
* `%WINDIR%\system32\cmd.exe` is used on Windows.
|
||||
@@ -133,6 +142,7 @@ abstract class Process {
|
||||
List<String> arguments,
|
||||
{String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
bool includeParentEnvironment: true,
|
||||
bool runInShell: false,
|
||||
Encoding stdoutEncoding: Encoding.SYSTEM,
|
||||
Encoding stderrEncoding: Encoding.SYSTEM});
|
||||
|
||||
@@ -7,7 +7,7 @@ import "dart:io";
|
||||
import "dart:isolate";
|
||||
import "process_test_util.dart";
|
||||
|
||||
runEnvironmentProcess(Map environment, name, callback) {
|
||||
runEnvironmentProcess(Map environment, name, includeParent, callback) {
|
||||
var dartExecutable = new Options().executable;
|
||||
var printEnv = 'tests/standalone/io/print_env.dart';
|
||||
if (!new File(printEnv).existsSync()) {
|
||||
@@ -15,7 +15,8 @@ runEnvironmentProcess(Map environment, name, callback) {
|
||||
}
|
||||
Process.run(dartExecutable,
|
||||
[printEnv, name],
|
||||
environment: environment)
|
||||
environment: environment,
|
||||
includeParentEnvironment: includeParent)
|
||||
.then((result) {
|
||||
Expect.equals(0, result.exitCode);
|
||||
callback(result.stdout);
|
||||
@@ -29,7 +30,7 @@ testEnvironment() {
|
||||
// Check that some value in the environment stays the same when passed
|
||||
// to another process.
|
||||
for (var k in env.keys) {
|
||||
runEnvironmentProcess(env, k, (output) {
|
||||
runEnvironmentProcess({}, k, true, (output) {
|
||||
// Only check startsWith. The print statements will add
|
||||
// newlines at the end.
|
||||
Expect.isTrue(output.startsWith(env[k]));
|
||||
@@ -39,7 +40,7 @@ testEnvironment() {
|
||||
var name = 'MYENVVAR';
|
||||
while (env.containsKey(name)) name = '${name}_';
|
||||
copy[name] = 'value';
|
||||
runEnvironmentProcess(copy, name, (output) {
|
||||
runEnvironmentProcess(copy, name, true, (output) {
|
||||
Expect.isTrue(output.startsWith('value'));
|
||||
donePort.close();
|
||||
});
|
||||
@@ -50,6 +51,15 @@ testEnvironment() {
|
||||
}
|
||||
}
|
||||
|
||||
testNoIncludeEnvironment() {
|
||||
var donePort = new ReceivePort();
|
||||
runEnvironmentProcess({}, "PATH", false, (output) {
|
||||
donePort.close();
|
||||
Expect.isTrue(output.startsWith("null"));
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
testEnvironment();
|
||||
testNoIncludeEnvironment();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user