Reland: "ART: Hook Runtime APEX checker into build"

This reverts commit 9ba8a877f003f715863d0942cc73e5effe3183b0.

Reason for revert: https://android-review.googlesource.com/c/platform/build/soong/+/894073 fixes the problem

Change-Id: I2e5e0ace82056c3533913a537cdc2841fa11bbde
diff --git a/Android.mk b/Android.mk
index 526cd59..1a7ed43 100644
--- a/Android.mk
+++ b/Android.mk
@@ -352,13 +352,18 @@
   # Module with both release and debug variants, as well as
   # additional tools.
   TARGET_RUNTIME_APEX := com.android.runtime.debug
+  APEX_TEST_MODULE := art-check-debug-apex-gen-fakebin
 else
   # Release module (without debug variants nor tools).
   TARGET_RUNTIME_APEX := com.android.runtime.release
+  APEX_TEST_MODULE := art-check-release-apex-gen-fakebin
 endif
 
 LOCAL_MODULE := com.android.runtime
 LOCAL_REQUIRED_MODULES := $(TARGET_RUNTIME_APEX)
+ifneq ($(HOST_OS),darwin)
+  LOCAL_REQUIRED_MODULES += $(APEX_TEST_MODULE)
+endif
 
 # Clear locally used variable.
 art_target_include_debug_build :=
diff --git a/build/apex/Android.bp b/build/apex/Android.bp
index 47a1e4b..7e82944 100644
--- a/build/apex/Android.bp
+++ b/build/apex/Android.bp
@@ -231,3 +231,72 @@
         },
     },
 }
+
+python_binary_host {
+    name: "art-apex-tester",
+    srcs: ["art_apex_test.py"],
+    main: "art_apex_test.py",
+    version: {
+        py2: {
+            enabled: false,
+        },
+        py3: {
+            enabled: true,
+        },
+    },
+}
+
+// Genrules so we can run the checker, and empty Java library so that it gets executed.
+
+genrule {
+    name: "art-check-release-apex-gen",
+    srcs: [":com.android.runtime.release"],
+    tools: [
+        "art-apex-tester",
+        "debugfs",
+    ],
+    cmd: "$(location art-apex-tester)"
+              + " --debugfs $(location debugfs)"
+              + " --tmpdir $(genDir)"
+              + " $(in)"
+         + " && touch $(out)",
+    out: ["art-check-release-apex-gen.dummy"],
+}
+cc_prebuilt_binary {
+    name: "art-check-release-apex-gen-fakebin",
+    srcs: [":art-check-release-apex-gen"],
+    host_supported: true,
+    device_supported: false,
+    target: {
+        darwin: {
+            enabled: false,  // No python3.
+        },
+    },
+}
+
+genrule {
+    name: "art-check-debug-apex-gen",
+    srcs: [":com.android.runtime.debug"],
+    tools: [
+        "art-apex-tester",
+        "debugfs",
+    ],
+    cmd: "$(location art-apex-tester)"
+              + " --debugfs $(location debugfs)"
+              + " --tmpdir $(genDir)"
+              + " --debug"
+              + " $(in)"
+         + " && touch $(out)",
+    out: ["art-check-debug-apex-gen.dummy"],
+}
+cc_prebuilt_binary {
+    name: "art-check-debug-apex-gen-fakebin",
+    srcs: [":art-check-debug-apex-gen"],
+    host_supported: true,
+    device_supported: false,
+    target: {
+        darwin: {
+            enabled: false,  // No python3.
+        },
+    },
+}