summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rwxr-xr-xjava/app.go55
-rw-r--r--java/app_test.go115
-rw-r--r--java/builder.go3
-rw-r--r--java/config/config.go2
-rw-r--r--java/java.go15
-rw-r--r--java/java_test.go64
-rw-r--r--java/system_modules.go31
7 files changed, 270 insertions, 15 deletions
diff --git a/java/app.go b/java/app.go
index 05fa50598..e9941f2d2 100755
--- a/java/app.go
+++ b/java/app.go
@@ -644,20 +644,38 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
a.generateAndroidBuildActions(ctx)
- a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config,
+ testConfig := tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config,
a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, a.testProperties.Auto_gen_config)
+ a.testConfig = a.FixTestConfig(ctx, testConfig)
+ a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
+}
+
+func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path {
+ if testConfig == nil {
+ return nil
+ }
+
+ fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", "AndroidTest.xml")
+ rule := android.NewRuleBuilder()
+ command := rule.Command().BuiltTool(ctx, "test_config_fixer").Input(testConfig).Output(fixedConfig)
+ fixNeeded := false
+
+ if ctx.ModuleName() != a.installApkName {
+ fixNeeded = true
+ command.FlagWithArg("--test-file-name ", a.installApkName+".apk")
+ }
+
if a.overridableAppProperties.Package_name != nil {
- fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", "AndroidTest.xml")
- rule := android.NewRuleBuilder()
- rule.Command().BuiltTool(ctx, "test_config_fixer").
- FlagWithInput("--manifest ", a.manifestPath).
- FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name).
- Input(a.testConfig).
- Output(fixedConfig)
+ fixNeeded = true
+ command.FlagWithInput("--manifest ", a.manifestPath).
+ FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name)
+ }
+
+ if fixNeeded {
rule.Build(pctx, ctx, "fix_test_config", "fix test config")
- a.testConfig = fixedConfig
+ return fixedConfig
}
- a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
+ return testConfig
}
func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -752,6 +770,7 @@ func AndroidTestHelperAppFactory() android.Module {
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
+ android.InitApexModule(module)
return module
}
@@ -925,6 +944,16 @@ func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) {
func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
+ // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing
+ // with them may invalidate pre-existing signature data.
+ if ctx.InstallInTestcases() && Bool(a.properties.Presigned) {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Output: outputPath,
+ Input: inputPath,
+ })
+ return
+ }
rule := android.NewRuleBuilder()
rule.Command().
Textf(`if (zipinfo %s 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
@@ -1002,6 +1031,8 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext
var installDir android.InstallPath
if Bool(a.properties.Privileged) {
installDir = android.PathForModuleInstall(ctx, "priv-app", a.BaseModuleName())
+ } else if ctx.InstallInTestcases() {
+ installDir = android.PathForModuleInstall(ctx, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch())
} else {
installDir = android.PathForModuleInstall(ctx, "app", a.BaseModuleName())
}
@@ -1158,6 +1189,10 @@ func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContex
a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
}
+func (a *AndroidTestImport) InstallInTestcases() bool {
+ return true
+}
+
// android_test_import imports a prebuilt test apk with additional processing specified in the
// module. DPI or arch variant configurations can be made as with android_app_import.
func AndroidTestImportFactory() android.Module {
diff --git a/java/app_test.go b/java/app_test.go
index 9bdef4e92..6f89da410 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -1305,6 +1305,87 @@ func TestOverrideAndroidTest(t *testing.T) {
}
}
+func TestAndroidTest_FixTestConfig(t *testing.T) {
+ ctx, _ := testJava(t, `
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ package_name: "com.android.foo",
+ sdk_version: "current",
+ }
+
+ android_test {
+ name: "foo_test",
+ srcs: ["b.java"],
+ instrumentation_for: "foo",
+ }
+
+ android_test {
+ name: "bar_test",
+ srcs: ["b.java"],
+ package_name: "com.android.bar.test",
+ instrumentation_for: "foo",
+ }
+
+ override_android_test {
+ name: "baz_test",
+ base: "foo_test",
+ package_name: "com.android.baz.test",
+ }
+ `)
+
+ testCases := []struct {
+ moduleName string
+ variantName string
+ expectedFlags []string
+ }{
+ {
+ moduleName: "foo_test",
+ variantName: "android_common",
+ },
+ {
+ moduleName: "bar_test",
+ variantName: "android_common",
+ expectedFlags: []string{
+ "--manifest " + buildDir + "/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml",
+ "--package-name com.android.bar.test",
+ },
+ },
+ {
+ moduleName: "foo_test",
+ variantName: "android_common_baz_test",
+ expectedFlags: []string{
+ "--manifest " + buildDir +
+ "/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
+ "--package-name com.android.baz.test",
+ "--test-file-name baz_test.apk",
+ },
+ },
+ }
+
+ for _, test := range testCases {
+ variant := ctx.ModuleForTests(test.moduleName, test.variantName)
+ params := variant.MaybeOutput("test_config_fixer/AndroidTest.xml")
+
+ if len(test.expectedFlags) > 0 {
+ if params.Rule == nil {
+ t.Errorf("test_config_fixer was expected to run, but didn't")
+ } else {
+ for _, flag := range test.expectedFlags {
+ if !strings.Contains(params.RuleParams.Command, flag) {
+ t.Errorf("Flag %q was not found in command: %q", flag, params.RuleParams.Command)
+ }
+ }
+ }
+ } else {
+ if params.Rule != nil {
+ t.Errorf("test_config_fixer was not expected to run, but did: %q", params.RuleParams.Command)
+ }
+ }
+
+ }
+}
+
func TestAndroidAppImport(t *testing.T) {
ctx, _ := testJava(t, `
android_app_import {
@@ -1628,6 +1709,40 @@ func TestAndroidTestImport(t *testing.T) {
}
}
+func TestAndroidTestImport_NoJinUncompressForPresigned(t *testing.T) {
+ ctx, _ := testJava(t, `
+ android_test_import {
+ name: "foo",
+ apk: "prebuilts/apk/app.apk",
+ certificate: "cert/new_cert",
+ data: [
+ "testdata/data",
+ ],
+ }
+
+ android_test_import {
+ name: "foo_presigned",
+ apk: "prebuilts/apk/app.apk",
+ presigned: true,
+ data: [
+ "testdata/data",
+ ],
+ }
+ `)
+
+ variant := ctx.ModuleForTests("foo", "android_common")
+ jniRule := variant.Output("jnis-uncompressed/foo.apk").RuleParams.Command
+ if !strings.HasPrefix(jniRule, "if (zipinfo") {
+ t.Errorf("Unexpected JNI uncompress rule command: " + jniRule)
+ }
+
+ variant = ctx.ModuleForTests("foo_presigned", "android_common")
+ jniRule = variant.Output("jnis-uncompressed/foo_presigned.apk").BuildParams.Rule.String()
+ if jniRule != android.Cp.String() {
+ t.Errorf("Unexpected JNI uncompress rule: " + jniRule)
+ }
+}
+
func TestStl(t *testing.T) {
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
cc_library {
diff --git a/java/builder.go b/java/builder.go
index 417a7fa54..26a49ea53 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -64,6 +64,8 @@ var (
_ = pctx.VariableFunc("kytheCorpus",
func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() })
+ _ = pctx.VariableFunc("kytheCuEncoding",
+ func(ctx android.PackageVarContext) string { return ctx.Config().XrefCuEncoding() })
_ = pctx.SourcePathVariable("kytheVnames", "build/soong/vnames.json")
// Run it with -add-opens=java.base/java.nio=ALL-UNNAMED to avoid JDK9's warning about
// "Illegal reflective access by com.google.protobuf.Utf8$UnsafeProcessor ...
@@ -76,6 +78,7 @@ var (
`KYTHE_ROOT_DIRECTORY=. KYTHE_OUTPUT_FILE=$out ` +
`KYTHE_CORPUS=${kytheCorpus} ` +
`KYTHE_VNAMES=${kytheVnames} ` +
+ `KYTHE_KZIP_ENCODING=${kytheCuEncoding} ` +
`${config.SoongJavacWrapper} ${config.JavaCmd} ` +
`--add-opens=java.base/java.nio=ALL-UNNAMED ` +
`-jar ${config.JavaKytheExtractorJar} ` +
diff --git a/java/config/config.go b/java/config/config.go
index 97384545e..6da7279c3 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -45,7 +45,9 @@ var (
"core-icu4j",
"core-oj",
"core-libart",
+ // TODO: Could this be all updatable bootclasspath jars?
"updatable-media",
+ "framework-sdkextensions",
"ike",
}
)
diff --git a/java/java.go b/java/java.go
index a546cd524..4c6a5a5ac 100644
--- a/java/java.go
+++ b/java/java.go
@@ -500,6 +500,14 @@ var (
usesLibTag = dependencyTag{name: "uses-library"}
)
+func IsLibDepTag(depTag blueprint.DependencyTag) bool {
+ return depTag == libTag
+}
+
+func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
+ return depTag == staticLibTag
+}
+
type sdkDep struct {
useModule, useFiles, useDefaultLibs, invalidVersion bool
@@ -619,12 +627,9 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
}
linkType, _ := j.getLinkType(ctx.ModuleName())
- if linkType == javaSystem {
+ // only platform modules can use internal props
+ if linkType != javaPlatform {
ret[idx] = stub
- } else if linkType != javaPlatform {
- ctx.PropertyErrorf("sdk_version",
- "can't link against sysprop_library %q from a module using public or core API",
- lib)
}
}
diff --git a/java/java_test.go b/java/java_test.go
index 30a8ca682..a2788cb8e 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1227,3 +1227,67 @@ func TestPatchModule(t *testing.T) {
checkPatchModuleFlag(t, ctx, "baz", expected)
})
}
+
+func TestJavaSystemModules(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_system_modules {
+ name: "system-modules",
+ libs: ["system-module1", "system-module2"],
+ }
+ java_library {
+ name: "system-module1",
+ srcs: ["a.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ }
+ java_library {
+ name: "system-module2",
+ srcs: ["b.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ }
+ `)
+
+ // check the existence of the module
+ systemModules := ctx.ModuleForTests("system-modules", "android_common")
+
+ cmd := systemModules.Rule("jarsTosystemModules")
+
+ // make sure the command compiles against the supplied modules.
+ for _, module := range []string{"system-module1.jar", "system-module2.jar"} {
+ if !strings.Contains(cmd.Args["classpath"], module) {
+ t.Errorf("system modules classpath %v does not contain %q", cmd.Args["classpath"],
+ module)
+ }
+ }
+}
+
+func TestJavaSystemModulesImport(t *testing.T) {
+ ctx, _ := testJava(t, `
+ java_system_modules_import {
+ name: "system-modules",
+ libs: ["system-module1", "system-module2"],
+ }
+ java_import {
+ name: "system-module1",
+ jars: ["a.jar"],
+ }
+ java_import {
+ name: "system-module2",
+ jars: ["b.jar"],
+ }
+ `)
+
+ // check the existence of the module
+ systemModules := ctx.ModuleForTests("system-modules", "android_common")
+
+ cmd := systemModules.Rule("jarsTosystemModules")
+
+ // make sure the command compiles against the supplied modules.
+ for _, module := range []string{"system-module1.jar", "system-module2.jar"} {
+ if !strings.Contains(cmd.Args["classpath"], module) {
+ t.Errorf("system modules classpath %v does not contain %q", cmd.Args["classpath"],
+ module)
+ }
+ }
+}
diff --git a/java/system_modules.go b/java/system_modules.go
index ed2fc1856..92297c416 100644
--- a/java/system_modules.go
+++ b/java/system_modules.go
@@ -35,6 +35,7 @@ func init() {
func RegisterSystemModulesBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_system_modules", SystemModulesFactory)
+ ctx.RegisterModuleType("java_system_modules_import", systemModulesImportFactory)
}
var (
@@ -92,6 +93,9 @@ func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths)
return outDir, outputs.Paths()
}
+// java_system_modules creates a system module from a set of java libraries that can
+// be referenced from the system_modules property. It must contain at a minimum the
+// java.base module which must include classes from java.lang amongst other java packages.
func SystemModulesFactory() android.Module {
module := &SystemModules{}
module.AddProperties(&module.properties)
@@ -157,3 +161,30 @@ func (system *SystemModules) AndroidMk() android.AndroidMkData {
},
}
}
+
+// A prebuilt version of java_system_modules. It does not import the
+// generated system module, it generates the system module from imported
+// java libraries in the same way that java_system_modules does. It just
+// acts as a prebuilt, i.e. can have the same base name as another module
+// type and the one to use is selected at runtime.
+func systemModulesImportFactory() android.Module {
+ module := &systemModulesImport{}
+ module.AddProperties(&module.properties)
+ android.InitPrebuiltModule(module, &module.properties.Libs)
+ android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
+ android.InitDefaultableModule(module)
+ return module
+}
+
+type systemModulesImport struct {
+ SystemModules
+ prebuilt android.Prebuilt
+}
+
+func (system *systemModulesImport) Name() string {
+ return system.prebuilt.Name(system.ModuleBase.Name())
+}
+
+func (system *systemModulesImport) Prebuilt() *android.Prebuilt {
+ return &system.prebuilt
+}