From ba57ea09d17a30c05d6771cffdb6d10250b2f359 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 25 Mar 2020 14:59:03 -0700 Subject: [PATCH] Revert "Move processUtils into globals (#53209)" (#53301) --- .../lib/src/android/android_device.dart | 28 +++++++++---------- .../lib/src/android/android_emulator.dart | 5 ++-- .../lib/src/android/android_sdk.dart | 4 +-- .../lib/src/android/android_studio.dart | 2 +- .../lib/src/android/android_workflow.dart | 5 ++-- .../flutter_tools/lib/src/android/gradle.dart | 6 ++-- .../lib/src/android/gradle_errors.dart | 2 +- .../lib/src/application_package.dart | 2 +- .../flutter_tools/lib/src/base/process.dart | 4 +++ .../lib/src/build_system/targets/ios.dart | 2 +- packages/flutter_tools/lib/src/cache.dart | 2 +- .../lib/src/commands/build_ios_framework.dart | 20 ++++++------- .../lib/src/commands/channel.dart | 11 ++++---- .../flutter_tools/lib/src/commands/drive.dart | 3 +- .../lib/src/commands/format.dart | 4 +-- .../lib/src/commands/upgrade.dart | 16 +++++------ .../lib/src/commands/version.dart | 8 +++--- packages/flutter_tools/lib/src/dart/pub.dart | 5 ++-- packages/flutter_tools/lib/src/doctor.dart | 3 +- packages/flutter_tools/lib/src/emulator.dart | 6 ++-- .../lib/src/fuchsia/fuchsia_build.dart | 3 +- .../lib/src/fuchsia/fuchsia_device.dart | 4 +-- .../src/fuchsia/fuchsia_kernel_compiler.dart | 3 +- .../lib/src/fuchsia/fuchsia_pm.dart | 4 +-- packages/flutter_tools/lib/src/globals.dart | 2 -- .../lib/src/ios/ios_emulators.dart | 2 +- packages/flutter_tools/lib/src/ios/mac.dart | 4 +-- .../flutter_tools/lib/src/ios/simulators.dart | 6 ++-- .../lib/src/linux/build_linux.dart | 3 +- .../lib/src/macos/build_macos.dart | 3 +- .../lib/src/test/coverage_collector.dart | 2 +- packages/flutter_tools/lib/src/version.dart | 14 +++++----- .../lib/src/windows/build_windows.dart | 3 +- .../lib/src/windows/windows_device.dart | 2 +- 34 files changed, 103 insertions(+), 90 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 6c8d6d0318..d1bd4e6138 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -225,7 +225,7 @@ class AndroidDevice extends Device { bool allowReentrantFlutter = false, Map environment, }) { - return globals.processUtils.runSync( + return processUtils.runSync( adbCommandForDevice(params), throwOnError: true, workingDirectory: workingDirectory, @@ -240,7 +240,7 @@ class AndroidDevice extends Device { String workingDirectory, bool allowReentrantFlutter = false, }) async { - return globals.processUtils.run( + return processUtils.run( adbCommandForDevice(params), throwOnError: true, workingDirectory: workingDirectory, @@ -278,7 +278,7 @@ class AndroidDevice extends Device { } try { - final RunResult adbVersion = await globals.processUtils.run( + final RunResult adbVersion = await processUtils.run( [getAdbPath(androidSdk), 'version'], throwOnError: true, ); @@ -299,7 +299,7 @@ class AndroidDevice extends Device { // output lines like this, which we want to ignore: // adb server is out of date. killing.. // * daemon started successfully * - await globals.processUtils.run( + await processUtils.run( [getAdbPath(androidSdk), 'start-server'], throwOnError: true, ); @@ -336,7 +336,7 @@ class AndroidDevice extends Device { } Future _getDeviceApkSha1(AndroidApk apk) async { - final RunResult result = await globals.processUtils.run( + final RunResult result = await processUtils.run( adbCommandForDevice(['shell', 'cat', _getDeviceSha1Path(apk)])); return result.stdout; } @@ -380,7 +380,7 @@ class AndroidDevice extends Device { } final Status status = globals.logger.startProgress('Installing ${globals.fs.path.relative(app.file.path)}...', timeout: timeoutConfiguration.slowOperation); - final RunResult installResult = await globals.processUtils.run( + final RunResult installResult = await processUtils.run( adbCommandForDevice(['install', '-t', '-r', app.file.path])); status.stop(); // Some versions of adb exit with exit code 0 even on failure :( @@ -416,7 +416,7 @@ class AndroidDevice extends Device { String uninstallOut; try { - final RunResult uninstallResult = await globals.processUtils.run( + final RunResult uninstallResult = await processUtils.run( adbCommandForDevice(['uninstall', app.id]), throwOnError: true, ); @@ -647,13 +647,13 @@ class AndroidDevice extends Device { @override Future stopApp(AndroidApk app) { final List command = adbCommandForDevice(['shell', 'am', 'force-stop', app.id]); - return globals.processUtils.stream(command).then( + return processUtils.stream(command).then( (int exitCode) => exitCode == 0 || allowHeapCorruptionOnWindows(exitCode)); } @override Future queryMemoryInfo() async { - final RunResult runResult = await globals.processUtils.run(adbCommandForDevice([ + final RunResult runResult = await processUtils.run(adbCommandForDevice([ 'shell', 'dumpsys', 'meminfo', @@ -669,7 +669,7 @@ class AndroidDevice extends Device { @override void clearLogs() { - globals.processUtils.runSync(adbCommandForDevice(['logcat', '-c'])); + processUtils.runSync(adbCommandForDevice(['logcat', '-c'])); } @override @@ -709,7 +709,7 @@ class AndroidDevice extends Device { Future takeScreenshot(File outputFile) async { const String remotePath = '/data/local/tmp/flutter_screenshot.png'; await runAdbCheckedAsync(['shell', 'screencap', '-p', remotePath]); - await globals.processUtils.run( + await processUtils.run( adbCommandForDevice(['pull', remotePath, outputFile.path]), throwOnError: true, ); @@ -1074,7 +1074,7 @@ class _AndroidDevicePortForwarder extends DevicePortForwarder { String stdout; try { - stdout = globals.processUtils.runSync( + stdout = processUtils.runSync( device.adbCommandForDevice(['forward', '--list']), throwOnError: true, ).stdout.trim(); @@ -1118,7 +1118,7 @@ class _AndroidDevicePortForwarder extends DevicePortForwarder { 'tcp:$hostPort', 'tcp:$devicePort', ]; - final RunResult process = await globals.processUtils.run( + final RunResult process = await processUtils.run( device.adbCommandForDevice(forwardCommand), throwOnError: true, ); @@ -1171,7 +1171,7 @@ class _AndroidDevicePortForwarder extends DevicePortForwarder { '--remove', 'tcp:${forwardedPort.hostPort}', ]; - await globals.processUtils.run( + await processUtils.run( device.adbCommandForDevice(unforwardCommand), throwOnError: true, ); diff --git a/packages/flutter_tools/lib/src/android/android_emulator.dart b/packages/flutter_tools/lib/src/android/android_emulator.dart index 45c57191c2..0aeb57d58f 100644 --- a/packages/flutter_tools/lib/src/android/android_emulator.dart +++ b/packages/flutter_tools/lib/src/android/android_emulator.dart @@ -11,6 +11,7 @@ import '../android/android_workflow.dart'; import '../base/common.dart'; import '../base/file_system.dart'; import '../base/io.dart'; +import '../base/process.dart'; import '../base/utils.dart'; import '../convert.dart'; import '../device.dart'; @@ -53,7 +54,7 @@ class AndroidEmulator extends Emulator { @override Future launch() async { - final Process process = await globals.processUtils.start( + final Process process = await processUtils.start( [getEmulatorPath(androidSdk), '-avd', id], ); @@ -116,7 +117,7 @@ List getEmulatorAvds() { return []; } - final String listAvdsOutput = globals.processUtils.runSync( + final String listAvdsOutput = processUtils.runSync( [emulatorPath, '-list-avds']).stdout.trim(); final List emulators = []; diff --git a/packages/flutter_tools/lib/src/android/android_sdk.dart b/packages/flutter_tools/lib/src/android/android_sdk.dart index a76427fcc6..98a5293f76 100644 --- a/packages/flutter_tools/lib/src/android/android_sdk.dart +++ b/packages/flutter_tools/lib/src/android/android_sdk.dart @@ -582,7 +582,7 @@ class AndroidSdk { // See: http://stackoverflow.com/questions/14292698/how-do-i-check-if-the-java-jdk-is-installed-on-mac. if (platform.isMacOS) { try { - final String javaHomeOutput = globals.processUtils.runSync( + final String javaHomeOutput = processUtils.runSync( ['/usr/libexec/java_home'], throwOnError: true, hideStdout: true, @@ -628,7 +628,7 @@ class AndroidSdk { if (!globals.processManager.canRun(sdkManagerPath)) { throwToolExit('Android sdkmanager not found. Update to the latest Android SDK to resolve this.'); } - final RunResult result = globals.processUtils.runSync( + final RunResult result = processUtils.runSync( [sdkManagerPath, '--version'], environment: sdkManagerEnv, ); diff --git a/packages/flutter_tools/lib/src/android/android_studio.dart b/packages/flutter_tools/lib/src/android/android_studio.dart index 71fb5bfdd5..eb07945b2c 100644 --- a/packages/flutter_tools/lib/src/android/android_studio.dart +++ b/packages/flutter_tools/lib/src/android/android_studio.dart @@ -310,7 +310,7 @@ class AndroidStudio implements Comparable { } else { RunResult result; try { - result = globals.processUtils.runSync([javaExecutable, '-version']); + result = processUtils.runSync([javaExecutable, '-version']); } on ProcessException catch (e) { _validationMessages.add('Failed to run Java: $e'); } diff --git a/packages/flutter_tools/lib/src/android/android_workflow.dart b/packages/flutter_tools/lib/src/android/android_workflow.dart index 8e96a53514..772050262f 100644 --- a/packages/flutter_tools/lib/src/android/android_workflow.dart +++ b/packages/flutter_tools/lib/src/android/android_workflow.dart @@ -14,6 +14,7 @@ import '../base/file_system.dart'; import '../base/io.dart'; import '../base/logger.dart'; import '../base/os.dart'; +import '../base/process.dart'; import '../base/user_messages.dart'; import '../base/utils.dart'; import '../base/version.dart'; @@ -322,7 +323,7 @@ class AndroidLicenseValidator extends DoctorValidator { } try { - final Process process = await globals.processUtils.start( + final Process process = await processUtils.start( [androidSdk.sdkManagerPath, '--licenses'], environment: androidSdk.sdkManagerEnv, ); @@ -359,7 +360,7 @@ class AndroidLicenseValidator extends DoctorValidator { } try { - final Process process = await globals.processUtils.start( + final Process process = await processUtils.start( [androidSdk.sdkManagerPath, '--licenses'], environment: androidSdk.sdkManagerEnv, ); diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart index 5cb5f07569..5fadda7504 100644 --- a/packages/flutter_tools/lib/src/android/gradle.dart +++ b/packages/flutter_tools/lib/src/android/gradle.dart @@ -142,7 +142,7 @@ Future checkGradleDependencies() async { timeout: timeoutConfiguration.slowOperation, ); final FlutterProject flutterProject = FlutterProject.current(); - await globals.processUtils.run([ + await processUtils.run([ gradleUtils.getExecutable(flutterProject), 'dependencies', ], @@ -382,7 +382,7 @@ Future buildGradleApp({ final Stopwatch sw = Stopwatch()..start(); int exitCode = 1; try { - exitCode = await globals.processUtils.stream( + exitCode = await processUtils.stream( command, workingDirectory: project.android.hostAppGradleRoot.path, allowReentrantFlutter: true, @@ -584,7 +584,7 @@ Future buildGradleAar({ final Stopwatch sw = Stopwatch()..start(); RunResult result; try { - result = await globals.processUtils.run( + result = await processUtils.run( command, workingDirectory: project.android.hostAppGradleRoot.path, allowReentrantFlutter: true, diff --git a/packages/flutter_tools/lib/src/android/gradle_errors.dart b/packages/flutter_tools/lib/src/android/gradle_errors.dart index c4503d3eee..fddea7c7b2 100644 --- a/packages/flutter_tools/lib/src/android/gradle_errors.dart +++ b/packages/flutter_tools/lib/src/android/gradle_errors.dart @@ -270,7 +270,7 @@ final GradleHandledError flavorUndefinedHandler = GradleHandledError( bool usesAndroidX, bool shouldBuildPluginAsAar, }) async { - final RunResult tasksRunResult = await globals.processUtils.run( + final RunResult tasksRunResult = await processUtils.run( [ gradleUtils.getExecutable(project), 'app:tasks' , diff --git a/packages/flutter_tools/lib/src/application_package.dart b/packages/flutter_tools/lib/src/application_package.dart index 3ec4038648..251e856074 100644 --- a/packages/flutter_tools/lib/src/application_package.dart +++ b/packages/flutter_tools/lib/src/application_package.dart @@ -117,7 +117,7 @@ class AndroidApk extends ApplicationPackage { String apptStdout; try { - apptStdout = globals.processUtils.runSync( + apptStdout = processUtils.runSync( [ aaptPath, 'dump', diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index fb63b06a7f..ea4e7efe77 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -180,6 +180,8 @@ class RunResult { typedef RunResultChecker = bool Function(int); +ProcessUtils get processUtils => ProcessUtils.instance; + abstract class ProcessUtils { factory ProcessUtils({ @required ProcessManager processManager, @@ -189,6 +191,8 @@ abstract class ProcessUtils { logger: logger, ); + static ProcessUtils get instance => context.get(); + /// Spawns a child process to run the command [cmd]. /// /// When [throwOnError] is `true`, if the child process finishes with a non-zero diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart index 1dd7c6ff49..8d1943d9a6 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -224,7 +224,7 @@ class DebugUniveralFramework extends Target { '-output', lipoOutputFile.path ]; - final RunResult lipoResult = await globals.processUtils.run( + final RunResult lipoResult = await processUtils.run( lipoCommand, ); diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 1b6cc7377f..33837f0e37 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -984,7 +984,7 @@ class AndroidMavenArtifacts extends ArtifactSet { try { final String gradleExecutable = gradle.absolute.path; final String flutterSdk = globals.fsUtils.escapePath(Cache.flutterRoot); - final RunResult processResult = await globals.processUtils.run( + final RunResult processResult = await processUtils.run( [ gradleExecutable, '-b', globals.fs.path.join(flutterSdk, 'packages', 'flutter_tools', 'gradle', 'resolve_dependencies.gradle'), diff --git a/packages/flutter_tools/lib/src/commands/build_ios_framework.dart b/packages/flutter_tools/lib/src/commands/build_ios_framework.dart index 15d574999f..1784a906d3 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios_framework.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios_framework.dart @@ -324,7 +324,7 @@ end '-output', fatFlutterFrameworkBinary.path ]; - final RunResult lipoResult = await globals.processUtils.run( + final RunResult lipoResult = await processUtils.run( lipoCommand, allowReentrantFlutter: false, ); @@ -406,7 +406,7 @@ end destinationAppFrameworkDirectory.childFile(binaryName).path ]; - final RunResult lipoResult = await globals.processUtils.run( + final RunResult lipoResult = await processUtils.run( lipoCommand, allowReentrantFlutter: false, ); @@ -478,7 +478,7 @@ end 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES', ]; - RunResult buildPluginsResult = await globals.processUtils.run( + RunResult buildPluginsResult = await processUtils.run( pluginsBuildCommand, workingDirectory: _project.ios.hostAppRoot.childDirectory('Pods').path, allowReentrantFlutter: false, @@ -504,7 +504,7 @@ end 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES', ]; - buildPluginsResult = await globals.processUtils.run( + buildPluginsResult = await processUtils.run( pluginsBuildCommand, workingDirectory: _project.ios.hostAppRoot .childDirectory('Pods') @@ -556,7 +556,7 @@ end modeDirectory.childDirectory(podFrameworkName).childFile(binaryName).path ]; - final RunResult pluginsLipoResult = await globals.processUtils.run( + final RunResult pluginsLipoResult = await processUtils.run( lipoCommand, workingDirectory: outputDirectory.path, allowReentrantFlutter: false, @@ -587,7 +587,7 @@ end modeDirectory.childFile('$binaryName.xcframework').path ]; - final RunResult xcframeworkResult = await globals.processUtils.run( + final RunResult xcframeworkResult = await processUtils.run( xcframeworkCommand, workingDirectory: outputDirectory.path, allowReentrantFlutter: false, @@ -664,7 +664,7 @@ end armFlutterFrameworkBinary.path ]; - RunResult lipoResult = await globals.processUtils.run( + RunResult lipoResult = await processUtils.run( lipoCommand, allowReentrantFlutter: false, ); @@ -690,7 +690,7 @@ end simulatorFlutterFrameworkBinary.path ]; - lipoResult = await globals.processUtils.run( + lipoResult = await processUtils.run( lipoCommand, allowReentrantFlutter: false, ); @@ -712,7 +712,7 @@ end .path ]; - final RunResult xcframeworkResult = await globals.processUtils.run( + final RunResult xcframeworkResult = await processUtils.run( xcframeworkCommand, allowReentrantFlutter: false, ); @@ -744,7 +744,7 @@ end .path ]; - final RunResult xcframeworkResult = await globals.processUtils.run( + final RunResult xcframeworkResult = await processUtils.run( xcframeworkCommand, allowReentrantFlutter: false, ); diff --git a/packages/flutter_tools/lib/src/commands/channel.dart b/packages/flutter_tools/lib/src/commands/channel.dart index ec7c28d1b1..b7f91db366 100644 --- a/packages/flutter_tools/lib/src/commands/channel.dart +++ b/packages/flutter_tools/lib/src/commands/channel.dart @@ -5,6 +5,7 @@ import 'dart:async'; import '../base/common.dart'; +import '../base/process.dart'; import '../cache.dart'; import '../globals.dart' as globals; import '../runner/flutter_command.dart'; @@ -60,7 +61,7 @@ class ChannelCommand extends FlutterCommand { showAll = showAll || currentChannel != currentBranch; globals.printStatus('Flutter channels:'); - final int result = await globals.processUtils.stream( + final int result = await processUtils.stream( ['git', 'branch', '-r'], workingDirectory: Cache.flutterRoot, mapFunction: (String line) { @@ -139,28 +140,28 @@ class ChannelCommand extends FlutterCommand { static Future _checkout(String branchName) async { // Get latest refs from upstream. - int result = await globals.processUtils.stream( + int result = await processUtils.stream( ['git', 'fetch'], workingDirectory: Cache.flutterRoot, prefix: 'git: ', ); if (result == 0) { - result = await globals.processUtils.stream( + result = await processUtils.stream( ['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'], workingDirectory: Cache.flutterRoot, prefix: 'git: ', ); if (result == 0) { // branch already exists, try just switching to it - result = await globals.processUtils.stream( + result = await processUtils.stream( ['git', 'checkout', branchName, '--'], workingDirectory: Cache.flutterRoot, prefix: 'git: ', ); } else { // branch does not exist, we have to create it - result = await globals.processUtils.stream( + result = await processUtils.stream( ['git', 'checkout', '--track', '-b', branchName, 'origin/$branchName'], workingDirectory: Cache.flutterRoot, prefix: 'git: ', diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 561352cf80..39c344738d 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -11,6 +11,7 @@ import 'package:webdriver/async_io.dart' as async_io; import '../application_package.dart'; import '../base/common.dart'; import '../base/file_system.dart'; +import '../base/process.dart'; import '../build_info.dart'; import '../cache.dart'; import '../dart/package_map.dart'; @@ -467,7 +468,7 @@ Future _runTests(List testArgs, Map environment) a PackageMap.globalPackagesPath = globals.fs.path.normalize(globals.fs.path.absolute(PackageMap.globalPackagesPath)); final String dartVmPath = globals.fs.path.join(dartSdkPath, 'bin', 'dart'); - final int result = await globals.processUtils.stream( + final int result = await processUtils.stream( [ dartVmPath, ...dartVmFlags, diff --git a/packages/flutter_tools/lib/src/commands/format.dart b/packages/flutter_tools/lib/src/commands/format.dart index 68b4d93354..7d6e4f4b94 100644 --- a/packages/flutter_tools/lib/src/commands/format.dart +++ b/packages/flutter_tools/lib/src/commands/format.dart @@ -5,8 +5,8 @@ import 'dart:async'; import '../base/common.dart'; +import '../base/process.dart'; import '../dart/sdk.dart'; -import '../globals.dart' as globals; import '../runner/flutter_command.dart'; class FormatCommand extends FlutterCommand { @@ -71,7 +71,7 @@ class FormatCommand extends FlutterCommand { ...argResults.rest, ]; - final int result = await globals.processUtils.stream(command); + final int result = await processUtils.stream(command); if (result != 0) { throwToolExit('Formatting failed: $result', exitCode: result); } diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index 2df91555c8..021c5d785e 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -61,7 +61,7 @@ class UpgradeCommand extends FlutterCommand { force: boolArg('force'), continueFlow: boolArg('continue'), testFlow: stringArg('working-directory') != null, - gitTagVersion: GitTagVersion.determine(globals.processUtils), + gitTagVersion: GitTagVersion.determine(processUtils), flutterVersion: stringArg('working-directory') == null ? globals.flutterVersion : FlutterVersion(const SystemClock(), _commandRunner.workingDirectory), @@ -152,7 +152,7 @@ class UpgradeCommandRunner { } Future flutterUpgradeContinue() async { - final int code = await globals.processUtils.stream( + final int code = await processUtils.stream( [ globals.fs.path.join('bin', 'flutter'), 'upgrade', @@ -182,7 +182,7 @@ class UpgradeCommandRunner { Future hasUncomittedChanges() async { try { - final RunResult result = await globals.processUtils.run( + final RunResult result = await processUtils.run( ['git', 'status', '-s'], throwOnError: true, workingDirectory: workingDirectory, @@ -205,7 +205,7 @@ class UpgradeCommandRunner { /// Exits tool if there is no upstream. Future verifyUpstreamConfigured() async { try { - await globals.processUtils.run( + await processUtils.run( [ 'git', 'rev-parse', '@{u}'], throwOnError: true, workingDirectory: workingDirectory, @@ -232,7 +232,7 @@ class UpgradeCommandRunner { tag = 'v${gitTagVersion.x}.${gitTagVersion.y}.${gitTagVersion.z}'; } try { - await globals.processUtils.run( + await processUtils.run( ['git', 'reset', '--hard', tag], throwOnError: true, workingDirectory: workingDirectory, @@ -264,7 +264,7 @@ class UpgradeCommandRunner { /// If the fast forward lands us on the same channel and revision, then /// returns true, otherwise returns false. Future attemptFastForward(FlutterVersion oldFlutterVersion) async { - final int code = await globals.processUtils.stream( + final int code = await processUtils.stream( ['git', 'pull', '--ff'], workingDirectory: workingDirectory, mapFunction: (String line) => matchesGitLine(line) ? null : line, @@ -293,7 +293,7 @@ class UpgradeCommandRunner { Future precacheArtifacts() async { globals.printStatus(''); globals.printStatus('Upgrading engine...'); - final int code = await globals.processUtils.stream( + final int code = await processUtils.stream( [ globals.fs.path.join('bin', 'flutter'), '--no-color', '--no-version-check', 'precache', ], @@ -321,7 +321,7 @@ class UpgradeCommandRunner { Future runDoctor() async { globals.printStatus(''); globals.printStatus('Running flutter doctor...'); - await globals.processUtils.stream( + await processUtils.stream( [ globals.fs.path.join('bin', 'flutter'), '--no-version-check', 'doctor', ], diff --git a/packages/flutter_tools/lib/src/commands/version.dart b/packages/flutter_tools/lib/src/commands/version.dart index 1c890f7925..6282698b35 100644 --- a/packages/flutter_tools/lib/src/commands/version.dart +++ b/packages/flutter_tools/lib/src/commands/version.dart @@ -44,7 +44,7 @@ class VersionCommand extends FlutterCommand { globals.flutterVersion.fetchTagsAndUpdate(); RunResult runResult; try { - runResult = await globals.processUtils.run( + runResult = await processUtils.run( ['git', 'tag', '-l', 'v*', '--sort=-creatordate'], throwOnError: true, workingDirectory: Cache.flutterRoot, @@ -112,7 +112,7 @@ class VersionCommand extends FlutterCommand { } try { - await globals.processUtils.run( + await processUtils.run( ['git', 'checkout', 'v$version'], throwOnError: true, workingDirectory: Cache.flutterRoot, @@ -131,7 +131,7 @@ class VersionCommand extends FlutterCommand { // if necessary. globals.printStatus(''); globals.printStatus('Downloading engine...'); - int code = await globals.processUtils.stream([ + int code = await processUtils.stream([ globals.fs.path.join('bin', 'flutter'), '--no-color', 'precache', @@ -158,7 +158,7 @@ class VersionCommand extends FlutterCommand { // Run a doctor check in case system requirements have changed. globals.printStatus(''); globals.printStatus('Running flutter doctor...'); - code = await globals.processUtils.stream( + code = await processUtils.stream( [ globals.fs.path.join('bin', 'flutter'), 'doctor', diff --git a/packages/flutter_tools/lib/src/dart/pub.dart b/packages/flutter_tools/lib/src/dart/pub.dart index 035d16e5b6..10ae1b9205 100644 --- a/packages/flutter_tools/lib/src/dart/pub.dart +++ b/packages/flutter_tools/lib/src/dart/pub.dart @@ -11,6 +11,7 @@ import '../base/context.dart'; import '../base/file_system.dart'; import '../base/io.dart' as io; import '../base/logger.dart'; +import '../base/process.dart'; import '../cache.dart'; import '../globals.dart' as globals; import '../reporting/reporting.dart'; @@ -254,7 +255,7 @@ class _DefaultPub implements Pub { int code; loop: while (true) { attempts += 1; - code = await globals.processUtils.stream( + code = await processUtils.stream( _pubCommand(arguments), workingDirectory: directory, mapFunction: filterWrapper, // may set versionSolvingFailed, lastPubMessage @@ -300,7 +301,7 @@ class _DefaultPub implements Pub { String directory, }) async { Cache.releaseLockEarly(); - final io.Process process = await globals.processUtils.start( + final io.Process process = await processUtils.start( _pubCommand(arguments), workingDirectory: directory, environment: await _createPubEnvironment(PubContext.interactive), diff --git a/packages/flutter_tools/lib/src/doctor.dart b/packages/flutter_tools/lib/src/doctor.dart index 0ca6f0c8b1..8549e29509 100644 --- a/packages/flutter_tools/lib/src/doctor.dart +++ b/packages/flutter_tools/lib/src/doctor.dart @@ -13,6 +13,7 @@ import 'base/async_guard.dart'; import 'base/context.dart'; import 'base/file_system.dart'; import 'base/logger.dart'; +import 'base/process.dart'; import 'base/terminal.dart'; import 'base/user_messages.dart'; import 'base/utils.dart'; @@ -666,7 +667,7 @@ class FlutterValidator extends DoctorValidator { bool _genSnapshotRuns(String genSnapshotPath) { const int kExpectedExitCode = 255; try { - return globals.processUtils.runSync([genSnapshotPath]).exitCode == kExpectedExitCode; + return processUtils.runSync([genSnapshotPath]).exitCode == kExpectedExitCode; } on Exception { return false; } diff --git a/packages/flutter_tools/lib/src/emulator.dart b/packages/flutter_tools/lib/src/emulator.dart index 1d6c8cd450..7a9141014f 100644 --- a/packages/flutter_tools/lib/src/emulator.dart +++ b/packages/flutter_tools/lib/src/emulator.dart @@ -120,7 +120,7 @@ class EmulatorManager { '-k', sdkId, '-d', device, ]; - final RunResult runResult = globals.processUtils.runSync(args, + final RunResult runResult = processUtils.runSync(args, environment: androidSdk?.sdkManagerEnv); return CreateEmulatorResult( name, @@ -141,7 +141,7 @@ class EmulatorManager { 'device', '-c', ]; - final RunResult runResult = globals.processUtils.runSync(args, + final RunResult runResult = processUtils.runSync(args, environment: androidSdk?.sdkManagerEnv); if (runResult.exitCode != 0) { return null; @@ -168,7 +168,7 @@ class EmulatorManager { 'avd', '-n', 'temp', ]; - final RunResult runResult = globals.processUtils.runSync(args, + final RunResult runResult = processUtils.runSync(args, environment: androidSdk?.sdkManagerEnv); // Get the list of IDs that match our criteria diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart index 9dfda6fe79..c0e2875b6c 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart @@ -12,6 +12,7 @@ import '../base/common.dart'; import '../base/file_system.dart'; import '../base/io.dart'; import '../base/logger.dart'; +import '../base/process.dart'; import '../base/utils.dart'; import '../build_info.dart'; import '../bundle.dart'; @@ -107,7 +108,7 @@ Future _genSnapshot( timeout: null, ); try { - result = await globals.processUtils.stream(command, trace: true); + result = await processUtils.stream(command, trace: true); } finally { status.cancel(); } diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart index 0609126493..4c3d6ff906 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart @@ -575,7 +575,7 @@ class FuchsiaDevice extends Device { throwToolExit('Cannot interact with device. No ssh config.\n' 'Try setting FUCHSIA_SSH_CONFIG or FUCHSIA_BUILD_DIR.'); } - return await globals.processUtils.run([ + return await processUtils.run([ 'ssh', '-F', globals.fuchsiaArtifacts.sshConfig.absolute.path, @@ -590,7 +590,7 @@ class FuchsiaDevice extends Device { throwToolExit('Cannot interact with device. No ssh config.\n' 'Try setting FUCHSIA_SSH_CONFIG or FUCHSIA_BUILD_DIR.'); } - return await globals.processUtils.run([ + return await processUtils.run([ 'scp', '-F', globals.fuchsiaArtifacts.sshConfig.absolute.path, diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart index 8847a393ed..1d23520006 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart @@ -7,6 +7,7 @@ import 'package:meta/meta.dart'; import '../artifacts.dart'; import '../base/common.dart'; import '../base/logger.dart'; +import '../base/process.dart'; import '../build_info.dart'; import '../globals.dart' as globals; import '../project.dart'; @@ -94,7 +95,7 @@ class FuchsiaKernelCompiler { ); int result; try { - result = await globals.processUtils.stream(command, trace: true); + result = await processUtils.stream(command, trace: true); } finally { status.cancel(); } diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart index 9a4bca0257..53875dd646 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart @@ -121,7 +121,7 @@ class FuchsiaPM { '-l', '$host:$port', ]; - final Process process = await globals.processUtils.start(command); + final Process process = await processUtils.start(command); process.stdout .transform(utf8.decoder) .transform(const LineSplitter()) @@ -155,7 +155,7 @@ class FuchsiaPM { throwToolExit('Fuchsia pm tool not found'); } final List command = [globals.fuchsiaArtifacts.pm.path, ...args]; - final RunResult result = await globals.processUtils.run(command); + final RunResult result = await processUtils.run(command); return result.exitCode == 0; } } diff --git a/packages/flutter_tools/lib/src/globals.dart b/packages/flutter_tools/lib/src/globals.dart index da2245cb5c..2d80c8cd54 100644 --- a/packages/flutter_tools/lib/src/globals.dart +++ b/packages/flutter_tools/lib/src/globals.dart @@ -17,7 +17,6 @@ import 'base/io.dart'; import 'base/logger.dart'; import 'base/net.dart'; import 'base/os.dart'; -import 'base/process.dart'; import 'base/template.dart'; import 'base/terminal.dart'; import 'base/user_messages.dart'; @@ -65,7 +64,6 @@ const ProcessManager _kLocalProcessManager = LocalProcessManager(); /// The active process manager. ProcessManager get processManager => context.get() ?? _kLocalProcessManager; -ProcessUtils get processUtils => context.get(); const Platform _kLocalPlatform = LocalPlatform(); diff --git a/packages/flutter_tools/lib/src/ios/ios_emulators.dart b/packages/flutter_tools/lib/src/ios/ios_emulators.dart index 3e77b498ab..e094266438 100644 --- a/packages/flutter_tools/lib/src/ios/ios_emulators.dart +++ b/packages/flutter_tools/lib/src/ios/ios_emulators.dart @@ -46,7 +46,7 @@ class IOSEmulator extends Emulator { globals.xcode.getSimulatorPath(), ]; - final RunResult launchResult = await globals.processUtils.run(args); + final RunResult launchResult = await processUtils.run(args); if (launchResult.exitCode != 0) { globals.printError('$launchResult'); return false; diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 3cb33276a5..3894bdb6cb 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -329,7 +329,7 @@ Future buildXcodeProject({ const Duration showBuildSettingsTimeout = Duration(minutes: 1); Map buildSettings; try { - final RunResult showBuildSettingsResult = await globals.processUtils.run( + final RunResult showBuildSettingsResult = await processUtils.run( showBuildSettingsCommand, throwOnError: true, workingDirectory: app.project.hostAppRoot.path, @@ -413,7 +413,7 @@ Future _runBuildWithRetries(List buildCommands, BuildableIOSA remainingTries--; buildRetryDelaySeconds *= 2; - buildResult = await globals.processUtils.run( + buildResult = await processUtils.run( buildCommands, workingDirectory: app.project.hostAppRoot.path, allowReentrantFlutter: true, diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index 530000ac61..f6943660e3 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -579,12 +579,12 @@ class IOSSimulator extends Device { Future launchDeviceLogTool(IOSSimulator device) async { // Versions of iOS prior to iOS 11 log to the simulator syslog file. if (await device.sdkMajorVersion < 11) { - return globals.processUtils.start(['tail', '-n', '0', '-F', device.logFilePath]); + return processUtils.start(['tail', '-n', '0', '-F', device.logFilePath]); } // For iOS 11 and above, use /usr/bin/log to tail process logs. // Run in interactive mode (via script), otherwise /usr/bin/log buffers in 4k chunks. (radar: 34420207) - return globals.processUtils.start([ + return processUtils.start([ 'script', '/dev/null', '/usr/bin/log', 'stream', '--style', 'syslog', '--predicate', 'processImagePath CONTAINS "${device.id}"', ]); } @@ -592,7 +592,7 @@ Future launchDeviceLogTool(IOSSimulator device) async { Future launchSystemLogTool(IOSSimulator device) async { // Versions of iOS prior to 11 tail the simulator syslog file. if (await device.sdkMajorVersion < 11) { - return globals.processUtils.start(['tail', '-n', '0', '-F', '/private/var/log/system.log']); + return processUtils.start(['tail', '-n', '0', '-F', '/private/var/log/system.log']); } // For iOS 11 and later, all relevant detail is in the device log. diff --git a/packages/flutter_tools/lib/src/linux/build_linux.dart b/packages/flutter_tools/lib/src/linux/build_linux.dart index 00c9e79a87..3e88654059 100644 --- a/packages/flutter_tools/lib/src/linux/build_linux.dart +++ b/packages/flutter_tools/lib/src/linux/build_linux.dart @@ -6,6 +6,7 @@ import '../artifacts.dart'; import '../base/common.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; +import '../base/process.dart'; import '../build_info.dart'; import '../cache.dart'; import '../globals.dart' as globals; @@ -72,7 +73,7 @@ export PROJECT_DIR=${linuxProject.project.directory.path} ); int result; try { - result = await globals.processUtils.stream([ + result = await processUtils.stream([ 'make', '-C', linuxProject.makeFile.parent.path, diff --git a/packages/flutter_tools/lib/src/macos/build_macos.dart b/packages/flutter_tools/lib/src/macos/build_macos.dart index a54553862c..6f7cb3e566 100644 --- a/packages/flutter_tools/lib/src/macos/build_macos.dart +++ b/packages/flutter_tools/lib/src/macos/build_macos.dart @@ -5,6 +5,7 @@ import '../base/common.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; +import '../base/process.dart'; import '../build_info.dart'; import '../globals.dart' as globals; import '../ios/xcodeproj.dart'; @@ -72,7 +73,7 @@ Future buildMacOS({ ); int result; try { - result = await globals.processUtils.stream([ + result = await processUtils.stream([ '/usr/bin/env', 'xcrun', 'xcodebuild', diff --git a/packages/flutter_tools/lib/src/test/coverage_collector.dart b/packages/flutter_tools/lib/src/test/coverage_collector.dart index 67963c96b8..e1fa2cf15c 100644 --- a/packages/flutter_tools/lib/src/test/coverage_collector.dart +++ b/packages/flutter_tools/lib/src/test/coverage_collector.dart @@ -161,7 +161,7 @@ class CoverageCollector extends TestWatcher { final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_test_coverage.'); try { final File sourceFile = coverageFile.copySync(globals.fs.path.join(tempDir.path, 'lcov.source.info')); - final RunResult result = globals.processUtils.runSync([ + final RunResult result = processUtils.runSync([ 'lcov', '--add-tracefile', baseCoverageData, '--add-tracefile', sourceFile.path, diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index c52be31378..3010942362 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart @@ -53,10 +53,10 @@ class FlutterVersion { FlutterVersion([this._clock = const SystemClock(), this._workingDirectory]) { _frameworkRevision = _runGit( gitLog(['-n', '1', '--pretty=format:%H']).join(' '), - globals.processUtils, + processUtils, _workingDirectory, ); - _gitTagVersion = GitTagVersion.determine(globals.processUtils, workingDirectory: _workingDirectory, fetchTags: false); + _gitTagVersion = GitTagVersion.determine(processUtils, workingDirectory: _workingDirectory, fetchTags: false); _frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision); } @@ -67,7 +67,7 @@ class FlutterVersion { /// user explicitly wants to get the version, e.g. for `flutter --version` or /// `flutter doctor`. void fetchTagsAndUpdate() { - _gitTagVersion = GitTagVersion.determine(globals.processUtils, workingDirectory: _workingDirectory, fetchTags: true); + _gitTagVersion = GitTagVersion.determine(processUtils, workingDirectory: _workingDirectory, fetchTags: true); _frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision); } @@ -112,7 +112,7 @@ class FlutterVersion { if (_channel == null) { final String channel = _runGit( 'git rev-parse --abbrev-ref --symbolic @{u}', - globals.processUtils, + processUtils, _workingDirectory, ); final int slash = channel.indexOf('/'); @@ -120,7 +120,7 @@ class FlutterVersion { final String remote = channel.substring(0, slash); _repositoryUrl = _runGit( 'git ls-remote --get-url $remote', - globals.processUtils, + processUtils, _workingDirectory, ); _channel = channel.substring(slash + 1); @@ -148,7 +148,7 @@ class FlutterVersion { String get frameworkAge { return _frameworkAge ??= _runGit( gitLog(['-n', '1', '--pretty=format:%ar']).join(' '), - globals.processUtils, + processUtils, _workingDirectory, ); } @@ -288,7 +288,7 @@ class FlutterVersion { /// the branch name will be returned as `'[user-branch]'`. String getBranchName({ bool redactUnknownBranches = false }) { _branch ??= () { - final String branch = _runGit('git rev-parse --abbrev-ref HEAD', globals.processUtils); + final String branch = _runGit('git rev-parse --abbrev-ref HEAD', processUtils); return branch == 'HEAD' ? channel : branch; }(); if (redactUnknownBranches || _branch.isEmpty) { diff --git a/packages/flutter_tools/lib/src/windows/build_windows.dart b/packages/flutter_tools/lib/src/windows/build_windows.dart index 8f8de801f5..77b23a30ab 100644 --- a/packages/flutter_tools/lib/src/windows/build_windows.dart +++ b/packages/flutter_tools/lib/src/windows/build_windows.dart @@ -6,6 +6,7 @@ import '../artifacts.dart'; import '../base/common.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; +import '../base/process.dart'; import '../build_info.dart'; import '../cache.dart'; import '../globals.dart' as globals; @@ -85,7 +86,7 @@ Future buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, { // Run the script with a relative path to the project using the enclosing // directory as the workingDirectory, to avoid hitting the limit on command // lengths in batch scripts if the absolute path to the project is long. - result = await globals.processUtils.stream([ + result = await processUtils.stream([ buildScript, vcvarsScript, globals.fs.path.basename(solutionPath), diff --git a/packages/flutter_tools/lib/src/windows/windows_device.dart b/packages/flutter_tools/lib/src/windows/windows_device.dart index 6d6d63f886..5b6ac09b62 100644 --- a/packages/flutter_tools/lib/src/windows/windows_device.dart +++ b/packages/flutter_tools/lib/src/windows/windows_device.dart @@ -87,7 +87,7 @@ final RegExp _whitespace = RegExp(r'\s+'); @visibleForTesting List runningProcess(String processName) { // TODO(jonahwilliams): find a way to do this without powershell. - final RunResult result = globals.processUtils.runSync( + final RunResult result = processUtils.runSync( ['powershell', '-script="Get-CimInstance Win32_Process"'], ); if (result.exitCode != 0) {