Implement detecting container violations.
This change introduces a method to detect violating inter-container
dependencies between modules. The method is run in
`ModuleBase.GenerateBuildActions`, after the container info provider is
set. Given that the provider of the direct dependencies would have been
set at this time, the method utilizes this information to determine
the violations, which are introduced in https://r.android.com/3141104.
Note that this enforcement does not turn all inter-container
dependencies as errors. Instead, it will only turn dependencies that
matches the pre-defined violations into errors. Even if the dependency
matches the violation, an error will not be thrown if the dependency
satisfies any of the exception functions (e.g. the dependent module is
stubs, or the two modules belong to the same apexes).
Test: m nothing --no-skip-soong-tests
Bug: 338660802
Change-Id: I36e9cd956c5a076a53635be0c6ff27f77725516e
diff --git a/apex/aconfig_test.go b/apex/aconfig_test.go
index 14c0b63..bb811f5 100644
--- a/apex/aconfig_test.go
+++ b/apex/aconfig_test.go
@@ -74,6 +74,8 @@
apex_available: [
"myapex",
],
+ sdk_version: "none",
+ system_modules: "none",
}`,
},
{
@@ -122,6 +124,8 @@
apex_available: [
"myapex",
],
+ sdk_version: "none",
+ system_modules: "none",
}`,
},
{
@@ -345,6 +349,8 @@
apex_available: [
"myapex",
],
+ sdk_version: "none",
+ system_modules: "none",
}`,
expectedError: `.*my_java_library_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`,
},
@@ -392,6 +398,8 @@
apex_available: [
"myapex",
],
+ sdk_version: "none",
+ system_modules: "none",
}`,
expectedError: `.*my_android_app_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`,
},
@@ -693,6 +701,8 @@
apex_available: [
"myapex",
],
+ sdk_version: "none",
+ system_modules: "none",
}`,
expectedError: `.*my_android_app_foo/myapex depends on my_java_aconfig_library_foo/otherapex/production across containers`,
},
@@ -769,6 +779,8 @@
apex_available: [
"myapex",
],
+ sdk_version: "none",
+ system_modules: "none",
}`,
},
}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 6b9944d..3df43b1 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -4893,6 +4893,7 @@
java_import {
name: "libfoo",
jars: ["libfoo.jar"],
+ sdk_version: "core_current",
}
java_sdk_library_import {
@@ -4933,6 +4934,22 @@
t.Run("prebuilt with source preferred", func(t *testing.T) {
bp := `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ updatable: false,
+ java_libs: [
+ "libfoo",
+ "libbar",
+ ],
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
prebuilt_apex {
name: "myapex",
arch: {
@@ -4949,10 +4966,21 @@
java_import {
name: "libfoo",
jars: ["libfoo.jar"],
+ apex_available: [
+ "myapex",
+ ],
+ compile_dex: true,
+ sdk_version: "core_current",
}
java_library {
name: "libfoo",
+ srcs: ["foo/bar/MyClass.java"],
+ apex_available: [
+ "myapex",
+ ],
+ compile_dex: true,
+ sdk_version: "core_current",
}
java_sdk_library_import {
@@ -4960,12 +4988,21 @@
public: {
jars: ["libbar.jar"],
},
+ apex_available: [
+ "myapex",
+ ],
+ compile_dex: true,
}
java_sdk_library {
name: "libbar",
srcs: ["foo/bar/MyClass.java"],
unsafe_ignore_missing_latest_api: true,
+ apex_available: [
+ "myapex",
+ ],
+ compile_dex: true,
+ sdk_version: "core_current",
}
`
@@ -4974,11 +5011,9 @@
checkDexJarBuildPath(t, ctx, "prebuilt_libfoo")
checkDexJarInstallPath(t, ctx, "prebuilt_libfoo")
- ensureNoSourceVariant(t, ctx, "libfoo")
checkDexJarBuildPath(t, ctx, "prebuilt_libbar")
checkDexJarInstallPath(t, ctx, "prebuilt_libbar")
- ensureNoSourceVariant(t, ctx, "libbar")
})
t.Run("prebuilt preferred with source", func(t *testing.T) {
@@ -5004,6 +5039,7 @@
java_library {
name: "libfoo",
+ sdk_version: "core_current",
}
java_sdk_library_import {
@@ -5130,6 +5166,7 @@
jars: ["libfoo.jar"],
apex_available: ["myapex"],
permitted_packages: ["foo"],
+ sdk_version: "core_current",
}
java_sdk_library_import {
@@ -5284,12 +5321,14 @@
name: "libfoo",
jars: ["libfoo.jar"],
apex_available: ["myapex"],
+ sdk_version: "core_current",
}
java_library {
name: "libfoo",
srcs: ["foo/bar/MyClass.java"],
apex_available: ["myapex"],
+ sdk_version: "core_current",
}
java_sdk_library_import {
@@ -5381,6 +5420,7 @@
jars: ["libfoo.jar"],
apex_available: ["myapex"],
permitted_packages: ["foo"],
+ sdk_version: "core_current",
}
java_library {
@@ -5388,6 +5428,7 @@
srcs: ["foo/bar/MyClass.java"],
apex_available: ["myapex"],
installable: true,
+ sdk_version: "core_current",
}
java_sdk_library_import {
@@ -5478,6 +5519,7 @@
name: "libfoo",
jars: ["libfoo.jar"],
apex_available: ["myapex"],
+ sdk_version: "core_current",
}
java_library {
@@ -5486,6 +5528,7 @@
apex_available: ["myapex"],
permitted_packages: ["foo"],
installable: true,
+ sdk_version: "core_current",
}
java_sdk_library_import {
@@ -5504,6 +5547,7 @@
apex_available: ["myapex"],
permitted_packages: ["bar"],
compile_dex: true,
+ sdk_version: "core_current",
}
`
@@ -6098,6 +6142,7 @@
name: "TesterHelpAppFoo",
srcs: ["foo/bar/MyClass.java"],
apex_available: [ "myapex" ],
+ sdk_version: "test_current",
}
`)
@@ -7700,7 +7745,7 @@
srcs: ["foo/bar/MyClass.java"],
sdk_version: "none",
system_modules: "none",
- libs: ["myotherjar"],
+ static_libs: ["myotherjar"],
apex_available: [
"myapex",
"myapex.updatable",
@@ -8361,6 +8406,7 @@
apex_available: [
"myapex",
],
+ sdk_version: "current",
}
systemserverclasspath_fragment {
@@ -9403,6 +9449,7 @@
srcs: ["mybootclasspathlib.java"],
apex_available: ["myapex"],
compile_dex: true,
+ sdk_version: "current",
}
systemserverclasspath_fragment {
@@ -9718,6 +9765,7 @@
unsafe_ignore_missing_latest_api: true,
min_sdk_version: "31",
static_libs: ["util"],
+ sdk_version: "core_current",
}
java_library {
@@ -9726,6 +9774,7 @@
apex_available: ["myapex"],
min_sdk_version: "31",
static_libs: ["another_util"],
+ sdk_version: "core_current",
}
java_library {
@@ -9733,6 +9782,7 @@
srcs: ["a.java"],
min_sdk_version: "31",
apex_available: ["myapex"],
+ sdk_version: "core_current",
}
`)
})
@@ -9788,7 +9838,7 @@
})
t.Run("bootclasspath_fragment jar must set min_sdk_version", func(t *testing.T) {
- preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "mybootclasspathlib".*must set min_sdk_version`)).
+ preparer.
RunTestWithBp(t, `
apex {
name: "myapex",
@@ -9819,6 +9869,8 @@
apex_available: ["myapex"],
compile_dex: true,
unsafe_ignore_missing_latest_api: true,
+ sdk_version: "current",
+ min_sdk_version: "30",
}
`)
})
@@ -10071,6 +10123,9 @@
key: "myapex.key",
bootclasspath_fragments: ["mybootclasspathfragment"],
min_sdk_version: "29",
+ java_libs: [
+ "jacocoagent",
+ ],
}
apex_key {
name: "myapex.key",
diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go
index 25131ee..7cad337 100644
--- a/apex/bootclasspath_fragment_test.go
+++ b/apex/bootclasspath_fragment_test.go
@@ -104,6 +104,7 @@
test: {
enabled: true,
},
+ sdk_version: "core_current",
}
java_library {
@@ -749,6 +750,7 @@
],
srcs: ["b.java"],
compile_dex: true,
+ sdk_version: "core_current",
}
java_sdk_library {
@@ -922,6 +924,7 @@
],
srcs: ["b.java"],
compile_dex: true,
+ sdk_version: "core_current",
}
java_library {
@@ -1093,6 +1096,7 @@
],
srcs: ["b.java"],
compile_dex: true,
+ sdk_version: "core_current",
}
java_library {
@@ -1245,6 +1249,7 @@
],
srcs: ["b.java"],
compile_dex: true,
+ sdk_version: "core_current",
}
java_library {
diff --git a/apex/classpath_element_test.go b/apex/classpath_element_test.go
index b9a9198..9e1ac94 100644
--- a/apex/classpath_element_test.go
+++ b/apex/classpath_element_test.go
@@ -92,6 +92,7 @@
],
srcs: ["b.java"],
installable: true,
+ sdk_version: "core_current",
}
java_library {
diff --git a/apex/container_test.go b/apex/container_test.go
index 3931174..d28b1a6 100644
--- a/apex/container_test.go
+++ b/apex/container_test.go
@@ -30,7 +30,7 @@
result := android.GroupFixturePreparers(
prepareForApexTest,
java.PrepareForTestWithJavaSdkLibraryFiles,
- java.FixtureWithLastReleaseApis("mybootclasspathlib"),
+ java.FixtureWithLastReleaseApis("mybootclasspathlib", "bar"),
).RunTestWithBp(t, `
apex {
name: "myapex",
@@ -68,16 +68,17 @@
],
compile_dex: true,
static_libs: [
- "foo",
+ "food",
"baz",
],
libs: [
- "bar",
+ "bar.stubs",
],
min_sdk_version: "30",
+ sdk_version: "current",
}
java_library {
- name: "foo",
+ name: "food",
srcs:[
"A.java",
],
@@ -85,13 +86,15 @@
"myapex",
],
min_sdk_version: "30",
+ sdk_version: "core_current",
}
- java_library {
+ java_sdk_library {
name: "bar",
srcs:[
"A.java",
],
min_sdk_version: "30",
+ sdk_version: "core_current",
}
java_library {
name: "baz",
@@ -103,6 +106,7 @@
"myapex",
],
min_sdk_version: "30",
+ sdk_version: "core_current",
}
`)
testcases := []struct {
@@ -130,7 +134,7 @@
isApexContainer: false,
},
{
- moduleName: "foo",
+ moduleName: "food",
variant: "android_common_apex30",
isSystemContainer: true,
isApexContainer: true,
@@ -162,7 +166,7 @@
result := android.GroupFixturePreparers(
prepareForApexTest,
java.PrepareForTestWithJavaSdkLibraryFiles,
- java.FixtureWithLastReleaseApis("mybootclasspathlib"),
+ java.FixtureWithLastReleaseApis("mybootclasspathlib", "bar"),
).RunTestWithBp(t, `
apex {
name: "myapex",
@@ -199,26 +203,30 @@
],
compile_dex: true,
static_libs: [
- "foo",
+ "food",
],
libs: [
- "bar",
+ "bar.stubs",
],
+ sdk_version: "current",
}
java_library {
- name: "foo",
+ name: "food",
srcs:[
"A.java",
],
apex_available: [
"myapex",
],
+ sdk_version: "core_current",
}
- java_library {
+ java_sdk_library {
name: "bar",
srcs:[
"A.java",
],
+ sdk_version: "none",
+ system_modules: "none",
}
`)
testcases := []struct {
@@ -246,7 +254,7 @@
isApexContainer: false,
},
{
- moduleName: "foo",
+ moduleName: "food",
variant: "android_common_apex10000",
isSystemContainer: true,
isApexContainer: true,
diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go
index 920fc0c..8fd42b4 100644
--- a/apex/platform_bootclasspath_test.go
+++ b/apex/platform_bootclasspath_test.go
@@ -293,6 +293,7 @@
],
srcs: ["b.java"],
installable: true,
+ sdk_version: "core_current",
}
// Add a java_import that is not preferred and so won't have an appropriate apex variant created
diff --git a/apex/systemserver_classpath_fragment_test.go b/apex/systemserver_classpath_fragment_test.go
index 452a43e..fd9020b 100644
--- a/apex/systemserver_classpath_fragment_test.go
+++ b/apex/systemserver_classpath_fragment_test.go
@@ -80,6 +80,7 @@
apex_available: [
"myapex",
],
+ sdk_version: "core_current",
}
systemserverclasspath_fragment {
@@ -350,6 +351,7 @@
apex_available: [
"myapex",
],
+ sdk_version: "core_current",
}
systemserverclasspath_fragment {