Reland "[ DDS ] Fix DDS AOT snapshot build rules"

This is a reland of commit 0a393f1b697671a4bb42ba0ec9b1c4dda91b013b

The problem was that the checks for whether or not dartaotruntime
existed were always returning false on Windows because the ".exe" suffix
wasn't being taken into account. Patchset 2 addresses this.

Original change's description:
> [ DDS ] Fix DDS AOT snapshot build rules
>
> dds_aot.dart.snapshot was not being generated for runtime build targets,
> and dds.dart.snapshot was being built regardless of whether or not we
> were building for an IA32 target.
>
> This change also adds a check for IA32 in 'dart run' so the "Could not
> find dds_aot.dart.snapshot. Have you built the full Dart SDK?" message
> isn't printed when we fall back to using dds.dart.snapshot.
>
> This change also reverts 2cc08595a644cd6761730629af7ad86669655a2a, which
> failed to fix the issue it was attempting to fix.
>
> TEST=pkg/vm_service tests
>
> Change-Id: Ic990082c25b0d022093ad66600332dfb2878709f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341760
> Reviewed-by: Siva Annamalai <asiva@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

TEST=pkg-win-release-try, pkg-win-release-arm64-try, and pkg/vm_service
tests

Change-Id: Ieab41edcb6bffca3be6bf628e357871f28949323
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342640
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 16905da..23d5403 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -50,7 +50,6 @@
     "runtime/vm:kernel_platform_files($host_toolchain)",
     "samples/ffi/http:fake_http",
     "utils/dartdev:dartdev",
-    "utils/dds:dds",
     "utils/kernel-service:kernel-service",
   ]
 
diff --git a/pkg/dartdev/lib/src/commands/run.dart b/pkg/dartdev/lib/src/commands/run.dart
index 940d2bb..52b830d 100644
--- a/pkg/dartdev/lib/src/commands/run.dart
+++ b/pkg/dartdev/lib/src/commands/run.dart
@@ -397,10 +397,15 @@
         ? sdk.ddsAotSnapshot
         : absolute(sdkDir, 'dds_aot.dart.snapshot');
     String execName = sdk.dartAotRuntime;
-    if (!Sdk.checkArtifactExists(snapshotName)) {
-      // An AOT snapshot of dds is not available, we could
-      // be running on the ia32 platform so check for a regular
-      // kernel file being present.
+    // Check to see if the AOT snapshot and dartaotruntime are available.
+    // If not, fall back to running from the AppJIT snapshot.
+    //
+    // This can happen if:
+    //  - The SDK is built for IA32 which doesn't support AOT compilation
+    //  - We only have artifacts available from the 'runtime' build
+    //    configuration, which the VM SDK build bots frequently run from
+    if (!Sdk.checkArtifactExists(snapshotName, logError: false) ||
+        !Sdk.checkArtifactExists(sdk.dartAotRuntime, logError: false)) {
       snapshotName =
           fullSdk ? sdk.ddsSnapshot : absolute(sdkDir, 'dds.dart.snapshot');
       if (!Sdk.checkArtifactExists(snapshotName)) {
diff --git a/pkg/dartdev/lib/src/sdk.dart b/pkg/dartdev/lib/src/sdk.dart
index 962dbdf..105c9a5 100644
--- a/pkg/dartdev/lib/src/sdk.dart
+++ b/pkg/dartdev/lib/src/sdk.dart
@@ -29,7 +29,11 @@
   // if the SDK isn't completely built.
   String get dart => Platform.resolvedExecutable;
 
-  String get dartAotRuntime => path.join(sdkPath, 'bin', 'dartaotruntime');
+  String get dartAotRuntime => path.join(
+        sdkPath,
+        'bin',
+        'dartaotruntime${Platform.isWindows ? '.exe' : ''}',
+      );
 
   String get analysisServerSnapshot => path.absolute(
         sdkPath,
@@ -80,10 +84,13 @@
         'devtools',
       );
 
-  static bool checkArtifactExists(String path) {
+  static bool checkArtifactExists(String path, {bool logError = true}) {
     if (!File(path).existsSync()) {
-      log.stderr('Could not find $path. Have you built the full '
-          'Dart SDK?');
+      if (logError) {
+        log.stderr(
+          'Could not find $path. Have you built the full Dart SDK?',
+        );
+      }
       return false;
     }
     return true;
diff --git a/sdk/lib/_internal/vm/bin/vmservice_io.dart b/sdk/lib/_internal/vm/bin/vmservice_io.dart
index bdd4db0..3a31302 100644
--- a/sdk/lib/_internal/vm/bin/vmservice_io.dart
+++ b/sdk/lib/_internal/vm/bin/vmservice_io.dart
@@ -83,7 +83,9 @@
 
     final dartAotPath = [
       dartDir,
-      fullSdk ? 'dartaotruntime' : 'dart_precompiled_runtime_product',
+      fullSdk
+          ? 'dartaotruntime${Platform.isWindows ? '.exe' : ''}'
+          : 'dart_precompiled_runtime_product${Platform.isWindows ? '.exe' : ''}',
     ].join('/');
     String snapshotName = [
       dartDir,
@@ -91,7 +93,7 @@
       'dds_aot.dart.snapshot',
     ].join('/');
     String execName = dartAotPath;
-    if (!File(snapshotName).existsSync()) {
+    if (!File(snapshotName).existsSync() || !File(dartAotPath).existsSync()) {
       snapshotName = [
         dartDir,
         fullSdk ? 'snapshots' : 'gen',
diff --git a/utils/dartdev/BUILD.gn b/utils/dartdev/BUILD.gn
index 9e9dd6e..b33ec48 100644
--- a/utils/dartdev/BUILD.gn
+++ b/utils/dartdev/BUILD.gn
@@ -22,7 +22,14 @@
 application_snapshot("generate_dartdev_snapshot") {
   main_dart = "../../pkg/dartdev/bin/dartdev.dart"
   training_args = [ "--help" ]
+
   deps = [ "../dds:dds" ]
+
+  # DDS should be run from AOT snapshot on all architectures except IA32/X86.
+  if (dart_target_arch != "ia32" && dart_target_arch != "x86") {
+    deps += [ "../dds:dds_aot" ]
+  }
+
   vm_args = [ "--sound-null-safety" ]
   output = "$root_gen_dir/dartdev.dart.snapshot"
 }