Re-Re-Re-land implement flutter build bundle with assemble (#41302)
This commit is contained in:
@@ -11,7 +11,10 @@ import 'artifacts.dart';
|
||||
import 'asset.dart';
|
||||
import 'base/common.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'build_info.dart';
|
||||
import 'build_system/build_system.dart';
|
||||
import 'build_system/targets/dart.dart';
|
||||
import 'compile.dart';
|
||||
import 'dart/package_map.dart';
|
||||
import 'devfs.dart';
|
||||
@@ -69,6 +72,7 @@ class BundleBuilder {
|
||||
List<String> extraGenSnapshotOptions = const <String>[],
|
||||
List<String> fileSystemRoots,
|
||||
String fileSystemScheme,
|
||||
bool shouldBuildWithAssemble = false,
|
||||
}) async {
|
||||
mainPath ??= defaultMainPath;
|
||||
depfilePath ??= defaultDepfilePath;
|
||||
@@ -77,6 +81,18 @@ class BundleBuilder {
|
||||
applicationKernelFilePath ??= getDefaultApplicationKernelPath(trackWidgetCreation: trackWidgetCreation);
|
||||
final FlutterProject flutterProject = FlutterProject.current();
|
||||
|
||||
if (shouldBuildWithAssemble) {
|
||||
await buildWithAssemble(
|
||||
buildMode: buildMode ?? BuildMode.debug,
|
||||
targetPlatform: platform,
|
||||
mainPath: mainPath,
|
||||
flutterProject: flutterProject,
|
||||
outputDir: assetDirPath,
|
||||
depfilePath: depfilePath,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
DevFSContent kernelContent;
|
||||
if (!precompiledSnapshot) {
|
||||
if ((extraFrontEndOptions != null) && extraFrontEndOptions.isNotEmpty) {
|
||||
@@ -124,6 +140,66 @@ class BundleBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build an application bundle using flutter assemble.
|
||||
///
|
||||
/// This is a temporary shim to migrate the build implementations.
|
||||
Future<void> buildWithAssemble({
|
||||
@required FlutterProject flutterProject,
|
||||
@required BuildMode buildMode,
|
||||
@required TargetPlatform targetPlatform,
|
||||
@required String mainPath,
|
||||
@required String outputDir,
|
||||
@required String depfilePath,
|
||||
}) async {
|
||||
final Environment environment = Environment(
|
||||
projectDir: flutterProject.directory,
|
||||
outputDir: fs.directory(outputDir),
|
||||
buildDir: flutterProject.dartTool.childDirectory('flutter_build'),
|
||||
defines: <String, String>{
|
||||
kTargetFile: mainPath,
|
||||
kBuildMode: getNameForBuildMode(buildMode),
|
||||
kTargetPlatform: getNameForTargetPlatform(targetPlatform),
|
||||
}
|
||||
);
|
||||
final Target target = buildMode == BuildMode.debug
|
||||
? const CopyFlutterBundle()
|
||||
: const ReleaseCopyFlutterBundle();
|
||||
final BuildResult result = await buildSystem.build(target, environment);
|
||||
|
||||
if (!result.success) {
|
||||
for (ExceptionMeasurement measurement in result.exceptions.values) {
|
||||
printError(measurement.exception.toString());
|
||||
printError(measurement.stackTrace.toString());
|
||||
}
|
||||
throwToolExit('Failed to build bundle.');
|
||||
}
|
||||
|
||||
// Output depfile format:
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write('flutter_bundle');
|
||||
_writeFilesToBuffer(result.outputFiles, buffer);
|
||||
buffer.write(': ');
|
||||
_writeFilesToBuffer(result.inputFiles, buffer);
|
||||
|
||||
final File depfile = fs.file(depfilePath);
|
||||
if (!depfile.parent.existsSync()) {
|
||||
depfile.parent.createSync(recursive: true);
|
||||
}
|
||||
depfile.writeAsStringSync(buffer.toString());
|
||||
}
|
||||
|
||||
void _writeFilesToBuffer(List<File> files, StringBuffer buffer) {
|
||||
for (File outputFile in files) {
|
||||
if (platform.isWindows) {
|
||||
// Paths in a depfile have to be escaped on windows.
|
||||
final String escapedPath = outputFile.path.replaceAll(r'\', r'\\');
|
||||
buffer.write(' $escapedPath');
|
||||
} else {
|
||||
buffer.write(' ${outputFile.path}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<AssetBundle> buildAssets({
|
||||
String manifestPath,
|
||||
String assetDirPath,
|
||||
|
||||
Reference in New Issue
Block a user