Merge "Fixups after llvm rebase"
diff --git a/android/module.go b/android/module.go
index 2b93d8e..d485fbc 100644
--- a/android/module.go
+++ b/android/module.go
@@ -836,12 +836,21 @@
 	return &buildTargetSingleton{}
 }
 
+func parentDir(dir string) string {
+	dir, _ = filepath.Split(dir)
+	return filepath.Clean(dir)
+}
+
 type buildTargetSingleton struct{}
 
 func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
 	checkbuildDeps := []string{}
 
-	dirModules := make(map[string][]string)
+	mmTarget := func(dir string) string {
+		return filepath.Join("mm", dir)
+	}
+
+	modulesInDir := make(map[string][]string)
 
 	ctx.VisitAllModules(func(module blueprint.Module) {
 		if a, ok := module.(Module); ok {
@@ -851,11 +860,11 @@
 
 			if checkbuildTarget != "" {
 				checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
-				dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget)
+				modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
 			}
 
 			if installTarget != "" {
-				dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget)
+				modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
 			}
 		}
 	})
@@ -873,13 +882,35 @@
 		Optional:  true,
 	})
 
-	// Create a mm/<directory> target that depends on all modules in a directory
-	dirs := sortedKeys(dirModules)
+	// Ensure ancestor directories are in modulesInDir
+	dirs := sortedKeys(modulesInDir)
+	for _, dir := range dirs {
+		dir := parentDir(dir)
+		for dir != "." && dir != "/" {
+			if _, exists := modulesInDir[dir]; exists {
+				break
+			}
+			modulesInDir[dir] = nil
+			dir = parentDir(dir)
+		}
+	}
+
+	// Make directories build their direct subdirectories
+	dirs = sortedKeys(modulesInDir)
+	for _, dir := range dirs {
+		p := parentDir(dir)
+		if p != "." && p != "/" {
+			modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
+		}
+	}
+
+	// Create a mm/<directory> target that depends on all modules in a directory, and depends
+	// on the mm/* targets of all of its subdirectories that contain Android.bp files.
 	for _, dir := range dirs {
 		ctx.Build(pctx, blueprint.BuildParams{
 			Rule:      blueprint.Phony,
-			Outputs:   []string{filepath.Join("mm", dir)},
-			Implicits: dirModules[dir],
+			Outputs:   []string{mmTarget(dir)},
+			Implicits: modulesInDir[dir],
 			// HACK: checkbuild should be an optional build, but force it
 			// enabled for now in standalone builds
 			Optional: ctx.Config().(Config).EmbeddedInMake(),
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 481dbb4..f853b13 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -200,6 +200,13 @@
 
 func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
 	ctx.subAndroidMk(ret, benchmark.binaryDecorator)
+	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
+		if len(benchmark.Properties.Test_suites) > 0 {
+			fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
+				strings.Join(benchmark.Properties.Test_suites, " "))
+		}
+		return nil
+	})
 }
 
 func (test *testBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
diff --git a/cc/test.go b/cc/test.go
index 145b5b0..448f089 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -299,8 +299,15 @@
 	return module
 }
 
+type BenchmarkProperties struct {
+	// list of compatibility suites (for example "cts", "vts") that the module should be
+	// installed into.
+	Test_suites []string
+}
+
 type benchmarkDecorator struct {
 	*binaryDecorator
+	Properties BenchmarkProperties
 }
 
 func (benchmark *benchmarkDecorator) linkerInit(ctx BaseModuleContext) {
@@ -312,6 +319,12 @@
 	benchmark.binaryDecorator.linkerInit(ctx)
 }
 
+func (benchmark *benchmarkDecorator) linkerProps() []interface{} {
+	props := benchmark.binaryDecorator.linkerProps()
+	props = append(props, &benchmark.Properties)
+	return props
+}
+
 func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
 	deps = benchmark.binaryDecorator.linkerDeps(ctx, deps)
 	deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark")
diff --git a/root.bp b/root.bp
index 4f9775b..4c29f4d 100644
--- a/root.bp
+++ b/root.bp
@@ -20,6 +20,7 @@
     "frameworks/*",
     "frameworks/compile/*",
     "frameworks/hardware/interfaces",
+    "frameworks/opt/net/wifi",
     "hardware/*",
     "libcore",
     "libnativehelper",