Unverified Commit a13c9cfc authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] fix toFilePath called on null (#52931)

In certain circumstances, the .packages file or dart cache could be missing - since the tool runs from a snapshot this is otherwise fine. 
parent 763729f7
......@@ -20,8 +20,10 @@ import '../base/net.dart';
import '../base/terminal.dart';
import '../base/utils.dart';
import '../build_info.dart';
import '../cache.dart';
import '../compile.dart';
import '../convert.dart';
import '../dart/pub.dart';
import '../devfs.dart';
import '../device.dart';
import '../features.dart';
......@@ -403,6 +405,14 @@ class _ResidentWebRunner extends ResidentWebRunner {
try {
return await asyncGuard(() async {
// Ensure dwds resources are cached. If the .packages file is missing then
// the client.js script cannot be located by the injected handler in dwds.
// This will result in a NoSuchMethodError thrown by injected_handler.darts
await pub.get(
context: PubContext.pubGet,
directory: globals.fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools')
);
device.devFS = WebDevFS(
hostname: effectiveHostname,
port: hostPort,
......
......@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
......@@ -54,7 +55,9 @@ void main() {
stayResident: true,
urlTunneller: null,
) as ResidentWebRunner;
},
}, overrides: <Type, Generator>{
Pub: () => MockPub(),
}
);
});
......@@ -166,3 +169,4 @@ class MockChromeConnection extends Mock implements ChromeConnection {}
class MockChromeTab extends Mock implements ChromeTab {}
class MockWipConnection extends Mock implements WipConnection {}
class MockBuildSystem extends Mock implements BuildSystem {}
class MockPub extends Mock implements Pub {}
......@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_runner/resident_web_runner.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
......@@ -82,6 +83,9 @@ void main() {
globals.fs.currentDirectory.childFile('.packages')
.writeAsStringSync('\n');
},
overrides: <Type, Generator>{
Pub: () => MockPub(),
}
);
});
......@@ -214,6 +218,10 @@ void main() {
verify(mockAppConnection.runMain()).called(1);
verify(mockVmService.registerService('reloadSources', 'FlutterTools')).called(1);
verify(status.stop()).called(1);
verify(pub.get(
context: PubContext.pubGet,
directory: globals.fs.path.join('packages', 'flutter_tools')
)).called(1);
expect(bufferLogger.statusText, contains('Debug service listening on ws://127.0.0.1/abcd/'));
expect(debugConnectionInfo.wsUri.toString(), 'ws://127.0.0.1/abcd/');
......@@ -978,3 +986,4 @@ class MockWipConnection extends Mock implements WipConnection {}
class MockWipDebugger extends Mock implements WipDebugger {}
class MockWebServerDevice extends Mock implements WebServerDevice {}
class MockDevice extends Mock implements Device {}
class MockPub extends Mock implements Pub {}
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