From 673c5485ae52eb8db85fa49b716705b03d28aea4 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Fri, 2 Mar 2018 11:33:13 -0800 Subject: [PATCH] Generate and use dep-file for --preview-dart-2 (#15077) * Use depfile in --preview-dart-2 mode. * Generate and use frontend_server.d to guard against reusing outdated dill files when frontend_server changes. --- packages/flutter_tools/gradle/flutter.gradle | 8 +++++++- packages/flutter_tools/lib/src/commands/build_aot.dart | 5 +++++ packages/flutter_tools/lib/src/compile.dart | 4 ++++ packages/flutter_tools/lib/src/flx.dart | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/gradle/flutter.gradle b/packages/flutter_tools/gradle/flutter.gradle index 403575a357c..0f95bba0f5d 100644 --- a/packages/flutter_tools/gradle/flutter.gradle +++ b/packages/flutter_tools/gradle/flutter.gradle @@ -438,9 +438,9 @@ abstract class BaseFlutterTask extends DefaultTask { if (buildMode != "debug") { args "--precompiled" } else { + args "--depfile", "${intermediateDir}/snapshot_blob.bin.d" if (!previewDart2) { args "--snapshot", "${intermediateDir}/snapshot_blob.bin" - args "--depfile", "${intermediateDir}/snapshot_blob.bin.d" } } args "--working-dir", "${intermediateDir}/flutter_assets" @@ -508,6 +508,12 @@ class FlutterTask extends BaseFlutterTask { if (snapshotter != null) { sources = sources.plus(snapshotter) } + if (previewDart2) { + FileCollection frontendServer = readDependencies(project.file("${intermediateDir}/frontend_server.d")) + if (frontendServer != null) { + sources = sources.plus(frontendServer) + } + } if (localEngineSrcPath != null) { sources = sources.plus(project.files("$localEngineSrcPath/$localEngine")) } diff --git a/packages/flutter_tools/lib/src/commands/build_aot.dart b/packages/flutter_tools/lib/src/commands/build_aot.dart index 5180509c676..a4409c55f87 100644 --- a/packages/flutter_tools/lib/src/commands/build_aot.dart +++ b/packages/flutter_tools/lib/src/commands/build_aot.dart @@ -367,6 +367,7 @@ Future _buildAotSnapshot( sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), mainPath: mainPath, outputFilePath: kApplicationKernelPath, + depFilePath: dependencies, extraFrontEndOptions: extraFrontEndOptions, linkPlatformKernelIn : true, aot : true, @@ -376,6 +377,10 @@ Future _buildAotSnapshot( printError('Compiler terminated unexpectedly.'); return null; } + // Write path to frontend_server, since things need to be re-generated when + // that changes. + await outputDir.childFile('frontend_server.d') + .writeAsString('frontend_server.d: ${artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk)}\n'); genSnapshotCmd.addAll([ '--reify-generic-functions', diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index b74327ecd9d..bfee499b37a 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -59,6 +59,7 @@ Future compile( {String sdkRoot, String mainPath, String outputFilePath, + String depFilePath, bool linkPlatformKernelIn: false, bool aot: false, bool trackWidgetCreation: false, @@ -96,6 +97,9 @@ Future compile( if (outputFilePath != null) { command.addAll(['--output-dill', outputFilePath]); } + if (depFilePath != null) { + command.addAll(['--depfile', depFilePath]); + } if (extraFrontEndOptions != null) command.addAll(extraFrontEndOptions); diff --git a/packages/flutter_tools/lib/src/flx.dart b/packages/flutter_tools/lib/src/flx.dart index fd0b13632dc..b7b8236e88c 100644 --- a/packages/flutter_tools/lib/src/flx.dart +++ b/packages/flutter_tools/lib/src/flx.dart @@ -80,11 +80,15 @@ Future build({ incrementalCompilerByteStorePath: fs.path.absolute(getIncrementalCompilerByteStoreDirectory()), mainPath: fs.file(mainPath).absolute.path, outputFilePath: applicationKernelFilePath, + depFilePath: depfilePath, trackWidgetCreation: trackWidgetCreation, ); if (kernelBinaryFilename == null) { throwToolExit('Compiler terminated unexpectedly on $mainPath'); } + await fs.directory(getBuildDirectory()).childFile('frontend_server.d') + .writeAsString('frontend_server.d: ${artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk)}\n'); + kernelContent = new DevFSFileContent(fs.file(kernelBinaryFilename)); }