[dyn_modules] add snapshot target for faster iteration.

This adds a target for running pkg/dynamic_modules/test/runner/main.dart from
an aot snapshot, useful when repeating runs for local iteration.

I'm not including it with other build targets or using it in the
test_matrix because each bot only runs this script once, so it doesn't
provide much savings there.

Change-Id: I20fe50a82d2a59aca6a0e697658b26b5b7da97c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480744
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
diff --git a/pkg/dynamic_modules/test/runner/util.dart b/pkg/dynamic_modules/test/runner/util.dart
index cfe7384..aa611ad 100644
--- a/pkg/dynamic_modules/test/runner/util.dart
+++ b/pkg/dynamic_modules/test/runner/util.dart
@@ -14,12 +14,17 @@
 /// Note: we don't search for the directory "sdk" because this may not be
 /// available when running this test in a shard.
 Uri repoRoot = (() {
+  var root = Platform.environment['REPO_ROOT'];
+  if (root != null) return Uri.base.resolve(root);
   Uri script = Platform.script;
   var segments = script.pathSegments;
   var index = segments.lastIndexOf('pkg');
   if (index == -1) {
-    exitCode = 1;
-    throw "error: cannot find the root of the Dart SDK";
+    index = segments.lastIndexOf(_outFolder); // running from snapshot
+    if (index == -1) {
+      exitCode = 1;
+      throw "error: cannot find the root of the Dart SDK";
+    }
   }
   return script.resolve("../" * (segments.length - index - 1));
 })();
diff --git a/utils/dynamic_module_runner/BUILD.gn b/utils/dynamic_module_runner/BUILD.gn
index 42abc5a..d550347d 100644
--- a/utils/dynamic_module_runner/BUILD.gn
+++ b/utils/dynamic_module_runner/BUILD.gn
@@ -17,3 +17,8 @@
       [ "--dynamic-interface=" + rebase_path(
             "$_dart_root/utils/dynamic_module_runner/dynamic_interface.yaml") ]
 }
+
+aot_snapshot("dynamic_modules_test_suite_snapshot") {
+  main_dart = "../../pkg/dynamic_modules/test/runner/main.dart"
+  name = "dynamic_modules_test_suite"
+}