Revert "[build] Don't list Dart sources up front when creating application snapshots."

This reverts commit a23c31bf8d3263897bc50d9540c3a51cd577d364.

Reason for revert: The bootstrapping compilations are a bit confused about whose deps they're writing

Original change's description:
> [build] Don't list Dart sources up front when creating application snapshots.
>
> GN/Ninja will discover them via the depfile created alongside the snapshot.
>
> Bug: https://github.com/flutter/flutter/issues/81074
> Change-Id: I6e0f07214e8ea29e6d23261c71558da06fd2223a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196982
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

TBR=bkonyi@google.com,rmacnak@google.com,chinmaygarde@google.com

Change-Id: I267b6bac2676a18f57291c8472fab5c2aaa60284
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/flutter/flutter/issues/81074
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197000
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/pkg/BUILD.gn b/pkg/BUILD.gn
new file mode 100644
index 0000000..173b32f
--- /dev/null
+++ b/pkg/BUILD.gn
@@ -0,0 +1,62 @@
+# Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+import("../utils/create_timestamp.gni")
+
+template("make_third_party_pkg_files_stamp") {
+  assert(defined(invoker.id), "Must define the stamp file id")
+  path = rebase_path("../third_party/pkg")
+  if (defined(invoker.path)) {
+    path = invoker.path
+  }
+  id = invoker.id
+  create_timestamp_file(target_name) {
+    if (defined(invoker.pattern)) {
+      pattern = invoker.pattern
+    }
+    path = path
+    output = "$target_gen_dir/third_party_pkg_files_$id.stamp"
+  }
+}
+
+make_third_party_pkg_files_stamp("make_third_party_pkg_files_0_stamp") {
+  path = rebase_path(".")
+  id = "0"
+}
+
+make_third_party_pkg_files_stamp("make_third_party_pkg_files_1_stamp") {
+  pattern = "[a-k].*"
+  id = "1"
+}
+
+make_third_party_pkg_files_stamp("make_third_party_pkg_files_2_stamp") {
+  pattern = "[l-r].*"
+  id = "2"
+}
+
+make_third_party_pkg_files_stamp("make_third_party_pkg_files_3_stamp") {
+  pattern = "[s-z].*"
+  id = "3"
+}
+
+action("pkg_files_stamp") {
+  deps = [
+    ":make_third_party_pkg_files_0_stamp",
+    ":make_third_party_pkg_files_1_stamp",
+    ":make_third_party_pkg_files_2_stamp",
+    ":make_third_party_pkg_files_3_stamp",
+  ]
+
+  stamp0_outputs = get_target_outputs(":make_third_party_pkg_files_0_stamp")
+  stamp1_outputs = get_target_outputs(":make_third_party_pkg_files_1_stamp")
+  stamp2_outputs = get_target_outputs(":make_third_party_pkg_files_2_stamp")
+  stamp3_outputs = get_target_outputs(":make_third_party_pkg_files_3_stamp")
+
+  inputs = stamp0_outputs + stamp1_outputs + stamp2_outputs + stamp3_outputs
+
+  outputs = [ "$root_gen_dir/pkg_files.stamp" ]
+
+  script = "../tools/create_timestamp_file.py"
+  args = [ rebase_path("$root_gen_dir/pkg_files.stamp") ]
+}
diff --git a/utils/analysis_server/BUILD.gn b/utils/analysis_server/BUILD.gn
index d8d0cea..29c34d9 100644
--- a/utils/analysis_server/BUILD.gn
+++ b/utils/analysis_server/BUILD.gn
@@ -4,6 +4,13 @@
 
 import("../application_snapshot.gni")
 
+analysis_server_files = exec_script("../../tools/list_dart_files.py",
+                                    [
+                                      "absolute",
+                                      rebase_path("../../pkg/analysis_server"),
+                                    ],
+                                    "list lines")
+
 application_snapshot("analysis_server") {
   main_dart = "../../pkg/analysis_server/bin/server.dart"
   training_args = [
@@ -12,4 +19,5 @@
     # "--sdk=" + rebase_path("../../sdk/"),
     # "--train-using=" + rebase_path("../../pkg/analyzer_cli")
   ]
+  inputs = analysis_server_files
 }
