Merge "Change bool, and string properties to *bool, and *string for cc"
diff --git a/android/hooks.go b/android/hooks.go
index 7530f8d..a9bfd33 100644
--- a/android/hooks.go
+++ b/android/hooks.go
@@ -16,7 +16,6 @@
 
 import (
 	"github.com/google/blueprint"
-	"github.com/google/blueprint/proptools"
 )
 
 // This file implements hooks that external module types can use to inject logic into existing
@@ -31,6 +30,7 @@
 	BaseContext
 	AppendProperties(...interface{})
 	PrependProperties(...interface{})
+	CreateModule(blueprint.ModuleFactory, ...interface{})
 }
 
 // Arch hooks are run after the module has been split into architecture variants, and can be used
@@ -51,62 +51,22 @@
 	h.arch = append(h.arch, hook)
 }
 
-type propertyHookContext struct {
-	BaseContext
-
-	module *ModuleBase
-}
-
-func (ctx *propertyHookContext) AppendProperties(props ...interface{}) {
-	for _, p := range props {
-		err := proptools.AppendMatchingProperties(ctx.module.customizableProperties, p, nil)
-		if err != nil {
-			if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
-				ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
-			} else {
-				panic(err)
-			}
-		}
-	}
-}
-
-func (ctx *propertyHookContext) PrependProperties(props ...interface{}) {
-	for _, p := range props {
-		err := proptools.PrependMatchingProperties(ctx.module.customizableProperties, p, nil)
-		if err != nil {
-			if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
-				ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
-			} else {
-				panic(err)
-			}
-		}
-	}
-}
-
-func (x *hooks) runLoadHooks(ctx BaseContext, m *ModuleBase) {
+func (x *hooks) runLoadHooks(ctx LoadHookContext, m *ModuleBase) {
 	if len(x.load) > 0 {
-		mctx := &propertyHookContext{
-			BaseContext: ctx,
-			module:      m,
-		}
 		for _, x := range x.load {
-			x(mctx)
-			if mctx.Failed() {
+			x(ctx)
+			if ctx.Failed() {
 				return
 			}
 		}
 	}
 }
 
-func (x *hooks) runArchHooks(ctx BaseContext, m *ModuleBase) {
+func (x *hooks) runArchHooks(ctx ArchHookContext, m *ModuleBase) {
 	if len(x.arch) > 0 {
-		mctx := &propertyHookContext{
-			BaseContext: ctx,
-			module:      m,
-		}
 		for _, x := range x.arch {
-			x(mctx)
-			if mctx.Failed() {
+			x(ctx)
+			if ctx.Failed() {
 				return
 			}
 		}
@@ -165,12 +125,18 @@
 
 func loadHookMutator(ctx TopDownMutatorContext) {
 	if m, ok := ctx.Module().(Module); ok {
-		m.base().hooks.runLoadHooks(ctx, m.base())
+		// Cast through *androidTopDownMutatorContext because AppendProperties is implemented
+		// on *androidTopDownMutatorContext but not exposed through TopDownMutatorContext
+		var loadHookCtx LoadHookContext = ctx.(*androidTopDownMutatorContext)
+		m.base().hooks.runLoadHooks(loadHookCtx, m.base())
 	}
 }
 
 func archHookMutator(ctx TopDownMutatorContext) {
 	if m, ok := ctx.Module().(Module); ok {
-		m.base().hooks.runArchHooks(ctx, m.base())
+		// Cast through *androidTopDownMutatorContext because AppendProperties is implemented
+		// on *androidTopDownMutatorContext but not exposed through TopDownMutatorContext
+		var archHookCtx ArchHookContext = ctx.(*androidTopDownMutatorContext)
+		m.base().hooks.runArchHooks(archHookCtx, m.base())
 	}
 }
diff --git a/android/mutator.go b/android/mutator.go
index afff700..cc3f1f3 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -16,6 +16,7 @@
 
 import (
 	"github.com/google/blueprint"
+	"github.com/google/blueprint/proptools"
 )
 
 // Phases:
@@ -112,7 +113,7 @@
 
 	OtherModuleExists(name string) bool
 	Rename(name string)
-	Module() blueprint.Module
+	Module() Module
 
 	OtherModuleName(m blueprint.Module) string
 	OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
@@ -192,6 +193,11 @@
 	}
 }
 
+func (a *androidTopDownMutatorContext) Module() Module {
+	module, _ := a.TopDownMutatorContext.Module().(Module)
+	return module
+}
+
 func (a *androidTopDownMutatorContext) VisitDirectDeps(visit func(Module)) {
 	a.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) {
 		if aModule, _ := module.(Module); aModule != nil {
@@ -251,3 +257,31 @@
 		}
 	})
 }
+
+func (a *androidTopDownMutatorContext) AppendProperties(props ...interface{}) {
+	for _, p := range props {
+		err := proptools.AppendMatchingProperties(a.Module().base().customizableProperties,
+			p, nil)
+		if err != nil {
+			if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
+				a.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
+			} else {
+				panic(err)
+			}
+		}
+	}
+}
+
+func (a *androidTopDownMutatorContext) PrependProperties(props ...interface{}) {
+	for _, p := range props {
+		err := proptools.PrependMatchingProperties(a.Module().base().customizableProperties,
+			p, nil)
+		if err != nil {
+			if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
+				a.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
+			} else {
+				panic(err)
+			}
+		}
+	}
+}
diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go
index 2c439f0..6703969 100644
--- a/cc/config/arm_device.go
+++ b/cc/config/arm_device.go
@@ -77,6 +77,7 @@
 			"-mfpu=vfpv3-d16",
 		},
 		"armv7-a-neon": []string{
+			"-march=armv7-a",
 			"-mfloat-abi=softfp",
 			"-mfpu=neon",
 		},
