Propagate unexported deps via implementation_deps

Test: bp2build and mixed_libc CI
Test: Manually verified that libc_bionic_ndk compilation gets the
appropriate headers (and no extra headers) from downstream

Change-Id: I79eb6e8ec1d415bd50d12105da4cf97101f95474
This commit is contained in:
Chris Parsons
2021-05-18 18:35:24 -04:00
parent 50d601731b
commit d6358775c8
7 changed files with 65 additions and 53 deletions

View File

@@ -220,15 +220,12 @@ var (
// Per-module denylist to opt modules out of mixed builds. Such modules will
// still be generated via bp2build.
mixedBuildsDisabledList = []string{
"libc_bionic_ndk", // cparsons@ cc_library_static, depends on //bionic/libc:libsystemproperties
"libc_common", // cparsons@ cc_library_static, depends on //bionic/libc:libc_nopthread
"libc_common_static", // cparsons@ cc_library_static, depends on //bionic/libc:libc_common
"libc_common_shared", // cparsons@ cc_library_static, depends on //bionic/libc:libc_common
"libc_netbsd", // lberki@, cc_library_static, version script assignment of 'LIBC_PRIVATE' to symbol 'SHA1Final' failed: symbol not defined
"libc_nopthread", // cparsons@ cc_library_static, depends on //bionic/libc:libc_bionic_ndk
"libc_nopthread", // cparsons@ cc_library_static, version script assignment of 'LIBC' to symbol 'memcmp' failed: symbol not defined
"libc_openbsd", // ruperts@, cc_library_static, OK for bp2build but error: duplicate symbol: strcpy for mixed builds
"libsystemproperties", // cparsons@, cc_library_static, wrong include paths
"libpropertyinfoparser", // cparsons@, cc_library_static, wrong include paths
"libarm-optimized-routines-string", // jingwen@, cc_library_static, OK for bp2build but b/186615213 (asflags not handled in bp2build), version script assignment of 'LIBC' to symbol 'memcmp' failed: symbol not defined (also for memrchr, strnlen)
"fmtlib_ndk", // http://b/187040371, cc_library_static, OK for bp2build but format-inl.h:11:10: fatal error: 'cassert' file not found for mixed builds
"libc_nomalloc", // cc_library_static, OK for bp2build but ld.lld: error: undefined symbol: pthread_mutex_lock (and others)

View File

@@ -115,7 +115,7 @@ cc_library {
"-I.",
"-I$(BINDIR)/.",
],
deps = [":some-headers"],
implementation_deps = [":some-headers"],
includes = ["foo-dir"],
linkopts = ["-Wl,--exclude-libs=bar.a"] + select({
"//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"],
@@ -186,7 +186,7 @@ cc_library {
"-I.",
"-I$(BINDIR)/.",
],
deps = [":libc_headers"],
implementation_deps = [":libc_headers"],
linkopts = [
"-Wl,--exclude-libs=libgcc.a",
"-Wl,--exclude-libs=libgcc_stripped.a",
@@ -317,10 +317,10 @@ cc_library { name: "shared_dep_for_both" }
"-Ifoo/bar",
"-I$(BINDIR)/foo/bar",
],
deps = [":static_dep_for_both"],
dynamic_deps = [":shared_dep_for_both"],
dynamic_deps_for_shared = [":shared_dep_for_shared"],
dynamic_deps_for_static = [":shared_dep_for_static"],
implementation_deps = [":static_dep_for_both"],
shared_copts = ["sharedflag"],
shared_srcs = ["sharedonly.cpp"],
srcs = ["both.cpp"],

View File

@@ -135,7 +135,7 @@ cc_library_headers {
"-I.",
"-I$(BINDIR)/.",
],
deps = [
implementation_deps = [
":lib-1",
":lib-2",
],
@@ -216,7 +216,7 @@ cc_library_headers {
"-I.",
"-I$(BINDIR)/.",
],
deps = [":base-lib"] + select({
implementation_deps = [":base-lib"] + select({
"//build/bazel/platforms/os:android": [":android-lib"],
"//build/bazel/platforms/os:darwin": [":darwin-lib"],
"//build/bazel/platforms/os:fuchsia": [":fuchsia-lib"],
@@ -286,10 +286,11 @@ cc_library_headers {
"-I$(BINDIR)/.",
],
deps = select({
"//build/bazel/platforms/os:android": [
":android-lib",
":exported-lib",
],
"//build/bazel/platforms/os:android": [":exported-lib"],
"//conditions:default": [],
}),
implementation_deps = select({
"//build/bazel/platforms/os:android": [":android-lib"],
"//conditions:default": [],
}),
)`},

View File

@@ -83,7 +83,7 @@ func TestCcLibraryStaticBp2Build(t *testing.T) {
dir string
}{
{
description: "cc_library_static test",
description: "cc_library_static simple test",
moduleTypeUnderTest: "cc_library_static",
moduleTypeUnderTestFactory: cc.LibraryStaticFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
@@ -191,7 +191,7 @@ cc_library_static {
"-I.",
"-I$(BINDIR)/.",
],
deps = [
implementation_deps = [
":header_lib_1",
":header_lib_2",
":static_lib_1",
@@ -464,7 +464,7 @@ cc_library_static {
"-I.",
"-I$(BINDIR)/.",
],
deps = select({
implementation_deps = select({
"//build/bazel/platforms/arch:arm64": [":static_dep"],
"//conditions:default": [],
}),
@@ -509,7 +509,7 @@ cc_library_static {
"-I.",
"-I$(BINDIR)/.",
],
deps = select({
implementation_deps = select({
"//build/bazel/platforms/os:android": [":static_dep"],
"//conditions:default": [],
}),
@@ -559,7 +559,7 @@ cc_library_static {
"-I.",
"-I$(BINDIR)/.",
],
deps = [":static_dep"] + select({
implementation_deps = [":static_dep"] + select({
"//build/bazel/platforms/arch:arm64": [":static_dep4"],
"//conditions:default": [],
}) + select({
@@ -827,7 +827,7 @@ cc_library_static {
"-I.",
"-I$(BINDIR)/.",
],
deps = [":static_dep"],
implementation_deps = [":static_dep"],
linkstatic = True,
)`, `cc_library_static(
name = "static_dep",

View File

@@ -329,6 +329,7 @@ type linkerAttributes struct {
deps bazel.LabelListAttribute
dynamicDeps bazel.LabelListAttribute
wholeArchiveDeps bazel.LabelListAttribute
exportedDeps bazel.LabelListAttribute
linkopts bazel.StringListAttribute
versionScript bazel.LabelAttribute
}
@@ -346,6 +347,7 @@ func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string {
// configurable attribute values.
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
var deps bazel.LabelListAttribute
var exportedDeps bazel.LabelListAttribute
var dynamicDeps bazel.LabelListAttribute
var wholeArchiveDeps bazel.LabelListAttribute
var linkopts bazel.StringListAttribute
@@ -354,11 +356,12 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
for _, linkerProps := range module.linker.linkerProps() {
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
libs := baseLinkerProps.Header_libs
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
libs = append(libs, baseLinkerProps.Static_libs...)
exportedLibs := baseLinkerProps.Export_header_lib_headers
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
libs = android.SortedUniqueStrings(libs)
deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))
exportedDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, exportedLibs))
linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps)
wholeArchiveDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
@@ -376,11 +379,12 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
for arch, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
libs := baseLinkerProps.Header_libs
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
libs = append(libs, baseLinkerProps.Static_libs...)
exportedLibs := baseLinkerProps.Export_header_lib_headers
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
libs = android.SortedUniqueStrings(libs)
deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs))
exportedDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, exportedLibs))
linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps))
wholeArchiveDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
@@ -397,12 +401,13 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
for os, p := range module.GetTargetProperties(ctx, &BaseLinkerProperties{}) {
if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
libs := baseLinkerProps.Header_libs
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
libs = append(libs, baseLinkerProps.Static_libs...)
exportedLibs := baseLinkerProps.Export_header_lib_headers
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
libs = android.SortedUniqueStrings(libs)
wholeArchiveDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs))
exportedDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, exportedLibs))
linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps))
@@ -413,6 +418,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
return linkerAttributes{
deps: deps,
exportedDeps: exportedDeps,
dynamicDeps: dynamicDeps,
wholeArchiveDeps: wholeArchiveDeps,
linkopts: linkopts,

View File

@@ -224,6 +224,7 @@ type bazelCcLibraryAttributes struct {
Srcs bazel.LabelListAttribute
Hdrs bazel.LabelListAttribute
Deps bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute
Dynamic_deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute
Copts bazel.StringListAttribute
@@ -232,6 +233,7 @@ type bazelCcLibraryAttributes struct {
// Attributes pertaining to shared variant.
Shared_copts bazel.StringListAttribute
Shared_srcs bazel.LabelListAttribute
Exported_deps_for_shared bazel.LabelListAttribute
Static_deps_for_shared bazel.LabelListAttribute
Dynamic_deps_for_shared bazel.LabelListAttribute
Whole_archive_deps_for_shared bazel.LabelListAttribute
@@ -240,6 +242,7 @@ type bazelCcLibraryAttributes struct {
// Attributes pertaining to static variant.
Static_copts bazel.StringListAttribute
Static_srcs bazel.LabelListAttribute
Exported_deps_for_static bazel.LabelListAttribute
Static_deps_for_static bazel.LabelListAttribute
Dynamic_deps_for_static bazel.LabelListAttribute
Whole_archive_deps_for_static bazel.LabelListAttribute
@@ -292,7 +295,8 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
attrs := &bazelCcLibraryAttributes{
Srcs: srcs,
Deps: linkerAttrs.deps,
Implementation_deps: linkerAttrs.deps,
Deps: linkerAttrs.exportedDeps,
Dynamic_deps: linkerAttrs.dynamicDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Copts: compilerAttrs.copts,
@@ -2219,6 +2223,7 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu
type bazelCcLibraryStaticAttributes struct {
Copts bazel.StringListAttribute
Srcs bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute
Deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute
Linkopts bazel.StringListAttribute
@@ -2247,7 +2252,8 @@ func ccLibraryStaticBp2BuildInternal(ctx android.TopDownMutatorContext, module *
attrs := &bazelCcLibraryStaticAttributes{
Copts: compilerAttrs.copts,
Srcs: compilerAttrs.srcs,
Deps: linkerAttrs.deps,
Implementation_deps: linkerAttrs.deps,
Deps: linkerAttrs.exportedDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Linkopts: linkerAttrs.linkopts,

View File

@@ -113,6 +113,7 @@ type bazelCcLibraryHeadersAttributes struct {
Hdrs bazel.LabelListAttribute
Includes bazel.StringListAttribute
Deps bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute
}
type bazelCcLibraryHeaders struct {
@@ -149,7 +150,8 @@ func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) {
attrs := &bazelCcLibraryHeadersAttributes{
Copts: compilerAttrs.copts,
Includes: exportedIncludes,
Deps: linkerAttrs.deps,
Implementation_deps: linkerAttrs.deps,
Deps: linkerAttrs.exportedDeps,
}
props := bazel.BazelTargetModuleProperties{