Revert "Eliminate snapshot/depfile options to build bundle (#21507)" (#21563)

This tickled a bug in KernelCompiler.compile() where the fingerprinter
doesn't include the outputFilePath in its list of dependencies. As such,
if the output .dill file is missing or corrupted, the fingerprint still
matches and re-compile is skipped, even though it shouldn't be. I'll fix
that in a followup, then look at how this triggered that issue. My
hypothesis is that that it's due to the aot kernel compile and bundle
kernel compile have separate output directories for the .dill files
(build/ vs build/aot) but the same output directory for the associated
depfiles (due to this patch).

This reverts commit 43a106e95a615679609ffd11a3ca3fa466a9712c.
diff --git a/packages/flutter_tools/bin/xcode_backend.sh b/packages/flutter_tools/bin/xcode_backend.sh
index 9d163fc..100b158 100755
--- a/packages/flutter_tools/bin/xcode_backend.sh
+++ b/packages/flutter_tools/bin/xcode_backend.sh
@@ -176,7 +176,9 @@
     build bundle                                                            \
     --target-platform=ios                                                   \
     --target="${target_path}"                                               \
+    --snapshot="${build_dir}/snapshot_blob.bin"                             \
     --${build_mode}                                                         \
+    --depfile="${build_dir}/snapshot_blob.bin.d"                            \
     --asset-dir="${derived_dir}/flutter_assets"                             \
     ${precompilation_flag}                                                  \
     ${local_engine_flag}                                                    \
diff --git a/packages/flutter_tools/gradle/flutter.gradle b/packages/flutter_tools/gradle/flutter.gradle
index f3a9e68..6f4cbe3 100644
--- a/packages/flutter_tools/gradle/flutter.gradle
+++ b/packages/flutter_tools/gradle/flutter.gradle
@@ -409,6 +409,11 @@
         // first stage of AOT build in this mode, and it includes all the Dart
         // sources.
         depfiles += project.files("${intermediateDir}/kernel_compile.d")
+
+        // Include Core JIT kernel compiler depfile, since kernel compile is
+        // the first stage of JIT builds in this mode, and it includes all the
+        // Dart sources.
+        depfiles += project.files("${intermediateDir}/snapshot_blob.bin.d")
         return depfiles
     }
 
