Squash vendor sources before linkageMutator runs

linkageMutator removes srcs property of the shared variant of a lib in
order to reuse *.o files compiled for the static variant also to the
shared variant.

However, this causes problem when vendor-specific srcs are specified in
target: {vendor: {srcs: ["..."]}}. For example, let's assume

cc_library {
    name: "libfoo",
    srcs: ["foo.c"],
    target: {
        vendor: {
            srcs: ["bar.c"],
        },
    },
}

Then,
static_vendor: inputs = foo.o, bar.o
shared_vendor: inputs = foo.o (from static_vendor), bar.o (from
static_vendor), bar.o

So, bar.o is included twice and this causes multiple symbol definition
error.

In order to handle the problem, vendor mutator is applied before the
linkage mutator and the vendor-specific srcs are squashed in the vendor
mutator.

Bug: 67731122
Test: build
Test: cc_test.go

Change-Id: I2a5390295dddfc41260e9b6f02746908cdf47228
This commit is contained in:
Jiyong Park
2017-10-12 23:05:00 +09:00
parent 432a2d4033
commit 6a43f04777
4 changed files with 145 additions and 13 deletions

View File

@@ -34,9 +34,9 @@ func init() {
android.RegisterModuleType("cc_defaults", defaultsFactory)
android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("image", vendorMutator).Parallel()
ctx.BottomUp("link", linkageMutator).Parallel()
ctx.BottomUp("vndk", vndkMutator).Parallel()
ctx.BottomUp("image", vendorMutator).Parallel()
ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
ctx.BottomUp("begin", beginMutator).Parallel()
@@ -1297,6 +1297,16 @@ const (
vendorMode = "vendor"
)
func squashVendorSrcs(m *Module) {
if lib, ok := m.compiler.(*libraryDecorator); ok {
lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
lib.baseCompiler.Properties.Target.Vendor.Srcs...)
lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
}
}
func vendorMutator(mctx android.BottomUpMutatorContext) {
if mctx.Os() != android.Android {
return
@@ -1352,11 +1362,15 @@ func vendorMutator(mctx android.BottomUpMutatorContext) {
// This will be available in both /system and /vendor
// or a /system directory that is available to vendor.
mod := mctx.CreateVariations(coreMode, vendorMode)
mod[1].(*Module).Properties.UseVndk = true
vendor := mod[1].(*Module)
vendor.Properties.UseVndk = true
squashVendorSrcs(vendor)
} else if mctx.Vendor() && m.Properties.Sdk_version == "" {
// This will be available in /vendor only
mod := mctx.CreateVariations(vendorMode)
mod[0].(*Module).Properties.UseVndk = true
vendor := mod[0].(*Module)
vendor.Properties.UseVndk = true
squashVendorSrcs(vendor)
} else {
// This is either in /system (or similar: /data), or is a
// modules built with the NDK. Modules built with the NDK