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 (
|
|
|
|
"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
|
2022-05-10 19:50:12 +02:00
|
|
|
bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKey(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *libraryHeaderBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
|
|
|
bazelCtx := ctx.Config().BazelContext
|
|
|
|
ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(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
|
|
|
}
|
|
|
|
|
|
|
|
outputPath := android.PathForBazelOut(ctx, outputPaths[0])
|
|
|
|
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{}
|
|
|
|
}
|
|
|
|
|
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
|
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
|
|
|
|
2021-08-31 22:30:36 +02:00
|
|
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
|
2021-02-15 12:04:32 +01:00
|
|
|
}
|