2021-02-18 09:21:34 +01:00
|
|
|
// Copyright 2021 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package bp2build
|
|
|
|
|
|
|
|
import (
|
2021-05-21 09:37:00 +02:00
|
|
|
"testing"
|
|
|
|
|
2021-02-18 09:21:34 +01:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
)
|
|
|
|
|
2021-05-21 09:37:00 +02:00
|
|
|
func registerCcObjectModuleTypes(ctx android.RegistrationContext) {
|
|
|
|
// Always register cc_defaults module factory
|
|
|
|
ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() })
|
2022-12-06 06:18:13 +01:00
|
|
|
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
|
2021-05-21 09:37:00 +02:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runCcObjectTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2021-05-25 16:39:35 +02:00
|
|
|
t.Helper()
|
2022-06-21 21:28:33 +02:00
|
|
|
(&tc).ModuleTypeUnderTest = "cc_object"
|
|
|
|
(&tc).ModuleTypeUnderTestFactory = cc.ObjectFactory
|
|
|
|
RunBp2BuildTestCase(t, registerCcObjectModuleTypes, tc)
|
2021-05-21 09:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcObjectSimple(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "simple cc_object generates cc_object with include header dep",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"a/b/foo.h": "",
|
|
|
|
"a/b/bar.h": "",
|
|
|
|
"a/b/exclude.c": "",
|
|
|
|
"a/b/c.c": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `cc_object {
|
2021-02-18 09:21:34 +01:00
|
|
|
name: "foo",
|
|
|
|
local_include_dirs: ["include"],
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-02-18 09:21:34 +01:00
|
|
|
cflags: [
|
|
|
|
"-Wno-gcc-compat",
|
|
|
|
"-Wall",
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
srcs: [
|
2021-02-23 06:46:47 +01:00
|
|
|
"a/b/*.c"
|
2021-02-18 09:21:34 +01:00
|
|
|
],
|
2021-02-23 06:46:47 +01:00
|
|
|
exclude_srcs: ["a/b/exclude.c"],
|
2022-03-02 00:44:08 +01:00
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29",
|
2023-01-25 22:52:36 +01:00
|
|
|
crt: true,
|
2021-02-18 09:21:34 +01:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `[
|
2021-02-18 09:21:34 +01:00
|
|
|
"-fno-addrsig",
|
|
|
|
"-Wno-gcc-compat",
|
|
|
|
"-Wall",
|
|
|
|
"-Werror",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"local_includes": `[
|
2021-09-10 16:07:07 +02:00
|
|
|
"include",
|
|
|
|
".",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs": `["a/b/c.c"]`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
2022-06-21 21:28:33 +02:00
|
|
|
"sdk_version": `"current"`,
|
|
|
|
"min_sdk_version": `"29"`,
|
2023-01-25 22:52:36 +01:00
|
|
|
"crt": "True",
|
2021-11-08 18:56:31 +01:00
|
|
|
}),
|
2021-02-18 09:21:34 +01:00
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcObjectDefaults(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: `cc_object {
|
2021-02-18 09:21:34 +01:00
|
|
|
name: "foo",
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-02-18 09:21:34 +01:00
|
|
|
srcs: [
|
|
|
|
"a/b/*.h",
|
|
|
|
"a/b/c.c"
|
|
|
|
],
|
|
|
|
|
|
|
|
defaults: ["foo_defaults"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_defaults {
|
|
|
|
name: "foo_defaults",
|
|
|
|
defaults: ["foo_bar_defaults"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_defaults {
|
|
|
|
name: "foo_bar_defaults",
|
|
|
|
cflags: [
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `[
|
2021-02-18 09:21:34 +01:00
|
|
|
"-Werror",
|
|
|
|
"-fno-addrsig",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `["a/b/c.c"]`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
2021-05-21 09:37:00 +02:00
|
|
|
}})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcObjectCcObjetDepsInObjs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_object with cc_object deps in objs props",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"a/b/c.c": "",
|
|
|
|
"x/y/z.c": "",
|
2021-02-23 06:46:47 +01:00
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `cc_object {
|
2021-02-23 06:46:47 +01:00
|
|
|
name: "foo",
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-02-23 06:46:47 +01:00
|
|
|
srcs: ["a/b/c.c"],
|
|
|
|
objs: ["bar"],
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-02-23 06:46:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_object {
|
|
|
|
name: "bar",
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-02-23 06:46:47 +01:00
|
|
|
srcs: ["x/y/z.c"],
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-02-23 06:46:47 +01:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "bar", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `["-fno-addrsig"]`,
|
|
|
|
"srcs": `["x/y/z.c"]`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
2022-08-31 20:28:19 +02:00
|
|
|
}), MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `["-fno-addrsig"]`,
|
2022-12-06 06:18:13 +01:00
|
|
|
"objs": `[":bar"]`,
|
2021-11-08 18:56:31 +01:00
|
|
|
"srcs": `["a/b/c.c"]`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
2021-03-18 21:56:36 +01:00
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcObjectIncludeBuildDirFalse(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_object with include_build_dir: false",
|
|
|
|
Filesystem: map[string]string{
|
2021-05-21 09:37:00 +02:00
|
|
|
"a/b/c.c": "",
|
|
|
|
"x/y/z.c": "",
|
|
|
|
},
|
2022-06-21 21:28:33 +02:00
|
|
|
Blueprint: `cc_object {
|
2021-03-18 21:56:36 +01:00
|
|
|
name: "foo",
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-03-18 21:56:36 +01:00
|
|
|
srcs: ["a/b/c.c"],
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `["-fno-addrsig"]`,
|
|
|
|
"srcs": `["a/b/c.c"]`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
2021-03-24 15:14:47 +01:00
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcObjectProductVariable(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_object with product variable",
|
|
|
|
Blueprint: `cc_object {
|
2021-03-24 15:14:47 +01:00
|
|
|
name: "foo",
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-03-24 15:14:47 +01:00
|
|
|
include_build_directory: false,
|
|
|
|
product_variables: {
|
|
|
|
platform_sdk_version: {
|
|
|
|
asflags: ["-DPLATFORM_SDK_VERSION=%d"],
|
|
|
|
},
|
|
|
|
},
|
2021-07-13 17:47:44 +02:00
|
|
|
srcs: ["src.S"],
|
2021-03-24 15:14:47 +01:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", 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-06 19:54:29 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"copts": `["-fno-addrsig"]`,
|
|
|
|
"srcs_as": `["src.S"]`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
2021-02-18 09:21:34 +01:00
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
2021-02-24 13:20:12 +01:00
|
|
|
}
|
|
|
|
|
2021-05-21 09:37:00 +02:00
|
|
|
func TestCcObjectCflagsOneArch(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_object setting cflags for one arch",
|
|
|
|
Blueprint: `cc_object {
|
2021-02-24 13:20:12 +01:00
|
|
|
name: "foo",
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-03-15 11:02:43 +01:00
|
|
|
srcs: ["a.cpp"],
|
2021-02-24 13:20:12 +01:00
|
|
|
arch: {
|
|
|
|
x86: {
|
2021-03-15 11:02:43 +01:00
|
|
|
cflags: ["-fPIC"], // string list
|
|
|
|
},
|
|
|
|
arm: {
|
2021-07-13 17:47:44 +02:00
|
|
|
srcs: ["arch/arm/file.cpp"], // label list
|
2021-02-24 13:20:12 +01:00
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-02-24 13:20:12 +01:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `["-fno-addrsig"] + select({
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/arch:x86": ["-fPIC"],
|
2021-03-15 11:02:43 +01:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"srcs": `["a.cpp"] + select({
|
2021-07-13 17:47:44 +02:00
|
|
|
"//build/bazel/platforms/arch:arm": ["arch/arm/file.cpp"],
|
2021-03-15 11:02:43 +01:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
2021-02-24 13:20:12 +01:00
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcObjectCflagsFourArch(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_object setting cflags for 4 architectures",
|
|
|
|
Blueprint: `cc_object {
|
2021-02-24 13:20:12 +01:00
|
|
|
name: "foo",
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-03-15 11:02:43 +01:00
|
|
|
srcs: ["base.cpp"],
|
2021-02-24 13:20:12 +01:00
|
|
|
arch: {
|
|
|
|
x86: {
|
2021-03-15 11:02:43 +01:00
|
|
|
srcs: ["x86.cpp"],
|
2021-02-24 13:20:12 +01:00
|
|
|
cflags: ["-fPIC"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
2021-03-15 11:02:43 +01:00
|
|
|
srcs: ["x86_64.cpp"],
|
2021-02-24 13:20:12 +01:00
|
|
|
cflags: ["-fPIC"],
|
|
|
|
},
|
|
|
|
arm: {
|
2021-03-15 11:02:43 +01:00
|
|
|
srcs: ["arm.cpp"],
|
2021-02-24 13:20:12 +01:00
|
|
|
cflags: ["-Wall"],
|
|
|
|
},
|
|
|
|
arm64: {
|
2021-03-15 11:02:43 +01:00
|
|
|
srcs: ["arm64.cpp"],
|
2021-02-24 13:20:12 +01:00
|
|
|
cflags: ["-Wall"],
|
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-02-24 13:20:12 +01:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `["-fno-addrsig"] + select({
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/arch:arm": ["-Wall"],
|
|
|
|
"//build/bazel/platforms/arch:arm64": ["-Wall"],
|
|
|
|
"//build/bazel/platforms/arch:x86": ["-fPIC"],
|
|
|
|
"//build/bazel/platforms/arch:x86_64": ["-fPIC"],
|
2021-03-15 11:02:43 +01:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"srcs": `["base.cpp"] + select({
|
2021-04-08 16:40:57 +02:00
|
|
|
"//build/bazel/platforms/arch:arm": ["arm.cpp"],
|
|
|
|
"//build/bazel/platforms/arch:arm64": ["arm64.cpp"],
|
|
|
|
"//build/bazel/platforms/arch:x86": ["x86.cpp"],
|
|
|
|
"//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
|
2021-03-15 11:02:43 +01:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
}),
|
2021-04-05 12:35:13 +02:00
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-28 22:47:36 +02:00
|
|
|
func TestCcObjectLinkerScript(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_object setting linker_script",
|
|
|
|
Blueprint: `cc_object {
|
2021-04-05 12:35:13 +02:00
|
|
|
name: "foo",
|
2021-09-28 22:47:36 +02:00
|
|
|
srcs: ["base.cpp"],
|
|
|
|
linker_script: "bunny.lds",
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `["-fno-addrsig"]`,
|
|
|
|
"linker_script": `"bunny.lds"`,
|
|
|
|
"srcs": `["base.cpp"]`,
|
|
|
|
}),
|
2021-09-28 22:47:36 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcObjectDepsAndLinkerScriptSelects(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_object setting deps and linker_script across archs",
|
|
|
|
Blueprint: `cc_object {
|
2021-09-28 22:47:36 +02:00
|
|
|
name: "foo",
|
|
|
|
srcs: ["base.cpp"],
|
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
objs: ["x86_obj"],
|
|
|
|
linker_script: "x86.lds",
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
objs: ["x86_64_obj"],
|
|
|
|
linker_script: "x86_64.lds",
|
|
|
|
},
|
|
|
|
arm: {
|
|
|
|
objs: ["arm_obj"],
|
|
|
|
linker_script: "arm.lds",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
include_build_directory: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_object {
|
|
|
|
name: "x86_obj",
|
|
|
|
system_shared_libs: [],
|
|
|
|
srcs: ["x86.cpp"],
|
|
|
|
include_build_directory: false,
|
|
|
|
bazel_module: { bp2build_available: false },
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_object {
|
|
|
|
name: "x86_64_obj",
|
2021-07-22 20:39:44 +02:00
|
|
|
system_shared_libs: [],
|
2021-09-28 22:47:36 +02:00
|
|
|
srcs: ["x86_64.cpp"],
|
|
|
|
include_build_directory: false,
|
|
|
|
bazel_module: { bp2build_available: false },
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_object {
|
|
|
|
name: "arm_obj",
|
|
|
|
system_shared_libs: [],
|
|
|
|
srcs: ["arm.cpp"],
|
|
|
|
include_build_directory: false,
|
|
|
|
bazel_module: { bp2build_available: false },
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `["-fno-addrsig"]`,
|
2022-12-06 06:18:13 +01:00
|
|
|
"objs": `select({
|
2021-09-28 22:47:36 +02:00
|
|
|
"//build/bazel/platforms/arch:arm": [":arm_obj"],
|
|
|
|
"//build/bazel/platforms/arch:x86": [":x86_obj"],
|
|
|
|
"//build/bazel/platforms/arch:x86_64": [":x86_64_obj"],
|
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"linker_script": `select({
|
2021-09-28 22:47:36 +02:00
|
|
|
"//build/bazel/platforms/arch:arm": "arm.lds",
|
|
|
|
"//build/bazel/platforms/arch:x86": "x86.lds",
|
|
|
|
"//build/bazel/platforms/arch:x86_64": "x86_64.lds",
|
|
|
|
"//conditions:default": None,
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
"srcs": `["base.cpp"]`,
|
|
|
|
}),
|
2021-09-28 22:47:36 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "cc_object setting srcs based on linux and bionic archs",
|
|
|
|
Blueprint: `cc_object {
|
2021-09-28 22:47:36 +02:00
|
|
|
name: "foo",
|
2021-04-05 12:35:13 +02:00
|
|
|
srcs: ["base.cpp"],
|
|
|
|
target: {
|
2021-09-28 22:47:36 +02:00
|
|
|
linux_arm64: {
|
|
|
|
srcs: ["linux_arm64.cpp",]
|
2021-04-05 12:35:13 +02:00
|
|
|
},
|
2021-09-28 22:47:36 +02:00
|
|
|
linux_x86: {
|
|
|
|
srcs: ["linux_x86.cpp",]
|
2021-04-05 12:35:13 +02:00
|
|
|
},
|
2021-09-28 22:47:36 +02:00
|
|
|
bionic_arm64: {
|
|
|
|
srcs: ["bionic_arm64.cpp",]
|
2021-04-05 12:35:13 +02:00
|
|
|
},
|
|
|
|
},
|
2021-09-10 16:06:32 +02:00
|
|
|
include_build_directory: false,
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
2022-08-31 20:28:19 +02:00
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"copts": `["-fno-addrsig"]`,
|
|
|
|
"srcs": `["base.cpp"] + select({
|
2021-09-28 22:47:36 +02:00
|
|
|
"//build/bazel/platforms/os_arch:android_arm64": [
|
|
|
|
"linux_arm64.cpp",
|
2021-10-11 21:40:35 +02:00
|
|
|
"bionic_arm64.cpp",
|
2021-09-28 22:47:36 +02:00
|
|
|
],
|
|
|
|
"//build/bazel/platforms/os_arch:android_x86": ["linux_x86.cpp"],
|
|
|
|
"//build/bazel/platforms/os_arch:linux_bionic_arm64": [
|
|
|
|
"linux_arm64.cpp",
|
2021-10-11 21:40:35 +02:00
|
|
|
"bionic_arm64.cpp",
|
2021-09-28 22:47:36 +02:00
|
|
|
],
|
|
|
|
"//build/bazel/platforms/os_arch:linux_glibc_x86": ["linux_x86.cpp"],
|
2022-06-16 02:25:51 +02:00
|
|
|
"//build/bazel/platforms/os_arch:linux_musl_arm64": ["linux_arm64.cpp"],
|
2021-09-28 22:47:36 +02:00
|
|
|
"//build/bazel/platforms/os_arch:linux_musl_x86": ["linux_x86.cpp"],
|
2021-04-05 12:35:13 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-08 18:56:31 +01:00
|
|
|
})`,
|
|
|
|
}),
|
2021-02-24 13:20:12 +01:00
|
|
|
},
|
2021-05-21 09:37:00 +02:00
|
|
|
})
|
2021-02-18 09:21:34 +01:00
|
|
|
}
|
2022-12-06 06:18:13 +01:00
|
|
|
|
|
|
|
func TestCcObjectHeaderLib(t *testing.T) {
|
|
|
|
runCcObjectTestCase(t, Bp2buildTestCase{
|
|
|
|
Description: "simple cc_object generates cc_object with include header dep",
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
"a/b/foo.h": "",
|
|
|
|
"a/b/bar.h": "",
|
|
|
|
"a/b/exclude.c": "",
|
|
|
|
"a/b/c.c": "",
|
|
|
|
},
|
|
|
|
Blueprint: `cc_object {
|
|
|
|
name: "foo",
|
|
|
|
header_libs: ["libheaders"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
cflags: [
|
|
|
|
"-Wno-gcc-compat",
|
|
|
|
"-Wall",
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
srcs: [
|
|
|
|
"a/b/*.c"
|
|
|
|
],
|
|
|
|
exclude_srcs: ["a/b/exclude.c"],
|
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_headers {
|
|
|
|
name: "libheaders",
|
|
|
|
export_include_dirs: ["include"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
|
|
|
"copts": `[
|
|
|
|
"-fno-addrsig",
|
|
|
|
"-Wno-gcc-compat",
|
|
|
|
"-Wall",
|
|
|
|
"-Werror",
|
|
|
|
]`,
|
|
|
|
"deps": `[":libheaders"]`,
|
|
|
|
"local_includes": `["."]`,
|
|
|
|
"srcs": `["a/b/c.c"]`,
|
|
|
|
"system_dynamic_deps": `[]`,
|
|
|
|
"sdk_version": `"current"`,
|
|
|
|
"min_sdk_version": `"29"`,
|
|
|
|
}),
|
|
|
|
MakeBazelTarget("cc_library_headers", "libheaders", AttrNameToString{
|
|
|
|
"export_includes": `["include"]`,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|