Unverified Commit 9904a7f4 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Refactor core resident runner logic (#80462)

parent aa9f6a2a
......@@ -41,18 +41,7 @@ class FileSystemUtils {
/// Appends a number to a filename in order to make it unique under a
/// directory.
File getUniqueFile(Directory dir, String baseName, String ext) {
final FileSystem fs = dir.fileSystem;
int i = 1;
while (true) {
final String name = '${baseName}_${i.toString().padLeft(2, '0')}.$ext';
final File file = fs.file(_fileSystem.path.join(dir.path, name));
if (!file.existsSync()) {
file.createSync(recursive: true);
return file;
}
i += 1;
}
return _getUniqueFile(dir, baseName, ext);
}
/// Appends a number to a directory name in order to make it unique under a
......@@ -157,6 +146,27 @@ void copyDirectory(
}
}
File _getUniqueFile(Directory dir, String baseName, String ext) {
final FileSystem fs = dir.fileSystem;
int i = 1;
while (true) {
final String name = '${baseName}_${i.toString().padLeft(2, '0')}.$ext';
final File file = fs.file(dir.fileSystem.path.join(dir.path, name));
if (!file.existsSync()) {
file.createSync(recursive: true);
return file;
}
i += 1;
}
}
/// Appends a number to a filename in order to make it unique under a
/// directory.
File getUniqueFile(Directory dir, String baseName, String ext) {
return _getUniqueFile(dir, baseName, ext);
}
/// This class extends [local_fs.LocalFileSystem] in order to clean up
/// directories and files that the tool creates under the system temporary
/// directory when the tool exits either normally or when killed by a signal.
......
......@@ -29,6 +29,7 @@ import '../resident_runner.dart';
import '../run_cold.dart';
import '../run_hot.dart';
import '../runner/flutter_command.dart';
import '../vmservice.dart';
import '../web/web_runner.dart';
const String protocolVersion = '0.6.0';
......@@ -687,9 +688,16 @@ class AppDomain extends Domain {
if (app == null) {
throw "app '$appId' not found";
}
final Map<String, dynamic> result = await app.runner
.invokeFlutterExtensionRpcRawOnFirstIsolate(methodName, params: params);
final FlutterDevice device = app.runner.flutterDevices.first;
final List<FlutterView> views = await device.vmService.getFlutterViews();
final Map<String, dynamic> result = await device
.vmService
.invokeFlutterExtensionRpcRaw(
methodName,
args: params,
isolateId: views
.first.uiIsolate.id
);
if (result == null) {
throw 'method not available: $methodName';
}
......
......@@ -76,7 +76,6 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
systemClock: systemClock,
fileSystem: fileSystem,
logger: logger,
featureFlags: featureFlags,
);
}
}
......@@ -99,14 +98,12 @@ class ResidentWebRunner extends ResidentRunner {
@required SystemClock systemClock,
@required Usage usage,
@required UrlTunneller urlTunneller,
@required FeatureFlags featureFlags,
ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler,
}) : _fileSystem = fileSystem,
_logger = logger,
_systemClock = systemClock,
_usage = usage,
_urlTunneller = urlTunneller,
_featureFlags = featureFlags,
super(
<FlutterDevice>[device],
target: target ?? fileSystem.path.join('lib', 'main.dart'),
......@@ -122,7 +119,6 @@ class ResidentWebRunner extends ResidentRunner {
final SystemClock _systemClock;
final Usage _usage;
final UrlTunneller _urlTunneller;
final FeatureFlags _featureFlags;
FlutterDevice get device => flutterDevices.first;
final FlutterProject flutterProject;
......@@ -167,20 +163,7 @@ class ResidentWebRunner extends ResidentRunner {
FlutterVmService _instance;
@override
bool get canHotRestart {
return true;
}
@override
Future<Map<String, dynamic>> invokeFlutterExtensionRpcRawOnFirstIsolate(
String method, {
FlutterDevice device,
Map<String, dynamic> params,
}) async {
final vmservice.Response response =
await _vmService.service.callServiceExtension(method, args: params);
return response.toJson();
}
bool get supportsRestart => true;
@override
Future<void> cleanupAfterSignal() async {
......@@ -313,7 +296,7 @@ class ResidentWebRunner extends ResidentRunner {
?.flutterPlatformOverride(
isolateId: null,
);
final String platform = nextPlatform(currentPlatform, _featureFlags);
final String platform = nextPlatform(currentPlatform);
await _vmService
?.flutterPlatformOverride(
platform: platform,
......
......@@ -10,6 +10,7 @@ import 'package:meta/meta.dart';
import 'base/common.dart';
import 'base/file_system.dart';
import 'base/logger.dart';
import 'build_info.dart';
import 'device.dart';
import 'globals_null_migrated.dart' as globals;
......@@ -51,7 +52,10 @@ class ColdRunner extends ResidentRunner {
bool get canHotReload => false;
@override
bool get canHotRestart => false;
Logger get logger => globals.logger;
@override
FileSystem get fileSystem => globals.fs;
@override
Future<int> run({
......
......@@ -598,9 +598,6 @@ class HotRunner extends ResidentRunner {
return true;
}
@override
bool get supportsRestart => true;
@override
Future<OperationResult> restart({
bool fullRestart = false,
......@@ -670,7 +667,7 @@ class HotRunner extends ResidentRunner {
String reason,
bool silent,
}) async {
if (!canHotRestart) {
if (!supportsRestart) {
return OperationResult(1, 'hotRestart not supported');
}
Status status;
......@@ -1089,7 +1086,7 @@ class HotRunner extends ResidentRunner {
void printHelp({ @required bool details }) {
globals.printStatus('Flutter run key commands.');
commandHelp.r.print();
if (canHotRestart) {
if (supportsRestart) {
commandHelp.R.print();
}
commandHelp.h.print(); // TODO(ianh): print different message if "details" is false
......
......@@ -55,7 +55,6 @@ void main() {
ipv6: true,
stayResident: true,
urlTunneller: null,
featureFlags: TestFeatureFlags(),
fileSystem: globals.fs,
logger: globals.logger,
systemClock: globals.systemClock,
......
......@@ -195,7 +195,6 @@ void main() {
fileSystem: fileSystem,
logger: BufferLogger.test(),
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
......@@ -229,7 +228,7 @@ void main() {
fileSystem: fileSystem,
logger: BufferLogger.test(),
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
......@@ -253,7 +252,6 @@ void main() {
fileSystem: fileSystem,
logger: BufferLogger.test(),
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
......@@ -268,7 +266,6 @@ void main() {
fileSystem: fileSystem,
logger: BufferLogger.test(),
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
......@@ -373,7 +370,6 @@ void main() {
fileSystem: fileSystem,
logger: logger,
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
......@@ -398,7 +394,6 @@ void main() {
fileSystem: fileSystem,
logger: BufferLogger.test(),
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
......@@ -517,7 +512,6 @@ void main() {
fileSystem: fileSystem,
logger: BufferLogger.test(),
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
......@@ -1439,7 +1433,6 @@ void main() {
fileSystem: fileSystem,
logger: logger,
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
......@@ -1487,7 +1480,6 @@ void main() {
fileSystem: fileSystem,
logger: logger,
usage: globals.flutterUsage,
featureFlags: TestFeatureFlags(),
systemClock: globals.systemClock,
);
......@@ -1606,7 +1598,6 @@ ResidentRunner setUpResidentRunner(FlutterDevice flutterDevice, {
systemClock: systemClock ?? SystemClock.fixed(DateTime.now()),
fileSystem: globals.fs,
logger: logger ?? BufferLogger.test(),
featureFlags: TestFeatureFlags(),
);
}
......
......@@ -240,7 +240,7 @@ void main() {
});
testWithoutContext('R - hotRestart supported and succeeds', () async {
when(mockResidentRunner.canHotRestart).thenReturn(true);
when(mockResidentRunner.supportsRestart).thenReturn(true);
when(mockResidentRunner.hotMode).thenReturn(true);
when(mockResidentRunner.restart(fullRestart: true))
.thenAnswer((Invocation invocation) async {
......@@ -252,7 +252,7 @@ void main() {
});
testWithoutContext('R - hotRestart supported and fails', () async {
when(mockResidentRunner.canHotRestart).thenReturn(true);
when(mockResidentRunner.supportsRestart).thenReturn(true);
when(mockResidentRunner.hotMode).thenReturn(true);
when(mockResidentRunner.restart(fullRestart: true))
.thenAnswer((Invocation invocation) async {
......@@ -266,7 +266,7 @@ void main() {
});
testWithoutContext('R - hotRestart supported and fails fatally', () async {
when(mockResidentRunner.canHotRestart).thenReturn(true);
when(mockResidentRunner.supportsRestart).thenReturn(true);
when(mockResidentRunner.hotMode).thenReturn(true);
when(mockResidentRunner.restart(fullRestart: true))
.thenAnswer((Invocation invocation) async {
......@@ -276,12 +276,23 @@ void main() {
});
testWithoutContext('R - hot restart unsupported', () async {
when(mockResidentRunner.canHotRestart).thenReturn(false);
when(mockResidentRunner.supportsRestart).thenReturn(false);
await terminalHandler.processTerminalInput('R');
verifyNever(mockResidentRunner.restart(fullRestart: true));
});
testWithoutContext('ResidentRunner clears the screen when it should', () async {
const String message = 'This should be cleared';
expect(testLogger.statusText, equals(''));
testLogger.printStatus(message);
expect(testLogger.statusText, equals(message + '\n')); // printStatus makes a newline
await terminalHandler.processTerminalInput('c');
expect(testLogger.statusText, equals(''));
});
testWithoutContext('S - debugDumpSemanticsTreeInTraversalOrder with service protocol', () async {
await terminalHandler.processTerminalInput('S');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment