Replace flutter --build-snapshot with --precompile that takes input (#20574)
This commit is contained in:
committed by
GitHub
parent
393f9276ca
commit
2c0329a103
@@ -300,9 +300,9 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
if (project.hasProperty('track-widget-creation')) {
|
||||
trackWidgetCreationValue = project.property('track-widget-creation').toBoolean()
|
||||
}
|
||||
Boolean buildSnapshotValue = false
|
||||
if (project.hasProperty('build-snapshot')) {
|
||||
buildSnapshotValue = project.property('build-snapshot').toBoolean()
|
||||
String compilationTraceFilePathValue = null
|
||||
if (project.hasProperty('precompile')) {
|
||||
compilationTraceFilePathValue = project.property('precompile')
|
||||
}
|
||||
String extraFrontEndOptionsValue = null
|
||||
if (project.hasProperty('extra-front-end-options')) {
|
||||
@@ -346,7 +346,7 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
fileSystemRoots fileSystemRootsValue
|
||||
fileSystemScheme fileSystemSchemeValue
|
||||
trackWidgetCreation trackWidgetCreationValue
|
||||
buildSnapshot buildSnapshotValue
|
||||
compilationTraceFilePath compilationTraceFilePathValue
|
||||
buildSharedLibrary buildSharedLibraryValue
|
||||
targetPlatform targetPlatformValue
|
||||
sourceDir project.file(project.flutter.source)
|
||||
@@ -396,7 +396,7 @@ abstract class BaseFlutterTask extends DefaultTask {
|
||||
@Optional @Input
|
||||
Boolean trackWidgetCreation
|
||||
@Optional @Input
|
||||
Boolean buildSnapshot
|
||||
String compilationTraceFilePath
|
||||
@Optional @Input
|
||||
Boolean buildSharedLibrary
|
||||
@Optional @Input
|
||||
@@ -500,8 +500,8 @@ abstract class BaseFlutterTask extends DefaultTask {
|
||||
if (trackWidgetCreation) {
|
||||
args "--track-widget-creation"
|
||||
}
|
||||
if (buildSnapshot) {
|
||||
args "--build-snapshot"
|
||||
if (compilationTraceFilePath != null) {
|
||||
args "--precompile", compilationTraceFilePath
|
||||
}
|
||||
if (extraFrontEndOptions != null) {
|
||||
args "--extra-front-end-options", "${extraFrontEndOptions}"
|
||||
@@ -549,7 +549,7 @@ class FlutterTask extends BaseFlutterTask {
|
||||
|
||||
include "flutter_assets/**" // the working dir and its files
|
||||
|
||||
if (buildMode != 'debug' || buildSnapshot) {
|
||||
if (buildMode != 'debug' || compilationTraceFilePath) {
|
||||
if (buildSharedLibrary) {
|
||||
include "app.so"
|
||||
} else {
|
||||
|
||||
@@ -357,8 +357,8 @@ Future<Null> _buildGradleProjectV2(
|
||||
command.add('-Ppreview-dart-2=true');
|
||||
if (buildInfo.trackWidgetCreation)
|
||||
command.add('-Ptrack-widget-creation=true');
|
||||
if (buildInfo.buildSnapshot)
|
||||
command.add('-Pbuild-snapshot=true');
|
||||
if (buildInfo.compilationTraceFilePath != null)
|
||||
command.add('-Pprecompile=${buildInfo.compilationTraceFilePath}');
|
||||
if (buildInfo.extraFrontEndOptions != null)
|
||||
command.add('-Pextra-front-end-options=${buildInfo.extraFrontEndOptions}');
|
||||
if (buildInfo.extraGenSnapshotOptions != null)
|
||||
|
||||
@@ -427,6 +427,7 @@ class CoreJITSnapshotter {
|
||||
@required String mainPath,
|
||||
@required String packagesPath,
|
||||
@required String outputPath,
|
||||
@required String compilationTraceFilePath,
|
||||
List<String> extraGenSnapshotOptions = const <String>[],
|
||||
}) async {
|
||||
if (!_isValidCoreJitPlatform(platform)) {
|
||||
@@ -437,7 +438,7 @@ class CoreJITSnapshotter {
|
||||
final Directory outputDir = fs.directory(outputPath);
|
||||
outputDir.createSync(recursive: true);
|
||||
|
||||
final List<String> inputPaths = <String>[mainPath];
|
||||
final List<String> inputPaths = <String>[mainPath, compilationTraceFilePath];
|
||||
final Set<String> outputPaths = new Set<String>();
|
||||
|
||||
final String depfilePath = fs.path.join(outputDir.path, 'snapshot.d');
|
||||
@@ -466,7 +467,7 @@ class CoreJITSnapshotter {
|
||||
'--isolate_snapshot_data=$isolateSnapshotData',
|
||||
'--vm_snapshot_instructions=$vmSnapshotInstructions',
|
||||
'--isolate_snapshot_instructions=$isolateSnapshotInstructions',
|
||||
'--load_compilation_trace=trace.txt',
|
||||
'--load_compilation_trace=$compilationTraceFilePath',
|
||||
]);
|
||||
|
||||
if (platform == TargetPlatform.android_arm) {
|
||||
|
||||
@@ -13,7 +13,7 @@ class BuildInfo {
|
||||
const BuildInfo(this.mode, this.flavor, {
|
||||
this.previewDart2 = false,
|
||||
this.trackWidgetCreation = false,
|
||||
this.buildSnapshot = false,
|
||||
this.compilationTraceFilePath,
|
||||
this.extraFrontEndOptions,
|
||||
this.extraGenSnapshotOptions,
|
||||
this.buildSharedLibrary,
|
||||
@@ -43,8 +43,8 @@ class BuildInfo {
|
||||
/// Whether the build should track widget creation locations.
|
||||
final bool trackWidgetCreation;
|
||||
|
||||
/// Whether the build should create VM snapshot instead of using prebuilt one from engine.
|
||||
final bool buildSnapshot;
|
||||
/// Dart compilation trace file to use for JIT VM snapshot.
|
||||
final String compilationTraceFilePath;
|
||||
|
||||
/// Extra command-line options for front-end.
|
||||
final String extraFrontEndOptions;
|
||||
@@ -101,7 +101,7 @@ class BuildInfo {
|
||||
new BuildInfo(mode, flavor,
|
||||
previewDart2: previewDart2,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
buildSnapshot: buildSnapshot,
|
||||
compilationTraceFilePath: compilationTraceFilePath,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
extraGenSnapshotOptions: extraGenSnapshotOptions,
|
||||
buildSharedLibrary: buildSharedLibrary,
|
||||
|
||||
@@ -47,7 +47,7 @@ Future<void> build({
|
||||
bool precompiledSnapshot = false,
|
||||
bool reportLicensedPackages = false,
|
||||
bool trackWidgetCreation = false,
|
||||
bool buildSnapshot = false,
|
||||
String compilationTraceFilePath,
|
||||
List<String> extraFrontEndOptions = const <String>[],
|
||||
List<String> extraGenSnapshotOptions = const <String>[],
|
||||
List<String> fileSystemRoots,
|
||||
@@ -84,7 +84,7 @@ Future<void> build({
|
||||
ensureDirectoryExists(applicationKernelFilePath);
|
||||
final CompilerOutput compilerOutput = await kernelCompiler.compile(
|
||||
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
incrementalCompilerByteStorePath: buildSnapshot ? null :
|
||||
incrementalCompilerByteStorePath: compilationTraceFilePath != null ? null :
|
||||
fs.path.absolute(getIncrementalCompilerByteStoreDirectory()),
|
||||
mainPath: fs.file(mainPath).absolute.path,
|
||||
outputFilePath: applicationKernelFilePath,
|
||||
@@ -94,7 +94,7 @@ Future<void> build({
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
fileSystemScheme: fileSystemScheme,
|
||||
packagesPath: packagesPath,
|
||||
linkPlatformKernelIn: buildSnapshot,
|
||||
linkPlatformKernelIn: compilationTraceFilePath != null,
|
||||
);
|
||||
if (compilerOutput?.outputFilename == null) {
|
||||
throwToolExit('Compiler failed on $mainPath');
|
||||
@@ -104,7 +104,7 @@ Future<void> build({
|
||||
await fs.directory(getBuildDirectory()).childFile('frontend_server.d')
|
||||
.writeAsString('frontend_server.d: ${artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk)}\n');
|
||||
|
||||
if (buildSnapshot) {
|
||||
if (compilationTraceFilePath != null) {
|
||||
final CoreJITSnapshotter snapshotter = new CoreJITSnapshotter();
|
||||
final int snapshotExitCode = await snapshotter.build(
|
||||
platform: platform,
|
||||
@@ -112,6 +112,7 @@ Future<void> build({
|
||||
mainPath: applicationKernelFilePath,
|
||||
outputPath: getBuildDirectory(),
|
||||
packagesPath: packagesPath,
|
||||
compilationTraceFilePath: compilationTraceFilePath,
|
||||
extraGenSnapshotOptions: extraGenSnapshotOptions,
|
||||
);
|
||||
if (snapshotExitCode != 0) {
|
||||
@@ -135,7 +136,7 @@ Future<void> build({
|
||||
snapshotFile: snapshotFile,
|
||||
privateKeyPath: privateKeyPath,
|
||||
assetDirPath: assetDirPath,
|
||||
buildSnapshot: buildSnapshot,
|
||||
compilationTraceFilePath: compilationTraceFilePath,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -171,14 +172,14 @@ Future<void> assemble({
|
||||
File dylibFile,
|
||||
String privateKeyPath = defaultPrivateKeyPath,
|
||||
String assetDirPath,
|
||||
bool buildSnapshot,
|
||||
String compilationTraceFilePath,
|
||||
}) async {
|
||||
assetDirPath ??= getAssetBuildDirectory();
|
||||
printTrace('Building bundle');
|
||||
|
||||
final Map<String, DevFSContent> assetEntries = new Map<String, DevFSContent>.from(assetBundle.entries);
|
||||
if (kernelContent != null) {
|
||||
if (buildSnapshot) {
|
||||
if (compilationTraceFilePath != null) {
|
||||
final String vmSnapshotData = fs.path.join(getBuildDirectory(), _kVMSnapshotData);
|
||||
final String vmSnapshotInstr = fs.path.join(getBuildDirectory(), _kVMSnapshotInstr);
|
||||
final String isolateSnapshotData = fs.path.join(getBuildDirectory(), _kIsolateSnapshotData);
|
||||
|
||||
@@ -37,11 +37,14 @@ class BuildBundleCommand extends BuildSubCommand {
|
||||
hide: !verboseHelp,
|
||||
help: 'Track widget creation locations. Requires Dart 2.0 functionality.',
|
||||
)
|
||||
..addFlag('build-snapshot',
|
||||
..addOption('precompile',
|
||||
hide: !verboseHelp,
|
||||
defaultsTo: false,
|
||||
help: 'Build and use application-specific VM snapshot instead of\n'
|
||||
'prebuilt one provided by the engine.',
|
||||
help: 'Precompile functions specified in input file. This flag is only\n'
|
||||
'allowed when using --dynamic. It takes a Dart compilation trace\n'
|
||||
'file produced by the training run of the application. With this\n'
|
||||
'flag, instead of using default Dart VM snapshot provided by the\n'
|
||||
'engine, the application will use its own snapshot that includes\n'
|
||||
'additional functions.'
|
||||
)
|
||||
..addMultiOption(FlutterOptions.kExtraFrontEndOptions,
|
||||
splitCommas: true,
|
||||
@@ -106,7 +109,7 @@ class BuildBundleCommand extends BuildSubCommand {
|
||||
precompiledSnapshot: argResults['precompiled'],
|
||||
reportLicensedPackages: argResults['report-licensed-packages'],
|
||||
trackWidgetCreation: argResults['track-widget-creation'],
|
||||
buildSnapshot: argResults['build-snapshot'],
|
||||
compilationTraceFilePath: argResults['precompile'],
|
||||
extraFrontEndOptions: argResults[FlutterOptions.kExtraFrontEndOptions],
|
||||
extraGenSnapshotOptions: argResults[FlutterOptions.kExtraGenSnapshotOptions],
|
||||
fileSystemScheme: argResults['filesystem-scheme'],
|
||||
|
||||
@@ -124,11 +124,14 @@ class RunCommand extends RunCommandBase {
|
||||
hide: !verboseHelp,
|
||||
help: 'Preview Dart 2.0 functionality.',
|
||||
)
|
||||
..addFlag('build-snapshot',
|
||||
..addOption('precompile',
|
||||
hide: !verboseHelp,
|
||||
defaultsTo: false,
|
||||
help: 'Build and use application-specific VM snapshot instead of\n'
|
||||
'prebuilt one provided by the engine.',
|
||||
help: 'Precompile functions specified in input file. This flag is only\n'
|
||||
'allowed when using --dynamic. It takes a Dart compilation trace\n'
|
||||
'file produced by the training run of the application. With this\n'
|
||||
'flag, instead of using default Dart VM snapshot provided by the\n'
|
||||
'engine, the application will use its own snapshot that includes\n'
|
||||
'additional functions.'
|
||||
)
|
||||
..addFlag('track-widget-creation',
|
||||
hide: !verboseHelp,
|
||||
|
||||
@@ -224,9 +224,9 @@ abstract class FlutterCommand extends Command<Null> {
|
||||
: null,
|
||||
previewDart2: previewDart2,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
buildSnapshot: argParser.options.containsKey('build-snapshot')
|
||||
? argResults['build-snapshot']
|
||||
: false,
|
||||
compilationTraceFilePath: argParser.options.containsKey('precompile')
|
||||
? argResults['precompile']
|
||||
: null,
|
||||
extraFrontEndOptions: argParser.options.containsKey(FlutterOptions.kExtraFrontEndOptions)
|
||||
? argResults[FlutterOptions.kExtraFrontEndOptions]
|
||||
: null,
|
||||
@@ -474,6 +474,15 @@ abstract class FlutterCommand extends Command<Null> {
|
||||
if (!fs.isFileSync(targetPath))
|
||||
throw new ToolExit('Target file "$targetPath" not found.');
|
||||
}
|
||||
|
||||
final bool dynamicFlag = argParser.options.containsKey('dynamic')
|
||||
? argResults['dynamic'] : false;
|
||||
final String compilationTraceFilePath = argParser.options.containsKey('precompile')
|
||||
? argResults['precompile'] : null;
|
||||
if (compilationTraceFilePath != null && getBuildMode() == BuildMode.debug)
|
||||
throw new ToolExit('Error: --precompile is not allowed when --debug is specified.');
|
||||
if (compilationTraceFilePath != null && !dynamicFlag)
|
||||
throw new ToolExit('Error: --precompile is allowed only when --dynamic is specified.');
|
||||
}
|
||||
|
||||
ApplicationPackageStore applicationPackages;
|
||||
|
||||
@@ -813,6 +813,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
), isNot(equals(0)));
|
||||
}, overrides: contextOverrides);
|
||||
|
||||
@@ -836,6 +837,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
);
|
||||
|
||||
expect(genSnapshotExitCode, 0);
|
||||
@@ -880,6 +882,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
);
|
||||
|
||||
expect(genSnapshotExitCode, 0);
|
||||
@@ -910,6 +913,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
), isNot(equals(0)));
|
||||
}, overrides: contextOverrides);
|
||||
|
||||
@@ -933,6 +937,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
);
|
||||
|
||||
expect(genSnapshotExitCode, 0);
|
||||
@@ -976,6 +981,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
);
|
||||
|
||||
expect(genSnapshotExitCode, 0);
|
||||
@@ -1005,6 +1011,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
), isNot(equals(0)));
|
||||
}, overrides: contextOverrides);
|
||||
|
||||
@@ -1028,6 +1035,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
);
|
||||
|
||||
expect(genSnapshotExitCode, 0);
|
||||
@@ -1071,6 +1079,7 @@ void main() {
|
||||
mainPath: 'main.dill',
|
||||
packagesPath: '.packages',
|
||||
outputPath: outputPath,
|
||||
compilationTraceFilePath: kTrace,
|
||||
);
|
||||
|
||||
expect(genSnapshotExitCode, 0);
|
||||
|
||||
Reference in New Issue
Block a user