From fa52b456ec2afdf1529e40143cfe4fe2fcb41a19 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Sun, 25 Sep 2016 19:30:44 -0700 Subject: [PATCH] set the FLUTTER_ROOT env var when invoking pub (#6041) --- .../flutter_tools/lib/src/base/process.dart | 22 ++++++++++++++----- packages/flutter_tools/lib/src/dart/pub.dart | 3 ++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 48a4d0f3aee..2dd7716eda7 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -12,15 +12,23 @@ typedef String StringConverter(String string); // TODO(ianh): We have way too many ways to run subprocesses in this project. -Map _environment(bool allowReentrantFlutter) { - return allowReentrantFlutter ? { 'FLUTTER_ALREADY_LOCKED': 'true' } : null; +Map _environment(bool allowReentrantFlutter, [Map environment]) { + if (allowReentrantFlutter) { + if (environment == null) + environment = { 'FLUTTER_ALREADY_LOCKED': 'true' }; + else + environment['FLUTTER_ALREADY_LOCKED'] = 'true'; + } + + return environment; } /// This runs the command in the background from the specified working /// directory. Completes when the process has been started. Future runCommand(List cmd, { String workingDirectory, - bool allowReentrantFlutter: false + bool allowReentrantFlutter: false, + Map environment }) async { _traceCommand(cmd, workingDirectory: workingDirectory); String executable = cmd[0]; @@ -29,7 +37,7 @@ Future runCommand(List cmd, { executable, arguments, workingDirectory: workingDirectory, - environment: _environment(allowReentrantFlutter) + environment: _environment(allowReentrantFlutter, environment) ); return process; } @@ -42,12 +50,14 @@ Future runCommandAndStreamOutput(List cmd, { String prefix: '', bool trace: false, RegExp filter, - StringConverter mapFunction + StringConverter mapFunction, + Map environment }) async { Process process = await runCommand( cmd, workingDirectory: workingDirectory, - allowReentrantFlutter: allowReentrantFlutter + allowReentrantFlutter: allowReentrantFlutter, + environment: environment ); StreamSubscription subscription = process.stdout .transform(UTF8.decoder) diff --git a/packages/flutter_tools/lib/src/dart/pub.dart b/packages/flutter_tools/lib/src/dart/pub.dart index 2bfd52e48d5..738cd0b9cde 100644 --- a/packages/flutter_tools/lib/src/dart/pub.dart +++ b/packages/flutter_tools/lib/src/dart/pub.dart @@ -50,7 +50,8 @@ Future pubGet({ int code = await runCommandAndStreamOutput( [sdkBinaryName('pub'), '--verbosity=warning', command, '--no-packages-dir', '--no-precompile'], workingDirectory: directory, - mapFunction: _filterOverrideWarnings + mapFunction: _filterOverrideWarnings, + environment: { 'FLUTTER_ROOT': Cache.flutterRoot } ); status.stop(showElapsedTime: true); if (code != 0)