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