[flutter_tools] allow configuring libraries spec path for the web compilation (#51590)
diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart
index ebf6fcf..e26ecde 100644
--- a/packages/flutter_tools/lib/src/artifacts.dart
+++ b/packages/flutter_tools/lib/src/artifacts.dart
@@ -40,6 +40,7 @@
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 @@
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 @@
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 @@
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 469f73e..e89baa5 100644
--- a/packages/flutter_tools/lib/src/compile.dart
+++ b/packages/flutter_tools/lib/src/compile.dart
@@ -462,6 +462,7 @@
List<String> experimentalFlags,
String platformDill,
List<String> dartDefines,
+ String librariesSpec,
}) = DefaultResidentCompiler;
// TODO(jonahwilliams): find a better way to configure additional file system
@@ -526,6 +527,7 @@
this.experimentalFlags,
this.platformDill,
List<String> dartDefines,
+ this.librariesSpec,
}) : assert(sdkRoot != null),
_stdoutHandler = StdoutHandler(consumer: compilerMessageConsumer),
dartDefines = dartDefines ?? const <String>[],
@@ -542,6 +544,7 @@
final bool unsafePackageSerialization;
final List<String> experimentalFlags;
final List<String> dartDefines;
+ final String librariesSpec;
@override
void addFileSystemRoot(String root) {
@@ -664,6 +667,10 @@
'--output-dill',
outputPath,
],
+ if (librariesSpec != null) ...<String>[
+ '--libraries-spec',
+ librariesSpec,
+ ],
if (packagesFilePath != null) ...<String>[
'--packages',
packagesFilePath,
diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart
index d24e3c7..ab04d82 100644
--- a/packages/flutter_tools/lib/src/resident_runner.dart
+++ b/packages/flutter_tools/lib/src/resident_runner.dart
@@ -94,6 +94,8 @@
.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 d570b08..a9993ce 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 @@
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) + '/');