From 91756d2498fd84e566cd1e805231476072e343a8 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 21 Feb 2020 16:29:57 +0000 Subject: [PATCH] Add support for cc_library_headers in sdk/module_exports Bug: 148933848 Test: m nothing Change-Id: Ife6ee0f736238727a11b4421532eaeb29d46c1b7 --- cc/library_headers.go | 13 +++++ cc/library_sdk_member.go | 23 ++++++--- sdk/cc_sdk_test.go | 105 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 6 deletions(-) diff --git a/cc/library_headers.go b/cc/library_headers.go index c7edb9a6d..88cf7afdd 100644 --- a/cc/library_headers.go +++ b/cc/library_headers.go @@ -18,6 +18,18 @@ import "android/soong/android" func init() { RegisterLibraryHeadersBuildComponents(android.InitRegistrationContext) + + // Register sdk member types. + android.RegisterSdkMemberType(headersLibrarySdkMemberType) +} + +var headersLibrarySdkMemberType = &librarySdkMemberType{ + SdkMemberTypeBase: android.SdkMemberTypeBase{ + PropertyName: "native_header_libs", + SupportsSdk: true, + }, + prebuiltModuleType: "cc_prebuilt_library_headers", + linkTypes: nil, } func RegisterLibraryHeadersBuildComponents(ctx android.RegistrationContext) { @@ -32,6 +44,7 @@ func RegisterLibraryHeadersBuildComponents(ctx android.RegistrationContext) { func LibraryHeaderFactory() android.Module { module, library := NewLibrary(android.HostAndDeviceSupported) library.HeaderOnly() + module.sdkMemberTypes = []android.SdkMemberType{headersLibrarySdkMemberType} return module.Init() } diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index ff292ebc6..a36917eda 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -65,12 +65,19 @@ func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorCont if version == "" { version = LatestStubsVersionFor(mctx.Config(), name) } - for _, linkType := range mt.linkTypes { + if mt.linkTypes == nil { mctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ {Mutator: "image", Variation: android.CoreVariation}, - {Mutator: "link", Variation: linkType}, {Mutator: "version", Variation: version}, }...), dependencyTag, name) + } else { + for _, linkType := range mt.linkTypes { + mctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ + {Mutator: "image", Variation: android.CoreVariation}, + {Mutator: "link", Variation: linkType}, + {Mutator: "version", Variation: version}, + }...), dependencyTag, name) + } } } } @@ -207,10 +214,14 @@ func (info *nativeLibInfo) generatePrebuiltLibrary(sdkModuleContext android.Modu for _, av := range info.archVariantProperties { archTypeProperties := archProperties.AddPropertySet(av.archType) - // Copy the generated library to the snapshot and add a reference to it in the .bp module. - nativeLibraryPath := nativeLibraryPathFor(av) - builder.CopyToSnapshot(av.outputFile, nativeLibraryPath) - archTypeProperties.AddProperty("srcs", []string{nativeLibraryPath}) + // If the library has some link types then it produces an output binary file, otherwise it + // is header only. + if info.memberType.linkTypes != nil { + // Copy the generated library to the snapshot and add a reference to it in the .bp module. + nativeLibraryPath := nativeLibraryPathFor(av) + builder.CopyToSnapshot(av.outputFile, nativeLibraryPath) + archTypeProperties.AddProperty("srcs", []string{nativeLibraryPath}) + } // Add any arch specific properties inside the appropriate arch: {: {...}} block addPossiblyArchSpecificProperties(sdkModuleContext, builder, av, archTypeProperties) diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 4d7f943ba..ecb1da0a0 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -840,3 +840,108 @@ include/Test.h -> include/include/Test.h `), ) } + +func TestSnapshotWithCcHeadersLibrary(t *testing.T) { + result := testSdkWithCc(t, ` + sdk { + name: "mysdk", + native_header_libs: ["mynativeheaders"], + } + + cc_library_headers { + name: "mynativeheaders", + export_include_dirs: ["include"], + system_shared_libs: [], + stl: "none", + } + `) + + result.CheckSnapshot("mysdk", "android_common", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_library_headers { + name: "mysdk_mynativeheaders@current", + sdk_member_name: "mynativeheaders", + export_include_dirs: ["include/include"], + stl: "none", + system_shared_libs: [], +} + +cc_prebuilt_library_headers { + name: "mynativeheaders", + prefer: false, + export_include_dirs: ["include/include"], + stl: "none", + system_shared_libs: [], +} + +sdk_snapshot { + name: "mysdk@current", + native_header_libs: ["mysdk_mynativeheaders@current"], +} +`), + checkAllCopyRules(` +include/Test.h -> include/include/Test.h +`), + ) +} + +func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) { + // b/145598135 - Generating host snapshots for anything other than linux is not supported. + SkipIfNotLinux(t) + + result := testSdkWithCc(t, ` + sdk { + name: "mysdk", + device_supported: false, + host_supported: true, + native_header_libs: ["mynativeheaders"], + } + + cc_library_headers { + name: "mynativeheaders", + device_supported: false, + host_supported: true, + export_include_dirs: ["include"], + system_shared_libs: [], + stl: "none", + } + `) + + result.CheckSnapshot("mysdk", "linux_glibc_common", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_library_headers { + name: "mysdk_mynativeheaders@current", + sdk_member_name: "mynativeheaders", + device_supported: false, + host_supported: true, + export_include_dirs: ["include/include"], + stl: "none", + system_shared_libs: [], +} + +cc_prebuilt_library_headers { + name: "mynativeheaders", + prefer: false, + device_supported: false, + host_supported: true, + export_include_dirs: ["include/include"], + stl: "none", + system_shared_libs: [], +} + +sdk_snapshot { + name: "mysdk@current", + device_supported: false, + host_supported: true, + native_header_libs: ["mysdk_mynativeheaders@current"], +} +`), + checkAllCopyRules(` +include/Test.h -> include/include/Test.h +`), + ) +}