diff --git a/utils/bazel/BUILD.gn b/utils/bazel/BUILD.gn
index 6f6d3da..774f301 100644
--- a/utils/bazel/BUILD.gn
+++ b/utils/bazel/BUILD.gn
@@ -7,4 +7,5 @@
 application_snapshot("kernel_worker") {
   main_dart = "kernel_worker.dart"
   training_args = [ "--help" ]
+  deps = [ "../../pkg:pkg_files_stamp" ]
 }
diff --git a/utils/dartanalyzer/BUILD.gn b/utils/dartanalyzer/BUILD.gn
index 0c007ab..78c84b0 100644
--- a/utils/dartanalyzer/BUILD.gn
+++ b/utils/dartanalyzer/BUILD.gn
@@ -4,7 +4,6 @@
 
 import("../../build/dart/dart_action.gni")
 import("../application_snapshot.gni")
-import("../create_timestamp.gni")
 
 group("dartanalyzer") {
   deps = [
@@ -13,6 +12,13 @@
   ]
 }
 
+analyzer_files = exec_script("../../tools/list_dart_files.py",
+                             [
+                               "absolute",
+                               rebase_path("../../pkg/analyzer"),
+                             ],
+                             "list lines")
+
 application_snapshot("generate_dartanalyzer_snapshot") {
   main_dart = "../../pkg/analyzer_cli/bin/analyzer.dart"
   training_args = [
@@ -25,21 +31,21 @@
   name = "dartanalyzer"
 }
 
-sdk_root = "../../sdk"
-
-create_timestamp_file("sdk_lib_files") {
-  path = rebase_path("$sdk_root/lib")
-  output = "$target_gen_dir/sdk_lib_files.stamp"
-}
+sdk_lib_files = exec_script("../../tools/list_dart_files.py",
+                            [
+                              "absolute",
+                              rebase_path("../../sdk/lib"),
+                            ],
+                            "list lines")
 
 dart_action("generate_summary_strong") {
   deps = [
-    ":sdk_lib_files",
     "../../sdk:copy_libraries",
     "../../sdk:write_version_file",
   ]
   script = "../../pkg/analyzer/tool/summary/build_sdk_summaries.dart"
   packages = "../../.packages"
+  inputs = sdk_lib_files + analyzer_files
   output = "$root_gen_dir/strong.sum"
   outputs = [ output ]
   vm_args = [ "-Dsdk_hash=$sdk_hash" ]
diff --git a/utils/dartdev/BUILD.gn b/utils/dartdev/BUILD.gn
index 7f33d99..c7d8c12 100644
--- a/utils/dartdev/BUILD.gn
+++ b/utils/dartdev/BUILD.gn
@@ -4,6 +4,13 @@
 
 import("../application_snapshot.gni")
 
+dartdev_files = exec_script("../../tools/list_dart_files.py",
+                            [
+                              "absolute",
+                              rebase_path("../../pkg/dartdev"),
+                            ],
+                            "list lines")
+
 group("dartdev") {
   public_deps = [
     ":copy_dartdev_kernel",
@@ -23,6 +30,7 @@
   main_dart = "../../pkg/dartdev/bin/dartdev.dart"
   training_args = []
   deps = [ "../dds:dds" ]
+  inputs = dartdev_files
   output = "$root_gen_dir/dartdev.dill"
 }
 
@@ -37,5 +45,6 @@
   main_dart = "../../pkg/dartdev/bin/dartdev.dart"
   training_args = [ "--help" ]
   deps = [ "../dds:dds" ]
+  inputs = dartdev_files
   output = "$root_gen_dir/dartdev.dart.snapshot"
 }
diff --git a/utils/dartdevc/BUILD.gn b/utils/dartdevc/BUILD.gn
index 74c0cc3..9b9f07c 100644
--- a/utils/dartdevc/BUILD.gn
+++ b/utils/dartdevc/BUILD.gn
@@ -40,6 +40,27 @@
 
 sdk_root = "../../sdk"
 
+sdk_lib_files = exec_script("../../tools/list_dart_files.py",
+                            [
+                              "absolute",
+                              rebase_path("$sdk_root/lib"),
+                            ],
+                            "list lines")
+
+compiler_files = exec_script("../../tools/list_dart_files.py",
+                             [
+                               "absolute",
+                               rebase_path("../../pkg/compiler"),
+                             ],
+                             "list lines")
+
+dev_compiler_files = exec_script("../../tools/list_dart_files.py",
+                                 [
+                                   "absolute",
+                                   rebase_path("../../pkg/dev_compiler"),
+                                 ],
+                                 "list lines")
+
 template("dart2js_compile") {
   assert(defined(invoker.main), "Must specify the main file")
   main = invoker.main
@@ -49,12 +70,12 @@
   abs_output = rebase_path(out)
 
   prebuilt_dart_action(target_name) {
-    deps = invoker.deps + [ "../compiler:compile_dart2js_platform" ]
+    deps = [ "../compiler:compile_dart2js_platform" ]
 
-    inputs = [
-      "$root_out_dir/dart2js_platform.dill",
-      "$root_out_dir/dart2js_outline.dill",
-    ]
+    inputs = sdk_lib_files + compiler_files + dev_compiler_files + [
+               "$root_out_dir/dart2js_platform.dill",
+               "$root_out_dir/dart2js_outline.dill",
+             ]
     outputs = [ out ]
 
     script = "../../pkg/compiler/lib/src/dart2js.dart"
@@ -76,7 +97,6 @@
 dart2js_compile("stack_trace_mapper") {
   main = rebase_path("../../pkg/dev_compiler/web/stack_trace_mapper.dart")
   out = "$root_out_dir/dev_compiler/build/web/dart_stack_trace_mapper.js"
-  deps = [ ":dartdevc_files_stamp" ]
 }
 
 # Builds everything needed to run dartdevc tests using test.dart.
@@ -160,11 +180,16 @@
     deps = [
       ":dartdevc_files_stamp",
       platform_dep,
+
+      # TODO(sigmund): depend only on the compiler and the actual files in the
+      # package
+      "../../pkg:pkg_files_stamp",
     ]
 
     inputs = [
       sdk_outline,
       "$target_gen_dir/dartdevc_files.stamp",
+      "$root_gen_dir/pkg_files.stamp",
     ]
 
     outputs = [
@@ -302,9 +327,17 @@
   }
 
   prebuilt_dart_action(target_name) {
-    deps = [ platform_dep ]
+    deps = [
+      ":dartdevc_files_stamp",
+      "../../pkg:pkg_files_stamp",
+      platform_dep,
+    ]
 
-    inputs = [ platform_input ]
+    inputs = [
+      "$target_gen_dir/dartdevc_files.stamp",
+      "$root_gen_dir/pkg_files.stamp",
+      platform_input,
+    ]
 
     outputs = [
       "$js_gen_dir/amd/dart_sdk.js",
diff --git a/utils/dds/BUILD.gn b/utils/dds/BUILD.gn
index 2a5d36f..dd76925 100644
--- a/utils/dds/BUILD.gn
+++ b/utils/dds/BUILD.gn
@@ -4,6 +4,13 @@
 
 import("../application_snapshot.gni")
 
+dds_files = exec_script("../../tools/list_dart_files.py",
+                        [
+                          "absolute",
+                          rebase_path("../../pkg/dds"),
+                        ],
+                        "list lines")
+
 group("dds") {
   public_deps = [ ":copy_dds_snapshot" ]
 }
@@ -18,5 +25,6 @@
 application_snapshot("generate_dds_snapshot") {
   main_dart = "../../pkg/dds/bin/dds.dart"
   training_args = []
+  inputs = dds_files
   output = "$root_gen_dir/dds.dart.snapshot"
 }