bp2build for ndk_headers
Create bp2build converters for the following module types
- ndk_headers
- versioned_ndk_headers
Details
- Partial bp2build conversion. Only `cc_api_headers` targets will be
generted within the scope of this CL
- Glob expansion. Aligned with other bp2build converters, this impl will
expand globs in Android.bp so that all .h files are explicitly listed
in the generated BUILD files. As an extreme example, the size of
out/soong/workspace/bionic/libc/BUILD will increase from ~170KB to
~230KB (33% increase). This makes the BUILD files less readable, and
`cc_api_headers` section of the BUILD file should probably not be
checked into the tree in this format
Test: b cquery //bionic/libc:libc_uapi --output=starlark
--starlark:expr="providers(target).get('//build/bazel/rules/apis:cc_api_contribution.bzl%CcApiHeaderInfo')"
Test: go test ./bp2build
Test: go test ./cc
Change-Id: I810d5380f72dc90f4cdf4aa508570f3a80d8d932
diff --git a/bp2build/ndk_headers_conversion_test.go b/bp2build/ndk_headers_conversion_test.go
new file mode 100644
index 0000000..c7cc6b2
--- /dev/null
+++ b/bp2build/ndk_headers_conversion_test.go
@@ -0,0 +1,164 @@
+// 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,
+ },
+ )
+ RunBp2BuildTestCase(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,
+ },
+ )
+ RunBp2BuildTestCase(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",
+ ]`,
+ },
+ )
+ RunBp2BuildTestCase(t, cc.RegisterNdkModuleTypes, Bp2buildTestCase{
+ Blueprint: bp,
+ Filesystem: fs,
+ ExpectedBazelTargets: []string{expectedBazelTarget},
+ })
+}