Handle include_build_directory prop in bp2build
Test: go test cc tests
Test: generate bp2build, sync bp2build, bazel build //bionic/...
Bug: 181794963
Change-Id: I8dcef585e3025ef6f44d22430ed67b1e0429dca0
diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go
index 1d4e322..1c058ba 100644
--- a/bp2build/cc_object_conversion_test.go
+++ b/bp2build/cc_object_conversion_test.go
@@ -70,6 +70,7 @@
],
local_include_dirs = [
"include",
+ ".",
],
srcs = [
"a/b/bar.h",
@@ -120,6 +121,7 @@
],
local_include_dirs = [
"include",
+ ".",
],
srcs = [
"a/b/c.c",
@@ -156,6 +158,9 @@
copts = [
"-fno-addrsig",
],
+ local_include_dirs = [
+ ".",
+ ],
srcs = [
"x/y/z.c",
],
@@ -167,6 +172,37 @@
deps = [
":bar",
],
+ local_include_dirs = [
+ ".",
+ ],
+ srcs = [
+ "a/b/c.c",
+ ],
+)`,
+ },
+ },
+ {
+ description: "cc_object with include_build_dir: false",
+ moduleTypeUnderTest: "cc_object",
+ moduleTypeUnderTestFactory: cc.ObjectFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
+ filesystem: map[string]string{
+ "a/b/c.c": "",
+ "x/y/z.c": "",
+ },
+ blueprint: `cc_object {
+ name: "foo",
+ srcs: ["a/b/c.c"],
+ include_build_directory: false,
+
+ bazel_module: { bp2build_available: true },
+}
+`,
+ expectedBazelTargets: []string{`cc_object(
+ name = "foo",
+ copts = [
+ "-fno-addrsig",
+ ],
srcs = [
"a/b/c.c",
],
@@ -262,6 +298,9 @@
"//conditions:default": [
],
}),
+ local_include_dirs = [
+ ".",
+ ],
)`,
},
},
@@ -310,6 +349,9 @@
"//conditions:default": [
],
}),
+ local_include_dirs = [
+ ".",
+ ],
)`,
},
},
diff --git a/cc/compiler.go b/cc/compiler.go
index 2e71922..791c95b 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -256,6 +256,10 @@
return []interface{}{&compiler.Properties, &compiler.Proto}
}
+func (compiler *baseCompiler) includeBuildDirectory() bool {
+ return proptools.BoolDefault(compiler.Properties.Include_build_directory, true)
+}
+
func (compiler *baseCompiler) compilerInit(ctx BaseModuleContext) {}
func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
@@ -332,8 +336,7 @@
flags.Local.YasmFlags = append(flags.Local.YasmFlags, f)
}
- if compiler.Properties.Include_build_directory == nil ||
- *compiler.Properties.Include_build_directory {
+ if compiler.includeBuildDirectory() {
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+modulePath)
flags.Local.YasmFlags = append(flags.Local.YasmFlags, "-I"+modulePath)
}
diff --git a/cc/object.go b/cc/object.go
index f9e6d2d..6bea28b 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -160,6 +160,10 @@
}
}
+ if c, ok := m.compiler.(*baseCompiler); ok && c.includeBuildDirectory() {
+ localIncludeDirs = append(localIncludeDirs, ".")
+ }
+
var deps bazel.LabelList
for _, props := range m.linker.linkerProps() {
if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok {