Unverified Commit 0afddf35 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] use fixed entry for dill uploads (#67837)

For historical reasons, the flutter tool uploads dill files to paths based on the entrypoint URI. This isn't actually necessary, and the tool can use specific files : main.dart.incremental.dill for incremental dills, and main.dart.dill/main.dart.swap.dill for full dills. This allows hot restarting applications with an entrypoint outside of lib/ and simplifies the devFS code.

Fixes #63243
parent 8538b4f5
......@@ -548,16 +548,13 @@ class DevFS {
if (!bundleFirstUpload) {
final String compiledBinary = compilerOutput?.outputFilename;
if (compiledBinary != null && compiledBinary.isNotEmpty) {
final Uri entryUri = _fileSystem.path.toUri(projectRootPath != null
? _fileSystem.path.relative(pathToReload, from: projectRootPath)
: pathToReload,
);
final Uri entryUri = _fileSystem.path.toUri(pathToReload);
final DevFSFileContent content = DevFSFileContent(_fileSystem.file(compiledBinary));
syncedBytes += content.size;
dirtyEntries[entryUri] = content;
}
}
_logger.printTrace('Updating files');
_logger.printTrace('Updating files.');
if (dirtyEntries.isNotEmpty) {
await (devFSWriter ?? _httpWriter).write(dirtyEntries, _baseUri, _httpWriter);
}
......
......@@ -782,9 +782,9 @@ abstract class ResidentRunner {
@required bool swap,
}) {
if (!fullRestart) {
return '$mainPath.incremental.dill';
return 'main.dart.incremental.dill';
}
return '$mainPath${swap ? '.swap' : ''}.dill';
return 'main.dart${swap ? '.swap' : ''}.dill';
}
bool get debuggingEnabled => debuggingOptions.debuggingEnabled;
......
......@@ -451,12 +451,10 @@ class HotRunner extends ResidentRunner {
]);
}
Future<void> _launchFromDevFS(String mainScript) async {
final String entryUri = globals.fs.path.relative(mainScript, from: projectRootPath);
Future<void> _launchFromDevFS() async {
final List<Future<void>> futures = <Future<void>>[];
for (final FlutterDevice device in flutterDevices) {
final Uri deviceEntryUri = device.devFS.baseUri.resolveUri(
globals.fs.path.toUri(entryUri));
final Uri deviceEntryUri = device.devFS.baseUri.resolve(_swap ? 'main.dart.swap.dill' : 'main.dart.dill');
final Uri deviceAssetsDirectoryUri = device.devFS.baseUri.resolveUri(
globals.fs.path.toUri(getAssetBuildDirectory()));
futures.add(_launchInView(device,
......@@ -555,7 +553,7 @@ class HotRunner extends ResidentRunner {
}
await Future.wait(operations);
await _launchFromDevFS('$mainPath${_swap ? '.swap' : ''}.dill');
await _launchFromDevFS();
restartTimer.stop();
globals.printTrace('Hot restart performed in ${getElapsedAsMilliseconds(restartTimer.elapsed)}.');
_addBenchmarkData('hotRestartMillisecondsToFrame',
......@@ -793,7 +791,7 @@ class HotRunner extends ResidentRunner {
bool pause = false,
}) async {
final String deviceEntryUri = device.devFS.baseUri
.resolveUri(globals.fs.path.toUri(entryPath)).toString();
.resolve(entryPath).toString();
final vm_service.VM vm = await device.vmService.getVM();
return <Future<vm_service.ReloadReport>>[
for (final vm_service.IsolateRef isolateRef in vm.isolates)
......@@ -849,10 +847,7 @@ class HotRunner extends ResidentRunner {
final Stopwatch vmReloadTimer = Stopwatch()..start();
Map<String, dynamic> firstReloadDetails;
try {
final String entryPath = globals.fs.path.relative(
getReloadPath(fullRestart: false, swap: _swap),
from: projectRootPath,
);
const String entryPath = 'main.dart.incremental.dill';
final List<Future<DeviceReloadReport>> allReportsFutures = <Future<DeviceReloadReport>>[];
for (final FlutterDevice device in flutterDevices) {
if (_shouldResetAssetDirectory) {
......
......@@ -16,6 +16,7 @@ import '../base/logger.dart';
import '../build_info.dart';
import '../bundle.dart';
import '../convert.dart';
import '../devfs.dart';
import '../device.dart';
import '../project.dart';
import '../protocol_discovery.dart';
......@@ -44,7 +45,6 @@ class FlutterTesterApp extends ApplicationPackage {
/// Normally this is only used as the runner for `flutter test`, but it can
/// also be used as a regular device when `--show-test-device` is provided
/// to the flutter command.
// TODO(scheglov): This device does not currently work with full restarts.
class FlutterTesterDevice extends Device {
FlutterTesterDevice(String deviceId, {
@required ProcessManager processManager,
......@@ -245,6 +245,16 @@ class FlutterTesterDevice extends Device {
@override
bool isSupportedForProject(FlutterProject flutterProject) => true;
@override
DevFSWriter createDevFSWriter(
covariant ApplicationPackage app,
String userIdentifier,
) {
return LocalDevFSWriter(
fileSystem: _fileSystem,
);
}
@override
Future<void> dispose() async {
_logReader?.dispose();
......
......@@ -283,7 +283,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.dill',
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
}
),
......@@ -291,7 +291,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.dill',
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
}
),
......@@ -383,7 +383,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.dill',
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
}
),
......
......@@ -71,7 +71,7 @@ final vm_service.Isolate fakePausedIsolate = vm_service.Isolate(
id: 'test-breakpoint',
location: vm_service.SourceLocation(
tokenPos: 0,
script: vm_service.ScriptRef(id: 'test-script', uri: 'lib/foo.dart'),
script: vm_service.ScriptRef(id: 'test-script', uri: 'foo.dart'),
),
resolved: true,
),
......@@ -411,7 +411,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.dill',
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
}
),
......@@ -606,7 +606,7 @@ void main() {
args: <String, Object>{
'isolateId': '1',
'pause': false,
'rootLibUri': 'lib/main.dart.incremental.dill'
'rootLibUri': 'main.dart.incremental.dill'
},
jsonResponse: <String, Object>{
'type': 'ReloadReport',
......@@ -699,7 +699,7 @@ void main() {
args: <String, Object>{
'isolateId': '1',
'pause': false,
'rootLibUri': 'lib/main.dart.incremental.dill'
'rootLibUri': 'main.dart.incremental.dill'
},
jsonResponse: <String, Object>{
'type': 'ReloadReport',
......@@ -795,7 +795,7 @@ void main() {
args: <String, Object>{
'isolateId': '1',
'pause': false,
'rootLibUri': 'lib/main.dart.incremental.dill'
'rootLibUri': 'main.dart.incremental.dill'
},
jsonResponse: <String, Object>{
'type': 'ReloadReport',
......@@ -875,7 +875,7 @@ void main() {
args: <String, Object>{
'isolateId': '1',
'pause': false,
'rootLibUri': 'lib/main.dart.incremental.dill',
'rootLibUri': 'main.dart.incremental.dill',
},
jsonResponse: <String, Object>{
'type': 'ReloadReport',
......@@ -992,7 +992,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.dill',
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
},
),
......@@ -1074,7 +1074,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.dill',
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
},
),
......@@ -1136,7 +1136,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.dill',
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
},
),
......@@ -1170,7 +1170,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.swap.dill',
'mainScript': 'main.dart.swap.dill',
'assetDirectory': 'build/flutter_assets',
},
),
......@@ -1204,7 +1204,7 @@ void main() {
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'lib/main.dart.dill',
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
},
),
......
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