Support shared_libs, static_libs and default_shared_libs in cc_object
cc_object files don't link against static or shared libraries, but they can use headers from them. Make cc_object use the default_shared_libs headers, and add support for explicit static and shared library dependencies. Bug: 153662223 Test: go test ./cc/... Change-Id: I9ab160ede06db1b135d217d72770c22f500cfe1b
This commit is contained in:
@@ -46,6 +46,7 @@ func TestCcObjectSimple(t *testing.T) {
|
|||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
local_include_dirs: ["include"],
|
local_include_dirs: ["include"],
|
||||||
|
default_shared_libs: [],
|
||||||
cflags: [
|
cflags: [
|
||||||
"-Wno-gcc-compat",
|
"-Wno-gcc-compat",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
@@ -83,6 +84,7 @@ func TestCcObjectDefaults(t *testing.T) {
|
|||||||
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
default_shared_libs: [],
|
||||||
local_include_dirs: ["include"],
|
local_include_dirs: ["include"],
|
||||||
srcs: [
|
srcs: [
|
||||||
"a/b/*.h",
|
"a/b/*.h",
|
||||||
@@ -135,12 +137,14 @@ func TestCcObjectCcObjetDepsInObjs(t *testing.T) {
|
|||||||
},
|
},
|
||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
default_shared_libs: [],
|
||||||
srcs: ["a/b/c.c"],
|
srcs: ["a/b/c.c"],
|
||||||
objs: ["bar"],
|
objs: ["bar"],
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_object {
|
cc_object {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
|
default_shared_libs: [],
|
||||||
srcs: ["x/y/z.c"],
|
srcs: ["x/y/z.c"],
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
@@ -178,6 +182,7 @@ func TestCcObjectIncludeBuildDirFalse(t *testing.T) {
|
|||||||
},
|
},
|
||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
default_shared_libs: [],
|
||||||
srcs: ["a/b/c.c"],
|
srcs: ["a/b/c.c"],
|
||||||
include_build_directory: false,
|
include_build_directory: false,
|
||||||
}
|
}
|
||||||
@@ -199,6 +204,7 @@ func TestCcObjectProductVariable(t *testing.T) {
|
|||||||
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
default_shared_libs: [],
|
||||||
include_build_directory: false,
|
include_build_directory: false,
|
||||||
product_variables: {
|
product_variables: {
|
||||||
platform_sdk_version: {
|
platform_sdk_version: {
|
||||||
@@ -227,6 +233,7 @@ func TestCcObjectCflagsOneArch(t *testing.T) {
|
|||||||
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
default_shared_libs: [],
|
||||||
srcs: ["a.cpp"],
|
srcs: ["a.cpp"],
|
||||||
arch: {
|
arch: {
|
||||||
x86: {
|
x86: {
|
||||||
@@ -266,6 +273,7 @@ func TestCcObjectCflagsFourArch(t *testing.T) {
|
|||||||
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
default_shared_libs: [],
|
||||||
srcs: ["base.cpp"],
|
srcs: ["base.cpp"],
|
||||||
arch: {
|
arch: {
|
||||||
x86: {
|
x86: {
|
||||||
@@ -321,6 +329,7 @@ func TestCcObjectCflagsMultiOs(t *testing.T) {
|
|||||||
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
|
||||||
blueprint: `cc_object {
|
blueprint: `cc_object {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
|
default_shared_libs: [],
|
||||||
srcs: ["base.cpp"],
|
srcs: ["base.cpp"],
|
||||||
target: {
|
target: {
|
||||||
android: {
|
android: {
|
||||||
|
35
cc/object.go
35
cc/object.go
@@ -67,9 +67,19 @@ func (handler *objectBazelHandler) generateBazelBuildActions(ctx android.ModuleC
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ObjectLinkerProperties struct {
|
type ObjectLinkerProperties struct {
|
||||||
|
// list of static library modules that should only provide headers for this module.
|
||||||
|
Static_libs []string `android:"arch_variant,variant_prepend"`
|
||||||
|
|
||||||
|
// list of shared library modules should only provide headers for this module.
|
||||||
|
Shared_libs []string `android:"arch_variant"`
|
||||||
|
|
||||||
// list of modules that should only provide headers for this module.
|
// list of modules that should only provide headers for this module.
|
||||||
Header_libs []string `android:"arch_variant,variant_prepend"`
|
Header_libs []string `android:"arch_variant,variant_prepend"`
|
||||||
|
|
||||||
|
// list of default libraries that will provide headers for this module. If unset, generally
|
||||||
|
// defaults to libc, libm, and libdl. Set to [] to prevent using headers from the defaults.
|
||||||
|
Default_shared_libs []string `android:"arch_variant"`
|
||||||
|
|
||||||
// names of other cc_object modules to link into this module using partial linking
|
// names of other cc_object modules to link into this module using partial linking
|
||||||
Objs []string `android:"arch_variant"`
|
Objs []string `android:"arch_variant"`
|
||||||
|
|
||||||
@@ -198,7 +208,18 @@ func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
|
|||||||
|
|
||||||
func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
deps.HeaderLibs = append(deps.HeaderLibs, object.Properties.Header_libs...)
|
deps.HeaderLibs = append(deps.HeaderLibs, object.Properties.Header_libs...)
|
||||||
|
deps.SharedLibs = append(deps.SharedLibs, object.Properties.Shared_libs...)
|
||||||
|
deps.StaticLibs = append(deps.StaticLibs, object.Properties.Static_libs...)
|
||||||
deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
|
deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
|
||||||
|
|
||||||
|
deps.SystemSharedLibs = object.Properties.Default_shared_libs
|
||||||
|
if deps.SystemSharedLibs == nil {
|
||||||
|
// Provide a default set of shared libraries if default_shared_libs is unspecified.
|
||||||
|
// Note: If an empty list [] is specified, it implies that the module declines the
|
||||||
|
// default shared libraries.
|
||||||
|
deps.SystemSharedLibs = append(deps.SystemSharedLibs, ctx.toolchain().DefaultSharedLibraries()...)
|
||||||
|
}
|
||||||
|
deps.LateSharedLibs = append(deps.LateSharedLibs, deps.SystemSharedLibs...)
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,6 +268,20 @@ func (object *objectLinker) link(ctx ModuleContext,
|
|||||||
return outputFile
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (object *objectLinker) linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps {
|
||||||
|
specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, object.Properties.Shared_libs...)
|
||||||
|
|
||||||
|
// Must distinguish nil and [] in default_shared_libs - ensure that [] in
|
||||||
|
// either input list doesn't come out as nil.
|
||||||
|
if specifiedDeps.defaultSharedLibs == nil {
|
||||||
|
specifiedDeps.defaultSharedLibs = object.Properties.Default_shared_libs
|
||||||
|
} else {
|
||||||
|
specifiedDeps.defaultSharedLibs = append(specifiedDeps.defaultSharedLibs, object.Properties.Default_shared_libs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return specifiedDeps
|
||||||
|
}
|
||||||
|
|
||||||
func (object *objectLinker) unstrippedOutputFilePath() android.Path {
|
func (object *objectLinker) unstrippedOutputFilePath() android.Path {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -367,6 +367,7 @@ func commonDefaultModules() string {
|
|||||||
stl: "none",
|
stl: "none",
|
||||||
min_sdk_version: "16",
|
min_sdk_version: "16",
|
||||||
crt: true,
|
crt: true,
|
||||||
|
default_shared_libs: [],
|
||||||
apex_available: [
|
apex_available: [
|
||||||
"//apex_available:platform",
|
"//apex_available:platform",
|
||||||
"//apex_available:anyapex",
|
"//apex_available:anyapex",
|
||||||
|
@@ -347,6 +347,7 @@ func TestSnapshotWithObject(t *testing.T) {
|
|||||||
cc_object {
|
cc_object {
|
||||||
name: "crtobj",
|
name: "crtobj",
|
||||||
stl: "none",
|
stl: "none",
|
||||||
|
default_shared_libs: [],
|
||||||
sanitize: {
|
sanitize: {
|
||||||
never: true,
|
never: true,
|
||||||
},
|
},
|
||||||
@@ -364,6 +365,7 @@ cc_prebuilt_object {
|
|||||||
apex_available: ["//apex_available:platform"],
|
apex_available: ["//apex_available:platform"],
|
||||||
stl: "none",
|
stl: "none",
|
||||||
compile_multilib: "both",
|
compile_multilib: "both",
|
||||||
|
default_shared_libs: [],
|
||||||
sanitize: {
|
sanitize: {
|
||||||
never: true,
|
never: true,
|
||||||
},
|
},
|
||||||
@@ -388,6 +390,7 @@ cc_prebuilt_object {
|
|||||||
apex_available: ["//apex_available:platform"],
|
apex_available: ["//apex_available:platform"],
|
||||||
stl: "none",
|
stl: "none",
|
||||||
compile_multilib: "both",
|
compile_multilib: "both",
|
||||||
|
default_shared_libs: [],
|
||||||
sanitize: {
|
sanitize: {
|
||||||
never: true,
|
never: true,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user