@@ -490,6 +495,8 @@
             }
             if (buildMode == "release" || buildMode == "profile") {
                 args "--precompiled"
+            } else {
+                args "--depfile", "${intermediateDir}/snapshot_blob.bin.d"
             }
             args "--asset-dir", "${intermediateDir}/flutter_assets"
             if (buildMode == "debug") {
diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart
index db7fec3..a463ac3 100644
--- a/packages/flutter_tools/lib/src/base/build.dart
+++ b/packages/flutter_tools/lib/src/base/build.dart
@@ -311,10 +311,12 @@
     if ((extraFrontEndOptions != null) && extraFrontEndOptions.isNotEmpty)
       printTrace('Extra front-end options: $extraFrontEndOptions');
 
+    final String depfilePath = fs.path.join(outputPath, 'kernel_compile.d');
     final CompilerOutput compilerOutput = await kernelCompiler.compile(
       sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
       mainPath: mainPath,
       outputFilePath: fs.path.join(outputPath, 'app.dill'),
+      depFilePath: depfilePath,
       extraFrontEndOptions: extraFrontEndOptions,
       linkPlatformKernelIn: true,
       aot: true,
diff --git a/packages/flutter_tools/lib/src/bundle.dart b/packages/flutter_tools/lib/src/bundle.dart
index f0c3b59..8f3fe07 100644
--- a/packages/flutter_tools/lib/src/bundle.dart
+++ b/packages/flutter_tools/lib/src/bundle.dart
@@ -18,6 +18,8 @@
 const String defaultMainPath = 'lib/main.dart';
 const String defaultAssetBasePath = '.';
 const String defaultManifestPath = 'pubspec.yaml';
+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';
 
@@ -34,7 +36,9 @@
   BuildMode buildMode,
   String mainPath = defaultMainPath,
   String manifestPath = defaultManifestPath,
+  String snapshotPath,
   String applicationKernelFilePath,
+  String depfilePath,
   String privateKeyPath = defaultPrivateKeyPath,
   String assetDirPath,
   String packagesPath,
@@ -47,6 +51,8 @@
   List<String> fileSystemRoots,
   String fileSystemScheme,
 }) async {
+  snapshotPath ??= defaultSnapshotPath;
+  depfilePath ??= defaultDepfilePath;
   assetDirPath ??= getAssetBuildDirectory();
   packagesPath ??= fs.path.absolute(PackageMap.globalPackagesPath);
   applicationKernelFilePath ??= defaultApplicationKernelPath;
@@ -62,6 +68,7 @@
           fs.path.absolute(getIncrementalCompilerByteStoreDirectory()),
       mainPath: fs.file(mainPath).absolute.path,
       outputFilePath: applicationKernelFilePath,
+      depFilePath: depfilePath,
       trackWidgetCreation: trackWidgetCreation,
       extraFrontEndOptions: extraFrontEndOptions,
       fileSystemRoots: fileSystemRoots,
diff --git a/packages/flutter_tools/lib/src/commands/build_bundle.dart b/packages/flutter_tools/lib/src/commands/build_bundle.dart
index 0844d9a..3958e37 100644
--- a/packages/flutter_tools/lib/src/commands/build_bundle.dart
+++ b/packages/flutter_tools/lib/src/commands/build_bundle.dart
@@ -22,6 +22,8 @@
       ..addOption('asset-base', help: 'Ignored. Will be removed.', hide: !verboseHelp)
       ..addOption('manifest', defaultsTo: defaultManifestPath)
       ..addOption('private-key', defaultsTo: defaultPrivateKeyPath)
+      ..addOption('snapshot', defaultsTo: defaultSnapshotPath)
+      ..addOption('depfile', defaultsTo: defaultDepfilePath)
       ..addOption('kernel-file', defaultsTo: defaultApplicationKernelPath)
       ..addOption('target-platform',
         defaultsTo: 'android-arm',
@@ -83,7 +85,9 @@
       buildMode: buildMode,
       mainPath: targetFile,
       manifestPath: argResults['manifest'],
+      snapshotPath: argResults['snapshot'],
       applicationKernelFilePath: argResults['kernel-file'],
+      depfilePath: argResults['depfile'],
       privateKeyPath: argResults['private-key'],
       assetDirPath: argResults['asset-dir'],
       precompiledSnapshot: argResults['precompiled'],
diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart
index 199a544..fb8e251 100644
--- a/packages/flutter_tools/lib/src/compile.dart
+++ b/packages/flutter_tools/lib/src/compile.dart
@@ -10,11 +10,9 @@
 import 'artifacts.dart';
 import 'base/common.dart';
 import 'base/context.dart';
-import 'base/file_system.dart';
 import 'base/fingerprint.dart';
 import 'base/io.dart';
 import 'base/process_manager.dart';
-import 'build_info.dart';
 import 'globals.dart';
 
 KernelCompiler get kernelCompiler => context[KernelCompiler];
@@ -76,6 +74,7 @@
     String sdkRoot,
     String mainPath,
     String outputFilePath,
+    String depFilePath,
     bool linkPlatformKernelIn = false,
     bool aot = false,
     List<String> entryPointsJsonFiles,
@@ -94,22 +93,24 @@
     // TODO(cbracken): eliminate pathFilter.
     // Currently the compiler emits buildbot paths for the core libs in the
     // depfile. None of these are available on the local host.
-    final String depfilePath = fs.path.join(getBuildDirectory(), 'kernel_compile.d');
-    final Fingerprinter fingerprinter = new Fingerprinter(
-      fingerprintPath: '$depfilePath.fingerprint',
-      paths: <String>[mainPath],
-      properties: <String, String>{
-        'entryPoint': mainPath,
-        'trackWidgetCreation': trackWidgetCreation.toString(),
-        'linkPlatformKernelIn': linkPlatformKernelIn.toString(),
-      },
-      depfilePaths: <String>[depfilePath],
-      pathFilter: (String path) => !path.startsWith('/b/build/slave/'),
-    );
+    Fingerprinter fingerprinter;
+    if (depFilePath != null) {
+      fingerprinter = new Fingerprinter(
+        fingerprintPath: '$depFilePath.fingerprint',
+        paths: <String>[mainPath],
+        properties: <String, String>{
+          'entryPoint': mainPath,
+          'trackWidgetCreation': trackWidgetCreation.toString(),
+          'linkPlatformKernelIn': linkPlatformKernelIn.toString(),
+        },
+        depfilePaths: <String>[depFilePath],
+        pathFilter: (String path) => !path.startsWith('/b/build/slave/'),
+      );
 
-    if (await fingerprinter.doesFingerprintMatch()) {
-      printTrace('Skipping kernel compilation. Fingerprint match.');
-      return new CompilerOutput(outputFilePath, 0);
+      if (await fingerprinter.doesFingerprintMatch()) {
+        printTrace('Skipping kernel compilation. Fingerprint match.');
+        return new CompilerOutput(outputFilePath, 0);
+      }
     }
 
     // This is a URI, not a file path, so the forward slash is correct even on Windows.
@@ -152,8 +153,8 @@
     if (outputFilePath != null) {
       command.addAll(<String>['--output-dill', outputFilePath]);
     }
-    if (fileSystemRoots == null || fileSystemRoots.isEmpty) {
-      command.addAll(<String>['--depfile', depfilePath]);
+    if (depFilePath != null && (fileSystemRoots == null || fileSystemRoots.isEmpty)) {
+      command.addAll(<String>['--depfile', depFilePath]);
     }
     if (fileSystemRoots != null) {
       for (String root in fileSystemRoots) {
@@ -185,7 +186,9 @@
       .listen(_stdoutHandler.handler);
     final int exitCode = await server.exitCode;
     if (exitCode == 0) {
-      await fingerprinter.writeFingerprint();
+      if (fingerprinter != null) {
+        await fingerprinter.writeFingerprint();
+      }
       return _stdoutHandler.compilerOutput.future;
     }
     return null;
diff --git a/packages/flutter_tools/test/tester/flutter_tester_test.dart b/packages/flutter_tools/test/tester/flutter_tester_test.dart
index f5e6396..3ca867d 100644
--- a/packages/flutter_tools/test/tester/flutter_tester_test.dart
+++ b/packages/flutter_tools/test/tester/flutter_tester_test.dart
@@ -169,6 +169,7 @@
           incrementalCompilerByteStorePath: anyNamed('incrementalCompilerByteStorePath'),
           mainPath: anyNamed('mainPath'),
           outputFilePath: anyNamed('outputFilePath'),
+          depFilePath: anyNamed('depFilePath'),
           trackWidgetCreation: anyNamed('trackWidgetCreation'),
           extraFrontEndOptions: anyNamed('extraFrontEndOptions'),
           fileSystemRoots: anyNamed('fileSystemRoots'),