2021-10-04 19:55:44 +02: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 (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2022-03-02 00:44:08 +01:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
"android/soong/genrule"
|
2021-10-04 19:55:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-09-28 15:19:17 +02:00
|
|
|
ccBinaryTypePlaceHolder = "{rule_name}"
|
2021-10-04 19:55:44 +02:00
|
|
|
)
|
|
|
|
|
2021-11-08 18:56:31 +01:00
|
|
|
type testBazelTarget struct {
|
|
|
|
typ string
|
|
|
|
name string
|
2022-06-21 21:28:33 +02:00
|
|
|
attrs AttrNameToString
|
2021-11-08 18:56:31 +01:00
|
|
|
}
|
|
|
|
|
2022-05-13 23:20:20 +02:00
|
|
|
func generateBazelTargetsForTest(targets []testBazelTarget, hod android.HostOrDeviceSupported) []string {
|
2021-11-08 18:56:31 +01:00
|
|
|
ret := make([]string, 0, len(targets))
|
|
|
|
for _, t := range targets {
|
2022-05-13 23:20:20 +02:00
|
|
|
attrs := t.attrs.clone()
|
|
|
|
ret = append(ret, makeBazelTargetHostOrDevice(t.typ, t.name, attrs, hod))
|
2021-11-08 18:56:31 +01:00
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
type ccBinaryBp2buildTestCase struct {
|
|
|
|
description string
|
2022-09-16 15:01:29 +02:00
|
|
|
filesystem map[string]string
|
2021-11-08 18:56:31 +01:00
|
|
|
blueprint string
|
|
|
|
targets []testBazelTarget
|
|
|
|
}
|
|
|
|
|
2021-10-04 19:55:44 +02:00
|
|
|
func registerCcBinaryModuleTypes(ctx android.RegistrationContext) {
|
|
|
|
cc.RegisterCCBuildComponents(ctx)
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
|
|
|
|
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
|
2021-10-19 19:56:10 +02:00
|
|
|
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
|
2021-10-04 19:55:44 +02:00
|
|
|
}
|
|
|
|
|
2021-11-08 18:56:31 +01:00
|
|
|
var binaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary")
|
|
|
|
var hostBinaryReplacer = strings.NewReplacer(ccBinaryTypePlaceHolder, "cc_binary_host")
|
2021-10-04 19:55:44 +02:00
|
|
|
|
2021-11-08 18:56:31 +01:00
|
|
|
func runCcBinaryTests(t *testing.T, tc ccBinaryBp2buildTestCase) {
|
2021-10-04 19:55:44 +02:00
|
|
|
t.Helper()
|
|
|
|
runCcBinaryTestCase(t, tc)
|
|
|
|
runCcHostBinaryTestCase(t, tc)
|
|
|
|
}
|
|
|
|
|
2022-05-13 23:20:20 +02:00
|
|
|
func runCcBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) {
|
2021-10-04 19:55:44 +02:00
|
|
|
t.Helper()
|
2021-11-08 18:56:31 +01:00
|
|
|
moduleTypeUnderTest := "cc_binary"
|
2022-05-13 23:20:20 +02:00
|
|
|
|
|
|
|
description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description)
|
|
|
|
t.Run(description, func(t *testing.T) {
|
2021-11-01 20:32:43 +01:00
|
|
|
t.Helper()
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, registerCcBinaryModuleTypes, Bp2buildTestCase{
|
|
|
|
ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.DeviceSupported),
|
|
|
|
ModuleTypeUnderTest: moduleTypeUnderTest,
|
|
|
|
ModuleTypeUnderTestFactory: cc.BinaryFactory,
|
|
|
|
Description: description,
|
|
|
|
Blueprint: binaryReplacer.Replace(testCase.blueprint),
|
2022-09-16 15:01:29 +02:00
|
|
|
Filesystem: testCase.filesystem,
|
2022-05-13 23:20:20 +02:00
|
|
|
})
|
2021-10-04 19:55:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-13 23:20:20 +02:00
|
|
|
func runCcHostBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) {
|
2021-10-04 19:55:44 +02:00
|
|
|
t.Helper()
|
2021-11-08 18:56:31 +01:00
|
|
|
moduleTypeUnderTest := "cc_binary_host"
|
2022-05-13 23:20:20 +02:00
|
|
|
description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description)
|
|
|
|
t.Run(description, func(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, registerCcBinaryModuleTypes, Bp2buildTestCase{
|
|
|
|
ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostSupported),
|
|
|
|
ModuleTypeUnderTest: moduleTypeUnderTest,
|
|
|
|
ModuleTypeUnderTestFactory: cc.BinaryHostFactory,
|
|
|
|
Description: description,
|
|
|
|
Blueprint: hostBinaryReplacer.Replace(testCase.blueprint),
|
2022-09-16 15:01:29 +02:00
|
|
|
Filesystem: testCase.filesystem,
|
2021-11-08 18:56:31 +01:00
|
|
|
})
|
2021-10-04 19:55:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBasicCcBinary(t *testing.T) {
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: "basic -- properties -> attrs with little/no transformation",
|
2022-09-16 15:01:29 +02:00
|
|
|
filesystem: map[string]string{
|
|
|
|
soongCcVersionLibBpPath: soongCcVersionLibBp,
|
|
|
|
},
|
2021-10-04 19:55:44 +02:00
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.cc"],
|
|
|
|
local_include_dirs: ["dir"],
|
|
|
|
include_dirs: ["absolute_dir"],
|
|
|
|
cflags: ["-Dcopt"],
|
|
|
|
cppflags: ["-Dcppflag"],
|
|
|
|
conlyflags: ["-Dconlyflag"],
|
|
|
|
asflags: ["-Dasflag"],
|
|
|
|
ldflags: ["ld-flag"],
|
|
|
|
rtti: true,
|
|
|
|
strip: {
|
|
|
|
all: true,
|
|
|
|
keep_symbols: true,
|
|
|
|
keep_symbols_and_debug_frame: true,
|
|
|
|
keep_symbols_list: ["symbol"],
|
|
|
|
none: true,
|
|
|
|
},
|
2022-03-02 00:44:08 +01:00
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29",
|
2022-03-23 00:35:22 +01:00
|
|
|
use_version_lib: true,
|
2021-10-04 19:55:44 +02:00
|
|
|
}
|
|
|
|
`,
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"absolute_includes": `["absolute_dir"]`,
|
|
|
|
"asflags": `["-Dasflag"]`,
|
|
|
|
"conlyflags": `["-Dconlyflag"]`,
|
|
|
|
"copts": `["-Dcopt"]`,
|
|
|
|
"cppflags": `["-Dcppflag"]`,
|
|
|
|
"linkopts": `["ld-flag"]`,
|
|
|
|
"local_includes": `[
|
2021-10-04 19:55:44 +02:00
|
|
|
"dir",
|
|
|
|
".",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"rtti": `True`,
|
|
|
|
"srcs": `["a.cc"]`,
|
|
|
|
"strip": `{
|
2021-10-04 19:55:44 +02:00
|
|
|
"all": True,
|
|
|
|
"keep_symbols": True,
|
|
|
|
"keep_symbols_and_debug_frame": True,
|
|
|
|
"keep_symbols_list": ["symbol"],
|
|
|
|
"none": True,
|
2021-11-08 18:56:31 +01:00
|
|
|
}`,
|
2022-09-16 15:01:29 +02:00
|
|
|
"sdk_version": `"current"`,
|
|
|
|
"min_sdk_version": `"29"`,
|
|
|
|
"use_version_lib": `True`,
|
|
|
|
"whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
|
2021-11-08 18:56:31 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-04 19:55:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryWithSharedLdflagDisableFeature(t *testing.T) {
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: `ldflag "-shared" disables static_flag feature`,
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
ldflags: ["-shared"],
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`,
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"features": `["-static_flag"]`,
|
|
|
|
"linkopts": `["-shared"]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-04 19:55:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryWithLinkStatic(t *testing.T) {
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: "link static",
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
static_executable: true,
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`,
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"linkshared": `False`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-04 19:55:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryVersionScript(t *testing.T) {
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: `version script`,
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
include_build_directory: false,
|
|
|
|
version_script: "vs",
|
|
|
|
}
|
|
|
|
`,
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"additional_linker_inputs": `["vs"]`,
|
|
|
|
"linkopts": `["-Wl,--version-script,$(location vs)"]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-04 19:55:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinarySplitSrcsByLang(t *testing.T) {
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcHostBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: "split srcs by lang",
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"asonly.S",
|
|
|
|
"conly.c",
|
|
|
|
"cpponly.cpp",
|
|
|
|
":fg_foo",
|
|
|
|
],
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
` + simpleModuleDoNotConvertBp2build("filegroup", "fg_foo"),
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs": `[
|
2021-10-04 19:55:44 +02:00
|
|
|
"cpponly.cpp",
|
|
|
|
":fg_foo_cpp_srcs",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs_as": `[
|
2021-10-04 19:55:44 +02:00
|
|
|
"asonly.S",
|
|
|
|
":fg_foo_as_srcs",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs_c": `[
|
2021-10-04 19:55:44 +02:00
|
|
|
"conly.c",
|
|
|
|
":fg_foo_c_srcs",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-04 19:55:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryDoNotDistinguishBetweenDepsAndImplementationDeps(t *testing.T) {
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: "no implementation deps",
|
|
|
|
blueprint: `
|
2021-10-19 19:56:10 +02:00
|
|
|
genrule {
|
|
|
|
name: "generated_hdr",
|
|
|
|
cmd: "nothing to see here",
|
2021-11-01 20:32:43 +01:00
|
|
|
bazel_module: { bp2build_available: false },
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
genrule {
|
|
|
|
name: "export_generated_hdr",
|
|
|
|
cmd: "nothing to see here",
|
2021-11-01 20:32:43 +01:00
|
|
|
bazel_module: { bp2build_available: false },
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
|
2021-10-04 19:55:44 +02:00
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
2021-10-19 19:56:10 +02:00
|
|
|
srcs: ["foo.cpp"],
|
2021-10-04 19:55:44 +02:00
|
|
|
shared_libs: ["implementation_shared_dep", "shared_dep"],
|
|
|
|
export_shared_lib_headers: ["shared_dep"],
|
|
|
|
static_libs: ["implementation_static_dep", "static_dep"],
|
|
|
|
export_static_lib_headers: ["static_dep", "whole_static_dep"],
|
|
|
|
whole_static_libs: ["not_explicitly_exported_whole_static_dep", "whole_static_dep"],
|
|
|
|
include_build_directory: false,
|
2021-10-19 19:56:10 +02:00
|
|
|
generated_headers: ["generated_hdr", "export_generated_hdr"],
|
|
|
|
export_generated_headers: ["export_generated_hdr"],
|
2021-10-04 19:55:44 +02:00
|
|
|
}
|
|
|
|
` +
|
|
|
|
simpleModuleDoNotConvertBp2build("cc_library_static", "static_dep") +
|
|
|
|
simpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep") +
|
|
|
|
simpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep") +
|
|
|
|
simpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep") +
|
|
|
|
simpleModuleDoNotConvertBp2build("cc_library", "shared_dep") +
|
|
|
|
simpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep"),
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"deps": `[
|
2021-10-04 19:55:44 +02:00
|
|
|
":implementation_static_dep",
|
|
|
|
":static_dep",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"dynamic_deps": `[
|
2021-10-04 19:55:44 +02:00
|
|
|
":implementation_shared_dep",
|
|
|
|
":shared_dep",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs": `[
|
2021-10-19 19:56:10 +02:00
|
|
|
"foo.cpp",
|
|
|
|
":generated_hdr",
|
|
|
|
":export_generated_hdr",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"whole_archive_deps": `[
|
2021-10-04 19:55:44 +02:00
|
|
|
":not_explicitly_exported_whole_static_dep",
|
|
|
|
":whole_static_dep",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
2021-12-10 20:28:20 +01:00
|
|
|
"local_includes": `["."]`,
|
2021-11-08 18:56:31 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-04 19:55:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryNocrtTests(t *testing.T) {
|
|
|
|
baseTestCases := []struct {
|
|
|
|
description string
|
|
|
|
soongProperty string
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr AttrNameToString
|
2021-10-04 19:55:44 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
description: "nocrt: true",
|
|
|
|
soongProperty: `nocrt: true,`,
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{"link_crt": `False`},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "nocrt: false",
|
|
|
|
soongProperty: `nocrt: false,`,
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "nocrt: not set",
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
baseBlueprint := `{rule_name} {
|
|
|
|
name: "foo",%s
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
for _, btc := range baseTestCases {
|
|
|
|
prop := btc.soongProperty
|
|
|
|
if len(prop) > 0 {
|
|
|
|
prop = "\n" + prop
|
|
|
|
}
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: btc.description,
|
|
|
|
blueprint: fmt.Sprintf(baseBlueprint, prop),
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"cc_binary", "foo", btc.bazelAttr},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryNo_libcrtTests(t *testing.T) {
|
|
|
|
baseTestCases := []struct {
|
|
|
|
description string
|
|
|
|
soongProperty string
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr AttrNameToString
|
2021-10-04 19:55:44 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
description: "no_libcrt: true",
|
|
|
|
soongProperty: `no_libcrt: true,`,
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{"use_libcrt": `False`},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "no_libcrt: false",
|
|
|
|
soongProperty: `no_libcrt: false,`,
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{"use_libcrt": `True`},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "no_libcrt: not set",
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
baseBlueprint := `{rule_name} {
|
|
|
|
name: "foo",%s
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
for _, btc := range baseTestCases {
|
|
|
|
prop := btc.soongProperty
|
|
|
|
if len(prop) > 0 {
|
|
|
|
prop = "\n" + prop
|
|
|
|
}
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: btc.description,
|
|
|
|
blueprint: fmt.Sprintf(baseBlueprint, prop),
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"cc_binary", "foo", btc.bazelAttr},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryPropertiesToFeatures(t *testing.T) {
|
|
|
|
baseTestCases := []struct {
|
|
|
|
description string
|
|
|
|
soongProperty string
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr AttrNameToString
|
2021-10-04 19:55:44 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
description: "pack_relocation: true",
|
|
|
|
soongProperty: `pack_relocations: true,`,
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "pack_relocations: false",
|
|
|
|
soongProperty: `pack_relocations: false,`,
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{"features": `["disable_pack_relocations"]`},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "pack_relocations: not set",
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "pack_relocation: true",
|
|
|
|
soongProperty: `allow_undefined_symbols: true,`,
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{"features": `["-no_undefined_symbols"]`},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "allow_undefined_symbols: false",
|
|
|
|
soongProperty: `allow_undefined_symbols: false,`,
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "allow_undefined_symbols: not set",
|
2022-06-21 21:28:33 +02:00
|
|
|
bazelAttr: AttrNameToString{},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
baseBlueprint := `{rule_name} {
|
|
|
|
name: "foo",%s
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`
|
|
|
|
for _, btc := range baseTestCases {
|
|
|
|
prop := btc.soongProperty
|
|
|
|
if len(prop) > 0 {
|
|
|
|
prop = "\n" + prop
|
|
|
|
}
|
2021-11-08 18:56:31 +01:00
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
2021-10-04 19:55:44 +02:00
|
|
|
description: btc.description,
|
|
|
|
blueprint: fmt.Sprintf(baseBlueprint, prop),
|
2021-11-08 18:56:31 +01:00
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"cc_binary", "foo", btc.bazelAttr},
|
2021-10-04 19:55:44 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 15:19:17 +02:00
|
|
|
|
|
|
|
func TestCcBinarySharedProto(t *testing.T) {
|
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
|
|
|
blueprint: soongCcProtoLibraries + `{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["foo.proto"],
|
|
|
|
proto: {
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"proto_library", "foo_proto", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"srcs": `["foo.proto"]`,
|
2022-06-21 21:28:33 +02:00
|
|
|
}}, {"cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"deps": `[":foo_proto"]`,
|
2022-06-21 21:28:33 +02:00
|
|
|
}}, {"cc_binary", "foo", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"dynamic_deps": `[":libprotobuf-cpp-lite"]`,
|
|
|
|
"whole_archive_deps": `[":foo_cc_proto_lite"]`,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryStaticProto(t *testing.T) {
|
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
|
|
|
blueprint: soongCcProtoLibraries + `{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["foo.proto"],
|
|
|
|
static_executable: true,
|
|
|
|
proto: {
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
|
|
|
}`,
|
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"proto_library", "foo_proto", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"srcs": `["foo.proto"]`,
|
2022-06-21 21:28:33 +02:00
|
|
|
}}, {"cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"deps": `[":foo_proto"]`,
|
2022-06-21 21:28:33 +02:00
|
|
|
}}, {"cc_binary", "foo", AttrNameToString{
|
2021-09-28 15:19:17 +02:00
|
|
|
"deps": `[":libprotobuf-cpp-lite"]`,
|
|
|
|
"whole_archive_deps": `[":foo_cc_proto_lite"]`,
|
|
|
|
"linkshared": `False`,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-05-13 22:55:35 +02:00
|
|
|
|
|
|
|
func TestCcBinaryConvertLex(t *testing.T) {
|
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
|
|
|
description: `.l and .ll sources converted to .c and .cc`,
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
|
|
|
|
lex: { flags: ["--foo_opt", "--bar_opt"] },
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
targets: []testBazelTarget{
|
2022-06-21 21:28:33 +02:00
|
|
|
{"genlex", "foo_genlex_l", AttrNameToString{
|
2022-05-13 22:55:35 +02:00
|
|
|
"srcs": `[
|
|
|
|
"foo1.l",
|
|
|
|
"foo2.l",
|
|
|
|
]`,
|
|
|
|
"lexopts": `[
|
|
|
|
"--foo_opt",
|
|
|
|
"--bar_opt",
|
|
|
|
]`,
|
|
|
|
}},
|
2022-06-21 21:28:33 +02:00
|
|
|
{"genlex", "foo_genlex_ll", AttrNameToString{
|
2022-05-13 22:55:35 +02:00
|
|
|
"srcs": `[
|
|
|
|
"bar1.ll",
|
|
|
|
"bar2.ll",
|
|
|
|
]`,
|
|
|
|
"lexopts": `[
|
|
|
|
"--foo_opt",
|
|
|
|
"--bar_opt",
|
|
|
|
]`,
|
|
|
|
}},
|
2022-06-21 21:28:33 +02:00
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
2022-05-13 22:55:35 +02:00
|
|
|
"srcs": `[
|
|
|
|
"bar.cc",
|
|
|
|
":foo_genlex_ll",
|
|
|
|
]`,
|
|
|
|
"srcs_c": `[
|
|
|
|
"foo.c",
|
|
|
|
":foo_genlex_l",
|
|
|
|
]`,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-08-09 18:50:56 +02:00
|
|
|
|
|
|
|
func TestCcBinaryRuntimeLibs(t *testing.T) {
|
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
|
|
|
description: "cc_binary with runtime libs",
|
|
|
|
blueprint: `
|
|
|
|
cc_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.cc"],
|
|
|
|
}
|
|
|
|
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.cc"],
|
|
|
|
runtime_libs: ["bar"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"cc_library_static", "bar_bp2build_cc_library_static", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `["b.cc"]`,
|
|
|
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"cc_library_shared", "bar", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `["b.cc"]`,
|
|
|
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `["a.cc"]`,
|
|
|
|
"runtime_deps": `[":bar"]`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-08-22 23:31:04 +02:00
|
|
|
|
|
|
|
func TestCcBinaryWithInstructionSet(t *testing.T) {
|
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
|
|
|
description: "instruction set",
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
instruction_set: "arm",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
|
|
|
"features": `select({
|
|
|
|
"//build/bazel/platforms/arch:arm": [
|
|
|
|
"arm_isa_arm",
|
|
|
|
"-arm_isa_thumb",
|
|
|
|
],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"local_includes": `["."]`,
|
2022-02-24 00:39:59 +01:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryEmptySuffix(t *testing.T) {
|
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
|
|
|
description: "binary with empty suffix",
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
suffix: "",
|
|
|
|
}`,
|
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"suffix": `""`,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinarySuffix(t *testing.T) {
|
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
|
|
|
description: "binary with suffix",
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
suffix: "-suf",
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"suffix": `"-suf"`,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcArchVariantBinarySuffix(t *testing.T) {
|
|
|
|
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
|
|
|
description: "binary with suffix",
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
arch: {
|
|
|
|
arm64: { suffix: "-64" },
|
|
|
|
arm: { suffix: "-32" },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"suffix": `select({
|
|
|
|
"//build/bazel/platforms/arch:arm": "-32",
|
|
|
|
"//build/bazel/platforms/arch:arm64": "-64",
|
|
|
|
"//conditions:default": None,
|
|
|
|
})`,
|
|
|
|
}},
|
2022-08-22 23:31:04 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-09-06 21:31:25 +02:00
|
|
|
|
|
|
|
func TestCcBinaryWithSyspropSrcs(t *testing.T) {
|
|
|
|
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
|
|
|
description: "cc_binary with sysprop sources",
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"bar.sysprop",
|
|
|
|
"baz.sysprop",
|
|
|
|
"blah.cpp",
|
|
|
|
],
|
|
|
|
min_sdk_version: "5",
|
|
|
|
}`,
|
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"sysprop_library", "foo_sysprop_library", AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"bar.sysprop",
|
|
|
|
"baz.sysprop",
|
|
|
|
]`,
|
|
|
|
}},
|
|
|
|
{"cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
|
|
|
|
"dep": `":foo_sysprop_library"`,
|
|
|
|
"min_sdk_version": `"5"`,
|
|
|
|
}},
|
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
|
|
|
"srcs": `["blah.cpp"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"min_sdk_version": `"5"`,
|
|
|
|
"whole_archive_deps": `[":foo_cc_sysprop_library_static"]`,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcBinaryWithSyspropSrcsSomeConfigs(t *testing.T) {
|
|
|
|
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
|
|
|
description: "cc_binary with sysprop sources in some configs but not others",
|
|
|
|
blueprint: `
|
|
|
|
{rule_name} {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"blah.cpp",
|
|
|
|
],
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
srcs: ["bar.sysprop"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
min_sdk_version: "5",
|
|
|
|
}`,
|
|
|
|
targets: []testBazelTarget{
|
|
|
|
{"sysprop_library", "foo_sysprop_library", AttrNameToString{
|
|
|
|
"srcs": `select({
|
|
|
|
"//build/bazel/platforms/os:android": ["bar.sysprop"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}},
|
|
|
|
{"cc_sysprop_library_static", "foo_cc_sysprop_library_static", AttrNameToString{
|
|
|
|
"dep": `":foo_sysprop_library"`,
|
|
|
|
"min_sdk_version": `"5"`,
|
|
|
|
}},
|
|
|
|
{"cc_binary", "foo", AttrNameToString{
|
|
|
|
"srcs": `["blah.cpp"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"min_sdk_version": `"5"`,
|
|
|
|
"whole_archive_deps": `select({
|
|
|
|
"//build/bazel/platforms/os:android": [":foo_cc_sysprop_library_static"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|