Merge "Simplify bootstrapping"
diff --git a/cc/androidmk.go b/cc/androidmk.go
index d4965d8..831c0fb 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -100,8 +100,7 @@
 			fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DIRS :=", strings.Join(exportedIncludes, " "))
 		}
 
-		fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
-		fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)")
+		fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+outputFile.Ext())
 
 		fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
 
@@ -141,12 +140,10 @@
 
 func (benchmark *benchmarkDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
 	ctx.subAndroidMk(ret, benchmark.binaryDecorator)
-	ctx.subAndroidMk(ret, benchmark.baseInstaller)
 }
 
 func (test *testBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
 	ctx.subAndroidMk(ret, test.binaryDecorator)
-	ctx.subAndroidMk(ret, test.baseInstaller)
 	if Bool(test.Properties.Test_per_src) {
 		ret.SubName = "_" + test.binaryDecorator.Properties.Stem
 	}
@@ -191,6 +188,7 @@
 		path := installer.path.RelPathString()
 		dir, file := filepath.Split(path)
 		stem := strings.TrimSuffix(file, filepath.Ext(file))
+		fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+filepath.Ext(file))
 		fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
 		fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
 		if len(installer.Properties.Symlinks) > 0 {
diff --git a/cc/builder.go b/cc/builder.go
index b84c928..f016cbd 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -43,7 +43,7 @@
 		blueprint.RuleParams{
 			Depfile:     "${out}.d",
 			Deps:        blueprint.DepsGCC,
-			Command:     "$relPwd $ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
+			Command:     "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
 			CommandDeps: []string{"$ccCmd"},
 			Description: "cc $out",
 		},
diff --git a/cc/config/global.go b/cc/config/global.go
index 9d8a25d..f1989a2 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -127,6 +127,13 @@
 	pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
 
 	pctx.StaticVariable("ClangAsanLibDir", "${ClangPath}/lib64/clang/3.8/lib/linux")
+
+	pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
+		if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
+			return override + " ", nil
+		}
+		return "", nil
+	})
 }
 
 var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
diff --git a/cc/test.go b/cc/test.go
index 6ffa178..27b45d7 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -181,7 +181,6 @@
 	testDecorator
 	*binaryDecorator
 	*baseCompiler
-	*baseInstaller
 	Properties TestBinaryProperties
 }
 
@@ -209,14 +208,15 @@
 }
 
 func (test *testBinary) install(ctx ModuleContext, file android.Path) {
-	test.baseInstaller.dir = filepath.Join("nativetest", ctx.ModuleName())
-	test.baseInstaller.dir64 = filepath.Join("nativetest64", ctx.ModuleName())
-	test.baseInstaller.install(ctx, file)
+	test.binaryDecorator.baseInstaller.dir = filepath.Join("nativetest", ctx.ModuleName())
+	test.binaryDecorator.baseInstaller.dir64 = filepath.Join("nativetest64", ctx.ModuleName())
+	test.binaryDecorator.baseInstaller.install(ctx, file)
 }
 
 func NewTest(hod android.HostOrDeviceSupported) *Module {
 	module, binary := NewBinary(hod)
 	module.multilib = android.MultilibBoth
+	binary.baseInstaller = NewTestInstaller()
 
 	test := &testBinary{
 		testDecorator: testDecorator{
@@ -224,7 +224,6 @@
 		},
 		binaryDecorator: binary,
 		baseCompiler:    NewBaseCompiler(),
-		baseInstaller:   NewTestInstaller(),
 	}
 	test.testDecorator.Properties.Gtest = true
 	module.compiler = test
@@ -275,7 +274,6 @@
 
 type benchmarkDecorator struct {
 	*binaryDecorator
-	*baseInstaller
 }
 
 func (benchmark *benchmarkDecorator) linkerInit(ctx BaseModuleContext) {
@@ -294,18 +292,18 @@
 }
 
 func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) {
-	benchmark.baseInstaller.dir = filepath.Join("nativetest", ctx.ModuleName())
-	benchmark.baseInstaller.dir64 = filepath.Join("nativetest64", ctx.ModuleName())
-	benchmark.baseInstaller.install(ctx, file)
+	benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("nativetest", ctx.ModuleName())
+	benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("nativetest64", ctx.ModuleName())
+	benchmark.binaryDecorator.baseInstaller.install(ctx, file)
 }
 
 func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
 	module, binary := NewBinary(hod)
 	module.multilib = android.MultilibBoth
+	binary.baseInstaller = NewTestInstaller()
 
 	benchmark := &benchmarkDecorator{
 		binaryDecorator: binary,
-		baseInstaller:   NewTestInstaller(),
 	}
 	module.linker = benchmark
 	module.installer = benchmark
diff --git a/root.bp b/root.bp
index c4f2d57..c42dd58 100644
--- a/root.bp
+++ b/root.bp
@@ -12,6 +12,7 @@
     "build/tools/*",
     "dalvik",
     "external/*",
+    "frameworks/av",
     "frameworks/base",
     "frameworks/native",
     "hardware/*",