summaryrefslogtreecommitdiff
path: root/java/java_test.go
diff options
context:
space:
mode:
authorJeongik Cha <jeongik@google.com>2019-10-29 15:44:45 +0900
committerJeongik Cha <jeongik@google.com>2019-11-06 19:42:42 +0900
commit2cc570dc63232b3fcbab00fa65292abeb7828376 (patch)
tree4d4a531a54c7857ef2bbde6a77de4b95cf083ff3 /java/java_test.go
parentaf60d490ff6fdd716b343e0b29ce5b2bb95e7829 (diff)
Enforce hidden apis usage in product(soong)
Only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set, every app and java library in product cannot use hidden APIs anymore. checkSdkVersion() checks if sdk_version of app and library is narrow enough, checkLinkType() checks every library that app links agianst Bug: 132780927 Test: m Test: set PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE, and check whether build error occurs. Change-Id: Ic630503b875040f730feda4fef826ed6d71da111
Diffstat (limited to 'java/java_test.go')
-rw-r--r--java/java_test.go51
1 files changed, 36 insertions, 15 deletions
diff --git a/java/java_test.go b/java/java_test.go
index a6ae50375..e3e45d769 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -27,6 +27,8 @@ import (
"android/soong/cc"
"android/soong/dexpreopt"
"android/soong/genrule"
+
+ "github.com/google/blueprint/proptools"
)
var buildDir string
@@ -228,9 +230,13 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) {
android.FailIfErrored(t, errs)
}
-func testJavaError(t *testing.T, pattern string, bp string) {
+func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) {
+ t.Helper()
+ return testJavaErrorWithConfig(t, pattern, bp, testConfig(nil))
+}
+
+func testJavaErrorWithConfig(t *testing.T, pattern string, bp string, config android.Config) (*android.TestContext, android.Config) {
t.Helper()
- config := testConfig(nil)
ctx := testContext(bp, nil)
pathCtx := android.PathContextForTesting(config, nil)
@@ -240,20 +246,26 @@ func testJavaError(t *testing.T, pattern string, bp string) {
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
if len(errs) > 0 {
android.FailIfNoMatchingErrors(t, pattern, errs)
- return
+ return ctx, config
}
_, errs = ctx.PrepareBuildActions(config)
if len(errs) > 0 {
android.FailIfNoMatchingErrors(t, pattern, errs)
- return
+ return ctx, config
}
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
+
+ return ctx, config
}
func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) {
t.Helper()
- config := testConfig(nil)
+ return testJavaWithConfig(t, bp, testConfig(nil))
+}
+
+func testJavaWithConfig(t *testing.T, bp string, config android.Config) (*android.TestContext, android.Config) {
+ t.Helper()
ctx := testContext(bp, nil)
run(t, ctx, config)
@@ -315,29 +327,38 @@ func TestSimple(t *testing.T) {
}
}
-func TestSdkVersion(t *testing.T) {
- ctx, _ := testJava(t, `
+func TestSdkVersionByPartition(t *testing.T) {
+ testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", `
java_library {
name: "foo",
srcs: ["a.java"],
vendor: true,
}
+ `)
+ testJava(t, `
java_library {
name: "bar",
srcs: ["b.java"],
}
`)
- foo := ctx.ModuleForTests("foo", "android_common").Module().(*Library)
- bar := ctx.ModuleForTests("bar", "android_common").Module().(*Library)
-
- if foo.sdkVersion() != "system_current" {
- t.Errorf("If sdk version of vendor module is empty, it must change to system_current.")
- }
+ for _, enforce := range []bool{true, false} {
- if bar.sdkVersion() != "" {
- t.Errorf("If sdk version of non-vendor module is empty, it keeps empty.")
+ config := testConfig(nil)
+ config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
+ bp := `
+ java_library {
+ name: "foo",
+ srcs: ["a.java"],
+ product_specific: true,
+ }
+ `
+ if enforce {
+ testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", bp, config)
+ } else {
+ testJavaWithConfig(t, bp, config)
+ }
}
}