bp2build: support generated sources and hdrs
There are two pieces to make this work:
1. Local include paths must include $(BINDIR)-relative paths, to support
generated headers in those directories.
2. The srcs that bp2build outputs for BUILD targets must include labels
for targets given in generated_hdrs and generated_srcs.
Support for exported_generated_hdrs intentionally deferred.
This allows us to remove several targets from the bp2build denylist.
Some are moved to the mixed build denylist, because genreated headers are
still unsupported in mixed builds.
Test: bp2build.sh CI script
Change-Id: Ib4f9dac20f6445487b8dad53b91eac01f437a590
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 8afc82b..da5444c 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -113,6 +113,7 @@
copts = [
"-Wall",
"-I.",
+ "-I$(BINDIR)/.",
],
deps = [":some-headers"],
includes = ["foo-dir"],
@@ -183,6 +184,7 @@
"-Wunused",
"-Werror",
"-I.",
+ "-I$(BINDIR)/.",
],
deps = [":libc_headers"],
linkopts = [
@@ -242,7 +244,10 @@
bp: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "fake-libarm-optimized-routines-math",
- copts = ["-Iexternal"] + select({
+ copts = [
+ "-Iexternal",
+ "-I$(BINDIR)/external",
+ ] + select({
"//build/bazel/platforms/arch:arm64": ["-DHAVE_FAST_FMA=1"],
"//conditions:default": [],
}),
@@ -310,6 +315,7 @@
copts = [
"bothflag",
"-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
],
deps = [":static_dep_for_both"],
dynamic_deps = [":shared_dep_for_both"],
@@ -347,7 +353,10 @@
bp: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
- copts = ["-Ifoo/bar"],
+ copts = [
+ "-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
+ ],
srcs = ["a.cpp"],
version_script = "v.map",
)`},
@@ -380,7 +389,10 @@
bp: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
- copts = ["-Ifoo/bar"],
+ copts = [
+ "-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
+ ],
srcs = ["a.cpp"],
version_script = select({
"//build/bazel/platforms/arch:arm": "arm.map",
@@ -413,11 +425,17 @@
bp: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
- copts = ["-Ifoo/bar"],
+ copts = [
+ "-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
+ ],
dynamic_deps = [":mylib"],
)`, `cc_library(
name = "mylib",
- copts = ["-Ifoo/bar"],
+ copts = [
+ "-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
+ ],
)`},
},
{
@@ -461,12 +479,18 @@
bp: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
- copts = ["-Ifoo/bar"],
+ copts = [
+ "-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
+ ],
linkopts = ["-Wl,--pack-dyn-relocs=none"],
srcs = ["a.cpp"],
)`, `cc_library(
name = "b",
- copts = ["-Ifoo/bar"],
+ copts = [
+ "-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
+ ],
linkopts = select({
"//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"],
"//conditions:default": [],
@@ -474,7 +498,10 @@
srcs = ["b.cpp"],
)`, `cc_library(
name = "c",
- copts = ["-Ifoo/bar"],
+ copts = [
+ "-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
+ ],
linkopts = select({
"//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"],
"//conditions:default": [],
@@ -505,6 +532,7 @@
"-include",
"header.h",
"-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
],
)`},
},
@@ -548,6 +576,7 @@
"-fsigned-char",
"-pedantic",
"-Ifoo/bar",
+ "-I$(BINDIR)/foo/bar",
] + select({
"//build/bazel/platforms/arch:arm64": ["-DARM64=1"],
"//conditions:default": [],