2021-02-15 12:04:32 +01:00
|
|
|
// Copyright 2021 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 (
|
2021-05-21 09:37:00 +02:00
|
|
|
"testing"
|
|
|
|
|
2021-02-15 12:04:32 +01:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// See cc/testing.go for more context
|
2021-03-24 15:04:33 +01:00
|
|
|
soongCcLibraryHeadersPreamble = `
|
2021-02-15 12:04:32 +01:00
|
|
|
cc_defaults {
|
2021-09-10 16:06:32 +02:00
|
|
|
name: "linux_bionic_supported",
|
2021-02-15 12:04:32 +01:00
|
|
|
}`
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCcLibraryHeadersLoadStatement(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
bazelTargets BazelTargets
|
|
|
|
expectedLoadStatements string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
bazelTargets: BazelTargets{
|
|
|
|
BazelTarget{
|
|
|
|
name: "cc_library_headers_target",
|
|
|
|
ruleClass: "cc_library_headers",
|
|
|
|
// Note: no bzlLoadLocation for native rules
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedLoadStatements: ``,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
actual := testCase.bazelTargets.LoadStatements()
|
|
|
|
expected := testCase.expectedLoadStatements
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2021-05-21 09:37:00 +02:00
|
|
|
}
|
2021-02-15 12:04:32 +01:00
|
|
|
|
2021-05-21 09:37:00 +02:00
|
|
|
func registerCcLibraryHeadersModuleTypes(ctx android.RegistrationContext) {
|
|
|
|
cc.RegisterCCBuildComponents(ctx)
|
2023-09-18 15:23:38 +02:00
|
|
|
cc.RegisterLibraryHeadersBuildComponents(ctx)
|
2023-09-18 20:32:18 +02:00
|
|
|
ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
|
2021-02-15 12:04:32 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runCcLibraryHeadersTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2021-05-25 16:39:35 +02:00
|
|
|
t.Helper()
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, registerCcLibraryHeadersModuleTypes, tc)
|
2021-05-21 09:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryHeadersSimple(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
Description: "cc_library_headers test",
|
2022-06-21 21:28:33 +02:00
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"lib-1/lib1a.h": "",
|
|
|
|
"lib-1/lib1b.h": "",
|
|
|
|
"lib-2/lib2a.h": "",
|
|
|
|
"lib-2/lib2b.h": "",
|
|
|
|
"dir-1/dir1a.h": "",
|
|
|
|
"dir-1/dir1b.h": "",
|
|
|
|
"dir-2/dir2a.h": "",
|
|
|
|
"dir-2/dir2b.h": "",
|
|
|
|
"arch_arm64_exported_include_dir/a.h": "",
|
|
|
|
"arch_x86_exported_include_dir/b.h": "",
|
|
|
|
"arch_x86_64_exported_include_dir/c.h": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
2021-02-15 12:04:32 +01:00
|
|
|
cc_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
export_include_dirs: ["dir-1", "dir-2"],
|
|
|
|
header_libs: ["lib-1", "lib-2"],
|
2021-03-25 10:06:03 +01:00
|
|
|
|
2021-04-06 22:06:21 +02:00
|
|
|
arch: {
|
|
|
|
arm64: {
|
2021-09-10 16:06:32 +02:00
|
|
|
// We expect dir-1 headers to be dropped, because dir-1 is already in export_include_dirs
|
2021-04-06 22:06:21 +02:00
|
|
|
export_include_dirs: ["arch_arm64_exported_include_dir", "dir-1"],
|
|
|
|
},
|
|
|
|
x86: {
|
|
|
|
export_include_dirs: ["arch_x86_exported_include_dir"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
export_include_dirs: ["arch_x86_64_exported_include_dir"],
|
|
|
|
},
|
|
|
|
},
|
2022-03-02 00:44:08 +01:00
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29",
|
2021-04-06 22:06:21 +02:00
|
|
|
|
2021-03-25 10:06:03 +01:00
|
|
|
// TODO: Also support export_header_lib_headers
|
2021-02-15 12:04:32 +01:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
2022-12-10 01:08:54 +01:00
|
|
|
"export_includes": `select({
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/arch:arm64": ["arch_arm64_exported_include_dir"],
|
|
|
|
"//build/bazel/platforms/arch:x86": ["arch_x86_exported_include_dir"],
|
|
|
|
"//build/bazel/platforms/arch:x86_64": ["arch_x86_64_exported_include_dir"],
|
2021-04-06 22:06:21 +02:00
|
|
|
"//conditions:default": [],
|
2022-12-10 01:08:54 +01:00
|
|
|
}) + [
|
|
|
|
"dir-1",
|
|
|
|
"dir-2",
|
|
|
|
]`,
|
2022-06-17 21:42:28 +02:00
|
|
|
"sdk_version": `"current"`,
|
|
|
|
"min_sdk_version": `"29"`,
|
2023-09-19 21:51:52 +02:00
|
|
|
"deps": `select({
|
|
|
|
"//build/bazel/rules/apex:unbundled_app": ["//build/bazel/rules/cc:ndk_sysroot"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
2021-11-08 18:56:31 +01:00
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 20:06:54 +01:00
|
|
|
// header_libs has "variant_prepend" tag. In bp2build output,
|
|
|
|
// variant info(select) should go before general info.
|
2021-09-10 16:06:32 +02:00
|
|
|
func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
Description: "cc_library_headers test with os-specific header_libs props",
|
|
|
|
Filesystem: map[string]string{},
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"android-lib", "base-lib", "darwin-lib",
|
|
|
|
"linux-lib", "linux_bionic-lib", "windows-lib"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryPreamble + `
|
2021-09-10 16:06:32 +02:00
|
|
|
cc_library_headers {
|
|
|
|
name: "android-lib",
|
|
|
|
}
|
|
|
|
cc_library_headers {
|
|
|
|
name: "base-lib",
|
|
|
|
}
|
|
|
|
cc_library_headers {
|
|
|
|
name: "darwin-lib",
|
|
|
|
}
|
|
|
|
cc_library_headers {
|
|
|
|
name: "linux-lib",
|
|
|
|
}
|
|
|
|
cc_library_headers {
|
|
|
|
name: "linux_bionic-lib",
|
|
|
|
}
|
|
|
|
cc_library_headers {
|
|
|
|
name: "windows-lib",
|
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
cc_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
header_libs: ["base-lib"],
|
2022-06-17 21:42:28 +02:00
|
|
|
export_header_lib_headers: ["base-lib"],
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
target: {
|
2022-06-17 21:42:28 +02:00
|
|
|
android: {
|
|
|
|
header_libs: ["android-lib"],
|
|
|
|
export_header_lib_headers: ["android-lib"],
|
|
|
|
},
|
|
|
|
darwin: {
|
|
|
|
header_libs: ["darwin-lib"],
|
|
|
|
export_header_lib_headers: ["darwin-lib"],
|
|
|
|
},
|
|
|
|
linux_bionic: {
|
|
|
|
header_libs: ["linux_bionic-lib"],
|
|
|
|
export_header_lib_headers: ["linux_bionic-lib"],
|
|
|
|
},
|
|
|
|
linux_glibc: {
|
|
|
|
header_libs: ["linux-lib"],
|
|
|
|
export_header_lib_headers: ["linux-lib"],
|
|
|
|
},
|
|
|
|
windows: {
|
|
|
|
header_libs: ["windows-lib"],
|
|
|
|
export_header_lib_headers: ["windows-lib"],
|
|
|
|
},
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
2023-01-04 20:06:54 +01:00
|
|
|
"deps": `select({
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/os:android": [":android-lib"],
|
|
|
|
"//build/bazel/platforms/os:darwin": [":darwin-lib"],
|
|
|
|
"//build/bazel/platforms/os:linux_bionic": [":linux_bionic-lib"],
|
2022-12-21 00:29:31 +01:00
|
|
|
"//build/bazel/platforms/os:linux_glibc": [":linux-lib"],
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/os:windows": [":windows-lib"],
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
"//conditions:default": [],
|
2023-01-04 20:06:54 +01:00
|
|
|
}) + [":base-lib"]`,
|
2021-11-08 18:56:31 +01:00
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryHeadersOsSpecficHeaderLibsExportHeaderLibHeaders(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
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"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryPreamble + `
|
2021-09-10 16:06:32 +02:00
|
|
|
cc_library_headers {
|
|
|
|
name: "android-lib",
|
|
|
|
}
|
|
|
|
cc_library_headers {
|
|
|
|
name: "exported-lib",
|
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
cc_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
target: {
|
2021-09-22 21:52:58 +02:00
|
|
|
android: {
|
|
|
|
header_libs: ["android-lib", "exported-lib"],
|
|
|
|
export_header_lib_headers: ["exported-lib"]
|
|
|
|
},
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"deps": `select({
|
2021-05-19 00:35:24 +02:00
|
|
|
"//build/bazel/platforms/os:android": [":exported-lib"],
|
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
Description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props",
|
|
|
|
Filesystem: map[string]string{},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryPreamble + `cc_library_headers {
|
2021-04-26 13:49:08 +02:00
|
|
|
name: "foo_headers",
|
|
|
|
export_system_include_dirs: [
|
2021-09-10 16:06:32 +02:00
|
|
|
"shared_include_dir",
|
2021-04-26 13:49:08 +02:00
|
|
|
],
|
|
|
|
target: {
|
2021-09-10 16:06:32 +02:00
|
|
|
android: {
|
|
|
|
export_system_include_dirs: [
|
|
|
|
"android_include_dir",
|
2021-04-26 13:49:08 +02:00
|
|
|
],
|
2021-09-10 16:06:32 +02:00
|
|
|
},
|
2021-04-26 13:49:08 +02:00
|
|
|
linux_glibc: {
|
|
|
|
export_system_include_dirs: [
|
|
|
|
"linux_include_dir",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
darwin: {
|
|
|
|
export_system_include_dirs: [
|
|
|
|
"darwin_include_dir",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
arch: {
|
|
|
|
arm: {
|
2021-09-10 16:06:32 +02:00
|
|
|
export_system_include_dirs: [
|
|
|
|
"arm_include_dir",
|
2021-04-26 13:49:08 +02:00
|
|
|
],
|
2021-09-10 16:06:32 +02:00
|
|
|
},
|
2021-04-26 13:49:08 +02:00
|
|
|
x86_64: {
|
|
|
|
export_system_include_dirs: [
|
|
|
|
"x86_64_include_dir",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-26 13:49:08 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
2022-12-10 01:08:54 +01:00
|
|
|
"export_system_includes": `select({
|
2021-04-26 13:49:08 +02:00
|
|
|
"//build/bazel/platforms/os:android": ["android_include_dir"],
|
|
|
|
"//build/bazel/platforms/os:darwin": ["darwin_include_dir"],
|
2022-12-21 00:29:31 +01:00
|
|
|
"//build/bazel/platforms/os:linux_glibc": ["linux_include_dir"],
|
2021-04-26 13:49:08 +02:00
|
|
|
"//conditions:default": [],
|
2022-12-10 01:08:54 +01:00
|
|
|
}) + select({
|
|
|
|
"//build/bazel/platforms/arch:arm": ["arm_include_dir"],
|
|
|
|
"//build/bazel/platforms/arch:x86_64": ["x86_64_include_dir"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}) + ["shared_include_dir"]`,
|
2021-11-08 18:56:31 +01:00
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
2021-02-15 12:04:32 +01:00
|
|
|
}
|
2021-06-03 19:43:01 +02:00
|
|
|
|
|
|
|
func TestCcLibraryHeadersNoCrtIgnored(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
Description: "cc_library_headers test",
|
2022-06-21 21:28:33 +02:00
|
|
|
Filesystem: map[string]string{
|
2021-06-03 19:43:01 +02:00
|
|
|
"lib-1/lib1a.h": "",
|
|
|
|
"lib-1/lib1b.h": "",
|
|
|
|
"lib-2/lib2a.h": "",
|
|
|
|
"lib-2/lib2b.h": "",
|
|
|
|
"dir-1/dir1a.h": "",
|
|
|
|
"dir-1/dir1b.h": "",
|
|
|
|
"dir-2/dir2a.h": "",
|
|
|
|
"dir-2/dir2b.h": "",
|
|
|
|
"arch_arm64_exported_include_dir/a.h": "",
|
|
|
|
"arch_x86_exported_include_dir/b.h": "",
|
|
|
|
"arch_x86_64_exported_include_dir/c.h": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
2021-06-03 19:43:01 +02:00
|
|
|
cc_library_headers {
|
|
|
|
name: "lib-1",
|
|
|
|
export_include_dirs: ["lib-1"],
|
|
|
|
no_libcrt: true,
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-06-03 19:43:01 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "lib-1", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"export_includes": `["lib-1"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-06-03 19:43:01 +02:00
|
|
|
})
|
|
|
|
}
|
2022-06-22 22:30:55 +02:00
|
|
|
|
|
|
|
func TestCcLibraryHeadersExportedStaticLibHeadersReexported(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
Description: "cc_library_headers exported_static_lib_headers is reexported",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
StubbedBuildDefinitions: []string{"foo_export"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
2022-06-22 22:30:55 +02:00
|
|
|
cc_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
export_static_lib_headers: ["foo_export"],
|
|
|
|
static_libs: ["foo_export", "foo_no_reexport"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
2023-09-19 03:12:48 +02:00
|
|
|
` + simpleModule("cc_library_headers", "foo_export"),
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
2022-06-22 22:30:55 +02:00
|
|
|
"deps": `[":foo_export"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryHeadersExportedSharedLibHeadersReexported(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
Description: "cc_library_headers exported_shared_lib_headers is reexported",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
StubbedBuildDefinitions: []string{"foo_export"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
2022-06-22 22:30:55 +02:00
|
|
|
cc_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
export_shared_lib_headers: ["foo_export"],
|
|
|
|
shared_libs: ["foo_export", "foo_no_reexport"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
2023-09-19 03:12:48 +02:00
|
|
|
` + simpleModule("cc_library_headers", "foo_export"),
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
2022-06-22 22:30:55 +02:00
|
|
|
"deps": `[":foo_export"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryHeadersExportedHeaderLibHeadersReexported(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
Description: "cc_library_headers exported_header_lib_headers is reexported",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
StubbedBuildDefinitions: []string{"foo_export"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
2022-06-22 22:30:55 +02:00
|
|
|
cc_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
export_header_lib_headers: ["foo_export"],
|
|
|
|
header_libs: ["foo_export", "foo_no_reexport"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
2023-09-19 03:12:48 +02:00
|
|
|
` + simpleModule("cc_library_headers", "foo_export"),
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
2022-06-22 22:30:55 +02:00
|
|
|
"deps": `[":foo_export"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-08-18 17:53:00 +02:00
|
|
|
|
|
|
|
func TestCcLibraryHeadersWholeStaticLibsReexported(t *testing.T) {
|
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
2023-09-18 15:23:38 +02:00
|
|
|
Description: "cc_library_headers whole_static_libs is reexported",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
StubbedBuildDefinitions: []string{"foo_export"},
|
2022-08-18 17:53:00 +02:00
|
|
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
|
|
|
cc_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
whole_static_libs: ["foo_export"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
2023-09-19 03:12:48 +02:00
|
|
|
` + simpleModule("cc_library_headers", "foo_export"),
|
2022-08-18 17:53:00 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
2022-08-18 17:53:00 +02:00
|
|
|
"deps": `[":foo_export"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-09-18 15:23:38 +02:00
|
|
|
|
|
|
|
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"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-09-18 20:32:18 +02:00
|
|
|
|
|
|
|
func TestPrebuiltCcLibraryHeadersPreferredRdepUpdated(t *testing.T) {
|
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_headers prebuilt preferred is used as rdep",
|
|
|
|
StubbedBuildDefinitions: []string{"foo_export"},
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
|
|
|
},
|
|
|
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
|
|
|
cc_prebuilt_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
whole_static_libs: ["foo_export"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
prefer: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_shared {
|
|
|
|
name: "foo",
|
|
|
|
header_libs: ["foo_headers"],
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
` + simpleModule("cc_library_headers", "foo_export"),
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
|
|
|
"deps": `[":foo_export"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
|
|
|
"implementation_deps": `[":foo_headers"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrebuiltCcLibraryHeadersRdepUpdated(t *testing.T) {
|
|
|
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_headers not preferred is not used for rdep",
|
|
|
|
StubbedBuildDefinitions: []string{"foo_export"},
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
|
|
|
},
|
|
|
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
|
|
|
cc_prebuilt_library_headers {
|
|
|
|
name: "foo_headers",
|
|
|
|
whole_static_libs: ["foo_export"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
prefer: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_shared {
|
|
|
|
name: "foo",
|
|
|
|
header_libs: ["foo_headers"],
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
` + simpleModule("cc_library_headers", "foo_export"),
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
|
|
|
"deps": `[":foo_export"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
|
|
|
"implementation_deps": `["//foo/bar:foo_headers"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|