From 86a407f284e8a256e47dc804d21825e151359cfb Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Mon, 18 Sep 2023 09:23:38 -0400 Subject: [PATCH 1/3] Always convert prebuilt cc library headers Test: go tests Test: CI Test: patch in CL using prebuilts for mainline modules and build Bug: 300640274 Change-Id: I73f70dac679e341670e1484ce57bc984f413d409 --- android/allowlists/allowlists.go | 1 + .../cc_library_headers_conversion_test.go | 83 ++++++++++--------- cc/library_headers.go | 7 +- 3 files changed, 51 insertions(+), 40 deletions(-) diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 23ced731a..8cbf35064 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -922,6 +922,7 @@ var ( "aconfig_values", "aidl_interface_headers", "bpf", + "cc_prebuilt_library_headers", "combined_apis", "droiddoc_exported_dir", "java_import", diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go index 0fa20866f..bf3351ad8 100644 --- a/bp2build/cc_library_headers_conversion_test.go +++ b/bp2build/cc_library_headers_conversion_test.go @@ -57,6 +57,7 @@ func TestCcLibraryHeadersLoadStatement(t *testing.T) { func registerCcLibraryHeadersModuleTypes(ctx android.RegistrationContext) { cc.RegisterCCBuildComponents(ctx) + cc.RegisterLibraryHeadersBuildComponents(ctx) } func runCcLibraryHeadersTestCase(t *testing.T, tc Bp2buildTestCase) { @@ -66,9 +67,7 @@ func runCcLibraryHeadersTestCase(t *testing.T, tc Bp2buildTestCase) { func TestCcLibraryHeadersSimple(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers test", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Description: "cc_library_headers test", Filesystem: map[string]string{ "lib-1/lib1a.h": "", "lib-1/lib1b.h": "", @@ -127,10 +126,8 @@ cc_library_headers { // variant info(select) should go before general info. func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers test with os-specific header_libs props", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, - Filesystem: map[string]string{}, + Description: "cc_library_headers test with os-specific header_libs props", + Filesystem: map[string]string{}, StubbedBuildDefinitions: []string{"android-lib", "base-lib", "darwin-lib", "linux-lib", "linux_bionic-lib", "windows-lib"}, Blueprint: soongCcLibraryPreamble + ` @@ -197,11 +194,9 @@ cc_library_headers { func TestCcLibraryHeadersOsSpecficHeaderLibsExportHeaderLibHeaders(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, - Filesystem: map[string]string{}, - StubbedBuildDefinitions: []string{"android-lib", "exported-lib"}, + Description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props", + Filesystem: map[string]string{}, + StubbedBuildDefinitions: []string{"android-lib", "exported-lib"}, Blueprint: soongCcLibraryPreamble + ` cc_library_headers { name: "android-lib", @@ -232,10 +227,8 @@ cc_library_headers { func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, - Filesystem: map[string]string{}, + Description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props", + Filesystem: map[string]string{}, Blueprint: soongCcLibraryPreamble + `cc_library_headers { name: "foo_headers", export_system_include_dirs: [ @@ -291,9 +284,7 @@ func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) { func TestCcLibraryHeadersNoCrtIgnored(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers test", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, + Description: "cc_library_headers test", Filesystem: map[string]string{ "lib-1/lib1a.h": "", "lib-1/lib1b.h": "", @@ -324,11 +315,9 @@ cc_library_headers { func TestCcLibraryHeadersExportedStaticLibHeadersReexported(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers exported_static_lib_headers is reexported", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, - Filesystem: map[string]string{}, - StubbedBuildDefinitions: []string{"foo_export"}, + Description: "cc_library_headers exported_static_lib_headers is reexported", + Filesystem: map[string]string{}, + StubbedBuildDefinitions: []string{"foo_export"}, Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "foo_headers", @@ -347,11 +336,9 @@ cc_library_headers { func TestCcLibraryHeadersExportedSharedLibHeadersReexported(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers exported_shared_lib_headers is reexported", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, - Filesystem: map[string]string{}, - StubbedBuildDefinitions: []string{"foo_export"}, + Description: "cc_library_headers exported_shared_lib_headers is reexported", + Filesystem: map[string]string{}, + StubbedBuildDefinitions: []string{"foo_export"}, Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "foo_headers", @@ -370,11 +357,9 @@ cc_library_headers { func TestCcLibraryHeadersExportedHeaderLibHeadersReexported(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers exported_header_lib_headers is reexported", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, - Filesystem: map[string]string{}, - StubbedBuildDefinitions: []string{"foo_export"}, + Description: "cc_library_headers exported_header_lib_headers is reexported", + Filesystem: map[string]string{}, + StubbedBuildDefinitions: []string{"foo_export"}, Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "foo_headers", @@ -393,11 +378,9 @@ cc_library_headers { func TestCcLibraryHeadersWholeStaticLibsReexported(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ - Description: "cc_library_headers whole_static_libs is reexported", - ModuleTypeUnderTest: "cc_library_headers", - ModuleTypeUnderTestFactory: cc.LibraryHeaderFactory, - Filesystem: map[string]string{}, - StubbedBuildDefinitions: []string{"foo_export"}, + Description: "cc_library_headers whole_static_libs is reexported", + Filesystem: map[string]string{}, + StubbedBuildDefinitions: []string{"foo_export"}, Blueprint: soongCcLibraryHeadersPreamble + ` cc_library_headers { name: "foo_headers", @@ -412,3 +395,25 @@ cc_library_headers { }, }) } + +func TestPrebuiltCcLibraryHeadersWholeStaticLibsReexported(t *testing.T) { + runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ + Description: "cc_library_headers whole_static_libs is reexported", + Filesystem: map[string]string{ + "foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"), + }, + StubbedBuildDefinitions: []string{"foo_export"}, + Blueprint: soongCcLibraryHeadersPreamble + ` +cc_prebuilt_library_headers { + name: "foo_headers", + whole_static_libs: ["foo_export"], + bazel_module: { bp2build_available: true }, +} +` + simpleModule("cc_library_headers", "foo_export"), + ExpectedBazelTargets: []string{ + MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ + "deps": `[":foo_export"]`, + }), + }, + }) +} diff --git a/cc/library_headers.go b/cc/library_headers.go index ce9c4aacf..52198fc45 100644 --- a/cc/library_headers.go +++ b/cc/library_headers.go @@ -153,8 +153,13 @@ func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) { tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module) + name := module.Name() + if module.IsPrebuilt() { + name = android.RemoveOptionalPrebuiltPrefix(name) + } + ctx.CreateBazelTargetModule(props, android.CommonAttributes{ - Name: module.Name(), + Name: name, Tags: tags, }, attrs) } From e0cbc983ec710a718f762b2c94351c0ba1669a64 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Mon, 18 Sep 2023 09:12:41 -0400 Subject: [PATCH 2/3] Always convert prebuilt libraries Test: CI Test: patch in CL using prebuilt mainline modules & build Bug: 300640274 Change-Id: Ie00b111a04198b266985f3e1c34c960844c0a327 --- android/allowlists/allowlists.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 8cbf35064..8da82d379 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -922,7 +922,10 @@ var ( "aconfig_values", "aidl_interface_headers", "bpf", + "cc_prebuilt_library", "cc_prebuilt_library_headers", + "cc_prebuilt_library_shared", + "cc_prebuilt_library_static", "combined_apis", "droiddoc_exported_dir", "java_import", From 9a97a8f62ab19be0c544cdde40466a1286b3575e Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Mon, 18 Sep 2023 13:36:41 -0400 Subject: [PATCH 3/3] Implement bp2build for java_sdk_library_import Test: go test bp2build conversion tests Test: enable modules build from prebuilt and m nothing Bug: 300640274 Change-Id: I8c015aec546d052bef6c42869e12db4e87d39780 --- android/allowlists/allowlists.go | 1 + bp2build/Android.bp | 2 + ...java_sdk_library_import_conversion_test.go | 84 +++++++++++++++++++ java/sdk_library.go | 47 ++++++++--- 4 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 bp2build/java_sdk_library_import_conversion_test.go diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 8da82d379..5b77ba97d 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -931,6 +931,7 @@ var ( "java_import", "java_import_host", "java_sdk_library", + "java_sdk_library_import", "license", "linker_config", "sysprop_library", diff --git a/bp2build/Android.bp b/bp2build/Android.bp index b321b38cb..755b7a34a 100644 --- a/bp2build/Android.bp +++ b/bp2build/Android.bp @@ -74,6 +74,8 @@ bootstrap_go_package { "java_library_host_conversion_test.go", "java_plugin_conversion_test.go", "java_proto_conversion_test.go", + "java_sdk_library_conversion_test.go", + "java_sdk_library_import_conversion_test.go", "license_conversion_test.go", "license_kind_conversion_test.go", "linker_config_conversion_test.go", diff --git a/bp2build/java_sdk_library_import_conversion_test.go b/bp2build/java_sdk_library_import_conversion_test.go new file mode 100644 index 000000000..456f87268 --- /dev/null +++ b/bp2build/java_sdk_library_import_conversion_test.go @@ -0,0 +1,84 @@ +// Copyright 2023 Google Inc. All rights reserved. +// +// 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 bp2build + +import ( + "testing" + + "android/soong/java" +) + +func runJavaSdkLibraryImportTestCase(t *testing.T, tc Bp2buildTestCase) { + t.Helper() + RunBp2BuildTestCase(t, java.RegisterSdkLibraryBuildComponents, tc) +} + +func TestJavaSdkLibraryImport(t *testing.T) { + runJavaSdkLibraryImportTestCase(t, Bp2buildTestCase{ + Blueprint: ` +java_sdk_library_import { + name : "foo", + public: { + current_api: "foo_current.txt", + }, + system: { + current_api: "system_foo_current.txt", + }, +} +`, + ExpectedBazelTargets: []string{ + MakeBazelTarget("java_sdk_library", "foo", AttrNameToString{ + "public": `"foo_current.txt"`, + "system": `"system_foo_current.txt"`, + }), + }, + }) +} + +func TestJavaSdkLibraryImportPrebuiltPrefixRemoved(t *testing.T) { + runJavaSdkLibraryImportTestCase(t, Bp2buildTestCase{ + Filesystem: map[string]string{ + "foobar/Android.bp": ` +java_sdk_library { + name: "foo", + srcs: ["**/*.java"], +} +`, + "foobar/api/current.txt": "", + "foobar/api/system-current.txt": "", + "foobar/api/test-current.txt": "", + "foobar/api/removed.txt": "", + "foobar/api/system-removed.txt": "", + "foobar/api/test-removed.txt": "", + }, + Blueprint: ` +java_sdk_library_import { + name : "foo", + public: { + current_api: "foo_current.txt", + }, + system: { + current_api: "system_foo_current.txt", + }, +} +`, + ExpectedBazelTargets: []string{ + MakeBazelTarget("java_sdk_library", "foo", AttrNameToString{ + "public": `"foo_current.txt"`, + "system": `"system_foo_current.txt"`, + }), + }, + }) +} diff --git a/java/sdk_library.go b/java/sdk_library.go index 6349d92f5..e3e2427bc 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2276,11 +2276,11 @@ func SdkLibraryFactory() android.Module { } type bazelSdkLibraryAttributes struct { - Public bazel.StringAttribute - System bazel.StringAttribute - Test bazel.StringAttribute - Module_lib bazel.StringAttribute - System_server bazel.StringAttribute + Public *bazel.Label + System *bazel.Label + Test *bazel.Label + Module_lib *bazel.Label + System_server *bazel.Label } // java_sdk_library bp2build converter @@ -2290,13 +2290,11 @@ func (module *SdkLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) return } - nameToAttr := make(map[string]bazel.StringAttribute) + nameToAttr := make(map[string]*bazel.Label) for _, scope := range module.getGeneratedApiScopes(ctx) { - apiSurfaceFile := path.Join(module.getApiDir(), scope.apiFilePrefix+"current.txt") - var scopeStringAttribute bazel.StringAttribute - scopeStringAttribute.SetValue(apiSurfaceFile) - nameToAttr[scope.name] = scopeStringAttribute + apiSurfaceFile := android.BazelLabelForModuleSrcSingle(ctx, path.Join(module.getApiDir(), scope.apiFilePrefix+"current.txt")) + nameToAttr[scope.name] = &apiSurfaceFile } attrs := bazelSdkLibraryAttributes{ @@ -2355,6 +2353,7 @@ type sdkLibraryImportProperties struct { type SdkLibraryImport struct { android.ModuleBase android.DefaultableModuleBase + android.BazelModuleBase prebuilt android.Prebuilt android.ApexModuleBase @@ -2438,6 +2437,7 @@ func sdkLibraryImportFactory() android.Module { android.InitPrebuiltModule(module, &[]string{""}) android.InitApexModule(module) + android.InitBazelModule(module) InitJavaModule(module, android.HostAndDeviceSupported) module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { @@ -2448,6 +2448,33 @@ func sdkLibraryImportFactory() android.Module { return module } +// java_sdk_library bp2build converter +func (i *SdkLibraryImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) { + nameToAttr := make(map[string]*bazel.Label) + + for scope, props := range i.scopeProperties { + if api := proptools.String(props.Current_api); api != "" { + apiSurfaceFile := android.BazelLabelForModuleSrcSingle(ctx, api) + nameToAttr[scope.name] = &apiSurfaceFile + } + } + + attrs := bazelSdkLibraryAttributes{ + Public: nameToAttr["public"], + System: nameToAttr["system"], + Test: nameToAttr["test"], + Module_lib: nameToAttr["module-lib"], + System_server: nameToAttr["system-server"], + } + props := bazel.BazelTargetModuleProperties{ + Rule_class: "java_sdk_library", + Bzl_load_location: "//build/bazel/rules/java:sdk_library.bzl", + } + + name := android.RemoveOptionalPrebuiltPrefix(i.Name()) + ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs) +} + var _ PermittedPackagesForUpdatableBootJars = (*SdkLibraryImport)(nil) func (module *SdkLibraryImport) PermittedPackagesForUpdatableBootJars() []string {