Add support for headers from dependencies to bazel cc_object
The libc_musl_crt* cc_object modules use header_libs to add headers to the search path. Propagate static_libs, shared_libs and header_libs to includes_deps. Bug: 259266326 Test: TestCcObjectHeaderLib Change-Id: I8db4d6886761426d3ece38c43ac868d3248f7a9f
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
|||||||
func registerCcObjectModuleTypes(ctx android.RegistrationContext) {
|
func registerCcObjectModuleTypes(ctx android.RegistrationContext) {
|
||||||
// Always register cc_defaults module factory
|
// Always register cc_defaults module factory
|
||||||
ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() })
|
ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() })
|
||||||
|
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCcObjectTestCase(t *testing.T, tc Bp2buildTestCase) {
|
func runCcObjectTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||||
@@ -147,7 +148,7 @@ cc_object {
|
|||||||
"system_dynamic_deps": `[]`,
|
"system_dynamic_deps": `[]`,
|
||||||
}), MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
}), MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||||
"copts": `["-fno-addrsig"]`,
|
"copts": `["-fno-addrsig"]`,
|
||||||
"deps": `[":bar"]`,
|
"objs": `[":bar"]`,
|
||||||
"srcs": `["a/b/c.c"]`,
|
"srcs": `["a/b/c.c"]`,
|
||||||
"system_dynamic_deps": `[]`,
|
"system_dynamic_deps": `[]`,
|
||||||
}),
|
}),
|
||||||
@@ -362,7 +363,7 @@ cc_object {
|
|||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||||
"copts": `["-fno-addrsig"]`,
|
"copts": `["-fno-addrsig"]`,
|
||||||
"deps": `select({
|
"objs": `select({
|
||||||
"//build/bazel/platforms/arch:arm": [":arm_obj"],
|
"//build/bazel/platforms/arch:arm": [":arm_obj"],
|
||||||
"//build/bazel/platforms/arch:x86": [":x86_obj"],
|
"//build/bazel/platforms/arch:x86": [":x86_obj"],
|
||||||
"//build/bazel/platforms/arch:x86_64": [":x86_64_obj"],
|
"//build/bazel/platforms/arch:x86_64": [":x86_64_obj"],
|
||||||
@@ -422,3 +423,56 @@ func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
10
cc/object.go
10
cc/object.go
@@ -133,6 +133,7 @@ type bazelObjectAttributes struct {
|
|||||||
Srcs bazel.LabelListAttribute
|
Srcs bazel.LabelListAttribute
|
||||||
Srcs_as bazel.LabelListAttribute
|
Srcs_as bazel.LabelListAttribute
|
||||||
Hdrs bazel.LabelListAttribute
|
Hdrs bazel.LabelListAttribute
|
||||||
|
Objs bazel.LabelListAttribute
|
||||||
Deps bazel.LabelListAttribute
|
Deps bazel.LabelListAttribute
|
||||||
System_dynamic_deps bazel.LabelListAttribute
|
System_dynamic_deps bazel.LabelListAttribute
|
||||||
Copts bazel.StringListAttribute
|
Copts bazel.StringListAttribute
|
||||||
@@ -155,6 +156,7 @@ func objectBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
// Set arch-specific configurable attributes
|
// Set arch-specific configurable attributes
|
||||||
baseAttributes := bp2BuildParseBaseProps(ctx, m)
|
baseAttributes := bp2BuildParseBaseProps(ctx, m)
|
||||||
compilerAttrs := baseAttributes.compilerAttributes
|
compilerAttrs := baseAttributes.compilerAttributes
|
||||||
|
var objs bazel.LabelListAttribute
|
||||||
var deps bazel.LabelListAttribute
|
var deps bazel.LabelListAttribute
|
||||||
systemDynamicDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true}
|
systemDynamicDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true}
|
||||||
|
|
||||||
@@ -167,16 +169,19 @@ func objectBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
label := android.BazelLabelForModuleSrcSingle(ctx, *objectLinkerProps.Linker_script)
|
label := android.BazelLabelForModuleSrcSingle(ctx, *objectLinkerProps.Linker_script)
|
||||||
linkerScript.SetSelectValue(axis, config, label)
|
linkerScript.SetSelectValue(axis, config, label)
|
||||||
}
|
}
|
||||||
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
|
objs.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
|
||||||
systemSharedLibs := objectLinkerProps.System_shared_libs
|
systemSharedLibs := objectLinkerProps.System_shared_libs
|
||||||
if len(systemSharedLibs) > 0 {
|
if len(systemSharedLibs) > 0 {
|
||||||
systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs)
|
systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs)
|
||||||
}
|
}
|
||||||
systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
|
systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
|
||||||
|
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Static_libs))
|
||||||
|
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Shared_libs))
|
||||||
|
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Header_libs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deps.ResolveExcludes()
|
objs.ResolveExcludes()
|
||||||
|
|
||||||
// Don't split cc_object srcs across languages. Doing so would add complexity,
|
// Don't split cc_object srcs across languages. Doing so would add complexity,
|
||||||
// and this isn't typically done for cc_object.
|
// and this isn't typically done for cc_object.
|
||||||
@@ -192,6 +197,7 @@ func objectBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
attrs := &bazelObjectAttributes{
|
attrs := &bazelObjectAttributes{
|
||||||
Srcs: srcs,
|
Srcs: srcs,
|
||||||
Srcs_as: compilerAttrs.asSrcs,
|
Srcs_as: compilerAttrs.asSrcs,
|
||||||
|
Objs: objs,
|
||||||
Deps: deps,
|
Deps: deps,
|
||||||
System_dynamic_deps: systemDynamicDeps,
|
System_dynamic_deps: systemDynamicDeps,
|
||||||
Copts: compilerAttrs.copts,
|
Copts: compilerAttrs.copts,
|
||||||
|
Reference in New Issue
Block a user