Merge changes Idd50ed38,Icbc86b21,I62d016d9 into rvc-dev

* changes:
  Add cc_prebuilt_library_headers
  Separate cc_library_headers to its own file and add tests
  Allow compile_multilib to be specified on module exports
This commit is contained in:
TreeHugger Robot
2020-04-23 15:18:31 +00:00
committed by Android (Google) Code Review
9 changed files with 280 additions and 36 deletions

View File

@@ -207,6 +207,7 @@ bootstrap_go_package {
"cc/binary_sdk_member.go",
"cc/fuzz.go",
"cc/library.go",
"cc/library_headers.go",
"cc/library_sdk_member.go",
"cc/object.go",
"cc/test.go",
@@ -232,6 +233,7 @@ bootstrap_go_package {
"cc/compiler_test.go",
"cc/gen_test.go",
"cc/genrule_test.go",
"cc/library_headers_test.go",
"cc/library_test.go",
"cc/object_test.go",
"cc/prebuilt_test.go",

View File

@@ -16,6 +16,7 @@ package cc
import (
"path/filepath"
"strings"
"android/soong/android"
"github.com/google/blueprint"
@@ -98,7 +99,23 @@ func (mt *binarySdkMemberType) organizeVariants(member android.SdkMember) *nativ
func buildSharedNativeBinarySnapshot(info *nativeBinaryInfo, builder android.SnapshotBuilder, member android.SdkMember) {
pbm := builder.AddPrebuiltModule(member, "cc_prebuilt_binary")
pbm.AddProperty("compile_multilib", "both")
archVariantCount := len(info.archVariantProperties)
// Choose setting for compile_multilib that is appropriate for the arch variants supplied.
var multilib string
if archVariantCount == 2 {
multilib = "both"
} else if archVariantCount == 1 {
if strings.HasSuffix(info.archVariantProperties[0].archType, "64") {
multilib = "64"
} else {
multilib = "32"
}
}
if multilib != "" {
pbm.AddProperty("compile_multilib", multilib)
}
archProperties := pbm.AddPropertySet("arch")
for _, av := range info.archVariantProperties {
archTypeProperties := archProperties.AddPropertySet(av.archType)

View File

@@ -183,7 +183,6 @@ func RegisterLibraryBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("cc_library", LibraryFactory)
ctx.RegisterModuleType("cc_library_host_static", LibraryHostStaticFactory)
ctx.RegisterModuleType("cc_library_host_shared", LibraryHostSharedFactory)
ctx.RegisterModuleType("cc_library_headers", LibraryHeaderFactory)
}
// cc_library creates both static and/or shared libraries for a device and/or
@@ -233,16 +232,6 @@ func LibraryHostSharedFactory() android.Module {
return module.Init()
}
// cc_library_headers contains a set of c/c++ headers which are imported by
// other soong cc modules using the header_libs property. For best practices,
// use export_include_dirs property or LOCAL_EXPORT_C_INCLUDE_DIRS for
// Make.
func LibraryHeaderFactory() android.Module {
module, library := NewLibrary(android.HostAndDeviceSupported)
library.HeaderOnly()
return module.Init()
}
type flagExporter struct {
Properties FlagExporterProperties
@@ -1394,22 +1383,28 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
if cc_prebuilt {
library := mctx.Module().(*Module).linker.(prebuiltLibraryInterface)
// Always create both the static and shared variants for prebuilt libraries, and then disable the one
// that is not being used. This allows them to share the name of a cc_library module, which requires that
// all the variants of the cc_library also exist on the prebuilt.
modules := mctx.CreateLocalVariations("static", "shared")
static := modules[0].(*Module)
shared := modules[1].(*Module)
// Differentiate between header only and building an actual static/shared library
if library.buildStatic() || library.buildShared() {
// Always create both the static and shared variants for prebuilt libraries, and then disable the one
// that is not being used. This allows them to share the name of a cc_library module, which requires that
// all the variants of the cc_library also exist on the prebuilt.
modules := mctx.CreateLocalVariations("static", "shared")
static := modules[0].(*Module)
shared := modules[1].(*Module)
static.linker.(prebuiltLibraryInterface).setStatic()
shared.linker.(prebuiltLibraryInterface).setShared()
static.linker.(prebuiltLibraryInterface).setStatic()
shared.linker.(prebuiltLibraryInterface).setShared()
if !library.buildStatic() {
static.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
if !library.buildShared() {
shared.linker.(prebuiltLibraryInterface).disablePrebuilt()
if !library.buildStatic() {
static.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
if !library.buildShared() {
shared.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
} else {
// Header only
}
} else if library, ok := mctx.Module().(LinkableInterface); ok && library.CcLibraryInterface() {
// Non-cc.Modules may need an empty variant for their mutators.

43
cc/library_headers.go Normal file
View File

@@ -0,0 +1,43 @@
// Copyright 2020 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cc
import "android/soong/android"
func init() {
RegisterLibraryHeadersBuildComponents(android.InitRegistrationContext)
}
func RegisterLibraryHeadersBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("cc_library_headers", LibraryHeaderFactory)
ctx.RegisterModuleType("cc_prebuilt_library_headers", prebuiltLibraryHeaderFactory)
}
// cc_library_headers contains a set of c/c++ headers which are imported by
// other soong cc modules using the header_libs property. For best practices,
// use export_include_dirs property or LOCAL_EXPORT_C_INCLUDE_DIRS for
// Make.
func LibraryHeaderFactory() android.Module {
module, library := NewLibrary(android.HostAndDeviceSupported)
library.HeaderOnly()
return module.Init()
}
// cc_prebuilt_library_headers is a prebuilt version of cc_library_headers
func prebuiltLibraryHeaderFactory() android.Module {
module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported)
library.HeaderOnly()
return module.Init()
}

View File

@@ -0,0 +1,62 @@
// Copyright 2020 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cc
import (
"strings"
"testing"
)
func TestLibraryHeaders(t *testing.T) {
ctx := testCc(t, `
cc_library_headers {
name: "headers",
export_include_dirs: ["my_include"],
}
cc_library_static {
name: "lib",
srcs: ["foo.c"],
header_libs: ["headers"],
}
`)
// test if header search paths are correctly added
cc := ctx.ModuleForTests("lib", "android_arm64_armv8-a_static").Rule("cc")
cflags := cc.Args["cFlags"]
if !strings.Contains(cflags, " -Imy_include ") {
t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
}
}
func TestPrebuiltLibraryHeaders(t *testing.T) {
ctx := testCc(t, `
cc_prebuilt_library_headers {
name: "headers",
export_include_dirs: ["my_include"],
}
cc_library_static {
name: "lib",
srcs: ["foo.c"],
header_libs: ["headers"],
}
`)
// test if header search paths are correctly added
cc := ctx.ModuleForTests("lib", "android_arm64_armv8-a_static").Rule("cc")
cflags := cc.Args["cFlags"]
if !strings.Contains(cflags, " -Imy_include ") {
t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
}
}

View File

@@ -87,15 +87,16 @@ func (p *prebuiltLibraryLinker) linkerProps() []interface{} {
func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path {
p.libraryDecorator.exportIncludes(ctx)
p.libraryDecorator.reexportDirs(deps.ReexportedDirs...)
p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...)
p.libraryDecorator.reexportFlags(deps.ReexportedFlags...)
p.libraryDecorator.reexportDeps(deps.ReexportedDeps...)
p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
// TODO(ccross): verify shared library dependencies
if len(p.properties.Srcs) > 0 {
p.libraryDecorator.exportIncludes(ctx)
p.libraryDecorator.reexportDirs(deps.ReexportedDirs...)
p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...)
p.libraryDecorator.reexportFlags(deps.ReexportedFlags...)
p.libraryDecorator.reexportDeps(deps.ReexportedDeps...)
p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...)
builderFlags := flagsToBuilderFlags(flags)
in := p.Prebuilt.SingleSourcePath(ctx)

View File

@@ -25,6 +25,7 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
RegisterCCBuildComponents(ctx)
RegisterBinaryBuildComponents(ctx)
RegisterLibraryBuildComponents(ctx)
RegisterLibraryHeadersBuildComponents(ctx)
ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)

View File

@@ -749,3 +749,94 @@ include/Test.h -> include/include/Test.h
`),
)
}
func TestHostSnapshotWithMultiLib64(t *testing.T) {
// b/145598135 - Generating host snapshots for anything other than linux is not supported.
SkipIfNotLinux(t)
result := testSdkWithCc(t, `
module_exports {
name: "myexports",
device_supported: false,
host_supported: true,
target: {
host: {
compile_multilib: "64",
},
},
native_static_libs: ["mynativelib"],
}
cc_library_static {
name: "mynativelib",
device_supported: false,
host_supported: true,
srcs: [
"Test.cpp",
"aidl/foo/bar/Test.aidl",
],
export_include_dirs: ["include"],
aidl: {
export_aidl_headers: true,
},
system_shared_libs: [],
stl: "none",
}
`)
result.CheckSnapshot("myexports", "linux_glibc_common", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
cc_prebuilt_library_static {
name: "myexports_mynativelib@current",
sdk_member_name: "mynativelib",
device_supported: false,
host_supported: true,
export_include_dirs: ["include/include"],
arch: {
x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
},
stl: "none",
system_shared_libs: [],
}
cc_prebuilt_library_static {
name: "mynativelib",
prefer: false,
device_supported: false,
host_supported: true,
export_include_dirs: ["include/include"],
arch: {
x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
},
stl: "none",
system_shared_libs: [],
}
module_exports_snapshot {
name: "myexports@current",
device_supported: false,
host_supported: true,
target: {
host: {
compile_multilib: "64",
},
},
native_static_libs: ["myexports_mynativelib@current"],
}`),
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
`),
)
}

View File

@@ -107,10 +107,15 @@ func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderC
// The members are first grouped by type and then grouped by name. The order of
// the types is the order they are referenced in android.SdkMemberTypesRegistry.
// The names are in the order in which the dependencies were added.
func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember {
//
// Returns the members as well as the multilib setting to use.
func (s *sdk) collectMembers(ctx android.ModuleContext) ([]*sdkMember, string) {
byType := make(map[android.SdkMemberType][]*sdkMember)
byName := make(map[string]*sdkMember)
lib32 := false // True if any of the members have 32 bit version.
lib64 := false // True if any of the members have 64 bit version.
ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
tag := ctx.OtherModuleDependencyTag(child)
if memberTag, ok := tag.(android.SdkMemberTypeDependencyTag); ok {
@@ -122,7 +127,6 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember {
}
name := ctx.OtherModuleName(child)
member := byName[name]
if member == nil {
member = &sdkMember{memberType: memberType, name: name}
@@ -130,6 +134,13 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember {
byType[memberType] = append(byType[memberType], member)
}
multilib := child.Target().Arch.ArchType.Multilib
if multilib == "lib32" {
lib32 = true
} else if multilib == "lib64" {
lib64 = true
}
// Only append new variants to the list. This is needed because a member can be both
// exported by the sdk and also be a transitive sdk member.
member.variants = appendUniqueVariants(member.variants, child.(android.SdkAware))
@@ -148,7 +159,17 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember {
members = append(members, membersOfType...)
}
return members
// Compute the setting of multilib.
var multilib string
if lib32 && lib64 {
multilib = "both"
} else if lib32 {
multilib = "32"
} else if lib64 {
multilib = "64"
}
return members, multilib
}
func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware {
@@ -207,7 +228,8 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
}
s.builderForTests = builder
for _, member := range s.collectMembers(ctx) {
members, multilib := s.collectMembers(ctx)
for _, member := range members {
member.memberType.BuildSnapshot(ctx, builder, member)
}
@@ -249,6 +271,16 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
}
addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule)
// Compile_multilib defaults to both and must always be set to both on the
// device and so only needs to be set when targeted at the host and is neither
// unspecified or both.
if s.HostSupported() && multilib != "" && multilib != "both" {
targetSet := snapshotModule.AddPropertySet("target")
hostSet := targetSet.AddPropertySet("host")
hostSet.AddProperty("compile_multilib", multilib)
}
for _, memberListProperty := range s.memberListProperties() {
names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
if len(names) > 0 {