diff --git a/packages/flutter_tools/lib/src/commands/build_aot.dart b/packages/flutter_tools/lib/src/commands/build_aot.dart index fa20a92338..e10679c566 100644 --- a/packages/flutter_tools/lib/src/commands/build_aot.dart +++ b/packages/flutter_tools/lib/src/commands/build_aot.dart @@ -282,6 +282,7 @@ Future _buildAotSnapshot( final String kIsolateSnapshotDataC = fs.path.join(outputDir.path, '$kIsolateSnapshotData.c'); final String kVmSnapshotDataO = fs.path.join(outputDir.path, '$kVmSnapshotData.o'); final String kIsolateSnapshotDataO = fs.path.join(outputDir.path, '$kIsolateSnapshotData.o'); + final String kApplicationKernelPath = fs.path.join(getBuildDirectory(), 'app.dill'); switch (platform) { case TargetPlatform.android_arm: @@ -338,6 +339,7 @@ Future _buildAotSnapshot( mainPath = await compile( sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), mainPath: mainPath, + outputFilePath: kApplicationKernelPath, extraFrontEndOptions: extraFrontEndOptions, linkPlatformKernelIn : true, aot : true, diff --git a/packages/flutter_tools/lib/src/commands/build_flx.dart b/packages/flutter_tools/lib/src/commands/build_flx.dart index 57e39f843c..b7fbfdc4e4 100644 --- a/packages/flutter_tools/lib/src/commands/build_flx.dart +++ b/packages/flutter_tools/lib/src/commands/build_flx.dart @@ -20,6 +20,7 @@ class BuildFlxCommand extends BuildSubCommand { argParser.addOption('output-file', abbr: 'o', defaultsTo: defaultFlxOutputPath); argParser.addOption('snapshot', defaultsTo: defaultSnapshotPath); argParser.addOption('depfile', defaultsTo: defaultDepfilePath); + argParser.addOption('kernel-file', defaultsTo: defaultApplicationKernelPath); argParser.addFlag('preview-dart-2', negatable: false, hide: !verboseHelp); argParser.addFlag( 'track-widget-creation', @@ -51,6 +52,7 @@ class BuildFlxCommand extends BuildSubCommand { manifestPath: argResults['manifest'], outputPath: outputPath, snapshotPath: argResults['snapshot'], + applicationKernelFilePath: argResults['kernel-file'], depfilePath: argResults['depfile'], privateKeyPath: argResults['private-key'], workingDirPath: argResults['working-dir'], diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 7635028803..7a7ebc25dd 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -58,6 +58,7 @@ class _StdoutHandler { Future compile( {String sdkRoot, String mainPath, + String outputFilePath, bool linkPlatformKernelIn: false, bool aot: false, bool trackWidgetCreation: false, @@ -91,6 +92,9 @@ Future compile( if (packagesPath != null) { command.addAll(['--packages', packagesPath]); } + if (outputFilePath != null) { + command.addAll(['--output-dill', outputFilePath]); + } if (extraFrontEndOptions != null) command.addAll(extraFrontEndOptions); @@ -140,13 +144,14 @@ class ResidentCompiler { /// into new binary. /// Binary file name is returned if compilation was successful, otherwise /// null is returned. - Future recompile(String mainPath, List invalidatedFiles) async { + Future recompile(String mainPath, List invalidatedFiles, + {String outputPath}) async { stdoutHandler.reset(); // First time recompile is called we actually have to compile the app from // scratch ignoring list of invalidated files. if (_server == null) - return _compile(mainPath); + return _compile(mainPath, outputPath); final String inputKey = new Uuid().generateV4(); _server.stdin.writeln('recompile $inputKey'); @@ -156,7 +161,7 @@ class ResidentCompiler { return stdoutHandler.outputFilename.future; } - Future _compile(String scriptFilename) async { + Future _compile(String scriptFilename, String outputPath) async { final String frontendServer = artifacts.getArtifactPath( Artifact.frontendServerSnapshotForEngineDartSdk ); @@ -168,6 +173,9 @@ class ResidentCompiler { '--incremental', '--strong' ]; + if (outputPath != null) { + args.addAll(['--output-dill', outputPath]); + } if (_trackWidgetCreation) { args.add('--track-widget-creation'); } diff --git a/packages/flutter_tools/lib/src/devfs.dart b/packages/flutter_tools/lib/src/devfs.dart index 6882208764..22a97e8ab1 100644 --- a/packages/flutter_tools/lib/src/devfs.dart +++ b/packages/flutter_tools/lib/src/devfs.dart @@ -499,7 +499,8 @@ class DevFS { generator.reset(); } final String compiledBinary = - await generator.recompile(mainPath, invalidatedFiles); + await generator.recompile(mainPath, invalidatedFiles, + outputPath: fs.path.join(getBuildDirectory(), 'app.dill')); if (compiledBinary != null && compiledBinary.isNotEmpty) dirtyEntries.putIfAbsent( Uri.parse(target + '.dill'), diff --git a/packages/flutter_tools/lib/src/flx.dart b/packages/flutter_tools/lib/src/flx.dart index fe42e1524d..fd0b13632d 100644 --- a/packages/flutter_tools/lib/src/flx.dart +++ b/packages/flutter_tools/lib/src/flx.dart @@ -22,6 +22,7 @@ const String defaultManifestPath = 'pubspec.yaml'; String get defaultFlxOutputPath => fs.path.join(getBuildDirectory(), 'app.flx'); String get defaultSnapshotPath => fs.path.join(getBuildDirectory(), 'snapshot_blob.bin'); String get defaultDepfilePath => fs.path.join(getBuildDirectory(), 'snapshot_blob.bin.d'); +String get defaultApplicationKernelPath => fs.path.join(getBuildDirectory(), 'app.dill'); const String defaultPrivateKeyPath = 'privatekey.der'; const String _kKernelKey = 'kernel_blob.bin'; @@ -34,6 +35,7 @@ Future build({ String manifestPath: defaultManifestPath, String outputPath, String snapshotPath, + String applicationKernelFilePath, String depfilePath, String privateKeyPath: defaultPrivateKeyPath, String workingDirPath, @@ -48,6 +50,7 @@ Future build({ depfilePath ??= defaultDepfilePath; workingDirPath ??= getAssetBuildDirectory(); packagesPath ??= fs.path.absolute(PackageMap.globalPackagesPath); + applicationKernelFilePath ??= defaultApplicationKernelPath; File snapshotFile; if (!precompiledSnapshot && !previewDart2) { @@ -70,10 +73,13 @@ Future build({ DevFSContent kernelContent; if (!precompiledSnapshot && previewDart2) { + ensureDirectoryExists(applicationKernelFilePath); + final String kernelBinaryFilename = await compile( sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), incrementalCompilerByteStorePath: fs.path.absolute(getIncrementalCompilerByteStoreDirectory()), mainPath: fs.file(mainPath).absolute.path, + outputFilePath: applicationKernelFilePath, trackWidgetCreation: trackWidgetCreation, ); if (kernelBinaryFilename == null) {