Unverified Commit 2c0329a1 authored by Stanislav Baranov's avatar Stanislav Baranov Committed by GitHub

Replace flutter --build-snapshot with --precompile that takes input (#20574)

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