Merge "bp2build: make libdl build." am: a4a930feef am: b5267deaf2

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1688296

Change-Id: I209491d4f37abd468deba76eb958b7b055da9120
This commit is contained in:
Jingwen Chen 2021-04-29 11:07:54 +00:00 committed by Automerger Merge Worker
commit 5ada02a02f
4 changed files with 105 additions and 13 deletions

View File

@ -205,7 +205,6 @@ var (
// Linker error // Linker error
"libc_malloc_hooks", // jingwen@, cc_library, undefined symbol: __malloc_hook, etc. "libc_malloc_hooks", // jingwen@, cc_library, undefined symbol: __malloc_hook, etc.
"libdl", // jingwen@, cc_library, clang failed
"libstdc++", // jingwen@, cc_library, undefined symbol: free "libstdc++", // jingwen@, cc_library, undefined symbol: free
// Includes not found // Includes not found

View File

@ -50,6 +50,7 @@ func TestCcLibraryBp2Build(t *testing.T) {
expectedBazelTargets []string expectedBazelTargets []string
filesystem map[string]string filesystem map[string]string
dir string dir string
depsMutators []android.RegisterMutatorFunc
}{ }{
{ {
description: "cc_library - simple example", description: "cc_library - simple example",
@ -246,6 +247,34 @@ cc_library {
"//conditions:default": [], "//conditions:default": [],
}), }),
srcs = ["math/cosf.c"], srcs = ["math/cosf.c"],
)`},
},
{
description: "cc_library shared/static props",
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
dir: "foo/bar",
filesystem: map[string]string{
"foo/bar/a.cpp": "",
"foo/bar/Android.bp": `
cc_library {
name: "a",
shared: { whole_static_libs: ["b"] },
static: { srcs: ["a.cpp"] },
bazel_module: { bp2build_available: true },
}
cc_library_static { name: "b" }
`,
},
bp: soongCcLibraryPreamble,
expectedBazelTargets: []string{`cc_library(
name = "a",
copts = ["-Ifoo/bar"],
srcs = ["a.cpp"],
static_deps_for_shared = [":b"],
)`}, )`},
}, },
} }
@ -266,11 +295,15 @@ cc_library {
ctx := android.NewTestContext(config) ctx := android.NewTestContext(config)
cc.RegisterCCBuildComponents(ctx) cc.RegisterCCBuildComponents(ctx)
ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory)
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator) ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterBp2BuildConfig(bp2buildConfig) // TODO(jingwen): make this the default for all tests ctx.RegisterBp2BuildConfig(bp2buildConfig) // TODO(jingwen): make this the default for all tests
for _, m := range testCase.depsMutators {
ctx.DepsBp2BuildMutators(m)
}
ctx.RegisterForBazelConversion() ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse) _, errs := ctx.ParseFileList(dir, toParse)

View File

@ -68,9 +68,61 @@ func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
} }
} }
// Deps in the static: { .. } and shared: { .. } props of a cc_library.
if lib, ok := module.compiler.(*libraryDecorator); ok {
allDeps = append(allDeps, lib.SharedProperties.Shared.Static_libs...)
allDeps = append(allDeps, lib.SharedProperties.Shared.Whole_static_libs...)
allDeps = append(allDeps, lib.SharedProperties.Shared.Shared_libs...)
allDeps = append(allDeps, lib.SharedProperties.Shared.System_shared_libs...)
allDeps = append(allDeps, lib.StaticProperties.Static.Static_libs...)
allDeps = append(allDeps, lib.StaticProperties.Static.Whole_static_libs...)
allDeps = append(allDeps, lib.StaticProperties.Static.Shared_libs...)
allDeps = append(allDeps, lib.StaticProperties.Static.System_shared_libs...)
}
ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...) ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)
} }
type sharedAttributes struct {
staticDeps bazel.LabelListAttribute
}
// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) sharedAttributes {
lib, ok := module.compiler.(*libraryDecorator)
if !ok {
return sharedAttributes{}
}
var staticDeps bazel.LabelListAttribute
staticDeps.Value = android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)
return sharedAttributes{
staticDeps: staticDeps,
}
}
type staticAttributes struct {
srcs bazel.LabelListAttribute
}
// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticAttributes {
lib, ok := module.compiler.(*libraryDecorator)
if !ok {
return staticAttributes{}
}
var srcs bazel.LabelListAttribute
srcs.Value = android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)
return staticAttributes{
srcs: srcs,
}
}
// Convenience struct to hold all attributes parsed from compiler properties. // Convenience struct to hold all attributes parsed from compiler properties.
type compilerAttributes struct { type compilerAttributes struct {
copts bazel.StringListAttribute copts bazel.StringListAttribute

View File

@ -217,13 +217,14 @@ func RegisterLibraryBuildComponents(ctx android.RegistrationContext) {
// For bp2build conversion. // For bp2build conversion.
type bazelCcLibraryAttributes struct { type bazelCcLibraryAttributes struct {
Srcs bazel.LabelListAttribute Srcs bazel.LabelListAttribute
Hdrs bazel.LabelListAttribute Hdrs bazel.LabelListAttribute
Copts bazel.StringListAttribute Copts bazel.StringListAttribute
Linkopts bazel.StringListAttribute Linkopts bazel.StringListAttribute
Deps bazel.LabelListAttribute Deps bazel.LabelListAttribute
User_link_flags bazel.StringListAttribute User_link_flags bazel.StringListAttribute
Includes bazel.StringListAttribute Includes bazel.StringListAttribute
Static_deps_for_shared bazel.LabelListAttribute
} }
type bazelCcLibrary struct { type bazelCcLibrary struct {
@ -254,16 +255,23 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
return return
} }
sharedAttrs := bp2BuildParseSharedProps(ctx, m)
staticAttrs := bp2BuildParseStaticProps(ctx, m)
compilerAttrs := bp2BuildParseCompilerProps(ctx, m) compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
linkerAttrs := bp2BuildParseLinkerProps(ctx, m) linkerAttrs := bp2BuildParseLinkerProps(ctx, m)
exportedIncludes := bp2BuildParseExportedIncludes(ctx, m) exportedIncludes := bp2BuildParseExportedIncludes(ctx, m)
var srcs bazel.LabelListAttribute
srcs.Append(compilerAttrs.srcs)
srcs.Append(staticAttrs.srcs)
attrs := &bazelCcLibraryAttributes{ attrs := &bazelCcLibraryAttributes{
Srcs: compilerAttrs.srcs, Srcs: srcs,
Copts: compilerAttrs.copts, Copts: compilerAttrs.copts,
Linkopts: linkerAttrs.linkopts, Linkopts: linkerAttrs.linkopts,
Deps: linkerAttrs.deps, Deps: linkerAttrs.deps,
Includes: exportedIncludes, Static_deps_for_shared: sharedAttrs.staticDeps,
Includes: exportedIncludes,
} }
props := bazel.BazelTargetModuleProperties{ props := bazel.BazelTargetModuleProperties{