From 515027a91c244f2fce47aa446939756445b8de27 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 28 Feb 2020 11:26:02 -0800 Subject: [PATCH] [flutter_tools] allow configuring libraries spec path for the web compilation (#51590) --- packages/flutter_tools/lib/src/artifacts.dart | 7 +++++++ packages/flutter_tools/lib/src/compile.dart | 7 +++++++ packages/flutter_tools/lib/src/resident_runner.dart | 2 ++ .../test/general.shard/resident_runner_test.dart | 3 +++ 4 files changed, 19 insertions(+) diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart index ebf6fcf2b3..e26ecdebb6 100644 --- a/packages/flutter_tools/lib/src/artifacts.dart +++ b/packages/flutter_tools/lib/src/artifacts.dart @@ -40,6 +40,7 @@ enum Artifact { kernelWorkerSnapshot, /// The root of the web implementation of the dart SDK. flutterWebSdk, + flutterWebLibrariesJson, /// The summary dill for the dartdevc target. webPlatformKernelDill, iosDeploy, @@ -134,6 +135,8 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo return 'font-subset$exe'; case Artifact.constFinder: return 'const_finder.dart.snapshot'; + case Artifact.flutterWebLibrariesJson: + return 'libraries.json'; } assert(false, 'Invalid artifact $artifact.'); return null; @@ -333,6 +336,8 @@ class CachedArtifacts extends Artifacts { return _getFlutterPatchedSdkPath(mode); case Artifact.flutterWebSdk: return _getFlutterWebSdkPath(); + case Artifact.flutterWebLibrariesJson: + return _fileSystem.path.join(_getFlutterWebSdkPath(), _artifactToFileName(artifact)); case Artifact.webPlatformKernelDill: return _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact)); case Artifact.dart2jsSnapshot: @@ -536,6 +541,8 @@ class LocalEngineArtifacts extends Artifacts { return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); case Artifact.constFinder: return _fileSystem.path.join(_hostEngineOutPath, 'gen', artifactFileName); + case Artifact.flutterWebLibrariesJson: + return _fileSystem.path.join(_getFlutterWebSdkPath(), artifactFileName); } assert(false, 'Invalid artifact $artifact.'); return null; diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 469f73ef29..e89baa5836 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -462,6 +462,7 @@ abstract class ResidentCompiler { List experimentalFlags, String platformDill, List dartDefines, + String librariesSpec, }) = DefaultResidentCompiler; // TODO(jonahwilliams): find a better way to configure additional file system @@ -526,6 +527,7 @@ class DefaultResidentCompiler implements ResidentCompiler { this.experimentalFlags, this.platformDill, List dartDefines, + this.librariesSpec, }) : assert(sdkRoot != null), _stdoutHandler = StdoutHandler(consumer: compilerMessageConsumer), dartDefines = dartDefines ?? const [], @@ -542,6 +544,7 @@ class DefaultResidentCompiler implements ResidentCompiler { final bool unsafePackageSerialization; final List experimentalFlags; final List dartDefines; + final String librariesSpec; @override void addFileSystemRoot(String root) { @@ -664,6 +667,10 @@ class DefaultResidentCompiler implements ResidentCompiler { '--output-dill', outputPath, ], + if (librariesSpec != null) ...[ + '--libraries-spec', + librariesSpec, + ], if (packagesFilePath != null) ...[ '--packages', packagesFilePath, diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index d24e3c7e6e..ab04d8245f 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -94,6 +94,8 @@ class FlutterDevice { .getArtifactPath(Artifact.webPlatformKernelDill, mode: buildMode)) .absolute.uri.toString(), dartDefines: dartDefines, + librariesSpec: globals.fs.file(globals.artifacts + .getArtifactPath(Artifact.flutterWebLibrariesJson)).uri.toString() ); } else { generator = ResidentCompiler( diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index d570b08c99..a9993ce46c 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -688,6 +688,9 @@ void main() { trackWidgetCreation: true, )).generator as DefaultResidentCompiler; + expect(residentCompiler.librariesSpec, + globals.fs.file(globals.artifacts.getArtifactPath(Artifact.flutterWebLibrariesJson)) + .uri.toString()); expect(residentCompiler.targetModel, TargetModel.dartdevc); expect(residentCompiler.sdkRoot, globals.artifacts.getArtifactPath(Artifact.flutterWebSdk, mode: BuildMode.debug) + '/');