Support CUSTOM_TARGET_LINKER

Support overriding the dynamic linker setting in ART binaries when
CUSTOM_TARGET_LINKER is set.  Used for ART testing of new binaries on a
device flashed to an old platform.

Change-Id: I20396a1bedd37cdf884d0c5a68f93b9a3e7e10b2
diff --git a/build/art.go b/build/art.go
index ffe870b..d41b407 100644
--- a/build/art.go
+++ b/build/art.go
@@ -155,8 +155,24 @@
 
 type artGlobalDefaults struct{}
 
+func (a *artLinkerCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
+	linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
+	if linker != "" {
+		type props struct {
+			DynamicLinker string
+		}
+
+		p := &props{}
+		p.DynamicLinker = linker
+		ctx.AppendProperties(p)
+	}
+}
+
+type artLinkerCustomizer struct{}
+
 func init() {
 	soong.RegisterModuleType("art_cc_library", artLibrary)
+	soong.RegisterModuleType("art_cc_binary", artBinary)
 	soong.RegisterModuleType("art_cc_defaults", artDefaultsFactory)
 	soong.RegisterModuleType("art_global_defaults", artGlobalDefaultsFactory)
 }
@@ -187,6 +203,14 @@
 	return module, props
 }
 
+func artBinary() (blueprint.Module, []interface{}) {
+	binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
+	module, props := binary.Init()
+
+	android.AddCustomizer(binary, &artLinkerCustomizer{})
+	return module, props
+}
+
 func envDefault(ctx android.BaseContext, key string, defaultValue string) string {
 	ret := ctx.AConfig().Getenv(key)
 	if ret == "" {