@@ -88,9 +89,6 @@
 	}
 
 	armCpuVariantCflags = map[string][]string{
-		"": []string{
-			"-march=armv7-a",
-		},
 		"cortex-a7": []string{
 			"-mcpu=cortex-a7",
 			"-mfpu=neon-vfpv4",
diff --git a/cmd/multiproduct_kati/Android.bp b/cmd/multiproduct_kati/Android.bp
index b264c35..04a5802 100644
--- a/cmd/multiproduct_kati/Android.bp
+++ b/cmd/multiproduct_kati/Android.bp
@@ -18,6 +18,7 @@
         "soong-ui-build",
         "soong-ui-logger",
         "soong-ui-tracer",
+        "soong-zip",
     ],
     srcs: [
         "main.go",
diff --git a/cmd/multiproduct_kati/main.go b/cmd/multiproduct_kati/main.go
index 1c853d6..e4a05fc 100644
--- a/cmd/multiproduct_kati/main.go
+++ b/cmd/multiproduct_kati/main.go
@@ -30,6 +30,7 @@
 	"android/soong/ui/build"
 	"android/soong/ui/logger"
 	"android/soong/ui/tracer"
+	"android/soong/zip"
 )
 
 // We default to number of cpus / 4, which seems to be the sweet spot for my
@@ -45,7 +46,7 @@
 
 var numJobs = flag.Int("j", detectNumJobs(), "number of parallel kati jobs")
 
-var keep = flag.Bool("keep", false, "keep successful output files")
+var keepArtifacts = flag.Bool("keep", false, "keep archives of artifacts")
 
 var outDir = flag.String("out", "", "path to store output directories (defaults to tmpdir under $OUT when empty)")
 var alternateResultDir = flag.Bool("dist", false, "write select results to $DIST_DIR (or <out>/dist when empty)")
@@ -200,24 +201,19 @@
 		if err := os.MkdirAll(*outDir, 0777); err != nil {
 			log.Fatalf("Failed to create tempdir: %v", err)
 		}
-
-		if !*keep {
-			defer func() {
-				if status.Finished() == 0 {
-					os.RemoveAll(*outDir)
-				}
-			}()
-		}
 	}
 	config.Environment().Set("OUT_DIR", *outDir)
 	log.Println("Output directory:", *outDir)
 
+	logsDir := filepath.Join(config.OutDir(), "logs")
+	os.MkdirAll(logsDir, 0777)
+
 	build.SetupOutDir(buildCtx, config)
 	if *alternateResultDir {
-		logsDir := filepath.Join(config.DistDir(), "logs")
-		os.MkdirAll(logsDir, 0777)
-		log.SetOutput(filepath.Join(logsDir, "soong.log"))
-		trace.SetOutput(filepath.Join(logsDir, "build.trace"))
+		distLogsDir := filepath.Join(config.DistDir(), "logs")
+		os.MkdirAll(distLogsDir, 0777)
+		log.SetOutput(filepath.Join(distLogsDir, "soong.log"))
+		trace.SetOutput(filepath.Join(distLogsDir, "build.trace"))
 	} else {
 		log.SetOutput(filepath.Join(config.OutDir(), "soong.log"))
 		trace.SetOutput(filepath.Join(config.OutDir(), "build.trace"))
@@ -269,17 +265,14 @@
 			})
 
 			productOutDir := filepath.Join(config.OutDir(), product)
