2020-02-21 11:28:43 +01:00
|
|
|
// 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
|
|
|
|
|
2021-02-15 12:04:32 +01:00
|
|
|
import (
|
2022-09-09 03:38:47 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
2021-02-15 12:04:32 +01:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/bazel"
|
2022-05-10 19:50:12 +02:00
|
|
|
"android/soong/bazel/cquery"
|
2021-02-15 12:04:32 +01:00
|
|
|
)
|
2020-02-21 11:28:43 +01:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
RegisterLibraryHeadersBuildComponents(android.InitRegistrationContext)
|
2020-02-21 17:29:57 +01:00
|
|
|
|
|
|
|
// Register sdk member types.
|
|
|
|
android.RegisterSdkMemberType(headersLibrarySdkMemberType)
|
2021-02-15 12:04:32 +01:00
|
|
|
|
2020-02-21 17:29:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var headersLibrarySdkMemberType = &librarySdkMemberType{
|
|
|
|
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
2020-07-11 05:52:24 +02:00
|
|
|
PropertyName: "native_header_libs",
|
|
|
|
SupportsSdk: true,
|
|
|
|
HostOsDependent: true,
|
2019-11-19 20:44:10 +01:00
|
|
|
Traits: []android.SdkMemberTrait{
|
|
|
|
nativeBridgeSdkTrait,
|
2021-09-15 18:25:10 +02:00
|
|
|
ramdiskImageRequiredSdkTrait,
|
2021-09-06 11:28:34 +02:00
|
|
|
recoveryImageRequiredSdkTrait,
|
2019-11-19 20:44:10 +01:00
|
|
|
},
|
2020-02-21 17:29:57 +01:00
|
|
|
},
|
|
|
|
prebuiltModuleType: "cc_prebuilt_library_headers",
|
Add SDK member support for cc_object.
Test: m nothing
Test: Add
sdk {
name: "runtime-module-sdk",
native_shared_libs: [
"libc",
"libdl",
"libm",
"ld-android",
],
native_objects: [
"crtbegin_dynamic",
"crtbegin_static",
"crtend_android",
],
}
to bionic/apex/Android.bp. Then:
build/soong/scripts/build-aml-prebuilts.sh runtime-module-sdk
Take the generated runtime-module-sdk-current.zip and unzip into a
master-art tree without bionic/, edit the generated Android.bp to
extend cc_prebuilt_* modules with:
nocrt: true,
stl: "none",
system_shared_libs: [],
apex_available: ["//apex_available:anyapex"],
recovery_available: true,
vendor_available: true,
ramdisk_available: true,
Then "m com.android.art.debug". This passes Soong but fails in the
build step because more members are required.
Bug: 148934017
Change-Id: I2ab8f6aadb1440b325697cae4a8ed761c62d15d2
2020-03-10 23:37:59 +01:00
|
|
|
noOutputFiles: true,
|
2020-02-21 11:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterLibraryHeadersBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("cc_library_headers", LibraryHeaderFactory)
|
2020-02-21 11:57:00 +01:00
|
|
|
ctx.RegisterModuleType("cc_prebuilt_library_headers", prebuiltLibraryHeaderFactory)
|
2020-02-21 11:28:43 +01:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:50:12 +02:00
|
|
|
type libraryHeaderBazelHandler struct {
|
2021-04-12 21:42:51 +02:00
|
|
|
module *Module
|
|
|
|
library *libraryDecorator
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:54:17 +02:00
|
|
|
var _ BazelHandler = (*libraryHeaderBazelHandler)(nil)
|
|
|
|
|
2022-05-10 19:50:12 +02:00
|
|
|
func (handler *libraryHeaderBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
2021-04-12 21:42:51 +02:00
|
|
|
bazelCtx := ctx.Config().BazelContext
|
2023-01-18 18:15:31 +01:00
|
|
|
bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
2022-05-10 19:50:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *libraryHeaderBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
|
|
|
bazelCtx := ctx.Config().BazelContext
|
2023-01-18 18:15:31 +01:00
|
|
|
ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
2021-04-12 21:42:51 +02:00
|
|
|
if err != nil {
|
2022-05-10 19:50:12 +02:00
|
|
|
ctx.ModuleErrorf(err.Error())
|
|
|
|
return
|
2021-04-12 21:42:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
outputPaths := ccInfo.OutputFiles
|
|
|
|
if len(outputPaths) != 1 {
|
|
|
|
ctx.ModuleErrorf("expected exactly one output file for %q, but got %q", label, outputPaths)
|
2022-05-10 19:50:12 +02:00
|
|
|
return
|
2021-04-12 21:42:51 +02:00
|
|
|
}
|
|
|
|
|
2023-02-04 00:12:15 +01:00
|
|
|
var outputPath android.Path = android.PathForBazelOut(ctx, outputPaths[0])
|
|
|
|
if len(ccInfo.TidyFiles) > 0 {
|
|
|
|
h.module.tidyFiles = android.PathsForBazelOut(ctx, ccInfo.TidyFiles)
|
|
|
|
outputPath = android.AttachValidationActions(ctx, outputPath, h.module.tidyFiles)
|
|
|
|
}
|
2021-04-12 21:42:51 +02:00
|
|
|
h.module.outputFile = android.OptionalPathForPath(outputPath)
|
|
|
|
|
|
|
|
// HeaderLibraryInfo is an empty struct to indicate to dependencies that this is a header library
|
|
|
|
ctx.SetProvider(HeaderLibraryInfoProvider, HeaderLibraryInfo{})
|
|
|
|
|
2021-06-04 21:03:47 +02:00
|
|
|
h.library.setFlagExporterInfoFromCcInfo(ctx, ccInfo)
|
2021-04-12 21:42:51 +02:00
|
|
|
|
|
|
|
// Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise
|
|
|
|
// validation will fail. For now, set this to an empty list.
|
|
|
|
// TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation.
|
|
|
|
h.library.collectedSnapshotHeaders = android.Paths{}
|
2023-01-27 22:01:37 +01:00
|
|
|
|
|
|
|
h.module.setAndroidMkVariablesFromCquery(ccInfo.CcAndroidMkInfo)
|
2021-04-12 21:42:51 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 11:28:43 +01:00
|
|
|
// 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()
|
2020-02-21 17:29:57 +01:00
|
|
|
module.sdkMemberTypes = []android.SdkMemberType{headersLibrarySdkMemberType}
|
2021-11-01 20:32:43 +01:00
|
|
|
module.bazelable = true
|
2022-05-10 19:50:12 +02:00
|
|
|
module.bazelHandler = &libraryHeaderBazelHandler{module: module, library: library}
|
2020-02-21 11:28:43 +01:00
|
|
|
return module.Init()
|
|
|
|
}
|
2020-02-21 11:57:00 +01:00
|
|
|
|
|
|
|
// cc_prebuilt_library_headers is a prebuilt version of cc_library_headers
|
|
|
|
func prebuiltLibraryHeaderFactory() android.Module {
|
2021-11-23 02:24:06 +01:00
|
|
|
module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported, "")
|
2020-02-21 11:57:00 +01:00
|
|
|
library.HeaderOnly()
|
2022-01-11 17:02:50 +01:00
|
|
|
module.bazelable = true
|
|
|
|
module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
2020-02-21 11:57:00 +01:00
|
|
|
return module.Init()
|
|
|
|
}
|
2021-02-15 12:04:32 +01:00
|
|
|
|
|
|
|
type bazelCcLibraryHeadersAttributes struct {
|
2021-12-10 20:28:20 +01:00
|
|
|
Hdrs bazel.LabelListAttribute
|
|
|
|
Export_includes bazel.StringListAttribute
|
|
|
|
Export_absolute_includes bazel.StringListAttribute
|
|
|
|
Export_system_includes bazel.StringListAttribute
|
|
|
|
Deps bazel.LabelListAttribute
|
|
|
|
Implementation_deps bazel.LabelListAttribute
|
|
|
|
System_dynamic_deps bazel.LabelListAttribute
|
2022-03-02 00:44:08 +01:00
|
|
|
sdkAttributes
|
2021-02-15 12:04:32 +01:00
|
|
|
}
|
|
|
|
|
2021-11-01 20:32:43 +01:00
|
|
|
func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
|
2021-10-19 19:56:10 +02:00
|
|
|
baseAttributes := bp2BuildParseBaseProps(ctx, module)
|
2022-05-11 19:55:06 +02:00
|
|
|
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, &baseAttributes.includes)
|
2021-10-19 19:56:10 +02:00
|
|
|
linkerAttrs := baseAttributes.linkerAttributes
|
2022-06-22 22:30:55 +02:00
|
|
|
(&linkerAttrs.deps).Append(linkerAttrs.dynamicDeps)
|
2022-08-18 17:53:00 +02:00
|
|
|
(&linkerAttrs.deps).Append(linkerAttrs.wholeArchiveDeps)
|
2021-02-15 12:04:32 +01:00
|
|
|
|
|
|
|
attrs := &bazelCcLibraryHeadersAttributes{
|
2021-12-10 20:28:20 +01:00
|
|
|
Export_includes: exportedIncludes.Includes,
|
|
|
|
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
|
|
|
|
Export_system_includes: exportedIncludes.SystemIncludes,
|
|
|
|
Deps: linkerAttrs.deps,
|
|
|
|
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
|
|
|
|
Hdrs: baseAttributes.hdrs,
|
2022-03-02 00:44:08 +01:00
|
|
|
sdkAttributes: bp2BuildParseSdkAttributes(module),
|
2021-02-15 12:04:32 +01:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:06:17 +01:00
|
|
|
props := bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "cc_library_headers",
|
2022-01-12 18:00:49 +01:00
|
|
|
Bzl_load_location: "//build/bazel/rules/cc:cc_library_headers.bzl",
|
2021-02-19 17:06:17 +01:00
|
|
|
}
|
2021-02-15 12:04:32 +01:00
|
|
|
|
2023-04-12 21:05:49 +02:00
|
|
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
2022-12-02 23:31:58 +01:00
|
|
|
|
|
|
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{
|
|
|
|
Name: module.Name(),
|
|
|
|
Tags: tags,
|
|
|
|
}, attrs)
|
2021-02-15 12:04:32 +01:00
|
|
|
}
|
2022-09-09 03:38:47 +02:00
|
|
|
|
|
|
|
// Append .contribution suffix to input labels
|
|
|
|
func apiBazelTargets(ll bazel.LabelList) bazel.LabelList {
|
|
|
|
labels := make([]bazel.Label, 0)
|
|
|
|
for _, l := range ll.Includes {
|
|
|
|
labels = append(labels, bazel.Label{
|
|
|
|
Label: android.ApiContributionTargetName(l.Label),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return bazel.MakeLabelList(labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
func apiLibraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
|
|
|
|
// cc_api_library_headers have a 1:1 mapping to arch/no-arch
|
|
|
|
// For API export, create a top-level arch-agnostic target and list the arch-specific targets as its deps
|
|
|
|
|
|
|
|
// arch-agnostic includes
|
2023-01-27 00:02:00 +01:00
|
|
|
apiIncludes := getModuleLibApiIncludes(ctx, module)
|
2022-09-09 03:38:47 +02:00
|
|
|
// arch and os specific includes
|
|
|
|
archApiIncludes, androidOsIncludes := archOsSpecificApiIncludes(ctx, module)
|
|
|
|
for _, arch := range allArches { // sorted iteration
|
|
|
|
archApiInclude := archApiIncludes[arch]
|
|
|
|
if !archApiInclude.isEmpty() {
|
|
|
|
createApiHeaderTarget(ctx, archApiInclude)
|
|
|
|
apiIncludes.addDep(archApiInclude.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// os==android includes
|
|
|
|
if !androidOsIncludes.isEmpty() {
|
|
|
|
createApiHeaderTarget(ctx, androidOsIncludes)
|
|
|
|
apiIncludes.addDep(androidOsIncludes.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !apiIncludes.isEmpty() {
|
2023-01-27 00:02:00 +01:00
|
|
|
// override the name from <mod>.module-libapi.headers --> <mod>.contribution
|
2022-09-09 03:38:47 +02:00
|
|
|
apiIncludes.name = android.ApiContributionTargetName(module.Name())
|
|
|
|
createApiHeaderTarget(ctx, apiIncludes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createApiHeaderTarget(ctx android.TopDownMutatorContext, includes apiIncludes) {
|
|
|
|
props := bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "cc_api_library_headers",
|
|
|
|
Bzl_load_location: "//build/bazel/rules/apis:cc_api_contribution.bzl",
|
|
|
|
}
|
|
|
|
ctx.CreateBazelTargetModule(
|
|
|
|
props,
|
|
|
|
android.CommonAttributes{
|
|
|
|
Name: includes.name,
|
|
|
|
SkipData: proptools.BoolPtr(true),
|
|
|
|
},
|
|
|
|
&includes.attrs,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
allArches = []string{"arm", "arm64", "x86", "x86_64"}
|
|
|
|
)
|
|
|
|
|
|
|
|
type archApiIncludes map[string]apiIncludes
|
|
|
|
|
|
|
|
func archOsSpecificApiIncludes(ctx android.TopDownMutatorContext, module *Module) (archApiIncludes, apiIncludes) {
|
|
|
|
baseProps := bp2BuildParseBaseProps(ctx, module)
|
|
|
|
i := bp2BuildParseExportedIncludes(ctx, module, &baseProps.includes)
|
|
|
|
archRet := archApiIncludes{}
|
|
|
|
for _, arch := range allArches {
|
|
|
|
includes := i.Includes.SelectValue(
|
|
|
|
bazel.ArchConfigurationAxis,
|
|
|
|
arch)
|
|
|
|
systemIncludes := i.SystemIncludes.SelectValue(
|
|
|
|
bazel.ArchConfigurationAxis,
|
|
|
|
arch)
|
|
|
|
deps := baseProps.deps.SelectValue(
|
|
|
|
bazel.ArchConfigurationAxis,
|
|
|
|
arch)
|
|
|
|
attrs := bazelCcLibraryHeadersAttributes{
|
|
|
|
Export_includes: bazel.MakeStringListAttribute(includes),
|
|
|
|
Export_system_includes: bazel.MakeStringListAttribute(systemIncludes),
|
|
|
|
}
|
|
|
|
apiDeps := apiBazelTargets(deps)
|
|
|
|
if !apiDeps.IsEmpty() {
|
|
|
|
attrs.Deps = bazel.MakeLabelListAttribute(apiDeps)
|
|
|
|
}
|
|
|
|
apiIncludes := apiIncludes{
|
|
|
|
name: android.ApiContributionTargetName(module.Name()) + "." + arch,
|
|
|
|
attrs: bazelCcApiLibraryHeadersAttributes{
|
|
|
|
bazelCcLibraryHeadersAttributes: attrs,
|
|
|
|
Arch: proptools.StringPtr(arch),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
archRet[arch] = apiIncludes
|
|
|
|
}
|
|
|
|
|
|
|
|
// apiIncludes for os == Android
|
|
|
|
androidOsDeps := baseProps.deps.SelectValue(bazel.OsConfigurationAxis, bazel.OsAndroid)
|
|
|
|
androidOsAttrs := bazelCcLibraryHeadersAttributes{
|
|
|
|
Export_includes: bazel.MakeStringListAttribute(
|
|
|
|
i.Includes.SelectValue(bazel.OsConfigurationAxis, bazel.OsAndroid),
|
|
|
|
),
|
|
|
|
Export_system_includes: bazel.MakeStringListAttribute(
|
|
|
|
i.SystemIncludes.SelectValue(bazel.OsConfigurationAxis, bazel.OsAndroid),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
androidOsApiDeps := apiBazelTargets(androidOsDeps)
|
|
|
|
if !androidOsApiDeps.IsEmpty() {
|
|
|
|
androidOsAttrs.Deps = bazel.MakeLabelListAttribute(androidOsApiDeps)
|
|
|
|
}
|
|
|
|
osRet := apiIncludes{
|
|
|
|
name: android.ApiContributionTargetName(module.Name()) + ".androidos",
|
|
|
|
attrs: bazelCcApiLibraryHeadersAttributes{
|
|
|
|
bazelCcLibraryHeadersAttributes: androidOsAttrs,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return archRet, osRet
|
|
|
|
}
|