2021-03-25 10:06:03 +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 (
|
2022-08-09 18:50:56 +02:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2021-03-25 10:06:03 +01:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
2021-05-13 21:13:04 +02:00
|
|
|
"android/soong/genrule"
|
2021-03-25 10:06:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// See cc/testing.go for more context
|
|
|
|
soongCcLibraryStaticPreamble = `
|
|
|
|
cc_defaults {
|
2021-09-10 16:06:32 +02:00
|
|
|
name: "linux_bionic_supported",
|
2021-03-25 10:06:03 +01:00
|
|
|
}`
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCcLibraryStaticLoadStatement(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
bazelTargets BazelTargets
|
|
|
|
expectedLoadStatements string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
bazelTargets: BazelTargets{
|
|
|
|
BazelTarget{
|
|
|
|
name: "cc_library_static_target",
|
|
|
|
ruleClass: "cc_library_static",
|
|
|
|
// 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
|
|
|
func registerCcLibraryStaticModuleTypes(ctx android.RegistrationContext) {
|
|
|
|
cc.RegisterCCBuildComponents(ctx)
|
|
|
|
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
|
|
|
|
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
// Required for system_shared_libs dependencies.
|
|
|
|
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
|
2021-05-21 09:37:00 +02:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runCcLibraryStaticTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2021-05-25 16:39:35 +02:00
|
|
|
t.Helper()
|
2021-11-08 18:56:31 +01:00
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
(&tc).ModuleTypeUnderTest = "cc_library_static"
|
|
|
|
(&tc).ModuleTypeUnderTestFactory = cc.LibraryStaticFactory
|
|
|
|
RunBp2BuildTestCase(t, registerCcLibraryStaticModuleTypes, tc)
|
2021-05-21 09:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticSimple(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static test",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
// NOTE: include_dir headers *should not* appear in Bazel hdrs later (?)
|
|
|
|
"include_dir_1/include_dir_1_a.h": "",
|
|
|
|
"include_dir_1/include_dir_1_b.h": "",
|
|
|
|
"include_dir_2/include_dir_2_a.h": "",
|
|
|
|
"include_dir_2/include_dir_2_b.h": "",
|
|
|
|
// NOTE: local_include_dir headers *should not* appear in Bazel hdrs later (?)
|
|
|
|
"local_include_dir_1/local_include_dir_1_a.h": "",
|
|
|
|
"local_include_dir_1/local_include_dir_1_b.h": "",
|
|
|
|
"local_include_dir_2/local_include_dir_2_a.h": "",
|
|
|
|
"local_include_dir_2/local_include_dir_2_b.h": "",
|
|
|
|
// NOTE: export_include_dir headers *should* appear in Bazel hdrs later
|
|
|
|
"export_include_dir_1/export_include_dir_1_a.h": "",
|
|
|
|
"export_include_dir_1/export_include_dir_1_b.h": "",
|
|
|
|
"export_include_dir_2/export_include_dir_2_a.h": "",
|
|
|
|
"export_include_dir_2/export_include_dir_2_b.h": "",
|
|
|
|
// NOTE: Soong implicitly includes headers in the current directory
|
|
|
|
"implicit_include_1.h": "",
|
|
|
|
"implicit_include_2.h": "",
|
|
|
|
},
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"header_lib_1", "header_lib_2",
|
|
|
|
"static_lib_1", "static_lib_2", "whole_static_lib_1", "whole_static_lib_2"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-03-25 10:06:03 +01:00
|
|
|
cc_library_headers {
|
|
|
|
name: "header_lib_1",
|
|
|
|
export_include_dirs: ["header_lib_1"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_headers {
|
|
|
|
name: "header_lib_2",
|
|
|
|
export_include_dirs: ["header_lib_2"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_lib_1",
|
|
|
|
srcs: ["static_lib_1.cc"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_lib_2",
|
|
|
|
srcs: ["static_lib_2.cc"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "whole_static_lib_1",
|
|
|
|
srcs: ["whole_static_lib_1.cc"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "whole_static_lib_2",
|
|
|
|
srcs: ["whole_static_lib_2.cc"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: [
|
|
|
|
"foo_static1.cc",
|
2021-04-13 09:14:55 +02:00
|
|
|
"foo_static2.cc",
|
2021-03-25 10:06:03 +01:00
|
|
|
],
|
|
|
|
cflags: [
|
|
|
|
"-Dflag1",
|
2021-04-13 09:14:55 +02:00
|
|
|
"-Dflag2"
|
2021-03-25 10:06:03 +01:00
|
|
|
],
|
|
|
|
static_libs: [
|
|
|
|
"static_lib_1",
|
2021-04-13 09:14:55 +02:00
|
|
|
"static_lib_2"
|
2021-03-25 10:06:03 +01:00
|
|
|
],
|
|
|
|
whole_static_libs: [
|
|
|
|
"whole_static_lib_1",
|
2021-04-13 09:14:55 +02:00
|
|
|
"whole_static_lib_2"
|
2021-03-25 10:06:03 +01:00
|
|
|
],
|
|
|
|
include_dirs: [
|
2021-04-13 09:14:55 +02:00
|
|
|
"include_dir_1",
|
|
|
|
"include_dir_2",
|
2021-03-25 10:06:03 +01:00
|
|
|
],
|
|
|
|
local_include_dirs: [
|
|
|
|
"local_include_dir_1",
|
2021-04-13 09:14:55 +02:00
|
|
|
"local_include_dir_2",
|
2021-03-25 10:06:03 +01:00
|
|
|
],
|
|
|
|
export_include_dirs: [
|
2021-05-19 00:35:24 +02:00
|
|
|
"export_include_dir_1",
|
|
|
|
"export_include_dir_2"
|
2021-03-25 10:06:03 +01:00
|
|
|
],
|
|
|
|
header_libs: [
|
|
|
|
"header_lib_1",
|
2021-04-13 09:14:55 +02:00
|
|
|
"header_lib_2"
|
2021-03-25 10:06:03 +01:00
|
|
|
],
|
2022-03-02 00:44:08 +01:00
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29",
|
2021-03-25 10:06:03 +01:00
|
|
|
|
|
|
|
// TODO: Also support export_header_lib_headers
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"absolute_includes": `[
|
2021-09-10 16:07:07 +02:00
|
|
|
"include_dir_1",
|
|
|
|
"include_dir_2",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"copts": `[
|
2021-03-25 10:06:03 +01:00
|
|
|
"-Dflag1",
|
|
|
|
"-Dflag2",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"export_includes": `[
|
2021-09-09 20:08:21 +02:00
|
|
|
"export_include_dir_1",
|
|
|
|
"export_include_dir_2",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"implementation_deps": `[
|
2021-03-25 10:06:03 +01:00
|
|
|
":header_lib_1",
|
|
|
|
":header_lib_2",
|
|
|
|
":static_lib_1",
|
|
|
|
":static_lib_2",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"local_includes": `[
|
2021-09-10 16:07:07 +02:00
|
|
|
"local_include_dir_1",
|
|
|
|
"local_include_dir_2",
|
|
|
|
".",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs": `[
|
2021-03-25 10:06:03 +01:00
|
|
|
"foo_static1.cc",
|
|
|
|
"foo_static2.cc",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"whole_archive_deps": `[
|
2021-05-06 22:23:19 +02:00
|
|
|
":whole_static_lib_1",
|
|
|
|
":whole_static_lib_2",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
2022-05-12 17:42:33 +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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticSubpackage(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static subpackage test",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
// subpackage with subdirectory
|
|
|
|
"subpackage/Android.bp": "",
|
|
|
|
"subpackage/subpackage_header.h": "",
|
|
|
|
"subpackage/subdirectory/subdirectory_header.h": "",
|
|
|
|
// subsubpackage with subdirectory
|
|
|
|
"subpackage/subsubpackage/Android.bp": "",
|
|
|
|
"subpackage/subsubpackage/subsubpackage_header.h": "",
|
|
|
|
"subpackage/subsubpackage/subdirectory/subdirectory_header.h": "",
|
|
|
|
// subsubsubpackage with subdirectory
|
|
|
|
"subpackage/subsubpackage/subsubsubpackage/Android.bp": "",
|
|
|
|
"subpackage/subsubpackage/subsubsubpackage/subsubsubpackage_header.h": "",
|
|
|
|
"subpackage/subsubpackage/subsubsubpackage/subdirectory/subdirectory_header.h": "",
|
2021-04-13 19:08:04 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-13 19:08:04 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
2021-09-10 16:07:07 +02:00
|
|
|
srcs: [],
|
2021-04-13 19:08:04 +02:00
|
|
|
include_dirs: [
|
2021-09-10 16:07:07 +02:00
|
|
|
"subpackage",
|
2021-04-13 19:08:04 +02:00
|
|
|
],
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"absolute_includes": `["subpackage"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticExportIncludeDir(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static export include dir",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
// subpackage with subdirectory
|
|
|
|
"subpackage/Android.bp": "",
|
|
|
|
"subpackage/subpackage_header.h": "",
|
|
|
|
"subpackage/subdirectory/subdirectory_header.h": "",
|
2021-04-13 09:14:55 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-13 09:14:55 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
export_include_dirs: ["subpackage"],
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-13 09:14:55 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"export_includes": `["subpackage"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticExportSystemIncludeDir(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static export system include dir",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
// subpackage with subdirectory
|
|
|
|
"subpackage/Android.bp": "",
|
|
|
|
"subpackage/subpackage_header.h": "",
|
|
|
|
"subpackage/subdirectory/subdirectory_header.h": "",
|
2021-04-13 09:14:55 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-13 09:14:55 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
export_system_include_dirs: ["subpackage"],
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-13 09:14:55 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"export_system_includes": `["subpackage"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticManyIncludeDirs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
|
|
|
|
Dir: "subpackage",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
// subpackage with subdirectory
|
|
|
|
"subpackage/Android.bp": `
|
2021-04-13 09:14:55 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
// include_dirs are workspace/root relative
|
|
|
|
include_dirs: [
|
|
|
|
"subpackage/subsubpackage",
|
|
|
|
"subpackage2",
|
|
|
|
"subpackage3/subsubpackage"
|
|
|
|
],
|
|
|
|
local_include_dirs: ["subsubpackage2"], // module dir relative
|
|
|
|
export_include_dirs: ["./exported_subsubpackage"], // module dir relative
|
|
|
|
include_build_directory: true,
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`,
|
2021-05-21 09:37:00 +02:00
|
|
|
"subpackage/subsubpackage/header.h": "",
|
|
|
|
"subpackage/subsubpackage2/header.h": "",
|
|
|
|
"subpackage/exported_subsubpackage/header.h": "",
|
|
|
|
"subpackage2/header.h": "",
|
|
|
|
"subpackage3/subsubpackage/header.h": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble,
|
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"absolute_includes": `[
|
2021-09-10 16:07:07 +02:00
|
|
|
"subpackage/subsubpackage",
|
|
|
|
"subpackage2",
|
|
|
|
"subpackage3/subsubpackage",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"export_includes": `["./exported_subsubpackage"]`,
|
|
|
|
"local_includes": `[
|
2021-09-10 16:07:07 +02:00
|
|
|
"subsubpackage2",
|
|
|
|
".",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
})},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticIncludeBuildDirectoryDisabled(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static include_build_directory disabled",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
// subpackage with subdirectory
|
|
|
|
"subpackage/Android.bp": "",
|
|
|
|
"subpackage/subpackage_header.h": "",
|
|
|
|
"subpackage/subdirectory/subdirectory_header.h": "",
|
2021-04-13 09:14:55 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-13 09:14:55 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
|
|
|
|
local_include_dirs: ["subpackage2"],
|
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"absolute_includes": `["subpackage"]`,
|
|
|
|
"local_includes": `["subpackage2"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticIncludeBuildDirectoryEnabled(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static include_build_directory enabled",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
// subpackage with subdirectory
|
|
|
|
"subpackage/Android.bp": "",
|
|
|
|
"subpackage/subpackage_header.h": "",
|
|
|
|
"subpackage2/Android.bp": "",
|
|
|
|
"subpackage2/subpackage2_header.h": "",
|
|
|
|
"subpackage/subdirectory/subdirectory_header.h": "",
|
2021-04-13 09:14:55 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-13 09:14:55 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
|
|
|
|
local_include_dirs: ["subpackage2"],
|
|
|
|
include_build_directory: true,
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"absolute_includes": `["subpackage"]`,
|
|
|
|
"local_includes": `[
|
2021-09-10 16:07:07 +02:00
|
|
|
"subpackage2",
|
|
|
|
".",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticArchSpecificStaticLib(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "cc_library_static arch-specific static_libs",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
StubbedBuildDefinitions: []string{"static_dep", "static_dep2"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-09-10 16:06:32 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep",
|
|
|
|
}
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep2",
|
|
|
|
}
|
2021-04-13 09:14:55 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-13 09:14:55 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"implementation_deps": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm64": [":static_dep"],
|
2021-04-13 09:14:55 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"whole_archive_deps": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm64": [":static_dep2"],
|
2021-05-06 22:23:19 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticOsSpecificStaticLib(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "cc_library_static os-specific static_libs",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
StubbedBuildDefinitions: []string{"static_dep", "static_dep2"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-09-10 16:06:32 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep",
|
|
|
|
}
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep2",
|
|
|
|
}
|
2021-04-13 09:14:55 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-13 09:14:55 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"implementation_deps": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [":static_dep"],
|
2021-04-13 09:14:55 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"whole_archive_deps": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [":static_dep2"],
|
2021-05-06 22:23:19 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticBaseArchOsSpecificStaticLib(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static base, arch and os-specific static_libs",
|
|
|
|
Filesystem: map[string]string{},
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"static_dep", "static_dep2", "static_dep3",
|
|
|
|
"static_dep4"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-09-10 16:06:32 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep",
|
|
|
|
}
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep2",
|
|
|
|
}
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep3",
|
|
|
|
}
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep4",
|
|
|
|
}
|
2021-04-13 09:14:55 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
static_libs: ["static_dep"],
|
|
|
|
whole_static_libs: ["static_dep2"],
|
|
|
|
target: { android: { static_libs: ["static_dep3"] } },
|
|
|
|
arch: { arm64: { static_libs: ["static_dep4"] } },
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-13 09:14:55 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"implementation_deps": `[":static_dep"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm64": [":static_dep4"],
|
2021-04-13 09:14:55 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [":static_dep3"],
|
2021-04-13 09:14:55 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"whole_archive_deps": `[":static_dep2"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticSimpleExcludeSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static simple exclude_srcs",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"common.c": "",
|
|
|
|
"foo-a.c": "",
|
|
|
|
"foo-excluded.c": "",
|
2021-04-23 11:17:24 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-23 11:17:24 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.c", "foo-*.c"],
|
|
|
|
exclude_srcs: ["foo-excluded.c"],
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-23 11:17:24 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `[
|
2021-04-23 11:17:24 +02:00
|
|
|
"common.c",
|
|
|
|
"foo-a.c",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticOneArchSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static one arch specific srcs",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"common.c": "",
|
|
|
|
"foo-arm.c": "",
|
2021-04-23 11:17:24 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-23 11:17:24 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.c"],
|
2021-09-10 16:06:32 +02:00
|
|
|
arch: { arm: { srcs: ["foo-arm.c"] } },
|
|
|
|
include_build_directory: false,
|
2021-04-23 11:17:24 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `["common.c"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": ["foo-arm.c"],
|
2021-04-23 11:17:24 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticOneArchSrcsExcludeSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static one arch specific srcs and exclude_srcs",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"common.c": "",
|
|
|
|
"for-arm.c": "",
|
|
|
|
"not-for-arm.c": "",
|
|
|
|
"not-for-anything.c": "",
|
2021-04-23 11:17:24 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-23 11:17:24 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.c", "not-for-*.c"],
|
|
|
|
exclude_srcs: ["not-for-anything.c"],
|
|
|
|
arch: {
|
|
|
|
arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-23 11:17:24 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `["common.c"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": ["for-arm.c"],
|
2021-04-23 11:17:24 +02:00
|
|
|
"//conditions:default": ["not-for-arm.c"],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticTwoArchExcludeSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static arch specific exclude_srcs for 2 architectures",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"common.c": "",
|
|
|
|
"for-arm.c": "",
|
|
|
|
"for-x86.c": "",
|
|
|
|
"not-for-arm.c": "",
|
|
|
|
"not-for-x86.c": "",
|
2021-04-23 11:17:24 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-23 11:17:24 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.c", "not-for-*.c"],
|
|
|
|
exclude_srcs: ["not-for-everything.c"],
|
|
|
|
arch: {
|
|
|
|
arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
|
|
|
|
x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-23 11:17:24 +02:00
|
|
|
} `,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `["common.c"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": [
|
2021-04-23 11:17:24 +02:00
|
|
|
"not-for-x86.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-arm.c",
|
2021-04-23 11:17:24 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": [
|
2021-04-23 11:17:24 +02:00
|
|
|
"not-for-arm.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-x86.c",
|
2021-04-23 11:17:24 +02:00
|
|
|
],
|
|
|
|
"//conditions:default": [
|
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-x86.c",
|
|
|
|
],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
2021-11-08 18:56:31 +01:00
|
|
|
|
2021-05-21 09:37:00 +02:00
|
|
|
func TestCcLibraryStaticFourArchExcludeSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static arch specific exclude_srcs for 4 architectures",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"common.c": "",
|
|
|
|
"for-arm.c": "",
|
|
|
|
"for-arm64.c": "",
|
|
|
|
"for-x86.c": "",
|
|
|
|
"for-x86_64.c": "",
|
|
|
|
"not-for-arm.c": "",
|
|
|
|
"not-for-arm64.c": "",
|
|
|
|
"not-for-x86.c": "",
|
|
|
|
"not-for-x86_64.c": "",
|
|
|
|
"not-for-everything.c": "",
|
2021-04-23 11:17:24 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-23 11:17:24 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.c", "not-for-*.c"],
|
|
|
|
exclude_srcs: ["not-for-everything.c"],
|
|
|
|
arch: {
|
|
|
|
arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
|
|
|
|
arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
|
|
|
|
x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
|
|
|
|
x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
|
2021-09-10 16:06:32 +02:00
|
|
|
},
|
|
|
|
include_build_directory: false,
|
2021-04-23 11:17:24 +02:00
|
|
|
} `,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `["common.c"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": [
|
2021-04-23 11:17:24 +02:00
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-x86.c",
|
|
|
|
"not-for-x86_64.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-arm.c",
|
2021-04-23 11:17:24 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm64": [
|
2021-04-23 11:17:24 +02:00
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-x86.c",
|
|
|
|
"not-for-x86_64.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-arm64.c",
|
2021-04-23 11:17:24 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": [
|
2021-04-23 11:17:24 +02:00
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-x86_64.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-x86.c",
|
2021-04-23 11:17:24 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86_64": [
|
2021-04-23 11:17:24 +02:00
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-x86.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-x86_64.c",
|
2021-04-23 11:17:24 +02:00
|
|
|
],
|
|
|
|
"//conditions:default": [
|
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-x86.c",
|
|
|
|
"not-for-x86_64.c",
|
|
|
|
],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:08:27 +02:00
|
|
|
func TestCcLibraryStaticOneArchEmpty(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static one arch empty",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-26 21:08:27 +02:00
|
|
|
"common.cc": "",
|
|
|
|
"foo-no-arm.cc": "",
|
|
|
|
"foo-excluded.cc": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-05-26 21:08:27 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.cc", "foo-*.cc"],
|
|
|
|
exclude_srcs: ["foo-excluded.cc"],
|
|
|
|
arch: {
|
|
|
|
arm: { exclude_srcs: ["foo-no-arm.cc"] },
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-05-26 21:08:27 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs": `["common.cc"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": [],
|
2021-05-26 21:08:27 +02:00
|
|
|
"//conditions:default": ["foo-no-arm.cc"],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-26 21:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticOneArchEmptyOtherSet(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static one arch empty other set",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-26 21:08:27 +02:00
|
|
|
"common.cc": "",
|
|
|
|
"foo-no-arm.cc": "",
|
|
|
|
"x86-only.cc": "",
|
|
|
|
"foo-excluded.cc": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-05-26 21:08:27 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.cc", "foo-*.cc"],
|
|
|
|
exclude_srcs: ["foo-excluded.cc"],
|
|
|
|
arch: {
|
|
|
|
arm: { exclude_srcs: ["foo-no-arm.cc"] },
|
|
|
|
x86: { srcs: ["x86-only.cc"] },
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-05-26 21:08:27 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs": `["common.cc"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": [],
|
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": [
|
2021-05-26 21:08:27 +02:00
|
|
|
"foo-no-arm.cc",
|
|
|
|
"x86-only.cc",
|
|
|
|
],
|
|
|
|
"//conditions:default": ["foo-no-arm.cc"],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-26 21:08:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-21 09:37:00 +02:00
|
|
|
func TestCcLibraryStaticMultipleDepSameName(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "cc_library_static multiple dep same name panic",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
StubbedBuildDefinitions: []string{"static_dep"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-09-10 16:06:32 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "static_dep",
|
|
|
|
}
|
2021-04-26 21:47:28 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
2021-05-06 22:23:19 +02:00
|
|
|
static_libs: ["static_dep", "static_dep"],
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-26 21:47:28 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"implementation_deps": `[":static_dep"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticOneMultilibSrcsExcludeSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static 1 multilib srcs and exclude_srcs",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"common.c": "",
|
|
|
|
"for-lib32.c": "",
|
|
|
|
"not-for-lib32.c": "",
|
2021-04-30 00:06:50 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-30 00:06:50 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.c", "not-for-*.c"],
|
|
|
|
multilib: {
|
|
|
|
lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-30 00:06:50 +02:00
|
|
|
} `,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `["common.c"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": ["for-lib32.c"],
|
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": ["for-lib32.c"],
|
2021-04-30 00:06:50 +02:00
|
|
|
"//conditions:default": ["not-for-lib32.c"],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticTwoMultilibSrcsExcludeSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static 2 multilib srcs and exclude_srcs",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"common.c": "",
|
|
|
|
"for-lib32.c": "",
|
|
|
|
"for-lib64.c": "",
|
|
|
|
"not-for-lib32.c": "",
|
|
|
|
"not-for-lib64.c": "",
|
2021-04-30 00:06:50 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-30 00:06:50 +02:00
|
|
|
cc_library_static {
|
2021-11-08 18:56:31 +01:00
|
|
|
name: "foo_static",
|
2021-04-30 00:06:50 +02:00
|
|
|
srcs: ["common.c", "not-for-*.c"],
|
|
|
|
multilib: {
|
|
|
|
lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
|
|
|
|
lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-30 00:06:50 +02:00
|
|
|
} `,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `["common.c"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": [
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-lib64.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-lib32.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm64": [
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-lib32.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-lib64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:riscv64": [
|
2022-07-15 03:10:34 +02:00
|
|
|
"not-for-lib32.c",
|
|
|
|
"for-lib64.c",
|
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": [
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-lib64.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-lib32.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86_64": [
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-lib32.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-lib64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
],
|
|
|
|
"//conditions:default": [
|
|
|
|
"not-for-lib32.c",
|
|
|
|
"not-for-lib64.c",
|
|
|
|
],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibrarySTaticArchMultilibSrcsExcludeSrcs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static arch and multilib srcs and exclude_srcs",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"common.c": "",
|
|
|
|
"for-arm.c": "",
|
|
|
|
"for-arm64.c": "",
|
|
|
|
"for-x86.c": "",
|
|
|
|
"for-x86_64.c": "",
|
|
|
|
"for-lib32.c": "",
|
|
|
|
"for-lib64.c": "",
|
|
|
|
"not-for-arm.c": "",
|
|
|
|
"not-for-arm64.c": "",
|
2022-07-15 03:10:34 +02:00
|
|
|
"not-for-riscv64.c": "",
|
2021-05-21 09:37:00 +02:00
|
|
|
"not-for-x86.c": "",
|
|
|
|
"not-for-x86_64.c": "",
|
|
|
|
"not-for-lib32.c": "",
|
|
|
|
"not-for-lib64.c": "",
|
|
|
|
"not-for-everything.c": "",
|
2021-04-30 00:06:50 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-04-30 00:06:50 +02:00
|
|
|
cc_library_static {
|
2021-11-08 18:56:31 +01:00
|
|
|
name: "foo_static",
|
2021-04-30 00:06:50 +02:00
|
|
|
srcs: ["common.c", "not-for-*.c"],
|
|
|
|
exclude_srcs: ["not-for-everything.c"],
|
|
|
|
arch: {
|
|
|
|
arm: { srcs: ["for-arm.c"], exclude_srcs: ["not-for-arm.c"] },
|
|
|
|
arm64: { srcs: ["for-arm64.c"], exclude_srcs: ["not-for-arm64.c"] },
|
2022-07-15 03:10:34 +02:00
|
|
|
riscv64: { srcs: ["for-riscv64.c"], exclude_srcs: ["not-for-riscv64.c"] },
|
2021-04-30 00:06:50 +02:00
|
|
|
x86: { srcs: ["for-x86.c"], exclude_srcs: ["not-for-x86.c"] },
|
|
|
|
x86_64: { srcs: ["for-x86_64.c"], exclude_srcs: ["not-for-x86_64.c"] },
|
|
|
|
},
|
|
|
|
multilib: {
|
|
|
|
lib32: { srcs: ["for-lib32.c"], exclude_srcs: ["not-for-lib32.c"] },
|
|
|
|
lib64: { srcs: ["for-lib64.c"], exclude_srcs: ["not-for-lib64.c"] },
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-30 00:06:50 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `["common.c"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm": [
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-lib64.c",
|
2022-07-15 03:10:34 +02:00
|
|
|
"not-for-riscv64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-x86.c",
|
|
|
|
"not-for-x86_64.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-arm.c",
|
|
|
|
"for-lib32.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:arm64": [
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-lib32.c",
|
2022-07-15 03:10:34 +02:00
|
|
|
"not-for-riscv64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-x86.c",
|
|
|
|
"not-for-x86_64.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-arm64.c",
|
|
|
|
"for-lib64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:riscv64": [
|
2022-07-15 03:10:34 +02:00
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-lib32.c",
|
|
|
|
"not-for-x86.c",
|
|
|
|
"not-for-x86_64.c",
|
|
|
|
"for-riscv64.c",
|
|
|
|
"for-lib64.c",
|
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": [
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-lib64.c",
|
2022-07-15 03:10:34 +02:00
|
|
|
"not-for-riscv64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-x86_64.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-x86.c",
|
|
|
|
"for-lib32.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
],
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86_64": [
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-lib32.c",
|
2022-07-15 03:10:34 +02:00
|
|
|
"not-for-riscv64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-x86.c",
|
2021-10-11 21:40:35 +02:00
|
|
|
"for-x86_64.c",
|
|
|
|
"for-lib64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
],
|
|
|
|
"//conditions:default": [
|
|
|
|
"not-for-arm.c",
|
|
|
|
"not-for-arm64.c",
|
|
|
|
"not-for-lib32.c",
|
|
|
|
"not-for-lib64.c",
|
2022-07-15 03:10:34 +02:00
|
|
|
"not-for-riscv64.c",
|
2021-04-30 00:06:50 +02:00
|
|
|
"not-for-x86.c",
|
|
|
|
"not-for-x86_64.c",
|
|
|
|
],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-19 15:45:48 +02:00
|
|
|
func TestCcLibraryStaticGeneratedHeadersAllPartitions(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"generated_hdr", "export_generated_hdr"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-10-19 15:45:48 +02:00
|
|
|
genrule {
|
|
|
|
name: "generated_hdr",
|
|
|
|
cmd: "nothing to see here",
|
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
genrule {
|
|
|
|
name: "export_generated_hdr",
|
|
|
|
cmd: "nothing to see here",
|
|
|
|
}
|
|
|
|
|
2021-10-19 15:45:48 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["cpp_src.cpp", "as_src.S", "c_src.c"],
|
2021-10-19 19:56:10 +02:00
|
|
|
generated_headers: ["generated_hdr", "export_generated_hdr"],
|
|
|
|
export_generated_headers: ["export_generated_hdr"],
|
2021-10-19 15:45:48 +02:00
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-12-10 20:28:20 +01:00
|
|
|
"export_includes": `["."]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"hdrs": `[":export_generated_hdr"]`,
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs": `[
|
2021-10-19 15:45:48 +02:00
|
|
|
"cpp_src.cpp",
|
|
|
|
":generated_hdr",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs_as": `[
|
2021-10-19 15:45:48 +02:00
|
|
|
"as_src.S",
|
|
|
|
":generated_hdr",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs_c": `[
|
2021-10-19 15:45:48 +02:00
|
|
|
"c_src.c",
|
|
|
|
":generated_hdr",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-10-19 15:45:48 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-18 17:39:30 +02:00
|
|
|
func TestCcLibraryStaticGeneratedHeadersMultipleExports(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"generated_hdr", "export_generated_hdr"},
|
2023-07-18 17:39:30 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
|
|
|
genrule {
|
|
|
|
name: "generated_hdr",
|
|
|
|
cmd: "nothing to see here",
|
|
|
|
export_include_dirs: ["foo", "bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
genrule {
|
|
|
|
name: "export_generated_hdr",
|
|
|
|
cmd: "nothing to see here",
|
|
|
|
export_include_dirs: ["a", "b"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
generated_headers: ["generated_hdr", "export_generated_hdr"],
|
|
|
|
export_generated_headers: ["export_generated_hdr"],
|
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
|
|
|
"deps": `[":export_generated_hdr__header_library"]`,
|
|
|
|
"implementation_deps": `[":generated_hdr__header_library"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 20:06:54 +01:00
|
|
|
// generated_headers has "variant_prepend" tag. In bp2build output,
|
|
|
|
// variant info(select) should go before general info.
|
2021-05-21 09:37:00 +02:00
|
|
|
func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static arch srcs/exclude_srcs with generated files",
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//dep:generated_src_other_pkg", "//dep:generated_hdr_other_pkg",
|
|
|
|
"//dep:generated_src_other_pkg_x86", "//dep:generated_hdr_other_pkg_x86", "//dep:generated_hdr_other_pkg_android",
|
|
|
|
"generated_src", "generated_src_not_x86", "generated_src_android", "generated_hdr",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Filesystem: map[string]string{
|
2021-05-25 18:10:58 +02:00
|
|
|
"common.cpp": "",
|
|
|
|
"for-x86.cpp": "",
|
|
|
|
"not-for-x86.cpp": "",
|
|
|
|
"not-for-everything.cpp": "",
|
2023-09-19 03:12:48 +02:00
|
|
|
"dep/Android.bp": simpleModule("genrule", "generated_src_other_pkg") +
|
|
|
|
simpleModule("genrule", "generated_hdr_other_pkg") +
|
|
|
|
simpleModule("genrule", "generated_src_other_pkg_x86") +
|
|
|
|
simpleModule("genrule", "generated_hdr_other_pkg_x86") +
|
|
|
|
simpleModule("genrule", "generated_hdr_other_pkg_android"),
|
2021-05-21 09:37:00 +02:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble +
|
2023-09-19 03:12:48 +02:00
|
|
|
simpleModule("genrule", "generated_src") +
|
|
|
|
simpleModule("genrule", "generated_src_not_x86") +
|
|
|
|
simpleModule("genrule", "generated_src_android") +
|
|
|
|
simpleModule("genrule", "generated_hdr") + `
|
2021-05-13 21:13:04 +02:00
|
|
|
cc_library_static {
|
2021-11-08 18:56:31 +01:00
|
|
|
name: "foo_static",
|
2021-10-11 20:15:51 +02:00
|
|
|
srcs: ["common.cpp", "not-for-*.cpp"],
|
|
|
|
exclude_srcs: ["not-for-everything.cpp"],
|
|
|
|
generated_sources: ["generated_src", "generated_src_other_pkg", "generated_src_not_x86"],
|
|
|
|
generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
|
2021-12-10 20:28:20 +01:00
|
|
|
export_generated_headers: ["generated_hdr_other_pkg"],
|
2021-10-11 20:15:51 +02:00
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
srcs: ["for-x86.cpp"],
|
|
|
|
exclude_srcs: ["not-for-x86.cpp"],
|
|
|
|
generated_headers: ["generated_hdr_other_pkg_x86"],
|
|
|
|
exclude_generated_sources: ["generated_src_not_x86"],
|
2021-12-10 20:28:20 +01:00
|
|
|
export_generated_headers: ["generated_hdr_other_pkg_x86"],
|
2021-10-11 20:15:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
generated_sources: ["generated_src_android"],
|
|
|
|
generated_headers: ["generated_hdr_other_pkg_android"],
|
2021-12-10 20:28:20 +01:00
|
|
|
export_generated_headers: ["generated_hdr_other_pkg_android"],
|
2021-10-11 20:15:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-05-13 21:13:04 +02:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs": `[
|
2021-10-11 21:40:35 +02:00
|
|
|
"common.cpp",
|
2021-05-13 21:13:04 +02:00
|
|
|
":generated_src",
|
2021-10-11 21:40:35 +02:00
|
|
|
"//dep:generated_src_other_pkg",
|
2021-10-19 15:45:48 +02:00
|
|
|
":generated_hdr",
|
2021-05-13 21:13:04 +02:00
|
|
|
] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": ["for-x86.cpp"],
|
2021-10-11 20:15:51 +02:00
|
|
|
"//conditions:default": [
|
|
|
|
"not-for-x86.cpp",
|
2021-10-11 21:40:35 +02:00
|
|
|
":generated_src_not_x86",
|
2021-10-11 20:15:51 +02:00
|
|
|
],
|
|
|
|
}) + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [":generated_src_android"],
|
2021-12-10 20:28:20 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
2023-01-04 20:06:54 +01:00
|
|
|
"hdrs": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"],
|
2021-12-10 20:28:20 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"],
|
2021-10-11 20:15:51 +02:00
|
|
|
"//conditions:default": [],
|
2023-01-04 20:06:54 +01:00
|
|
|
}) + ["//dep:generated_hdr_other_pkg"]`,
|
2021-12-10 20:28:20 +01:00
|
|
|
"local_includes": `["."]`,
|
|
|
|
"export_absolute_includes": `["dep"]`,
|
2021-11-08 18:56:31 +01:00
|
|
|
}),
|
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
2021-03-25 10:06:03 +01:00
|
|
|
}
|
2021-05-06 19:54:29 +02:00
|
|
|
|
2021-05-19 12:49:02 +02:00
|
|
|
func TestCcLibraryStaticGetTargetProperties(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2021-05-19 12:49:02 +02:00
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
Description: "cc_library_static complex GetTargetProperties",
|
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-05-19 12:49:02 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
srcs: ["android_src.c"],
|
|
|
|
},
|
|
|
|
android_arm: {
|
|
|
|
srcs: ["android_arm_src.c"],
|
|
|
|
},
|
|
|
|
android_arm64: {
|
|
|
|
srcs: ["android_arm64_src.c"],
|
|
|
|
},
|
|
|
|
android_x86: {
|
|
|
|
srcs: ["android_x86_src.c"],
|
|
|
|
},
|
|
|
|
android_x86_64: {
|
|
|
|
srcs: ["android_x86_64_src.c"],
|
|
|
|
},
|
|
|
|
linux_bionic_arm64: {
|
|
|
|
srcs: ["linux_bionic_arm64_src.c"],
|
|
|
|
},
|
|
|
|
linux_bionic_x86_64: {
|
|
|
|
srcs: ["linux_bionic_x86_64_src.c"],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-05-19 12:49:02 +02:00
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs_c": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["android_src.c"],
|
2021-05-19 12:49:02 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_arm": ["android_arm_src.c"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_arm64": ["android_arm64_src.c"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_x86": ["android_x86_src.c"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_x86_64": ["android_x86_64_src.c"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:linux_bionic_arm64": ["linux_bionic_arm64_src.c"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:linux_bionic_x86_64": ["linux_bionic_x86_64_src.c"],
|
2021-05-19 12:49:02 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-19 12:49:02 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-06 19:54:29 +02:00
|
|
|
func TestCcLibraryStaticProductVariableSelects(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static product variable selects",
|
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-05-06 19:54:29 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.c"],
|
|
|
|
product_variables: {
|
|
|
|
malloc_not_svelte: {
|
|
|
|
cflags: ["-Wmalloc_not_svelte"],
|
|
|
|
},
|
|
|
|
malloc_zero_contents: {
|
|
|
|
cflags: ["-Wmalloc_zero_contents"],
|
|
|
|
},
|
|
|
|
binder32bit: {
|
|
|
|
cflags: ["-Wbinder32bit"],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-05-06 19:54:29 +02:00
|
|
|
} `,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:binder32bit": ["-Wbinder32bit"],
|
2021-05-10 17:39:53 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:malloc_not_svelte": ["-Wmalloc_not_svelte"],
|
2021-05-06 19:54:29 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:malloc_zero_contents": ["-Wmalloc_zero_contents"],
|
2021-05-06 19:54:29 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"srcs_c": `["common.c"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-10 17:39:53 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticProductVariableArchSpecificSelects(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static arch-specific product variable selects",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-05-10 17:39:53 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
|
|
|
srcs: ["common.c"],
|
|
|
|
product_variables: {
|
|
|
|
malloc_not_svelte: {
|
|
|
|
cflags: ["-Wmalloc_not_svelte"],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
product_variables: {
|
|
|
|
malloc_not_svelte: {
|
|
|
|
cflags: ["-Warm64_malloc_not_svelte"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
multilib: {
|
|
|
|
lib32: {
|
|
|
|
product_variables: {
|
|
|
|
malloc_not_svelte: {
|
|
|
|
cflags: ["-Wlib32_malloc_not_svelte"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
product_variables: {
|
|
|
|
malloc_not_svelte: {
|
|
|
|
cflags: ["-Wandroid_malloc_not_svelte"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
2021-05-10 17:39:53 +02:00
|
|
|
} `,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:malloc_not_svelte": ["-Wmalloc_not_svelte"],
|
2021-05-10 17:39:53 +02:00
|
|
|
"//conditions:default": [],
|
2021-05-06 19:54:29 +02:00
|
|
|
}) + select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:malloc_not_svelte-android": ["-Wandroid_malloc_not_svelte"],
|
2021-05-10 17:39:53 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:malloc_not_svelte-arm": ["-Wlib32_malloc_not_svelte"],
|
2021-05-10 17:39:53 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:malloc_not_svelte-arm64": ["-Warm64_malloc_not_svelte"],
|
2021-05-10 17:39:53 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
}) + select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:malloc_not_svelte-x86": ["-Wlib32_malloc_not_svelte"],
|
2021-05-06 19:54:29 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"srcs_c": `["common.c"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-06 19:54:29 +02:00
|
|
|
})
|
|
|
|
}
|
2021-05-26 14:45:30 +02:00
|
|
|
|
|
|
|
func TestCcLibraryStaticProductVariableStringReplacement(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static product variable string replacement",
|
|
|
|
Filesystem: map[string]string{},
|
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2021-05-26 14:45:30 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "foo_static",
|
2021-07-13 17:47:44 +02:00
|
|
|
srcs: ["common.S"],
|
2021-05-26 14:45:30 +02:00
|
|
|
product_variables: {
|
|
|
|
platform_sdk_version: {
|
|
|
|
asflags: ["-DPLATFORM_SDK_VERSION=%d"],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-05-26 14:45:30 +02:00
|
|
|
} `,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo_static", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"asflags": `select({
|
2023-07-31 21:10:12 +02:00
|
|
|
"//build/bazel/product_config/config_settings:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
|
2021-05-26 14:45:30 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"srcs_as": `["common.S"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-26 14:45:30 +02:00
|
|
|
})
|
|
|
|
}
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
|
|
|
|
func TestStaticLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static system_shared_lib empty root",
|
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "root_empty",
|
2021-09-10 16:06:32 +02:00
|
|
|
system_shared_libs: [],
|
|
|
|
include_build_directory: false,
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "root_empty", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
|
|
|
},
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static system_shared_lib empty static default",
|
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
cc_defaults {
|
|
|
|
name: "static_empty_defaults",
|
|
|
|
static: {
|
2021-09-10 16:06:32 +02:00
|
|
|
system_shared_libs: [],
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
}
|
|
|
|
cc_library_static {
|
|
|
|
name: "static_empty",
|
2021-09-10 16:06:32 +02:00
|
|
|
defaults: ["static_empty_defaults"],
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "static_empty", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
|
|
|
},
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "cc_library_static system_shared_lib empty for bionic variant",
|
|
|
|
StubbedBuildDefinitions: []string{"libc_musl"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2022-12-12 23:26:34 +01:00
|
|
|
cc_library {
|
|
|
|
name: "libc_musl",
|
|
|
|
}
|
|
|
|
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "target_bionic_empty",
|
|
|
|
target: {
|
|
|
|
bionic: {
|
|
|
|
system_shared_libs: [],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "target_bionic_empty", AttrNameToString{
|
2022-12-12 23:26:34 +01:00
|
|
|
"system_dynamic_deps": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:linux_musl": [":libc_musl"],
|
2022-12-12 23:26:34 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
2021-11-08 18:56:31 +01:00
|
|
|
}),
|
|
|
|
},
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
|
|
|
|
// Note that this behavior is technically incorrect (it's a simplification).
|
|
|
|
// The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
|
|
|
|
// only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
|
|
|
|
// b/195791252 tracks the fix.
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
|
|
|
|
StubbedBuildDefinitions: []string{"libc_musl"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
2022-12-12 23:26:34 +01:00
|
|
|
cc_library {
|
|
|
|
name: "libc_musl",
|
|
|
|
}
|
|
|
|
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "target_linux_bionic_empty",
|
|
|
|
target: {
|
|
|
|
linux_bionic: {
|
|
|
|
system_shared_libs: [],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "target_linux_bionic_empty", AttrNameToString{
|
2022-12-12 23:26:34 +01:00
|
|
|
"system_dynamic_deps": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:linux_musl": [":libc_musl"],
|
2022-12-12 23:26:34 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticLibrary_SystemSharedLibsMuslEmpty(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-21 17:30:27 +02:00
|
|
|
Description: "cc_library_static system_shared_lib empty for musl variant",
|
|
|
|
StubbedBuildDefinitions: []string{"libc_musl"},
|
2022-12-12 23:26:34 +01:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
|
|
|
cc_library {
|
|
|
|
name: "libc_musl",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "target_musl_empty",
|
|
|
|
target: {
|
|
|
|
musl: {
|
|
|
|
system_shared_libs: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "target_musl_empty", AttrNameToString{
|
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-21 17:30:27 +02:00
|
|
|
Description: "cc_library_static system_shared_lib empty for linux_musl variant",
|
|
|
|
StubbedBuildDefinitions: []string{"libc_musl"},
|
2022-12-12 23:26:34 +01:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble + `
|
|
|
|
cc_library {
|
|
|
|
name: "libc_musl",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "target_linux_musl_empty",
|
|
|
|
target: {
|
|
|
|
linux_musl: {
|
|
|
|
system_shared_libs: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "target_linux_musl_empty", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
|
|
|
},
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "cc_library_static system_shared_libs set for bionic variant",
|
|
|
|
StubbedBuildDefinitions: []string{"libc", "libc_musl"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble +
|
2023-09-19 03:12:48 +02:00
|
|
|
simpleModule("cc_library", "libc") + `
|
2022-12-12 23:26:34 +01:00
|
|
|
cc_library {
|
|
|
|
name: "libc_musl",
|
|
|
|
}
|
|
|
|
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "target_bionic",
|
|
|
|
target: {
|
|
|
|
bionic: {
|
|
|
|
system_shared_libs: ["libc"],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "target_bionic", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"system_dynamic_deps": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [":libc"],
|
|
|
|
"//build/bazel_common_rules/platforms/os:linux_bionic": [":libc"],
|
|
|
|
"//build/bazel_common_rules/platforms/os:linux_musl": [":libc_musl"],
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "cc_library_static system_shared_libs set for root and linux_bionic variant",
|
|
|
|
StubbedBuildDefinitions: []string{"libc", "libm", "libc_musl"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble +
|
2023-09-19 03:12:48 +02:00
|
|
|
simpleModule("cc_library", "libc") +
|
|
|
|
simpleModule("cc_library", "libm") + `
|
2022-12-12 23:26:34 +01:00
|
|
|
cc_library {
|
|
|
|
name: "libc_musl",
|
|
|
|
}
|
|
|
|
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
cc_library_static {
|
|
|
|
name: "target_linux_bionic",
|
2021-09-10 16:06:32 +02:00
|
|
|
system_shared_libs: ["libc"],
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
target: {
|
|
|
|
linux_bionic: {
|
|
|
|
system_shared_libs: ["libm"],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "target_linux_bionic", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"system_dynamic_deps": `[":libc"] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:linux_bionic": [":libm"],
|
|
|
|
"//build/bazel_common_rules/platforms/os:linux_musl": [":libc_musl"],
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
})
|
|
|
|
}
|
2021-09-28 15:19:17 +02:00
|
|
|
|
2021-12-14 18:21:22 +01:00
|
|
|
func TestCcLibrarystatic_SystemSharedLibUsedAsDep(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
|
|
|
|
StubbedBuildDefinitions: []string{"libc", "libm"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcLibraryStaticPreamble +
|
2023-09-19 03:12:48 +02:00
|
|
|
simpleModule("cc_library", "libc") + `
|
2022-09-13 17:27:11 +02:00
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libm",
|
|
|
|
stubs: {
|
|
|
|
symbol_file: "libm.map.txt",
|
|
|
|
versions: ["current"],
|
|
|
|
},
|
2023-04-18 08:20:40 +02:00
|
|
|
apex_available: ["com.android.runtime"],
|
2022-09-13 17:27:11 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 18:21:22 +01:00
|
|
|
cc_library_static {
|
|
|
|
name: "used_in_bionic_oses",
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
shared_libs: ["libc"],
|
|
|
|
},
|
|
|
|
linux_bionic: {
|
|
|
|
shared_libs: ["libc"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
2023-03-17 15:17:50 +01:00
|
|
|
apex_available: ["foo"],
|
2021-12-14 18:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "all",
|
|
|
|
shared_libs: ["libc"],
|
|
|
|
include_build_directory: false,
|
2023-03-17 15:17:50 +01:00
|
|
|
apex_available: ["foo"],
|
2021-12-14 18:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "keep_for_empty_system_shared_libs",
|
|
|
|
shared_libs: ["libc"],
|
2022-09-13 17:27:11 +02:00
|
|
|
system_shared_libs: [],
|
|
|
|
include_build_directory: false,
|
2023-03-17 15:17:50 +01:00
|
|
|
apex_available: ["foo"],
|
2022-09-13 17:27:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "used_with_stubs",
|
|
|
|
shared_libs: ["libm"],
|
|
|
|
include_build_directory: false,
|
2023-03-17 15:17:50 +01:00
|
|
|
apex_available: ["foo"],
|
2022-09-13 17:27:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "keep_with_stubs",
|
|
|
|
shared_libs: ["libm"],
|
|
|
|
system_shared_libs: [],
|
2021-12-14 18:21:22 +01:00
|
|
|
include_build_directory: false,
|
2023-03-17 15:17:50 +01:00
|
|
|
apex_available: ["foo"],
|
2021-12-14 18:21:22 +01:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2023-03-17 15:17:50 +01:00
|
|
|
MakeBazelTarget("cc_library_static", "all", AttrNameToString{
|
|
|
|
"tags": `["apex_available=foo"]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "keep_for_empty_system_shared_libs", AttrNameToString{
|
2021-12-14 18:21:22 +01:00
|
|
|
"implementation_dynamic_deps": `[":libc"]`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
2023-03-17 15:17:50 +01:00
|
|
|
"tags": `["apex_available=foo"]`,
|
2021-12-14 18:21:22 +01:00
|
|
|
}),
|
2022-09-13 17:27:11 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "keep_with_stubs", AttrNameToString{
|
|
|
|
"implementation_dynamic_deps": `select({
|
2023-04-18 08:20:40 +02:00
|
|
|
"//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:libm"],
|
|
|
|
"//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:libm"],
|
2022-09-13 17:27:11 +02:00
|
|
|
"//conditions:default": [":libm"],
|
|
|
|
})`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
2023-03-17 15:17:50 +01:00
|
|
|
"tags": `["apex_available=foo"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_library_static", "used_in_bionic_oses", AttrNameToString{
|
|
|
|
"tags": `["apex_available=foo"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_library_static", "used_with_stubs", AttrNameToString{
|
|
|
|
"tags": `["apex_available=foo"]`,
|
2022-09-13 17:27:11 +02:00
|
|
|
}),
|
2021-12-14 18:21:22 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-28 15:19:17 +02:00
|
|
|
func TestCcLibraryStaticProto(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcProtoPreamble + `cc_library_static {
|
2021-09-28 15:19:17 +02:00
|
|
|
name: "foo",
|
|
|
|
srcs: ["foo.proto"],
|
|
|
|
proto: {
|
|
|
|
export_proto_headers: true,
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"srcs": `["foo.proto"]`,
|
2022-08-31 20:28:19 +02:00
|
|
|
}), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"deps": `[":foo_proto"]`,
|
2022-08-31 20:28:19 +02:00
|
|
|
}), MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"deps": `[":libprotobuf-cpp-lite"]`,
|
|
|
|
"whole_archive_deps": `[":foo_cc_proto_lite"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2021-12-10 13:22:53 +01:00
|
|
|
|
|
|
|
func TestCcLibraryStaticUseVersionLib(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2022-09-16 15:01:29 +02:00
|
|
|
Filesystem: map[string]string{
|
|
|
|
soongCcVersionLibBpPath: soongCcVersionLibBp,
|
|
|
|
},
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion", "libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
|
2022-09-16 15:01:29 +02:00
|
|
|
Blueprint: soongCcProtoPreamble + `cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
use_version_lib: true,
|
|
|
|
static_libs: ["libbuildversion"],
|
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
2023-04-25 01:37:18 +02:00
|
|
|
"whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
|
2022-09-16 15:01:29 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticUseVersionLibHasDep(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
soongCcVersionLibBpPath: soongCcVersionLibBp,
|
|
|
|
},
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion", "libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcProtoPreamble + `cc_library_static {
|
2021-12-10 13:22:53 +01:00
|
|
|
name: "foo",
|
|
|
|
use_version_lib: true,
|
2022-09-16 15:01:29 +02:00
|
|
|
whole_static_libs: ["libbuildversion"],
|
2021-12-10 13:22:53 +01:00
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
2022-09-16 15:01:29 +02:00
|
|
|
"whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
|
2021-12-10 13:22:53 +01:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2021-12-16 20:19:32 +01:00
|
|
|
|
|
|
|
func TestCcLibraryStaticStdInFlags(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: soongCcProtoPreamble + `cc_library_static {
|
2021-12-16 20:19:32 +01:00
|
|
|
name: "foo",
|
|
|
|
cflags: ["-std=candcpp"],
|
|
|
|
conlyflags: ["-std=conly"],
|
|
|
|
cppflags: ["-std=cpp"],
|
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
2021-12-16 20:19:32 +01:00
|
|
|
"conlyflags": `["-std=conly"]`,
|
|
|
|
"cppflags": `["-std=cpp"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-05-12 17:42:33 +02:00
|
|
|
|
|
|
|
func TestCcLibraryStaticStl(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
prop string
|
2022-06-21 21:28:33 +02:00
|
|
|
attr AttrNameToString
|
2022-05-12 17:42:33 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "c++_shared deduped to libc++",
|
|
|
|
prop: `stl: "c++_shared",`,
|
2022-06-21 21:28:33 +02:00
|
|
|
attr: AttrNameToString{
|
2022-05-12 17:42:33 +02:00
|
|
|
"stl": `"libc++"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "libc++ to libc++",
|
|
|
|
prop: `stl: "libc++",`,
|
2022-06-21 21:28:33 +02:00
|
|
|
attr: AttrNameToString{
|
2022-05-12 17:42:33 +02:00
|
|
|
"stl": `"libc++"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "c++_static to libc++_static",
|
|
|
|
prop: `stl: "c++_static",`,
|
2022-06-21 21:28:33 +02:00
|
|
|
attr: AttrNameToString{
|
2022-05-12 17:42:33 +02:00
|
|
|
"stl": `"libc++_static"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "libc++_static to libc++_static",
|
|
|
|
prop: `stl: "libc++_static",`,
|
2022-06-21 21:28:33 +02:00
|
|
|
attr: AttrNameToString{
|
2022-05-12 17:42:33 +02:00
|
|
|
"stl": `"libc++_static"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "system to system",
|
|
|
|
prop: `stl: "system",`,
|
2022-06-21 21:28:33 +02:00
|
|
|
attr: AttrNameToString{
|
2022-05-12 17:42:33 +02:00
|
|
|
"stl": `"system"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "none to none",
|
|
|
|
prop: `stl: "none",`,
|
2022-06-21 21:28:33 +02:00
|
|
|
attr: AttrNameToString{
|
2022-05-12 17:42:33 +02:00
|
|
|
"stl": `"none"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "empty to empty",
|
2022-06-21 21:28:33 +02:00
|
|
|
attr: AttrNameToString{},
|
2022-05-12 17:42:33 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.desc, func(*testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: fmt.Sprintf(`cc_library_static {
|
2022-05-12 17:42:33 +02:00
|
|
|
name: "foo",
|
|
|
|
include_build_directory: false,
|
|
|
|
%s
|
|
|
|
}`, tc.prop),
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo", tc.attr),
|
2022-05-12 17:42:33 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-08-09 18:50:56 +02:00
|
|
|
|
|
|
|
func TestCCLibraryStaticRuntimeDeps(t *testing.T) {
|
|
|
|
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: `cc_library_shared {
|
|
|
|
name: "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
2023-09-19 03:12:48 +02:00
|
|
|
runtime_libs: ["bar"],
|
2022-08-09 18:50:56 +02:00
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
|
2022-08-09 18:50:56 +02:00
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
2023-09-19 03:12:48 +02:00
|
|
|
"runtime_deps": `[":bar"]`,
|
2022-08-09 18:50:56 +02:00
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-09-06 21:31:25 +02:00
|
|
|
|
|
|
|
func TestCcLibraryStaticWithSyspropSrcs(t *testing.T) {
|
|
|
|
runCcLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static with sysprop sources",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"bar.sysprop",
|
|
|
|
"baz.sysprop",
|
|
|
|
"blah.cpp",
|
|
|
|
],
|
|
|
|
min_sdk_version: "5",
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"bar.sysprop",
|
|
|
|
"baz.sysprop",
|
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
|
|
|
|
"dep": `":foo_sysprop_library"`,
|
|
|
|
"min_sdk_version": `"5"`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"srcs": `["blah.cpp"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"min_sdk_version": `"5"`,
|
|
|
|
"whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithSyspropSrcsSomeConfigs(t *testing.T) {
|
|
|
|
runCcLibraryTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static with sysprop sources in some configs but not others",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"blah.cpp",
|
|
|
|
],
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
srcs: ["bar.sysprop"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
min_sdk_version: "5",
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("sysprop_library", "foo_sysprop_library", AttrNameToString{
|
|
|
|
"srcs": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["bar.sysprop"],
|
2022-09-06 21:31:25 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
|
|
|
|
"dep": `":foo_sysprop_library"`,
|
|
|
|
"min_sdk_version": `"5"`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"srcs": `["blah.cpp"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"min_sdk_version": `"5"`,
|
|
|
|
"whole_archive_deps": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": [":foo_cc_sysprop_library_static"],
|
2022-09-06 21:31:25 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-10-28 18:48:18 +02:00
|
|
|
|
|
|
|
func TestCcLibraryStaticWithIntegerOverflowProperty(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when integer_overflow property is provided",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
sanitize: {
|
|
|
|
integer_overflow: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `["ubsan_integer_overflow"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithMiscUndefinedProperty(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when misc_undefined property is provided",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
sanitize: {
|
|
|
|
misc_undefined: ["undefined", "nullability"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `[
|
|
|
|
"ubsan_undefined",
|
|
|
|
"ubsan_nullability",
|
|
|
|
]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithUBSanPropertiesArchSpecific(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct feature select when UBSan props are specified in arch specific blocks",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
sanitize: {
|
|
|
|
misc_undefined: ["undefined", "nullability"],
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
sanitize: {
|
|
|
|
misc_undefined: ["alignment"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
linux_glibc: {
|
|
|
|
sanitize: {
|
|
|
|
integer_overflow: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `[
|
|
|
|
"ubsan_undefined",
|
|
|
|
"ubsan_nullability",
|
|
|
|
] + select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["ubsan_alignment"],
|
|
|
|
"//build/bazel_common_rules/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
|
2022-10-28 18:48:18 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-02-06 22:58:30 +01:00
|
|
|
|
2023-06-12 21:18:28 +02:00
|
|
|
func TestCcLibraryStaticWithSanitizerBlocklist(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when sanitize.blocklist is provided",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
sanitize: {
|
|
|
|
blocklist: "foo_blocklist.txt",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
2023-08-10 00:21:38 +02:00
|
|
|
"copts": `select({
|
|
|
|
"//build/bazel/rules/cc:sanitizers_enabled": ["-fsanitize-ignorelist=$(location foo_blocklist.txt)"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"additional_compiler_inputs": `select({
|
|
|
|
"//build/bazel/rules/cc:sanitizers_enabled": [":foo_blocklist.txt"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
2023-06-12 21:18:28 +02:00
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-06 22:58:30 +01:00
|
|
|
func TestCcLibraryStaticWithThinLto(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when thin lto is enabled",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
lto: {
|
|
|
|
thin: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `["android_thin_lto"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithLtoNever(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when thin lto is enabled",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
lto: {
|
|
|
|
never: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `["-android_thin_lto"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithThinLtoArchSpecific(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when LTO differs across arch and os variants",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
lto: {
|
|
|
|
thin: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
arch: {
|
|
|
|
riscv64: {
|
|
|
|
lto: {
|
|
|
|
thin: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"features": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_arm": ["android_thin_lto"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_arm64": ["android_thin_lto"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_riscv64": ["-android_thin_lto"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_x86": ["android_thin_lto"],
|
|
|
|
"//build/bazel_common_rules/platforms/os_arch:android_x86_64": ["android_thin_lto"],
|
2023-02-06 22:58:30 +01:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithThinLtoDisabledDefaultEnabledVariant(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when LTO disabled by default but enabled on a particular variant",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
lto: {
|
|
|
|
never: true,
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
lto: {
|
|
|
|
thin: true,
|
|
|
|
never: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"features": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["android_thin_lto"],
|
2023-02-06 22:58:30 +01:00
|
|
|
"//conditions:default": ["-android_thin_lto"],
|
|
|
|
})`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithThinLtoAndWholeProgramVtables(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when thin lto is enabled with whole_program_vtables",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
lto: {
|
|
|
|
thin: true,
|
|
|
|
},
|
|
|
|
whole_program_vtables: true,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `[
|
|
|
|
"android_thin_lto",
|
|
|
|
"android_thin_lto_whole_program_vtables",
|
|
|
|
]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-04-14 20:25:24 +02:00
|
|
|
|
|
|
|
func TestCcLibraryStaticHiddenVisibilityConvertedToFeature(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static changes hidden visibility flag to feature",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
cflags: ["-fvisibility=hidden"],
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `["visibility_hidden"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static changes hidden visibility flag to feature for specific os",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
cflags: ["-fvisibility=hidden"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["visibility_hidden"],
|
2023-04-14 20:25:24 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-03-28 22:47:10 +02:00
|
|
|
|
|
|
|
func TestCcLibraryStaticWithCfi(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when cfi is enabled",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
sanitize: {
|
|
|
|
cfi: true,
|
|
|
|
},
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `["android_cfi"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithCfiOsSpecific(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when cfi is enabled for specific variants",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
sanitize: {
|
|
|
|
cfi: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `select({
|
2023-10-11 12:51:28 +02:00
|
|
|
"//build/bazel_common_rules/platforms/os:android": ["android_cfi"],
|
2023-03-28 22:47:10 +02:00
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcLibraryStaticWithCfiAndCfiAssemblySupport(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static has correct features when cfi is enabled with cfi_assembly_support",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
sanitize: {
|
|
|
|
cfi: true,
|
|
|
|
config: {
|
|
|
|
cfi_assembly_support: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `[
|
|
|
|
"android_cfi",
|
|
|
|
"android_cfi_assembly_support",
|
|
|
|
]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-06-16 22:15:45 +02:00
|
|
|
|
|
|
|
func TestCcLibraryStaticExplicitlyDisablesCfiWhenFalse(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library_static disables cfi when explciitly set to false in the bp",
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static {
|
|
|
|
name: "foo",
|
|
|
|
sanitize: {
|
|
|
|
cfi: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"features": `["-android_cfi"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2023-04-24 16:57:32 +02:00
|
|
|
|
|
|
|
func TestCCLibraryStaticRscriptSrc(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: `cc_library_static with rscript files in sources`,
|
|
|
|
Blueprint: `
|
|
|
|
cc_library_static{
|
|
|
|
name : "foo",
|
|
|
|
srcs : [
|
|
|
|
"ccSrc.cc",
|
|
|
|
"rsSrc.rscript",
|
|
|
|
],
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("rscript_to_cpp", "foo_renderscript", AttrNameToString{
|
|
|
|
"srcs": `["rsSrc.rscript"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
|
|
|
"absolute_includes": `[
|
|
|
|
"frameworks/rs",
|
|
|
|
"frameworks/rs/cpp",
|
|
|
|
]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `[
|
|
|
|
"ccSrc.cc",
|
|
|
|
"foo_renderscript",
|
|
|
|
]`,
|
|
|
|
})}})
|
|
|
|
}
|
2023-08-02 01:10:05 +02:00
|
|
|
|
|
|
|
func TestCcLibraryWithProtoInGeneratedSrcs(t *testing.T) {
|
|
|
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_library with a .proto file generated from a genrule",
|
|
|
|
ModuleTypeUnderTest: "cc_library_static",
|
|
|
|
ModuleTypeUnderTestFactory: cc.LibraryStaticFactory,
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"libprotobuf-cpp-lite"},
|
2023-08-02 01:10:05 +02:00
|
|
|
Blueprint: soongCcLibraryPreamble + `
|
|
|
|
cc_library_static {
|
|
|
|
name: "mylib",
|
|
|
|
generated_sources: ["myprotogen"],
|
|
|
|
}
|
|
|
|
genrule {
|
|
|
|
name: "myprotogen",
|
|
|
|
out: ["myproto.proto"],
|
|
|
|
}
|
2023-09-19 03:12:48 +02:00
|
|
|
` + simpleModule("cc_library", "libprotobuf-cpp-lite"),
|
2023-08-02 01:10:05 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_library_static", "mylib", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"deps": `[":libprotobuf-cpp-lite"]`,
|
|
|
|
"implementation_whole_archive_deps": `[":mylib_cc_proto_lite"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_lite_proto_library", "mylib_cc_proto_lite", AttrNameToString{
|
|
|
|
"deps": `[":mylib_proto"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("proto_library", "mylib_proto", AttrNameToString{
|
|
|
|
"srcs": `[":myprotogen"]`,
|
|
|
|
}),
|
|
|
|
MakeBazelTargetNoRestrictions("genrule", "myprotogen", AttrNameToString{
|
|
|
|
"cmd": `""`,
|
|
|
|
"outs": `["myproto.proto"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|