-			productLogDir := productOutDir
-			if *alternateResultDir {
-				productLogDir = filepath.Join(config.DistDir(), product)
-				if err := os.MkdirAll(productLogDir, 0777); err != nil {
-					log.Fatalf("Error creating log directory: %v", err)
-				}
-			}
+			productLogDir := filepath.Join(logsDir, product)
 
 			if err := os.MkdirAll(productOutDir, 0777); err != nil {
 				log.Fatalf("Error creating out directory: %v", err)
 			}
+			if err := os.MkdirAll(productLogDir, 0777); err != nil {
+				log.Fatalf("Error creating log directory: %v", err)
+			}
 
 			stdLog = filepath.Join(productLogDir, "std.log")
 			f, err := os.Create(stdLog)
@@ -324,6 +317,26 @@
 						status.Fail(product.config.TargetProduct(), err, product.logFile)
 					})
 
+					defer func() {
+						if *keepArtifacts {
+							args := zip.ZipArgs{
+								FileArgs: []zip.FileArg{
+									{
+										GlobDir:             product.config.OutDir(),
+										SourcePrefixToStrip: product.config.OutDir(),
+									},
+								},
+								OutputFilePath:   filepath.Join(config.OutDir(), product.config.TargetProduct()+".zip"),
+								NumParallelJobs:  runtime.NumCPU(),
+								CompressionLevel: 5,
+							}
+							if err := zip.Run(args); err != nil {
+								log.Fatalf("Error zipping artifacts: %v", err)
+							}
+						}
+						os.RemoveAll(product.config.OutDir())
+					}()
+
 					buildWhat := 0
 					if !*onlyConfig {
 						buildWhat |= build.BuildSoong
@@ -332,9 +345,6 @@
 						}
 					}
 					build.Build(product.ctx, product.config, buildWhat)
-					if !*keep {
-						os.RemoveAll(product.config.OutDir())
-					}
 					status.Finish(product.config.TargetProduct())
 				}()
 			}
@@ -342,6 +352,20 @@
 	}
 	wg2.Wait()
 
+	if *alternateResultDir {
+		args := zip.ZipArgs{
+			FileArgs: []zip.FileArg{
+				{GlobDir: logsDir, SourcePrefixToStrip: logsDir},
+			},
+			OutputFilePath:   filepath.Join(config.DistDir(), "logs.zip"),
+			NumParallelJobs:  runtime.NumCPU(),
+			CompressionLevel: 5,
+		}
+		if err := zip.Run(args); err != nil {
+			log.Fatalf("Error zipping logs: %v", err)
+		}
+	}
+
 	if count := status.Finished(); count > 0 {
 		log.Fatalln(count, "products failed")
 	}
diff --git a/python/androidmk.go b/python/androidmk.go
index 25abdc9..4c94450 100644
--- a/python/androidmk.go
+++ b/python/androidmk.go
@@ -48,11 +48,25 @@
 
 func (p *binaryDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) {
 	ret.Class = "EXECUTABLES"
+
+	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
+		if len(p.binaryProperties.Test_suites) > 0 {
+			fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
+				strings.Join(p.binaryProperties.Test_suites, " "))
+		}
+	})
 	base.subAndroidMk(ret, p.baseInstaller)
 }
 
 func (p *testDecorator) AndroidMk(base *Module, ret *android.AndroidMkData) {
 	ret.Class = "NATIVE_TESTS"
+
+	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
+		if len(p.binaryDecorator.binaryProperties.Test_suites) > 0 {
+			fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
+				strings.Join(p.binaryDecorator.binaryProperties.Test_suites, " "))
+		}
+	})
 	base.subAndroidMk(ret, p.binaryDecorator.baseInstaller)
 }
 
diff --git a/python/binary.go b/python/binary.go
index c2e38bf..95b0606 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -40,6 +40,10 @@
 
 	// append to the name of the output binary.
 	Suffix string `android:"arch_variant"`
+
+	// list of compatibility suites (for example "cts", "vts") that the module should be
+	// installed into.
+	Test_suites []string `android:"arch_variant"`
 }
 
 type binaryDecorator struct {