aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-05-22 11:11:52 -0700
committerColin Cross <ccross@android.com>2018-05-24 14:53:58 -0700
commitae5caf554cb01b2bc73130dfe99c9f5a475b03d9 (patch)
tree71fd459d64024e74738697d546a4509a8f2ded21 /java
parente467f44f9bbfbb969fe867b8a1b2e68f017ac485 (diff)
downloadbuild_soong-ae5caf554cb01b2bc73130dfe99c9f5a475b03d9.tar.gz
build_soong-ae5caf554cb01b2bc73130dfe99c9f5a475b03d9.tar.bz2
build_soong-ae5caf554cb01b2bc73130dfe99c9f5a475b03d9.zip
Add support for android_test modules
android_test module are APKs that can be run as tests, either as standalone unit tests or as instrumentation tests for another APK. Test: m checkbuild Change-Id: I16661701637e4048fd99442029c3e195ebf373a4
Diffstat (limited to 'java')
-rw-r--r--java/androidmk.go13
-rw-r--r--java/app.go60
-rw-r--r--java/java.go4
3 files changed, 65 insertions, 12 deletions
diff --git a/java/androidmk.go b/java/androidmk.go
index 88dc6ef3..bc9544af 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -228,6 +228,19 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData {
}
}
+func (a *AndroidTest) AndroidMk() android.AndroidMkData {
+ data := a.AndroidApp.AndroidMk()
+ data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
+ fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
+ if len(a.testProperties.Test_suites) > 0 {
+ fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
+ strings.Join(a.testProperties.Test_suites, " "))
+ }
+ })
+
+ return data
+}
+
func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
data := a.Library.AndroidMk()
diff --git a/java/app.go b/java/app.go
index ae0592a6..37109b56 100644
--- a/java/app.go
+++ b/java/app.go
@@ -26,6 +26,7 @@ import (
func init() {
android.RegisterModuleType("android_app", AndroidAppFactory)
+ android.RegisterModuleType("android_test", AndroidTestFactory)
}
// AndroidManifest.xml merging
@@ -50,8 +51,6 @@ type appProperties struct {
// list of resource labels to generate individual resource packages
Package_splits []string
-
- Instrumentation_for *string
}
type AndroidApp struct {
@@ -61,6 +60,8 @@ type AndroidApp struct {
certificate certificate
appProperties appProperties
+
+ extraLinkFlags []string
}
func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
@@ -85,14 +86,11 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
}
func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- var linkFlags []string
- if String(a.appProperties.Instrumentation_for) != "" {
- linkFlags = append(linkFlags,
- "--rename-instrumentation-target-package",
- String(a.appProperties.Instrumentation_for))
- } else {
- a.properties.Instrument = true
- }
+ a.generateAndroidBuildActions(ctx)
+}
+
+func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
+ linkFlags := append([]string(nil), a.extraLinkFlags...)
hasProduct := false
for _, f := range a.aaptProperties.Aaptflags {
@@ -188,6 +186,8 @@ func AndroidAppFactory() android.Module {
module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
+ module.Module.properties.Instrument = true
+
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
@@ -198,3 +198,43 @@ func AndroidAppFactory() android.Module {
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
return module
}
+
+type appTestProperties struct {
+ Instrumentation_for *string
+}
+
+type AndroidTest struct {
+ AndroidApp
+
+ appTestProperties appTestProperties
+
+ testProperties testProperties
+}
+
+func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ if String(a.appTestProperties.Instrumentation_for) != "" {
+ a.AndroidApp.extraLinkFlags = append(a.AndroidApp.extraLinkFlags,
+ "--rename-instrumentation-target-package",
+ String(a.appTestProperties.Instrumentation_for))
+ }
+
+ a.generateAndroidBuildActions(ctx)
+}
+
+func AndroidTestFactory() android.Module {
+ module := &AndroidTest{}
+
+ module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
+
+ module.AddProperties(
+ &module.Module.properties,
+ &module.Module.deviceProperties,
+ &module.Module.protoProperties,
+ &module.aaptProperties,
+ &module.appProperties,
+ &module.appTestProperties)
+
+ android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
+
+ return module
+}
diff --git a/java/java.go b/java/java.go
index a4cb65b5..02fdc00f 100644
--- a/java/java.go
+++ b/java/java.go
@@ -212,8 +212,8 @@ type CompilerDeviceProperties struct {
}
Optimize struct {
- // If false, disable all optimization. Defaults to true for apps, false for
- // libraries and tests.
+ // If false, disable all optimization. Defaults to true for android_app and android_test
+ // modules, false for java_library and java_test modules.
Enabled *bool
// If true, optimize for size by removing unused code. Defaults to true for apps,