From 230c312f83b9ccdebfeb4125a708be9be4fbde4b Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Tue, 30 May 2023 23:09:36 +0000 Subject: [PATCH] Deprecate api bp2build of ndk_library and ndk_headers To support export of NDK APIs in multi-tree, we added functionality to generate Bazel targets of ndk related Soong module types. Since this use case does not exist anymore, deprecate this to prevent bitrot The removed code includes - `ConvertWithApi2Build` implementation of these libraries, which generates the Bazel targets in the synthetic `api_bp2build` workspace - (api) bp2build unit tests for these module types Test: go build ./cc Bug: 284029211 Change-Id: Id3278fa119e0ab87f31f39a3783197a81b655e43 --- bp2build/Android.bp | 1 - bp2build/ndk_headers_conversion_test.go | 164 ------------------------ bp2build/ndk_library_conversion_test.go | 77 ----------- cc/cc.go | 2 - cc/ndk_headers.go | 46 ------- cc/ndk_library.go | 21 --- 6 files changed, 311 deletions(-) delete mode 100644 bp2build/ndk_headers_conversion_test.go delete mode 100644 bp2build/ndk_library_conversion_test.go diff --git a/bp2build/Android.bp b/bp2build/Android.bp index 9ec3a40b9..4ecd05de7 100644 --- a/bp2build/Android.bp +++ b/bp2build/Android.bp @@ -72,7 +72,6 @@ bootstrap_go_package { "license_conversion_test.go", "license_kind_conversion_test.go", "linker_config_conversion_test.go", - "ndk_headers_conversion_test.go", "package_conversion_test.go", "performance_test.go", "prebuilt_etc_conversion_test.go", diff --git a/bp2build/ndk_headers_conversion_test.go b/bp2build/ndk_headers_conversion_test.go deleted file mode 100644 index 9d0f1f233..000000000 --- a/bp2build/ndk_headers_conversion_test.go +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2022 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 ( - "fmt" - "testing" - - "android/soong/cc" -) - -func TestNdkHeaderFilepaths(t *testing.T) { - bpTemplate := ` - ndk_headers { - name: "foo", - srcs: %v, - exclude_srcs: %v, - } - ` - testCases := []struct { - desc string - srcs string - excludeSrcs string - expectedHdrs string - }{ - { - desc: "Single header file", - srcs: `["foo.h"]`, - excludeSrcs: `[]`, - expectedHdrs: `["foo.h"]`, - }, - { - desc: "Multiple header files", - srcs: `["foo.h", "foo_other.h"]`, - excludeSrcs: `[]`, - expectedHdrs: `[ - "foo.h", - "foo_other.h", - ]`, - }, - { - desc: "Multiple header files with excludes", - srcs: `["foo.h", "foo_other.h"]`, - excludeSrcs: `["foo_other.h"]`, - expectedHdrs: `["foo.h"]`, - }, - { - desc: "Multiple header files via Soong-supported globs", - srcs: `["*.h"]`, - excludeSrcs: `[]`, - expectedHdrs: `[ - "foo.h", - "foo_other.h", - ]`, - }, - } - for _, testCase := range testCases { - fs := map[string]string{ - "foo.h": "", - "foo_other.h": "", - } - expectedApiContributionTargetName := "foo.contribution" - expectedBazelTarget := MakeBazelTargetNoRestrictions( - "cc_api_headers", - expectedApiContributionTargetName, - AttrNameToString{ - "hdrs": testCase.expectedHdrs, - }, - ) - RunApiBp2BuildTestCase(t, cc.RegisterNdkModuleTypes, Bp2buildTestCase{ - Description: testCase.desc, - Blueprint: fmt.Sprintf(bpTemplate, testCase.srcs, testCase.excludeSrcs), - ExpectedBazelTargets: []string{expectedBazelTarget}, - Filesystem: fs, - }) - } -} - -func TestNdkHeaderIncludeDir(t *testing.T) { - bpTemplate := ` - ndk_headers { - name: "foo", - from: %v, - to: "this/value/is/ignored", - } - ` - testCases := []struct { - desc string - from string - expectedIncludeDir string - }{ - { - desc: "Empty `from` value", - from: `""`, - expectedIncludeDir: `""`, - }, - { - desc: "Non-Empty `from` value", - from: `"include"`, - expectedIncludeDir: `"include"`, - }, - } - for _, testCase := range testCases { - expectedApiContributionTargetName := "foo.contribution" - expectedBazelTarget := MakeBazelTargetNoRestrictions( - "cc_api_headers", - expectedApiContributionTargetName, - AttrNameToString{ - "include_dir": testCase.expectedIncludeDir, - }, - ) - RunApiBp2BuildTestCase(t, cc.RegisterNdkModuleTypes, Bp2buildTestCase{ - Description: testCase.desc, - Blueprint: fmt.Sprintf(bpTemplate, testCase.from), - ExpectedBazelTargets: []string{expectedBazelTarget}, - }) - } -} - -func TestVersionedNdkHeaderFilepaths(t *testing.T) { - bp := ` - versioned_ndk_headers { - name: "common_libc", - from: "include" - } - ` - fs := map[string]string{ - "include/math.h": "", - "include/stdio.h": "", - "include/arm/arm.h": "", - "include/x86/x86.h": "", - } - expectedApiContributionTargetName := "common_libc.contribution" - expectedBazelTarget := MakeBazelTargetNoRestrictions( - "cc_api_headers", - expectedApiContributionTargetName, - AttrNameToString{ - "include_dir": `"include"`, - "hdrs": `[ - "include/math.h", - "include/stdio.h", - "include/arm/arm.h", - "include/x86/x86.h", - ]`, - }, - ) - RunApiBp2BuildTestCase(t, cc.RegisterNdkModuleTypes, Bp2buildTestCase{ - Blueprint: bp, - Filesystem: fs, - ExpectedBazelTargets: []string{expectedBazelTarget}, - }) -} diff --git a/bp2build/ndk_library_conversion_test.go b/bp2build/ndk_library_conversion_test.go deleted file mode 100644 index 819ab25f8..000000000 --- a/bp2build/ndk_library_conversion_test.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2022 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/cc" -) - -func TestNdkLibraryContributionSymbolFile(t *testing.T) { - bp := ` - ndk_library { - name: "libfoo", - symbol_file: "libfoo.map.txt", - } - ` - expectedBazelTarget := MakeBazelTargetNoRestrictions( - "cc_api_contribution", - "libfoo.ndk.contribution", - AttrNameToString{ - "api": `"libfoo.map.txt"`, - "api_surfaces": `["publicapi"]`, - "library_name": `"libfoo"`, - "target_compatible_with": `["//build/bazel/platforms/os:android"]`, - }, - ) - RunApiBp2BuildTestCase(t, cc.RegisterNdkModuleTypes, Bp2buildTestCase{ - Blueprint: bp, - ExpectedBazelTargets: []string{expectedBazelTarget}, - }) -} - -func TestNdkLibraryContributionHeaders(t *testing.T) { - bp := ` - ndk_library { - name: "libfoo", - symbol_file: "libfoo.map.txt", - export_header_libs: ["libfoo_headers"], - } - ` - fs := map[string]string{ - "header_directory/Android.bp": ` - ndk_headers { - name: "libfoo_headers", - } - `, - } - expectedBazelTarget := MakeBazelTargetNoRestrictions( - "cc_api_contribution", - "libfoo.ndk.contribution", - AttrNameToString{ - "api": `"libfoo.map.txt"`, - "api_surfaces": `["publicapi"]`, - "library_name": `"libfoo"`, - "hdrs": `["//header_directory:libfoo_headers.contribution"]`, - "target_compatible_with": `["//build/bazel/platforms/os:android"]`, - }, - ) - RunApiBp2BuildTestCase(t, cc.RegisterNdkModuleTypes, Bp2buildTestCase{ - Blueprint: bp, - Filesystem: fs, - ExpectedBazelTargets: []string{expectedBazelTarget}, - }) -} diff --git a/cc/cc.go b/cc/cc.go index 7237686e4..bbb3c72d6 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -4073,8 +4073,6 @@ func (c *Module) ConvertWithApiBp2build(ctx android.TopDownMutatorContext) { // Aggressively generate api targets for all header modules // This is necessary since the header module does not know if it is a dep of API surface stub library apiLibraryHeadersBp2Build(ctx, c) - case ndkLibrary: - ndkLibraryBp2build(ctx, c) } } diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go index 7354be9f7..d0ae4a56d 100644 --- a/cc/ndk_headers.go +++ b/cc/ndk_headers.go @@ -19,10 +19,8 @@ import ( "path/filepath" "github.com/google/blueprint" - "github.com/google/blueprint/proptools" "android/soong/android" - "android/soong/bazel" ) var ( @@ -81,7 +79,6 @@ type headerProperties struct { type headerModule struct { android.ModuleBase - android.BazelModuleBase properties headerProperties @@ -147,39 +144,6 @@ func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } -// TODO(b/243196151): Populate `system` and `arch` metadata -type bazelCcApiHeadersAttributes struct { - Hdrs bazel.LabelListAttribute - Include_dir *string -} - -func createCcApiHeadersTarget(ctx android.TopDownMutatorContext, includes []string, excludes []string, include_dir *string) { - props := bazel.BazelTargetModuleProperties{ - Rule_class: "cc_api_headers", - Bzl_load_location: "//build/bazel/rules/apis:cc_api_contribution.bzl", - } - attrs := &bazelCcApiHeadersAttributes{ - Hdrs: bazel.MakeLabelListAttribute( - android.BazelLabelForModuleSrcExcludes( - ctx, - includes, - excludes, - ), - ), - Include_dir: include_dir, - } - ctx.CreateBazelTargetModule(props, android.CommonAttributes{ - Name: android.ApiContributionTargetName(ctx.ModuleName()), - }, attrs) -} - -var _ android.ApiProvider = (*headerModule)(nil) - -func (h *headerModule) ConvertWithApiBp2build(ctx android.TopDownMutatorContext) { - // Generate `cc_api_headers` target for Multi-tree API export - createCcApiHeadersTarget(ctx, h.properties.Srcs, h.properties.Exclude_srcs, h.properties.From) -} - // ndk_headers installs the sets of ndk headers defined in the srcs property // to the sysroot base + "usr/include" + to directory + directory component. // ndk_headers requires the license file to be specified. Example: @@ -226,7 +190,6 @@ type versionedHeaderProperties struct { // Note that this is really only built to handle bionic/libc/include. type versionedHeaderModule struct { android.ModuleBase - android.BazelModuleBase properties versionedHeaderProperties @@ -264,15 +227,6 @@ func (m *versionedHeaderModule) GenerateAndroidBuildActions(ctx android.ModuleCo processHeadersWithVersioner(ctx, fromSrcPath, toOutputPath, srcFiles, installPaths) } -var _ android.ApiProvider = (*versionedHeaderModule)(nil) - -func (h *versionedHeaderModule) ConvertWithApiBp2build(ctx android.TopDownMutatorContext) { - // Glob all .h files under `From` - includePattern := headerGlobPattern(proptools.String(h.properties.From)) - // Generate `cc_api_headers` target for Multi-tree API export - createCcApiHeadersTarget(ctx, []string{includePattern}, []string{}, h.properties.From) -} - func processHeadersWithVersioner(ctx android.ModuleContext, srcDir, outDir android.Path, srcFiles android.Paths, installPaths []android.WritablePath) android.Path { // The versioner depends on a dependencies directory to simplify determining include paths diff --git a/cc/ndk_library.go b/cc/ndk_library.go index f8a355950..f0b7cc52b 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -599,24 +599,3 @@ func apiHeaderLabels(ctx android.TopDownMutatorContext, hdrLibs []string) bazel. } return android.BazelLabelForModuleDepsWithFn(ctx, hdrLibs, addSuffix) } - -func ndkLibraryBp2build(ctx android.TopDownMutatorContext, m *Module) { - props := bazel.BazelTargetModuleProperties{ - Rule_class: "cc_api_contribution", - Bzl_load_location: "//build/bazel/rules/apis:cc_api_contribution.bzl", - } - stubLibrary := m.compiler.(*stubDecorator) - attrs := &bazelCcApiContributionAttributes{ - Library_name: stubLibrary.implementationModuleName(m.Name()), - Api_surfaces: bazel.MakeStringListAttribute( - []string{android.PublicApi.String()}), - } - if symbolFile := stubLibrary.properties.Symbol_file; symbolFile != nil { - apiLabel := android.BazelLabelForModuleSrcSingle(ctx, proptools.String(symbolFile)).Label - attrs.Api = *bazel.MakeLabelAttribute(apiLabel) - } - apiHeaders := apiHeaderLabels(ctx, stubLibrary.properties.Export_header_libs) - attrs.Hdrs = bazel.MakeLabelListAttribute(apiHeaders) - apiContributionTargetName := android.ApiContributionTargetName(ctx.ModuleName()) - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: apiContributionTargetName}, attrs) -}