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
diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go
index a9d24ac..d00a1cb 100644
--- a/bp2build/cc_object_conversion_test.go
+++ b/bp2build/cc_object_conversion_test.go
@@ -55,8 +55,6 @@
"a/b/*.c"
],
exclude_srcs: ["a/b/exclude.c"],
-
- bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`cc_object(
@@ -66,16 +64,14 @@
"-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 @@
],
defaults: ["foo_defaults"],
- bazel_module: { bp2build_available: true },
}
cc_defaults {
@@ -117,10 +112,8 @@
"-Wall",
"-Werror",
"-fno-addrsig",
- ],
- local_include_dirs = [
- "include",
- ".",
+ "-Iinclude",
+ "-I.",
],
srcs = ["a/b/c.c"],
)`,
@@ -139,27 +132,27 @@
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 @@
name: "foo",
srcs: ["a/b/c.c"],
include_build_directory: false,
-
- bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`cc_object(
@@ -201,8 +192,6 @@
asflags: ["-DPLATFORM_SDK_VERSION=%d"],
},
},
-
- bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`cc_object(
@@ -233,6 +222,7 @@
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 @@
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 @@
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 @@
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 @@
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
+ ctx.RegisterBp2BuildConfig(bp2buildConfig)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)