Merge "Support .mm files"
diff --git a/android/module.go b/android/module.go
index 110f04c..c0b9c47 100644
--- a/android/module.go
+++ b/android/module.go
@@ -100,6 +100,7 @@
 	Enabled() bool
 	Target() Target
 	InstallInData() bool
+	SkipInstall()
 }
 
 type nameProperties struct {
diff --git a/android/mutator.go b/android/mutator.go
index 8114b3e..3420280 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -46,8 +46,8 @@
 
 	ctx.BottomUp("deps", depsMutator).Parallel()
 
+	ctx.TopDown("prebuilt_select", PrebuiltSelectModuleMutator).Parallel()
 	ctx.BottomUp("prebuilt_replace", PrebuiltReplaceMutator).Parallel()
-	ctx.TopDown("prebuilt_disable", PrebuiltDisableMutator).Parallel()
 
 	register(postDeps)
 }
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 7652429..5f9b4b0 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -21,20 +21,6 @@
 
 var prebuiltDependencyTag blueprint.BaseDependencyTag
 
-func SourceModuleHasPrebuilt(ctx ModuleContext) OptionalPath {
-	var path Path
-	ctx.VisitDirectDeps(func(m blueprint.Module) {
-		if ctx.OtherModuleDependencyTag(m) == prebuiltDependencyTag {
-			p := m.(PrebuiltInterface).Prebuilt()
-			if p.usePrebuilt(ctx) {
-				path = p.Path(ctx)
-			}
-		}
-	})
-
-	return OptionalPathForPath(path)
-}
-
 type Prebuilt struct {
 	Properties struct {
 		Srcs []string `android:"arch_variant"`
@@ -43,6 +29,7 @@
 		Prefer bool `android:"arch_variant"`
 
 		SourceExists bool `blueprint:"mutated"`
+		UsePrebuilt  bool `blueprint:"mutated"`
 	}
 	module Module
 }
@@ -68,11 +55,6 @@
 type PrebuiltInterface interface {
 	Module
 	Prebuilt() *Prebuilt
-	SkipInstall()
-}
-
-type PrebuiltSourceInterface interface {
-	SkipInstall()
 }
 
 // prebuiltMutator ensures that there is always a module with an undecorated name, and marks
@@ -90,6 +72,22 @@
 	}
 }
 
+// PrebuiltSelectModuleMutator marks prebuilts that are overriding source modules, and disables
+// installing the source module.
+func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
+	if s, ok := ctx.Module().(Module); ok {
+		ctx.VisitDirectDeps(func(m blueprint.Module) {
+			if ctx.OtherModuleDependencyTag(m) == prebuiltDependencyTag {
+				p := m.(PrebuiltInterface).Prebuilt()
+				if p.usePrebuilt(ctx, s) {
+					p.Properties.UsePrebuilt = true
+					s.SkipInstall()
+				}
+			}
+		})
+	}
+}
+
 // PrebuiltReplaceMutator replaces dependencies on the source module with dependencies on the
 // prebuilt when both modules exist and the prebuilt should be used.  When the prebuilt should not
 // be used, disable installing it.
@@ -97,7 +95,7 @@
 	if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
 		p := m.Prebuilt()
 		name := m.base().BaseModuleName()
-		if p.usePrebuilt(ctx) {
+		if p.Properties.UsePrebuilt {
 			if p.Properties.SourceExists {
 				ctx.ReplaceDependencies(name)
 			}
@@ -107,21 +105,17 @@
 	}
 }
 
-// PrebuiltDisableMutator disables source modules that have prebuilts that should be used instead.
-func PrebuiltDisableMutator(ctx TopDownMutatorContext) {
-	if s, ok := ctx.Module().(PrebuiltSourceInterface); ok {
-		ctx.VisitDirectDeps(func(m blueprint.Module) {
-			if ctx.OtherModuleDependencyTag(m) == prebuiltDependencyTag {
-				p := m.(PrebuiltInterface).Prebuilt()
-				if p.usePrebuilt(ctx) {
-					s.SkipInstall()
-				}
-			}
-		})
+// usePrebuilt returns true if a prebuilt should be used instead of the source module.  The prebuilt
+// will be used if it is marked "prefer" or if the source module is disabled.
+func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool {
+	if len(p.Properties.Srcs) == 0 {
+		return false
 	}
-}
 
-func (p *Prebuilt) usePrebuilt(ctx BaseContext) bool {
-	// TODO: use p.Properties.Name and ctx.ModuleDir to override prefer
-	return p.Properties.Prefer && len(p.Properties.Srcs) > 0
+	// TODO: use p.Properties.Name and ctx.ModuleDir to override preference
+	if p.Properties.Prefer {
+		return true
+	}
+
+	return !source.Enabled()
 }
diff --git a/java/java.go b/java/java.go
index 689fe75..4527b39 100644
--- a/java/java.go
+++ b/java/java.go
@@ -70,7 +70,7 @@
 	// list of directories that should be excluded from java_resource_dirs
 	Exclude_java_resource_dirs []string `android:"arch_variant"`
 
-	// don't build against the default libraries (core-libart, core-junit,
+	// don't build against the default libraries (legacy-test, core-junit,
 	// ext, and framework for device targets)
 	No_standard_libraries bool
 
@@ -188,7 +188,7 @@
 	}
 }
 
-var defaultJavaLibraries = []string{"core-libart", "core-junit", "ext", "framework"}
+var defaultJavaLibraries = []string{"core-libart", "legacy-test", "ext", "framework"}
 
 func (j *javaBase) DepsMutator(ctx android.BottomUpMutatorContext) {
 	if j, ok := ctx.Module().(JavaModuleType); ok {