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,19 +220,16 @@ var (
// Per-module denylist to opt modules out of mixed builds. Such modules will // Per-module denylist to opt modules out of mixed builds. Such modules will
// still be generated via bp2build. // still be generated via bp2build.
mixedBuildsDisabledList = []string{ 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", // 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_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_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_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 "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) "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 "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) "libc_nomalloc", // cc_library_static, OK for bp2build but ld.lld: error: undefined symbol: pthread_mutex_lock (and others)
} }
// Used for quicker lookups // Used for quicker lookups
bp2buildModuleDoNotConvert = map[string]bool{} bp2buildModuleDoNotConvert = map[string]bool{}

View File

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

View File

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

View File

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

View File

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

View File

@@ -221,17 +221,19 @@ func RegisterLibraryBuildComponents(ctx android.RegistrationContext) {
// For bp2build conversion. // For bp2build conversion.
type bazelCcLibraryAttributes struct { type bazelCcLibraryAttributes struct {
// Attributes pertaining to both static and shared variants. // Attributes pertaining to both static and shared variants.
Srcs bazel.LabelListAttribute Srcs bazel.LabelListAttribute
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
Dynamic_deps bazel.LabelListAttribute Implementation_deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute Dynamic_deps bazel.LabelListAttribute
Copts bazel.StringListAttribute Whole_archive_deps bazel.LabelListAttribute
Includes bazel.StringListAttribute Copts bazel.StringListAttribute
Linkopts bazel.StringListAttribute Includes bazel.StringListAttribute
Linkopts bazel.StringListAttribute
// Attributes pertaining to shared variant. // Attributes pertaining to shared variant.
Shared_copts bazel.StringListAttribute Shared_copts bazel.StringListAttribute
Shared_srcs bazel.LabelListAttribute Shared_srcs bazel.LabelListAttribute
Exported_deps_for_shared bazel.LabelListAttribute
Static_deps_for_shared bazel.LabelListAttribute Static_deps_for_shared bazel.LabelListAttribute
Dynamic_deps_for_shared bazel.LabelListAttribute Dynamic_deps_for_shared bazel.LabelListAttribute
Whole_archive_deps_for_shared bazel.LabelListAttribute Whole_archive_deps_for_shared bazel.LabelListAttribute
@@ -240,6 +242,7 @@ type bazelCcLibraryAttributes struct {
// Attributes pertaining to static variant. // Attributes pertaining to static variant.
Static_copts bazel.StringListAttribute Static_copts bazel.StringListAttribute
Static_srcs bazel.LabelListAttribute Static_srcs bazel.LabelListAttribute
Exported_deps_for_static bazel.LabelListAttribute
Static_deps_for_static bazel.LabelListAttribute Static_deps_for_static bazel.LabelListAttribute
Dynamic_deps_for_static bazel.LabelListAttribute Dynamic_deps_for_static bazel.LabelListAttribute
Whole_archive_deps_for_static bazel.LabelListAttribute Whole_archive_deps_for_static bazel.LabelListAttribute
@@ -292,7 +295,8 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
attrs := &bazelCcLibraryAttributes{ attrs := &bazelCcLibraryAttributes{
Srcs: srcs, Srcs: srcs,
Deps: linkerAttrs.deps, Implementation_deps: linkerAttrs.deps,
Deps: linkerAttrs.exportedDeps,
Dynamic_deps: linkerAttrs.dynamicDeps, Dynamic_deps: linkerAttrs.dynamicDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps, Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Copts: compilerAttrs.copts, Copts: compilerAttrs.copts,
@@ -2217,14 +2221,15 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu
} }
type bazelCcLibraryStaticAttributes struct { type bazelCcLibraryStaticAttributes struct {
Copts bazel.StringListAttribute Copts bazel.StringListAttribute
Srcs bazel.LabelListAttribute Srcs bazel.LabelListAttribute
Deps bazel.LabelListAttribute Implementation_deps bazel.LabelListAttribute
Whole_archive_deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
Linkopts bazel.StringListAttribute Whole_archive_deps bazel.LabelListAttribute
Linkstatic bool Linkopts bazel.StringListAttribute
Includes bazel.StringListAttribute Linkstatic bool
Hdrs bazel.LabelListAttribute Includes bazel.StringListAttribute
Hdrs bazel.LabelListAttribute
} }
type bazelCcLibraryStatic struct { type bazelCcLibraryStatic struct {
@@ -2245,10 +2250,11 @@ func ccLibraryStaticBp2BuildInternal(ctx android.TopDownMutatorContext, module *
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module) exportedIncludes := bp2BuildParseExportedIncludes(ctx, module)
attrs := &bazelCcLibraryStaticAttributes{ attrs := &bazelCcLibraryStaticAttributes{
Copts: compilerAttrs.copts, Copts: compilerAttrs.copts,
Srcs: compilerAttrs.srcs, Srcs: compilerAttrs.srcs,
Deps: linkerAttrs.deps, Implementation_deps: linkerAttrs.deps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps, Deps: linkerAttrs.exportedDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Linkopts: linkerAttrs.linkopts, Linkopts: linkerAttrs.linkopts,
Linkstatic: true, Linkstatic: true,

View File

@@ -109,10 +109,11 @@ func prebuiltLibraryHeaderFactory() android.Module {
} }
type bazelCcLibraryHeadersAttributes struct { type bazelCcLibraryHeadersAttributes struct {
Copts bazel.StringListAttribute Copts bazel.StringListAttribute
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Includes bazel.StringListAttribute Includes bazel.StringListAttribute
Deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
Implementation_deps bazel.LabelListAttribute
} }
type bazelCcLibraryHeaders struct { type bazelCcLibraryHeaders struct {
@@ -147,9 +148,10 @@ func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) {
linkerAttrs := bp2BuildParseLinkerProps(ctx, module) linkerAttrs := bp2BuildParseLinkerProps(ctx, module)
attrs := &bazelCcLibraryHeadersAttributes{ attrs := &bazelCcLibraryHeadersAttributes{
Copts: compilerAttrs.copts, Copts: compilerAttrs.copts,
Includes: exportedIncludes, Includes: exportedIncludes,
Deps: linkerAttrs.deps, Implementation_deps: linkerAttrs.deps,
Deps: linkerAttrs.exportedDeps,
} }
props := bazel.BazelTargetModuleProperties{ props := bazel.BazelTargetModuleProperties{