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

[flutter_tools] ensure all source maps load correctly for release and profile (#50702)

parent a833effb
...@@ -400,6 +400,7 @@ class _ResidentWebRunner extends ResidentWebRunner { ...@@ -400,6 +400,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
urlTunneller: urlTunneller, urlTunneller: urlTunneller,
buildMode: debuggingOptions.buildInfo.mode, buildMode: debuggingOptions.buildInfo.mode,
enableDwds: _enableDwds, enableDwds: _enableDwds,
entrypoint: globals.fs.file(target).uri,
); );
final Uri url = await device.devFS.create(); final Uri url = await device.devFS.create();
if (debuggingOptions.buildInfo.isDebug) { if (debuggingOptions.buildInfo.isDebug) {
......
...@@ -53,6 +53,7 @@ class WebAssetServer implements AssetReader { ...@@ -53,6 +53,7 @@ class WebAssetServer implements AssetReader {
UrlTunneller urlTunneller, UrlTunneller urlTunneller,
BuildMode buildMode, BuildMode buildMode,
bool enableDwds, bool enableDwds,
Uri entrypoint,
) async { ) async {
try { try {
final InternetAddress address = (await InternetAddress.lookup(hostname)).first; final InternetAddress address = (await InternetAddress.lookup(hostname)).first;
...@@ -63,7 +64,7 @@ class WebAssetServer implements AssetReader { ...@@ -63,7 +64,7 @@ class WebAssetServer implements AssetReader {
// In release builds deploy a simpler proxy server. // In release builds deploy a simpler proxy server.
if (buildMode != BuildMode.debug) { if (buildMode != BuildMode.debug) {
final ReleaseAssetServer releaseAssetServer = ReleaseAssetServer(); final ReleaseAssetServer releaseAssetServer = ReleaseAssetServer(entrypoint);
shelf.serveRequests(httpServer, releaseAssetServer.handle); shelf.serveRequests(httpServer, releaseAssetServer.handle);
return server; return server;
} }
...@@ -318,8 +319,10 @@ class WebDevFS implements DevFS { ...@@ -318,8 +319,10 @@ class WebDevFS implements DevFS {
@required this.urlTunneller, @required this.urlTunneller,
@required this.buildMode, @required this.buildMode,
@required this.enableDwds, @required this.enableDwds,
@required this.entrypoint,
}); });
final Uri entrypoint;
final String hostname; final String hostname;
final int port; final int port;
final String packagesFilePath; final String packagesFilePath;
...@@ -385,6 +388,7 @@ class WebDevFS implements DevFS { ...@@ -385,6 +388,7 @@ class WebDevFS implements DevFS {
urlTunneller, urlTunneller,
buildMode, buildMode,
enableDwds, enableDwds,
entrypoint,
); );
return Uri.parse('http://$hostname:$port'); return Uri.parse('http://$hostname:$port');
} }
...@@ -552,15 +556,22 @@ String _filePathToUriFragment(String path) { ...@@ -552,15 +556,22 @@ String _filePathToUriFragment(String path) {
} }
class ReleaseAssetServer { class ReleaseAssetServer {
ReleaseAssetServer(this.entrypoint);
final Uri entrypoint;
// Locations where source files, assets, or source maps may be located. // Locations where source files, assets, or source maps may be located.
final List<Uri> _searchPaths = <Uri>[ final List<Uri> _searchPaths = <Uri>[
globals.fs.directory(getWebBuildDirectory()).uri, globals.fs.directory(getWebBuildDirectory()).uri,
globals.fs.directory(Cache.flutterRoot).parent.uri, globals.fs.directory(Cache.flutterRoot).uri,
globals.fs.currentDirectory.childDirectory('lib').uri, globals.fs.currentDirectory.uri,
]; ];
Future<shelf.Response> handle(shelf.Request request) async { Future<shelf.Response> handle(shelf.Request request) async {
Uri fileUri; Uri fileUri;
if (request.url.toString() == 'main.dart') {
fileUri = entrypoint;
} else {
for (final Uri uri in _searchPaths) { for (final Uri uri in _searchPaths) {
final Uri potential = uri.resolve(request.url.path); final Uri potential = uri.resolve(request.url.path);
if (potential == null || !globals.fs.isFileSync(potential.toFilePath())) { if (potential == null || !globals.fs.isFileSync(potential.toFilePath())) {
...@@ -569,7 +580,7 @@ class ReleaseAssetServer { ...@@ -569,7 +580,7 @@ class ReleaseAssetServer {
fileUri = potential; fileUri = potential;
break; break;
} }
}
if (fileUri != null) { if (fileUri != null) {
final File file = globals.fs.file(fileUri); final File file = globals.fs.file(fileUri);
final Uint8List bytes = file.readAsBytesSync(); final Uint8List bytes = file.readAsBytesSync();
......
...@@ -289,6 +289,7 @@ void main() { ...@@ -289,6 +289,7 @@ void main() {
urlTunneller: null, urlTunneller: null,
buildMode: BuildMode.debug, buildMode: BuildMode.debug,
enableDwds: false, enableDwds: false,
entrypoint: Uri.base,
); );
webDevFS.requireJS.createSync(recursive: true); webDevFS.requireJS.createSync(recursive: true);
webDevFS.dartSdk.createSync(recursive: true); webDevFS.dartSdk.createSync(recursive: true);
......
...@@ -40,7 +40,7 @@ void main() { ...@@ -40,7 +40,7 @@ void main() {
}); });
test('release asset server serves correct mime type and content length for png', () => testbed.run(() async { test('release asset server serves correct mime type and content length for png', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer(); final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.png')) globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.png'))
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsBytesSync(kTransparentImage); ..writeAsBytesSync(kTransparentImage);
...@@ -54,7 +54,7 @@ void main() { ...@@ -54,7 +54,7 @@ void main() {
})); }));
test('release asset server serves correct mime type and content length for JavaScript', () => testbed.run(() async { test('release asset server serves correct mime type and content length for JavaScript', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer(); final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.js')) globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.js'))
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('function main() {}'); ..writeAsStringSync('function main() {}');
...@@ -68,7 +68,7 @@ void main() { ...@@ -68,7 +68,7 @@ void main() {
})); }));
test('release asset server serves correct mime type and content length for html', () => testbed.run(() async { test('release asset server serves correct mime type and content length for html', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer(); final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.html')) globals.fs.file(globals.fs.path.join('build', 'web', 'assets', 'foo.html'))
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('<!doctype html><html></html>'); ..writeAsStringSync('<!doctype html><html></html>');
...@@ -82,7 +82,7 @@ void main() { ...@@ -82,7 +82,7 @@ void main() {
})); }));
test('release asset server serves content from flutter root', () => testbed.run(() async { test('release asset server serves content from flutter root', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer(); final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('flutter', 'bar.dart')) globals.fs.file(globals.fs.path.join('flutter', 'bar.dart'))
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('void main() { }'); ..writeAsStringSync('void main() { }');
...@@ -93,8 +93,8 @@ void main() { ...@@ -93,8 +93,8 @@ void main() {
})); }));
test('release asset server serves content from project directory', () => testbed.run(() async { test('release asset server serves content from project directory', () => testbed.run(() async {
final ReleaseAssetServer assetServer = ReleaseAssetServer(); final ReleaseAssetServer assetServer = ReleaseAssetServer(Uri.base);
globals.fs.file(globals.fs.path.join('lib', 'bar.dart')) globals.fs.file(globals.fs.path.join('bar.dart'))
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('void main() { }'); ..writeAsStringSync('void main() { }');
final Response response = await assetServer final Response response = await assetServer
......
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