Rewrite cpp-define-generator

The new method works by generating temporary per-architecture
human-readable object file with the constants embedded in it.
Python script extracts those values and generates the header.

This means the values can now implicitly depend on pointer size,
compile time flags, or ABI specific object layout with no hacks.

Test: test-art-host-gtest-arch_test
Change-Id: Id6e8c77c01f9d6c49cd6d40e3487b56fa4777349
diff --git a/tools/cpp-define-generator/Android.bp b/tools/cpp-define-generator/Android.bp
index a94f404..0d3943e 100644
--- a/tools/cpp-define-generator/Android.bp
+++ b/tools/cpp-define-generator/Android.bp
@@ -14,16 +14,11 @@
 // limitations under the License.
 //
 
-// Build a "data" binary which will hold all the symbol values that will be parsed by the other scripts.
-//
-// Builds are for host only, target-specific define generation is possibly but is trickier and would need extra tooling.
-//
-// In the future we may wish to parameterize this on (32,64)x(read_barrier,no_read_barrier).
-
-cc_binary { // Do not use art_cc_binary because HOST_PREFER_32_BIT is incompatible with genrule.
-    name: "cpp-define-generator-data",
+// This produces human-readable asm_defines.s with the embedded compile-time constants.
+cc_object {
+    name: "asm_defines.s",
     host_supported: true,
-    device_supported: false,
+    device_supported: true,
     defaults: [
         "art_debug_defaults",
         "art_defaults",
@@ -33,20 +28,36 @@
         "art/libdexfile",
         "art/libartbase",
         "art/runtime",
+        "system/core/base/include",
     ],
-    srcs: ["main.cc"],
-    shared_libs: [
-        "libbase",
-    ],
+    // Produce text file rather than binary.
+    cflags: ["-S"],
+    srcs: ["asm_defines.cc"],
 }
 
-// Note: See $OUT_DIR/soong/build.ninja
-// For the exact filename that this generates to run make command on just
-// this rule later.
-genrule {
+// This extracts the compile-time constants from asm_defines.s and creates the header.
+cc_genrule {
     name: "cpp-define-generator-asm-support",
+    host_supported: true,
+    device_supported: true,
+    srcs: [":asm_defines.s"],
     out: ["asm_support_gen.h"],
-    tools: ["cpp-define-generator-data"],
-    tool_files: ["*.def"],
-    cmd: "$(location cpp-define-generator-data) > \"$(out)\"",
+    tool_files: ["make_header.py"],
+    cmd: "$(location make_header.py) \"$(in)\" > \"$(out)\"",
+}
+
+cc_library_headers {
+    name: "cpp-define-generator-definitions",
+    host_supported: true,
+    export_include_dirs: ["."],
+}
+
+python_binary_host {
+    name: "cpp-define-generator-test",
+    main: "make_header_test.py",
+    srcs: [
+        "make_header.py",
+        "make_header_test.py",
+    ],
+    test_suites: ["general-tests"],
 }