Loading apex/apex_test.go +39 −4 Original line number Diff line number Diff line Loading @@ -2187,6 +2187,7 @@ func TestJavaStableSdkVersion(t *testing.T) { name string expectedError string bp string preparer android.FixturePreparer }{ { name: "Non-updatable apex with non-stable dep", Loading Loading @@ -2257,6 +2258,30 @@ func TestJavaStableSdkVersion(t *testing.T) { } `, }, { name: "Updatable apex with non-stable legacy core platform dep", expectedError: `\Qcannot depend on "myjar-uses-legacy": non stable SDK core_platform_current - uses legacy core platform\E`, bp: ` apex { name: "myapex", java_libs: ["myjar-uses-legacy"], key: "myapex.key", updatable: true, } apex_key { name: "myapex.key", public_key: "testkey.avbpubkey", private_key: "testkey.pem", } java_library { name: "myjar-uses-legacy", srcs: ["foo/bar/MyClass.java"], sdk_version: "core_platform", apex_available: ["myapex"], } `, preparer: java.FixtureUseLegacyCorePlatformApi("myjar-uses-legacy"), }, { name: "Updatable apex with non-stable transitive dep", // This is not actually detecting that the transitive dependency is unstable, rather it is Loading Loading @@ -2293,12 +2318,22 @@ func TestJavaStableSdkVersion(t *testing.T) { } for _, test := range testCases { if test.name != "Updatable apex with non-stable legacy core platform dep" { continue } t.Run(test.name, func(t *testing.T) { if test.expectedError == "" { testApex(t, test.bp) } else { testApexError(t, test.expectedError, test.bp) errorHandler := android.FixtureExpectsNoErrors if test.expectedError != "" { errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) } android.GroupFixturePreparers( java.PrepareForTestWithJavaDefaultModules, PrepareForTestWithApexBuildComponents, prepareForTestWithMyapex, android.OptionalFixturePreparer(test.preparer), ). ExtendWithErrorHandler(errorHandler). RunTestWithBp(t, test.bp) }) } } Loading java/base.go +1 −1 Original line number Diff line number Diff line Loading @@ -382,7 +382,7 @@ func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error { return nil } if sdkVersion.Kind == android.SdkCorePlatform { if useLegacyCorePlatformApiByName(j.BaseModuleName()) { if useLegacyCorePlatformApi(ctx, j.BaseModuleName()) { return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion) } else { // Treat stable core platform as stable. Loading java/legacy_core_platform_api_usage.go +16 −6 Original line number Diff line number Diff line Loading @@ -163,17 +163,27 @@ func init() { } } func useLegacyCorePlatformApi(ctx android.EarlyModuleContext) bool { return useLegacyCorePlatformApiByName(ctx.ModuleName()) var legacyCorePlatformApiLookupKey = android.NewOnceKey("legacyCorePlatformApiLookup") func getLegacyCorePlatformApiLookup(config android.Config) map[string]struct{} { return config.Once(legacyCorePlatformApiLookupKey, func() interface{} { return legacyCorePlatformApiLookup }).(map[string]struct{}) } func useLegacyCorePlatformApiByName(name string) bool { _, found := legacyCorePlatformApiLookup[name] // useLegacyCorePlatformApi checks to see whether the supplied module name is in the list of modules // that are able to use the legacy core platform API and returns true if it does, false otherwise. // // This method takes the module name separately from the context as this may be being called for a // module that is not the target of the supplied context. func useLegacyCorePlatformApi(ctx android.EarlyModuleContext, moduleName string) bool { lookup := getLegacyCorePlatformApiLookup(ctx.Config()) _, found := lookup[moduleName] return found } func corePlatformSystemModules(ctx android.EarlyModuleContext) string { if useLegacyCorePlatformApi(ctx) { if useLegacyCorePlatformApi(ctx, ctx.ModuleName()) { return config.LegacyCorePlatformSystemModules } else { return config.StableCorePlatformSystemModules Loading @@ -181,7 +191,7 @@ func corePlatformSystemModules(ctx android.EarlyModuleContext) string { } func corePlatformBootclasspathLibraries(ctx android.EarlyModuleContext) []string { if useLegacyCorePlatformApi(ctx) { if useLegacyCorePlatformApi(ctx, ctx.ModuleName()) { return config.LegacyCorePlatformBootclasspathLibraries } else { return config.StableCorePlatformBootclasspathLibraries Loading java/testing.go +20 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,26 @@ func FixtureConfigureApexBootJars(bootJars ...string) android.FixturePreparer { ) } // FixtureUseLegacyCorePlatformApi prepares the fixture by setting the exception list of those // modules that are allowed to use the legacy core platform API to be the ones supplied. func FixtureUseLegacyCorePlatformApi(moduleNames ...string) android.FixturePreparer { lookup := make(map[string]struct{}) for _, moduleName := range moduleNames { lookup[moduleName] = struct{}{} } return android.FixtureModifyConfig(func(config android.Config) { // Try and set the legacyCorePlatformApiLookup in the config, the returned value will be the // actual value that is set. cached := config.Once(legacyCorePlatformApiLookupKey, func() interface{} { return lookup }) // Make sure that the cached value is the one we need. if !reflect.DeepEqual(cached, lookup) { panic(fmt.Errorf("attempting to set legacyCorePlatformApiLookupKey to %q but it has already been set to %q", lookup, cached)) } }) } // registerRequiredBuildComponentsForTest registers the build components used by // PrepareForTestWithJavaDefaultModules. // Loading Loading
apex/apex_test.go +39 −4 Original line number Diff line number Diff line Loading @@ -2187,6 +2187,7 @@ func TestJavaStableSdkVersion(t *testing.T) { name string expectedError string bp string preparer android.FixturePreparer }{ { name: "Non-updatable apex with non-stable dep", Loading Loading @@ -2257,6 +2258,30 @@ func TestJavaStableSdkVersion(t *testing.T) { } `, }, { name: "Updatable apex with non-stable legacy core platform dep", expectedError: `\Qcannot depend on "myjar-uses-legacy": non stable SDK core_platform_current - uses legacy core platform\E`, bp: ` apex { name: "myapex", java_libs: ["myjar-uses-legacy"], key: "myapex.key", updatable: true, } apex_key { name: "myapex.key", public_key: "testkey.avbpubkey", private_key: "testkey.pem", } java_library { name: "myjar-uses-legacy", srcs: ["foo/bar/MyClass.java"], sdk_version: "core_platform", apex_available: ["myapex"], } `, preparer: java.FixtureUseLegacyCorePlatformApi("myjar-uses-legacy"), }, { name: "Updatable apex with non-stable transitive dep", // This is not actually detecting that the transitive dependency is unstable, rather it is Loading Loading @@ -2293,12 +2318,22 @@ func TestJavaStableSdkVersion(t *testing.T) { } for _, test := range testCases { if test.name != "Updatable apex with non-stable legacy core platform dep" { continue } t.Run(test.name, func(t *testing.T) { if test.expectedError == "" { testApex(t, test.bp) } else { testApexError(t, test.expectedError, test.bp) errorHandler := android.FixtureExpectsNoErrors if test.expectedError != "" { errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) } android.GroupFixturePreparers( java.PrepareForTestWithJavaDefaultModules, PrepareForTestWithApexBuildComponents, prepareForTestWithMyapex, android.OptionalFixturePreparer(test.preparer), ). ExtendWithErrorHandler(errorHandler). RunTestWithBp(t, test.bp) }) } } Loading
java/base.go +1 −1 Original line number Diff line number Diff line Loading @@ -382,7 +382,7 @@ func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error { return nil } if sdkVersion.Kind == android.SdkCorePlatform { if useLegacyCorePlatformApiByName(j.BaseModuleName()) { if useLegacyCorePlatformApi(ctx, j.BaseModuleName()) { return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion) } else { // Treat stable core platform as stable. Loading
java/legacy_core_platform_api_usage.go +16 −6 Original line number Diff line number Diff line Loading @@ -163,17 +163,27 @@ func init() { } } func useLegacyCorePlatformApi(ctx android.EarlyModuleContext) bool { return useLegacyCorePlatformApiByName(ctx.ModuleName()) var legacyCorePlatformApiLookupKey = android.NewOnceKey("legacyCorePlatformApiLookup") func getLegacyCorePlatformApiLookup(config android.Config) map[string]struct{} { return config.Once(legacyCorePlatformApiLookupKey, func() interface{} { return legacyCorePlatformApiLookup }).(map[string]struct{}) } func useLegacyCorePlatformApiByName(name string) bool { _, found := legacyCorePlatformApiLookup[name] // useLegacyCorePlatformApi checks to see whether the supplied module name is in the list of modules // that are able to use the legacy core platform API and returns true if it does, false otherwise. // // This method takes the module name separately from the context as this may be being called for a // module that is not the target of the supplied context. func useLegacyCorePlatformApi(ctx android.EarlyModuleContext, moduleName string) bool { lookup := getLegacyCorePlatformApiLookup(ctx.Config()) _, found := lookup[moduleName] return found } func corePlatformSystemModules(ctx android.EarlyModuleContext) string { if useLegacyCorePlatformApi(ctx) { if useLegacyCorePlatformApi(ctx, ctx.ModuleName()) { return config.LegacyCorePlatformSystemModules } else { return config.StableCorePlatformSystemModules Loading @@ -181,7 +191,7 @@ func corePlatformSystemModules(ctx android.EarlyModuleContext) string { } func corePlatformBootclasspathLibraries(ctx android.EarlyModuleContext) []string { if useLegacyCorePlatformApi(ctx) { if useLegacyCorePlatformApi(ctx, ctx.ModuleName()) { return config.LegacyCorePlatformBootclasspathLibraries } else { return config.StableCorePlatformBootclasspathLibraries Loading
java/testing.go +20 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,26 @@ func FixtureConfigureApexBootJars(bootJars ...string) android.FixturePreparer { ) } // FixtureUseLegacyCorePlatformApi prepares the fixture by setting the exception list of those // modules that are allowed to use the legacy core platform API to be the ones supplied. func FixtureUseLegacyCorePlatformApi(moduleNames ...string) android.FixturePreparer { lookup := make(map[string]struct{}) for _, moduleName := range moduleNames { lookup[moduleName] = struct{}{} } return android.FixtureModifyConfig(func(config android.Config) { // Try and set the legacyCorePlatformApiLookup in the config, the returned value will be the // actual value that is set. cached := config.Once(legacyCorePlatformApiLookupKey, func() interface{} { return lookup }) // Make sure that the cached value is the one we need. if !reflect.DeepEqual(cached, lookup) { panic(fmt.Errorf("attempting to set legacyCorePlatformApiLookupKey to %q but it has already been set to %q", lookup, cached)) } }) } // registerRequiredBuildComponentsForTest registers the build components used by // PrepareForTestWithJavaDefaultModules. // Loading