From 540c7476566a8c5bf8445dd197a025e23be5b879 Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Tue, 16 Jul 2019 12:34:49 -0700 Subject: [PATCH] Revert "Keep LLDB connection to iOS device alive while running from CLI. (#36194)" (#36293) This reverts commit 5501a1c1e7d74a088f3fd11d84b5391a02c23918. --- .../flutter_tools/lib/src/base/process.dart | 47 +++++-------------- .../flutter_tools/lib/src/ios/devices.dart | 5 +- .../test/general.shard/base/process_test.dart | 42 +---------------- .../test/general.shard/dart/pub_get_test.dart | 3 -- 4 files changed, 13 insertions(+), 84 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index ed7084fda6..1dd5765821 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -129,11 +129,6 @@ Future runCommand( /// If [filter] is non-null, all lines that do not match it are removed. If /// [mapFunction] is present, all lines that match [filter] are also forwarded /// to [mapFunction] for further processing. -/// -/// If [detachFilter] is non-null, the returned future will complete with exit code `0` -/// when the process outputs something matching [detachFilter] to stderr. The process will -/// continue in the background, and the final exit code will not be reported. [filter] is -/// not considered on lines matching [detachFilter]. Future runCommandAndStreamOutput( List cmd, { String workingDirectory, @@ -143,9 +138,7 @@ Future runCommandAndStreamOutput( RegExp filter, StringConverter mapFunction, Map environment, - RegExp detachFilter, }) async { - final Completer result = Completer(); final Process process = await runCommand( cmd, workingDirectory: workingDirectory, @@ -155,15 +148,6 @@ Future runCommandAndStreamOutput( final StreamSubscription stdoutSubscription = process.stdout .transform(utf8.decoder) .transform(const LineSplitter()) - .map((String line) { - if (detachFilter != null && detachFilter.hasMatch(line) && !result.isCompleted) { - // Detach from the process, assuming it will eventually complete successfully. - // Output printed after detaching (incl. stdout and stderr) will still be - // processed by [filter] and [mapFunction]. - result.complete(0); - } - return line; - }) .where((String line) => filter == null || filter.hasMatch(line)) .listen((String line) { if (mapFunction != null) @@ -187,28 +171,19 @@ Future runCommandAndStreamOutput( printError('$prefix$line', wrap: false); }); - // Wait for stdout to be fully processed before completing with the exit code (non-detached case), - // because process.exitCode may complete first causing flaky tests. If the process detached, - // we at least have a predictable output for stdout, although (unavoidably) not for stderr. - Future readOutput() async { - await waitGroup(>[ - stdoutSubscription.asFuture(), - stderrSubscription.asFuture(), - ]); + // Wait for stdout to be fully processed + // because process.exitCode may complete first causing flaky tests. + await waitGroup(>[ + stdoutSubscription.asFuture(), + stderrSubscription.asFuture(), + ]); - await waitGroup(>[ - stdoutSubscription.cancel(), - stderrSubscription.cancel(), - ]); + await waitGroup(>[ + stdoutSubscription.cancel(), + stderrSubscription.cancel(), + ]); - // Complete the future if the we did not detach the process yet. - if (!result.isCompleted) { - result.complete(process.exitCode); - } - } - - unawaited(readOutput()); - return result.future; + return await process.exitCode; } /// Runs the [command] interactively, connecting the stdin/stdout/stderr diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index b38e2d63a4..33e520decf 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -48,7 +48,7 @@ class IOSDeploy { '--bundle', bundlePath, '--no-wifi', - '--noninteractive', + '--justlaunch', ]; if (launchArguments.isNotEmpty) { launchCommand.add('--args'); @@ -66,14 +66,11 @@ class IOSDeploy { iosDeployEnv['PATH'] = '/usr/bin:${iosDeployEnv['PATH']}'; iosDeployEnv.addEntries(>[cache.dyLdLibEntry]); - // Detach from the ios-deploy process once it' outputs 'autoexit', signaling that the - // App has been started and LLDB is in "autopilot" mode. return await runCommandAndStreamOutput( launchCommand, mapFunction: _monitorInstallationFailure, trace: true, environment: iosDeployEnv, - detachFilter: RegExp('.*autoexit.*') ); } diff --git a/packages/flutter_tools/test/general.shard/base/process_test.dart b/packages/flutter_tools/test/general.shard/base/process_test.dart index 14f7d383b7..8ffca5e785 100644 --- a/packages/flutter_tools/test/general.shard/base/process_test.dart +++ b/packages/flutter_tools/test/general.shard/base/process_test.dart @@ -2,20 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; - import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/process.dart'; import 'package:flutter_tools/src/base/terminal.dart'; -import 'package:flutter_tools/src/convert.dart'; import 'package:mockito/mockito.dart'; import 'package:process/process.dart'; import '../../src/common.dart'; import '../../src/context.dart'; -import '../../src/mocks.dart' show FakeProcess, MockProcess, MockProcessManager; +import '../../src/mocks.dart' show MockProcess, MockProcessManager; void main() { group('process exceptions', () { @@ -93,43 +90,6 @@ void main() { Platform: () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false, }); }); - - group('runCommandAndStreamOutput', () { - ProcessManager mockProcessManager; - const Utf8Encoder utf8 = Utf8Encoder(); - - setUp(() { - mockProcessManager = PlainMockProcessManager(); - }); - - testUsingContext('detach after detachFilter matches', () async { - // Create a fake process which outputs three lines ("foo", "bar" and "baz") - // to stdout, nothing to stderr, and doesn't exit. - final Process fake = FakeProcess( - exitCode: Completer().future, - stdout: Stream>.fromIterable( - ['foo\n', 'bar\n', 'baz\n'].map(utf8.convert)), - stderr: const Stream>.empty()); - - when(mockProcessManager.start(['test1'])).thenAnswer((_) => Future.value(fake)); - - // Detach when we see "bar", and check that: - // - mapFunction still gets run on "baz", - // - we don't wait for the process to terminate (it never will), and - // - we get an exit-code of 0 back. - bool seenBaz = false; - String mapFunction(String line) { - seenBaz = seenBaz || line == 'baz'; - return line; - } - - final int exitCode = await runCommandAndStreamOutput( - ['test1'], mapFunction: mapFunction, detachFilter: RegExp('.*baz.*')); - - expect(exitCode, 0); - expect(seenBaz, true); - }, overrides: {ProcessManager: () => mockProcessManager}); - }); } class PlainMockProcessManager extends Mock implements ProcessManager {} diff --git a/packages/flutter_tools/test/general.shard/dart/pub_get_test.dart b/packages/flutter_tools/test/general.shard/dart/pub_get_test.dart index 6e918c9176..48093cafd8 100644 --- a/packages/flutter_tools/test/general.shard/dart/pub_get_test.dart +++ b/packages/flutter_tools/test/general.shard/dart/pub_get_test.dart @@ -199,9 +199,6 @@ class MockStream implements Stream { @override Stream where(bool test(T event)) => MockStream(); - @override - Stream map(S Function(T) _) => MockStream(); - @override StreamSubscription listen(void onData(T event), { Function onError, void onDone(), bool cancelOnError }) { return MockStreamSubscription();