diff --git a/packages/flutter_tools/gradle/flutter.gradle b/packages/flutter_tools/gradle/flutter.gradle index 909b7f40ea..172b2d5dca 100644 --- a/packages/flutter_tools/gradle/flutter.gradle +++ b/packages/flutter_tools/gradle/flutter.gradle @@ -207,9 +207,45 @@ class FlutterTask extends DefaultTask { } } + FileCollection readDependencies(File dependenciesFile) { + if (dependenciesFile.exists()) { + try { + // Dependencies file has Makefile syntax: + // : + String depText = dependenciesFile.text + return project.files(depText.split(': ')[1].split()) + } catch (Exception e) { + logger.error("Error reading dependency file ${dependenciesFile}: ${e}") + } + } + return null + } + @InputFiles FileCollection getSourceFiles() { - return project.fileTree(dir: sourceDir, exclude: ['android', 'ios'], include: ['**/*.dart', 'pubspec.yaml', 'flutter.yaml']) + File dependenciesFile + if (buildMode != 'debug') { + dependenciesFile = project.file("${intermediateDir}/snapshot.d") + } else { + dependenciesFile = project.file("${intermediateDir}/snapshot_blob.bin.d") + } + FileCollection sources = readDependencies(dependenciesFile) + if (sources != null) { + // We have a dependencies file. Add a dependency on gen_snapshot as well, since the + // snapshots have to be rebuilt if it changes. + FileCollection snapshotter = readDependencies(project.file("${intermediateDir}/gen_snapshot.d")) + if (snapshotter != null) { + sources = sources.plus(snapshotter) + } + // Finally, add a dependency on pubspec.yaml as well. + return sources.plus(project.files('pubspec.yaml')) + } + // No dependencies file (or problems parsing it). Fall back to source files. + return project.fileTree( + dir: sourceDir, + exclude: ['android', 'ios'], + include: ['**/*.dart', 'pubspec.yaml'] + ) } @TaskAction diff --git a/packages/flutter_tools/lib/src/commands/build_aot.dart b/packages/flutter_tools/lib/src/commands/build_aot.dart index 6441115efd..e2bbeb03cd 100644 --- a/packages/flutter_tools/lib/src/commands/build_aot.dart +++ b/packages/flutter_tools/lib/src/commands/build_aot.dart @@ -124,6 +124,7 @@ Future _buildAotSnapshot( final String vmSnapshotInstructions = fs.path.join(outputDir.path, 'vm_snapshot_instr'); final String isolateSnapshotData = fs.path.join(outputDir.path, 'isolate_snapshot_data'); final String isolateSnapshotInstructions = fs.path.join(outputDir.path, 'isolate_snapshot_instr'); + final String dependencies = fs.path.join(outputDir.path, 'snapshot.d'); final String vmEntryPoints = artifacts.getArtifactPath(Artifact.dartVmEntryPointsTxt, platform, buildMode); final String ioEntryPoints = artifacts.getArtifactPath(Artifact.dartIoEntriesTxt, platform, buildMode); @@ -198,6 +199,7 @@ Future _buildAotSnapshot( '--url_mapping=dart:jni,$jniPath', '--url_mapping=dart:vmservice_sky,$vmServicePath', '--print_snapshot_sizes', + '--dependencies=$dependencies', ]; if (!interpreter) { @@ -249,6 +251,10 @@ Future _buildAotSnapshot( return null; } + // Write path to gen_snapshot, since snapshots have to be re-generated when we roll + // the Dart SDK. + await outputDir.childFile('gen_snapshot.d').writeAsString('snapshot.d: $genSnapshot\n'); + // On iOS, we use Xcode to compile the snapshot into a dynamic library that the // end-developer can link into their app. if (platform == TargetPlatform.ios) { diff --git a/packages/flutter_tools/lib/src/flx.dart b/packages/flutter_tools/lib/src/flx.dart index f79b308101..5b67cf4779 100644 --- a/packages/flutter_tools/lib/src/flx.dart +++ b/packages/flutter_tools/lib/src/flx.dart @@ -50,6 +50,7 @@ Future createSnapshot({ ]; if (depfilePath != null) { args.add('--dependencies=$depfilePath'); + fs.file(depfilePath).parent.childFile('gen_snapshot.d').writeAsString('$depfilePath: $snapshotterPath\n'); } args.add(mainPath); return runCommandAndStreamOutput(args);