Ensure APEX's Java deps use stable SDKs.
Test: m
Bug: 153333044
Change-Id: Ib1acf3073e96fe23c92d292ec0b1a91e2cd408db
Merged-In: Ib1acf3073e96fe23c92d292ec0b1a91e2cd408db
Exempt-From-Owner-Approval: cp from aosp
(cherry picked from commit 8cf899afcc
)
This commit is contained in:
20
apex/apex.go
20
apex/apex.go
@@ -1871,6 +1871,8 @@ func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
|
|||||||
if String(a.properties.Min_sdk_version) == "" {
|
if String(a.properties.Min_sdk_version) == "" {
|
||||||
ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
|
ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.checkJavaStableSdkVersion(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1940,7 +1942,6 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
|
|
||||||
a.checkApexAvailability(ctx)
|
a.checkApexAvailability(ctx)
|
||||||
a.checkUpdatable(ctx)
|
a.checkUpdatable(ctx)
|
||||||
|
|
||||||
a.collectDepsInfo(ctx)
|
a.collectDepsInfo(ctx)
|
||||||
|
|
||||||
handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
|
handleSpecialLibs := !android.Bool(a.properties.Ignore_system_library_special_case)
|
||||||
@@ -2247,6 +2248,23 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
a.buildApexDependencyInfo(ctx)
|
a.buildApexDependencyInfo(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enforce that Java deps of the apex are using stable SDKs to compile
|
||||||
|
func (a *apexBundle) checkJavaStableSdkVersion(ctx android.ModuleContext) {
|
||||||
|
// Visit direct deps only. As long as we guarantee top-level deps are using
|
||||||
|
// stable SDKs, java's checkLinkType guarantees correct usage for transitive deps
|
||||||
|
ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
|
||||||
|
tag := ctx.OtherModuleDependencyTag(module)
|
||||||
|
switch tag {
|
||||||
|
case javaLibTag, androidAppTag:
|
||||||
|
if m, ok := module.(interface{ CheckStableSdkVersion() error }); ok {
|
||||||
|
if err := m.CheckStableSdkVersion(); err != nil {
|
||||||
|
ctx.ModuleErrorf("cannot depend on \"%v\": %v", ctx.OtherModuleName(module), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func whitelistedApexAvailable(apex, moduleName string) bool {
|
func whitelistedApexAvailable(apex, moduleName string) bool {
|
||||||
key := apex
|
key := apex
|
||||||
moduleName = normalizeModuleName(moduleName)
|
moduleName = normalizeModuleName(moduleName)
|
||||||
|
@@ -1377,6 +1377,122 @@ func TestInvalidMinSdkVersion(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJavaStableSdkVersion(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
expectedError string
|
||||||
|
bp string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Non-updatable apex with non-stable dep",
|
||||||
|
bp: `
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
java_libs: ["myjar"],
|
||||||
|
key: "myapex.key",
|
||||||
|
}
|
||||||
|
apex_key {
|
||||||
|
name: "myapex.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
java_library {
|
||||||
|
name: "myjar",
|
||||||
|
srcs: ["foo/bar/MyClass.java"],
|
||||||
|
sdk_version: "core_platform",
|
||||||
|
apex_available: ["myapex"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Updatable apex with stable dep",
|
||||||
|
bp: `
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
java_libs: ["myjar"],
|
||||||
|
key: "myapex.key",
|
||||||
|
updatable: true,
|
||||||
|
min_sdk_version: "29",
|
||||||
|
}
|
||||||
|
apex_key {
|
||||||
|
name: "myapex.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
java_library {
|
||||||
|
name: "myjar",
|
||||||
|
srcs: ["foo/bar/MyClass.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
apex_available: ["myapex"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Updatable apex with non-stable dep",
|
||||||
|
expectedError: "cannot depend on \"myjar\"",
|
||||||
|
bp: `
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
java_libs: ["myjar"],
|
||||||
|
key: "myapex.key",
|
||||||
|
updatable: true,
|
||||||
|
}
|
||||||
|
apex_key {
|
||||||
|
name: "myapex.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
java_library {
|
||||||
|
name: "myjar",
|
||||||
|
srcs: ["foo/bar/MyClass.java"],
|
||||||
|
sdk_version: "core_platform",
|
||||||
|
apex_available: ["myapex"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Updatable apex with non-stable transitive dep",
|
||||||
|
expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against non-public Android API.",
|
||||||
|
bp: `
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
java_libs: ["myjar"],
|
||||||
|
key: "myapex.key",
|
||||||
|
updatable: true,
|
||||||
|
}
|
||||||
|
apex_key {
|
||||||
|
name: "myapex.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
java_library {
|
||||||
|
name: "myjar",
|
||||||
|
srcs: ["foo/bar/MyClass.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
apex_available: ["myapex"],
|
||||||
|
static_libs: ["transitive-jar"],
|
||||||
|
}
|
||||||
|
java_library {
|
||||||
|
name: "transitive-jar",
|
||||||
|
srcs: ["foo/bar/MyClass.java"],
|
||||||
|
sdk_version: "core_platform",
|
||||||
|
apex_available: ["myapex"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
if test.expectedError == "" {
|
||||||
|
testApex(t, test.bp)
|
||||||
|
} else {
|
||||||
|
testApexError(t, test.expectedError, test.bp)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFilesInSubDir(t *testing.T) {
|
func TestFilesInSubDir(t *testing.T) {
|
||||||
ctx, _ := testApex(t, `
|
ctx, _ := testApex(t, `
|
||||||
apex {
|
apex {
|
||||||
@@ -4289,6 +4405,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
|
|||||||
java_library {
|
java_library {
|
||||||
name: "some-updatable-apex-lib",
|
name: "some-updatable-apex-lib",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
apex_available: [
|
apex_available: [
|
||||||
"some-updatable-apex",
|
"some-updatable-apex",
|
||||||
],
|
],
|
||||||
@@ -4297,12 +4414,14 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
|
|||||||
java_library {
|
java_library {
|
||||||
name: "some-platform-lib",
|
name: "some-platform-lib",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
installable: true,
|
installable: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
java_library {
|
java_library {
|
||||||
name: "some-art-lib",
|
name: "some-art-lib",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
apex_available: [
|
apex_available: [
|
||||||
"com.android.art.something",
|
"com.android.art.something",
|
||||||
],
|
],
|
||||||
|
@@ -86,6 +86,14 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
|
|||||||
ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
|
ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Module) CheckStableSdkVersion() error {
|
||||||
|
sdkVersion := j.sdkVersion()
|
||||||
|
if sdkVersion.stable() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("non stable SDK %v", sdkVersion)
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
|
func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
|
||||||
if j.SocSpecific() || j.DeviceSpecific() ||
|
if j.SocSpecific() || j.DeviceSpecific() ||
|
||||||
(j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
|
(j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
|
||||||
|
@@ -170,9 +170,12 @@ func (s sdkSpec) stable() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
switch s.kind {
|
switch s.kind {
|
||||||
|
case sdkNone:
|
||||||
|
// there is nothing to manage and version in this case; de facto stable API.
|
||||||
|
return true
|
||||||
case sdkCore, sdkPublic, sdkSystem, sdkModule, sdkSystemServer:
|
case sdkCore, sdkPublic, sdkSystem, sdkModule, sdkSystemServer:
|
||||||
return true
|
return true
|
||||||
case sdkNone, sdkCorePlatform, sdkTest, sdkPrivate:
|
case sdkCorePlatform, sdkTest, sdkPrivate:
|
||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("unknown sdkKind=%v", s.kind))
|
panic(fmt.Errorf("unknown sdkKind=%v", s.kind))
|
||||||
|
Reference in New Issue
Block a user