Convert art gtests to Android.bp

This splits the compilation and running of the art gtests into two
separate locations.  The tests are now compiled in multiple Android.bp
modules in each directory.  art.go collects the installed locations of
each test and exports it as make variables.  art/build/Android.gtest.mk
converts the list into the rules to run the tests.

This has a few changes in behavior:
  - The rules to build tests are now always defined, and will build as
    part of mmma art or make checkbuild.
  - Host tests are no longer installed into out/host/linux-x86/bin, they
    are in out/host/linux-x86/nativetest[64]/<module name>/<test name>
  - Target tests are now in
    /data/nativetest[64]/art/<arch>/<module name>/<test name>

Test: mmma -j art
Test: m -j test-art-host
Test: m -j test-art-target
Change-Id: Iabcd99d43890e6b693688422b07a283c3226a496
diff --git a/build/codegen.go b/build/codegen.go
index d98ca4f..ba6f214 100644
--- a/build/codegen.go
+++ b/build/codegen.go
@@ -22,9 +22,11 @@
 	"android/soong/android"
 	"sort"
 	"strings"
+
+	"github.com/google/blueprint"
 )
 
-func codegen(ctx android.LoadHookContext, c *codegenProperties) {
+func codegen(ctx android.LoadHookContext, c *codegenProperties, library bool) {
 	var hostArches, deviceArches []string
 
 	e := envDefault(ctx, "ART_HOST_CODEGEN_ARCHS", "")
@@ -41,54 +43,77 @@
 		deviceArches = strings.Split(e, " ")
 	}
 
-	type props struct {
-		Target struct {
-			Android *codegenArchProperties
-			Host    *codegenArchProperties
+	addCodegenArchProperties := func(host bool, archName string) {
+		type props struct {
+			Target struct {
+				Android *CodegenCommonArchProperties
+				Host    *CodegenCommonArchProperties
+			}
 		}
-	}
 
-	addCodegenArchProperties := func(p *props, hod **codegenArchProperties, arch string) {
-		switch arch {
+		type libraryProps struct {
+			Target struct {
+				Android *CodegenLibraryArchProperties
+				Host    *CodegenLibraryArchProperties
+			}
+		}
+
+		var arch *codegenArchProperties
+		switch archName {
 		case "arm":
-			*hod = &c.Codegen.Arm
+			arch = &c.Codegen.Arm
 		case "arm64":
-			*hod = &c.Codegen.Arm64
+			arch = &c.Codegen.Arm64
 		case "mips":
-			*hod = &c.Codegen.Mips
+			arch = &c.Codegen.Mips
 		case "mips64":
-			*hod = &c.Codegen.Mips64
+			arch = &c.Codegen.Mips64
 		case "x86":
-			*hod = &c.Codegen.X86
+			arch = &c.Codegen.X86
 		case "x86_64":
-			*hod = &c.Codegen.X86_64
+			arch = &c.Codegen.X86_64
 		default:
-			ctx.ModuleErrorf("Unknown codegen architecture %q", arch)
+			ctx.ModuleErrorf("Unknown codegen architecture %q", archName)
 			return
 		}
+
+		p := &props{}
+		l := &libraryProps{}
+		if host {
+			p.Target.Host = &arch.CodegenCommonArchProperties
+			l.Target.Host = &arch.CodegenLibraryArchProperties
+		} else {
+			p.Target.Android = &arch.CodegenCommonArchProperties
+			l.Target.Android = &arch.CodegenLibraryArchProperties
+		}
+
 		ctx.AppendProperties(p)
+		if library {
+			ctx.AppendProperties(l)
+		}
 	}
 
-	for _, a := range deviceArches {
-		p := &props{}
-		addCodegenArchProperties(p, &p.Target.Android, a)
+	for _, arch := range deviceArches {
+		addCodegenArchProperties(false, arch)
 		if ctx.Failed() {
 			return
 		}
 	}
 
-	for _, a := range hostArches {
-		p := &props{}
-		addCodegenArchProperties(p, &p.Target.Host, a)
+	for _, arch := range hostArches {
+		addCodegenArchProperties(true, arch)
 		if ctx.Failed() {
 			return
 		}
 	}
 }
 
-type codegenArchProperties struct {
+type CodegenCommonArchProperties struct {
 	Srcs   []string
 	Cflags []string
+}
+
+type CodegenLibraryArchProperties struct {
 	Static struct {
 		Whole_static_libs []string
 	}
@@ -97,6 +122,11 @@
 	}
 }
 
+type codegenArchProperties struct {
+	CodegenCommonArchProperties
+	CodegenLibraryArchProperties
+}
+
 type codegenProperties struct {
 	Codegen struct {
 		Arm, Arm64, Mips, Mips64, X86, X86_64 codegenArchProperties
@@ -104,6 +134,7 @@
 }
 
 type codegenCustomizer struct {
+	library           bool
 	codegenProperties codegenProperties
 }
 
@@ -127,3 +158,11 @@
 	sort.Strings(ret)
 	return ret
 }
+
+func installCodegenCustomizer(module blueprint.Module, props []interface{}, library bool) []interface{} {
+	c := &codegenProperties{}
+	android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, library) })
+	props = append(props, c)
+
+	return props
+}