bp2build: refactor/standardize cc_* bp2build converters

This CL refactors the cc* bp2build converters to use the common
attribute extractors in cc/bp2build.go.

This also adds include_build_directory to be handled by the compiler
attr extractor to generate recursive headers as inputs.

This also turns include_dirs and local_include_dirs into the
execroot-relative -I flags.

e.g. if a module in  bionic/libc has "private" in local_include_dirs,
the "-Ibionic/libc/private" copt is generated for it.

Fixes: 185139955

Test: TH
Test: Forrest for mixed_clean-droid
Change-Id: Ib67056482227e62068fbbea0455035bdf5d56319
This commit is contained in:
Jingwen Chen
2021-04-13 07:14:55 +00:00
parent dac451715b
commit ed9c17d033
11 changed files with 579 additions and 224 deletions

View File

@@ -55,8 +55,6 @@ func TestCcObjectBp2Build(t *testing.T) {
"a/b/*.c"
],
exclude_srcs: ["a/b/exclude.c"],
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`cc_object(
@@ -66,16 +64,14 @@ func TestCcObjectBp2Build(t *testing.T) {
"-Wno-gcc-compat",
"-Wall",
"-Werror",
"-Iinclude",
"-I.",
],
hdrs = [
srcs = [
"a/b/c.c",
"a/b/bar.h",
"a/b/foo.h",
],
local_include_dirs = [
"include",
".",
],
srcs = ["a/b/c.c"],
)`,
},
},
@@ -93,7 +89,6 @@ func TestCcObjectBp2Build(t *testing.T) {
],
defaults: ["foo_defaults"],
bazel_module: { bp2build_available: true },
}
cc_defaults {
@@ -117,10 +112,8 @@ cc_defaults {
"-Wall",
"-Werror",
"-fno-addrsig",
],
local_include_dirs = [
"include",
".",
"-Iinclude",
"-I.",
],
srcs = ["a/b/c.c"],
)`,
@@ -139,27 +132,27 @@ cc_defaults {
name: "foo",
srcs: ["a/b/c.c"],
objs: ["bar"],
bazel_module: { bp2build_available: true },
}
cc_object {
name: "bar",
srcs: ["x/y/z.c"],
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`cc_object(
name = "bar",
copts = ["-fno-addrsig"],
local_include_dirs = ["."],
copts = [
"-fno-addrsig",
"-I.",
],
srcs = ["x/y/z.c"],
)`, `cc_object(
name = "foo",
copts = ["-fno-addrsig"],
copts = [
"-fno-addrsig",
"-I.",
],
deps = [":bar"],
local_include_dirs = ["."],
srcs = ["a/b/c.c"],
)`,
},
@@ -177,8 +170,6 @@ cc_object {
name: "foo",
srcs: ["a/b/c.c"],
include_build_directory: false,
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`cc_object(
@@ -201,8 +192,6 @@ cc_object {
asflags: ["-DPLATFORM_SDK_VERSION=%d"],
},
},
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`cc_object(
@@ -233,6 +222,7 @@ cc_object {
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterBp2BuildConfig(bp2buildConfig)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
@@ -290,17 +280,18 @@ func TestCcObjectConfigurableAttributesBp2Build(t *testing.T) {
srcs: ["arch/arm/file.S"], // label list
},
},
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{
`cc_object(
name = "foo",
copts = ["-fno-addrsig"] + select({
copts = [
"-fno-addrsig",
"-I.",
] + select({
"//build/bazel/platforms/arch:x86": ["-fPIC"],
"//conditions:default": [],
}),
local_include_dirs = ["."],
srcs = ["a.cpp"] + select({
"//build/bazel/platforms/arch:arm": ["arch/arm/file.S"],
"//conditions:default": [],
@@ -334,20 +325,21 @@ func TestCcObjectConfigurableAttributesBp2Build(t *testing.T) {
cflags: ["-Wall"],
},
},
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{
`cc_object(
name = "foo",
copts = ["-fno-addrsig"] + select({
copts = [
"-fno-addrsig",
"-I.",
] + select({
"//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"],
"//conditions:default": [],
}),
local_include_dirs = ["."],
srcs = ["base.cpp"] + select({
"//build/bazel/platforms/arch:arm": ["arm.cpp"],
"//build/bazel/platforms/arch:arm64": ["arm64.cpp"],
@@ -377,19 +369,20 @@ func TestCcObjectConfigurableAttributesBp2Build(t *testing.T) {
cflags: ["-Wall"],
},
},
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{
`cc_object(
name = "foo",
copts = ["-fno-addrsig"] + select({
copts = [
"-fno-addrsig",
"-I.",
] + select({
"//build/bazel/platforms/os:android": ["-fPIC"],
"//build/bazel/platforms/os:darwin": ["-Wall"],
"//build/bazel/platforms/os:windows": ["-fPIC"],
"//conditions:default": [],
}),
local_include_dirs = ["."],
srcs = ["base.cpp"],
)`,
},
@@ -409,6 +402,7 @@ func TestCcObjectConfigurableAttributesBp2Build(t *testing.T) {
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterBp2BuildConfig(bp2buildConfig)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)