Differentiate between cc library and binary
The cc library and cc binary (and other cc module types) are all instances of cc.Module. So, to differentiate between them and make sure that only appropriate library instances can be added to native_shared/static_libs this adds a special sdkMemberTypes field to Module which if set specifies the SdkMemberTypes the module supports. If it is not set then the module type cannot be used in the sdk at all. Corrects an issue with one of the tests where a prebuilt cc library was added to the sdk instead of a source cc library. Adds a new test to ensure that cc_library_(shared|static)_host module types work with the sdk as well and another test to ensure that cc_library can be used as either. Bug: 142918168 Test: m checkbuild Change-Id: I359cdbdd15328ca571f276d2b6ce9a229ebb2c86
This commit is contained in:
parent
6c26dc7392
commit
a0843f6a6f
3
cc/cc.go
3
cc/cc.go
|
@ -417,6 +417,9 @@ type Module struct {
|
|||
hod android.HostOrDeviceSupported
|
||||
multilib android.Multilib
|
||||
|
||||
// Allowable SdkMemberTypes of this module type.
|
||||
sdkMemberTypes []android.SdkMemberType
|
||||
|
||||
// delegates, initialize before calling Init
|
||||
features []feature
|
||||
compiler compiler
|
||||
|
|
|
@ -192,6 +192,11 @@ func RegisterLibraryBuildComponents(ctx android.RegistrationContext) {
|
|||
// host.
|
||||
func LibraryFactory() android.Module {
|
||||
module, _ := NewLibrary(android.HostAndDeviceSupported)
|
||||
// Can be used as both a static and a shared library.
|
||||
module.sdkMemberTypes = []android.SdkMemberType{
|
||||
sharedLibrarySdkMemberType,
|
||||
staticLibrarySdkMemberType,
|
||||
}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -199,6 +204,7 @@ func LibraryFactory() android.Module {
|
|||
func LibraryStaticFactory() android.Module {
|
||||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||
library.BuildOnlyStatic()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{staticLibrarySdkMemberType}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -206,6 +212,7 @@ func LibraryStaticFactory() android.Module {
|
|||
func LibrarySharedFactory() android.Module {
|
||||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||
library.BuildOnlyShared()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{sharedLibrarySdkMemberType}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -214,6 +221,7 @@ func LibrarySharedFactory() android.Module {
|
|||
func LibraryHostStaticFactory() android.Module {
|
||||
module, library := NewLibrary(android.HostSupported)
|
||||
library.BuildOnlyStatic()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{staticLibrarySdkMemberType}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -221,6 +229,7 @@ func LibraryHostStaticFactory() android.Module {
|
|||
func LibraryHostSharedFactory() android.Module {
|
||||
module, library := NewLibrary(android.HostSupported)
|
||||
library.BuildOnlyShared()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{sharedLibrarySdkMemberType}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
|
|
@ -24,23 +24,26 @@ import (
|
|||
|
||||
// This file contains support for using cc library modules within an sdk.
|
||||
|
||||
var sharedLibrarySdkMemberType = &librarySdkMemberType{
|
||||
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
||||
PropertyName: "native_shared_libs",
|
||||
},
|
||||
prebuiltModuleType: "cc_prebuilt_library_shared",
|
||||
linkTypes: []string{"shared"},
|
||||
}
|
||||
|
||||
var staticLibrarySdkMemberType = &librarySdkMemberType{
|
||||
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
||||
PropertyName: "native_static_libs",
|
||||
},
|
||||
prebuiltModuleType: "cc_prebuilt_library_static",
|
||||
linkTypes: []string{"static"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Register sdk member types.
|
||||
android.RegisterSdkMemberType(&librarySdkMemberType{
|
||||
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
||||
PropertyName: "native_shared_libs",
|
||||
},
|
||||
prebuiltModuleType: "cc_prebuilt_library_shared",
|
||||
linkTypes: []string{"shared"},
|
||||
})
|
||||
|
||||
android.RegisterSdkMemberType(&librarySdkMemberType{
|
||||
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
||||
PropertyName: "native_static_libs",
|
||||
},
|
||||
prebuiltModuleType: "cc_prebuilt_library_static",
|
||||
linkTypes: []string{"static"},
|
||||
})
|
||||
android.RegisterSdkMemberType(sharedLibrarySdkMemberType)
|
||||
android.RegisterSdkMemberType(staticLibrarySdkMemberType)
|
||||
}
|
||||
|
||||
type librarySdkMemberType struct {
|
||||
|
@ -72,8 +75,16 @@ func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorCont
|
|||
}
|
||||
|
||||
func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
|
||||
_, ok := module.(*Module)
|
||||
return ok
|
||||
// Check the module to see if it can be used with this module type.
|
||||
if m, ok := module.(*Module); ok {
|
||||
for _, allowableMemberType := range m.sdkMemberTypes {
|
||||
if allowableMemberType == mt {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// copy exported header files and stub *.so files
|
||||
|
|
|
@ -73,6 +73,10 @@ func TestBasicSdkWithCc(t *testing.T) {
|
|||
native_shared_libs: ["sdkmember"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "sdkmember",
|
||||
}
|
||||
|
||||
sdk_snapshot {
|
||||
name: "mysdk@1",
|
||||
native_shared_libs: ["sdkmember_mysdk_1"],
|
||||
|
@ -143,6 +147,66 @@ func TestBasicSdkWithCc(t *testing.T) {
|
|||
ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
|
||||
}
|
||||
|
||||
// Make sure the sdk can use host specific cc libraries static/shared and both.
|
||||
func TestHostSdkWithCc(t *testing.T) {
|
||||
testSdkWithCc(t, `
|
||||
sdk {
|
||||
name: "mysdk",
|
||||
device_supported: false,
|
||||
host_supported: true,
|
||||
native_shared_libs: ["sdkshared"],
|
||||
native_static_libs: ["sdkstatic"],
|
||||
}
|
||||
|
||||
cc_library_host_shared {
|
||||
name: "sdkshared",
|
||||
system_shared_libs: [],
|
||||
stl: "none",
|
||||
}
|
||||
|
||||
cc_library_host_static {
|
||||
name: "sdkstatic",
|
||||
system_shared_libs: [],
|
||||
stl: "none",
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
// Make sure the sdk can use cc libraries static/shared and both.
|
||||
func TestSdkWithCc(t *testing.T) {
|
||||
testSdkWithCc(t, `
|
||||
sdk {
|
||||
name: "mysdk",
|
||||
native_shared_libs: ["sdkshared", "sdkboth1"],
|
||||
native_static_libs: ["sdkstatic", "sdkboth2"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "sdkshared",
|
||||
system_shared_libs: [],
|
||||
stl: "none",
|
||||
}
|
||||
|
||||
cc_library_static {
|
||||
name: "sdkstatic",
|
||||
system_shared_libs: [],
|
||||
stl: "none",
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "sdkboth1",
|
||||
system_shared_libs: [],
|
||||
stl: "none",
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "sdkboth2",
|
||||
system_shared_libs: [],
|
||||
stl: "none",
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
|
||||
result := testSdkWithCc(t, `
|
||||
sdk {
|
||||
|
|
Loading…
Reference in New Issue