Loading api/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -31,10 +31,12 @@ bootstrap_go_package { "blueprint", "soong", "soong-android", "soong-bp2build", "soong-genrule", "soong-java", ], srcs: ["api.go"], testSrcs: ["api_test.go"], pluginFor: ["soong_build"], } Loading api/api.go +68 −4 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" "android/soong/bazel" "android/soong/genrule" "android/soong/java" ) Loading @@ -30,6 +31,7 @@ const i18n = "i18n.module.public.api" const virtualization = "framework-virtualization" var core_libraries_modules = []string{art, conscrypt, i18n} // List of modules that are not yet updatable, and hence they can still compile // against hidden APIs. These modules are filtered out when building the // updatable-framework-module-impl (because updatable-framework-module-impl is Loading Loading @@ -59,6 +61,7 @@ type CombinedApisProperties struct { type CombinedApis struct { android.ModuleBase android.BazelModuleBase properties CombinedApisProperties } Loading Loading @@ -99,6 +102,19 @@ type fgProps struct { Visibility []string } type Bazel_module struct { Bp2build_available *bool } type bazelProperties struct { *Bazel_module } var bp2buildNotAvailable = bazelProperties{ &Bazel_module{ Bp2build_available: proptools.BoolPtr(false), }, } // Struct to pass parameters for the various merged [current|removed].txt file modules we create. type MergedTxtDefinition struct { // "current.txt" or "removed.txt" Loading Loading @@ -144,7 +160,7 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { }, } props.Visibility = []string{"//visibility:public"} ctx.CreateModule(genrule.GenRuleFactory, &props) ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable) } func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) { Loading Loading @@ -174,7 +190,7 @@ func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, sys props := fgProps{} props.Name = proptools.StringPtr(i.name) props.Srcs = createSrcs(i.modules, i.tag) ctx.CreateModule(android.FileGroupFactory, &props) ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable) } } Loading Loading @@ -223,7 +239,7 @@ func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { props.Tools = []string{"api_versions_trimmer"} props.Cmd = proptools.StringPtr("$(location api_versions_trimmer) $(out) $(in)") props.Dists = []android.Dist{{Targets: []string{"sdk"}}} ctx.CreateModule(genrule.GenRuleFactory, &props) ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable) } } Loading Loading @@ -315,7 +331,7 @@ func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []str props.Name = proptools.StringPtr("all-modules-public-stubs-source") props.Srcs = createSrcs(modules, "{.public.stubs.source}") props.Visibility = []string{"//frameworks/base"} ctx.CreateModule(android.FileGroupFactory, &props) ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable) } func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) { Loading Loading @@ -389,9 +405,57 @@ func combinedApisModuleFactory() android.Module { module.AddProperties(&module.properties) android.InitAndroidModule(module) android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) }) android.InitBazelModule(module) return module } type bazelCombinedApisAttributes struct { Scope bazel.StringAttribute Base bazel.LabelAttribute Deps bazel.LabelListAttribute } // combined_apis bp2build converter func (a *CombinedApis) ConvertWithBp2build(ctx android.TopDownMutatorContext) { basePrefix := "non-updatable" scopeNames := []string{"public", "system", "module-lib", "system-server"} scopeToSuffix := map[string]string{ "public": "-current.txt", "system": "-system-current.txt", "module-lib": "-module-lib-current.txt", "system-server": "-system-server-current.txt", } for _, scopeName := range scopeNames{ suffix := scopeToSuffix[scopeName] name := a.Name() + suffix var scope bazel.StringAttribute scope.SetValue(scopeName) var base bazel.LabelAttribute base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix)) var deps bazel.LabelListAttribute classpath := a.properties.Bootclasspath if scopeName == "system-server" { classpath = a.properties.System_server_classpath } deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath)) attrs := bazelCombinedApisAttributes{ Scope: scope, Base: base, Deps: deps, } props := bazel.BazelTargetModuleProperties{ Rule_class: "merged_txts", Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl", } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs) } } // Various utility methods below. // Creates an array of ":<m><tag>" for each m in <modules>. Loading api/api_test.go 0 → 100644 +68 −0 Original line number Diff line number Diff line // Copyright (C) 2023 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package api import ( "testing" "android/soong/android" "android/soong/bp2build" ) func runCombinedApisTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2build.Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) { t.Helper() (&tc).ModuleTypeUnderTest = "combined_apis" (&tc).ModuleTypeUnderTestFactory = combinedApisModuleFactory bp2build.RunBp2BuildTestCase(t, registrationCtxFunc, tc) } func runCombinedApisTestCase(t *testing.T, tc bp2build.Bp2buildTestCase) { t.Helper() runCombinedApisTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {}) } func TestCombinedApisGeneral(t *testing.T) { runCombinedApisTestCase(t, bp2build.Bp2buildTestCase{ Description: "combined_apis, general case", Blueprint: `combined_apis { name: "foo", bootclasspath: ["bcp"], system_server_classpath: ["ssc"], } `, ExpectedBazelTargets: []string{ bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-current.txt", bp2build.AttrNameToString{ "scope": `"public"`, "base": `":non-updatable-current.txt__BP2BUILD__MISSING__DEP"`, "deps": `[":bcp__BP2BUILD__MISSING__DEP"]`, }), bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-system-current.txt", bp2build.AttrNameToString{ "scope": `"system"`, "base": `":non-updatable-system-current.txt__BP2BUILD__MISSING__DEP"`, "deps": `[":bcp__BP2BUILD__MISSING__DEP"]`, }), bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-module-lib-current.txt", bp2build.AttrNameToString{ "scope": `"module-lib"`, "base": `":non-updatable-module-lib-current.txt__BP2BUILD__MISSING__DEP"`, "deps": `[":bcp__BP2BUILD__MISSING__DEP"]`, }), bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-system-server-current.txt", bp2build.AttrNameToString{ "scope": `"system-server"`, "base": `":non-updatable-system-server-current.txt__BP2BUILD__MISSING__DEP"`, "deps": `[":ssc__BP2BUILD__MISSING__DEP"]`, }), }, }) } Loading
api/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -31,10 +31,12 @@ bootstrap_go_package { "blueprint", "soong", "soong-android", "soong-bp2build", "soong-genrule", "soong-java", ], srcs: ["api.go"], testSrcs: ["api_test.go"], pluginFor: ["soong_build"], } Loading
api/api.go +68 −4 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" "android/soong/bazel" "android/soong/genrule" "android/soong/java" ) Loading @@ -30,6 +31,7 @@ const i18n = "i18n.module.public.api" const virtualization = "framework-virtualization" var core_libraries_modules = []string{art, conscrypt, i18n} // List of modules that are not yet updatable, and hence they can still compile // against hidden APIs. These modules are filtered out when building the // updatable-framework-module-impl (because updatable-framework-module-impl is Loading Loading @@ -59,6 +61,7 @@ type CombinedApisProperties struct { type CombinedApis struct { android.ModuleBase android.BazelModuleBase properties CombinedApisProperties } Loading Loading @@ -99,6 +102,19 @@ type fgProps struct { Visibility []string } type Bazel_module struct { Bp2build_available *bool } type bazelProperties struct { *Bazel_module } var bp2buildNotAvailable = bazelProperties{ &Bazel_module{ Bp2build_available: proptools.BoolPtr(false), }, } // Struct to pass parameters for the various merged [current|removed].txt file modules we create. type MergedTxtDefinition struct { // "current.txt" or "removed.txt" Loading Loading @@ -144,7 +160,7 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { }, } props.Visibility = []string{"//visibility:public"} ctx.CreateModule(genrule.GenRuleFactory, &props) ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable) } func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) { Loading Loading @@ -174,7 +190,7 @@ func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, sys props := fgProps{} props.Name = proptools.StringPtr(i.name) props.Srcs = createSrcs(i.modules, i.tag) ctx.CreateModule(android.FileGroupFactory, &props) ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable) } } Loading Loading @@ -223,7 +239,7 @@ func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { props.Tools = []string{"api_versions_trimmer"} props.Cmd = proptools.StringPtr("$(location api_versions_trimmer) $(out) $(in)") props.Dists = []android.Dist{{Targets: []string{"sdk"}}} ctx.CreateModule(genrule.GenRuleFactory, &props) ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable) } } Loading Loading @@ -315,7 +331,7 @@ func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []str props.Name = proptools.StringPtr("all-modules-public-stubs-source") props.Srcs = createSrcs(modules, "{.public.stubs.source}") props.Visibility = []string{"//frameworks/base"} ctx.CreateModule(android.FileGroupFactory, &props) ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable) } func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) { Loading Loading @@ -389,9 +405,57 @@ func combinedApisModuleFactory() android.Module { module.AddProperties(&module.properties) android.InitAndroidModule(module) android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) }) android.InitBazelModule(module) return module } type bazelCombinedApisAttributes struct { Scope bazel.StringAttribute Base bazel.LabelAttribute Deps bazel.LabelListAttribute } // combined_apis bp2build converter func (a *CombinedApis) ConvertWithBp2build(ctx android.TopDownMutatorContext) { basePrefix := "non-updatable" scopeNames := []string{"public", "system", "module-lib", "system-server"} scopeToSuffix := map[string]string{ "public": "-current.txt", "system": "-system-current.txt", "module-lib": "-module-lib-current.txt", "system-server": "-system-server-current.txt", } for _, scopeName := range scopeNames{ suffix := scopeToSuffix[scopeName] name := a.Name() + suffix var scope bazel.StringAttribute scope.SetValue(scopeName) var base bazel.LabelAttribute base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix)) var deps bazel.LabelListAttribute classpath := a.properties.Bootclasspath if scopeName == "system-server" { classpath = a.properties.System_server_classpath } deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath)) attrs := bazelCombinedApisAttributes{ Scope: scope, Base: base, Deps: deps, } props := bazel.BazelTargetModuleProperties{ Rule_class: "merged_txts", Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl", } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs) } } // Various utility methods below. // Creates an array of ":<m><tag>" for each m in <modules>. Loading
api/api_test.go 0 → 100644 +68 −0 Original line number Diff line number Diff line // Copyright (C) 2023 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package api import ( "testing" "android/soong/android" "android/soong/bp2build" ) func runCombinedApisTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2build.Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) { t.Helper() (&tc).ModuleTypeUnderTest = "combined_apis" (&tc).ModuleTypeUnderTestFactory = combinedApisModuleFactory bp2build.RunBp2BuildTestCase(t, registrationCtxFunc, tc) } func runCombinedApisTestCase(t *testing.T, tc bp2build.Bp2buildTestCase) { t.Helper() runCombinedApisTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {}) } func TestCombinedApisGeneral(t *testing.T) { runCombinedApisTestCase(t, bp2build.Bp2buildTestCase{ Description: "combined_apis, general case", Blueprint: `combined_apis { name: "foo", bootclasspath: ["bcp"], system_server_classpath: ["ssc"], } `, ExpectedBazelTargets: []string{ bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-current.txt", bp2build.AttrNameToString{ "scope": `"public"`, "base": `":non-updatable-current.txt__BP2BUILD__MISSING__DEP"`, "deps": `[":bcp__BP2BUILD__MISSING__DEP"]`, }), bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-system-current.txt", bp2build.AttrNameToString{ "scope": `"system"`, "base": `":non-updatable-system-current.txt__BP2BUILD__MISSING__DEP"`, "deps": `[":bcp__BP2BUILD__MISSING__DEP"]`, }), bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-module-lib-current.txt", bp2build.AttrNameToString{ "scope": `"module-lib"`, "base": `":non-updatable-module-lib-current.txt__BP2BUILD__MISSING__DEP"`, "deps": `[":bcp__BP2BUILD__MISSING__DEP"]`, }), bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-system-server-current.txt", bp2build.AttrNameToString{ "scope": `"system-server"`, "base": `":non-updatable-system-server-current.txt__BP2BUILD__MISSING__DEP"`, "deps": `[":ssc__BP2BUILD__MISSING__DEP"]`, }), }, }) }