Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
// Copyright 2021 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
|
|
|
|
//
|
2022-07-30 00:58:33 +02:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
//
|
|
|
|
// 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 (
|
2021-10-04 19:54:37 +02:00
|
|
|
"fmt"
|
2021-04-13 09:14:55 +02:00
|
|
|
"path/filepath"
|
2021-05-12 06:33:00 +02:00
|
|
|
"strings"
|
2023-04-20 00:31:54 +02:00
|
|
|
"sync"
|
2021-05-13 21:13:04 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/bazel"
|
2022-05-17 00:56:04 +02:00
|
|
|
"android/soong/cc/config"
|
2021-09-22 21:52:58 +02:00
|
|
|
|
2021-09-20 21:14:39 +02:00
|
|
|
"github.com/google/blueprint"
|
2021-05-26 14:45:30 +02:00
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
)
|
|
|
|
|
2021-10-19 15:45:48 +02:00
|
|
|
const (
|
2022-09-06 21:31:25 +02:00
|
|
|
cSrcPartition = "c"
|
|
|
|
asSrcPartition = "as"
|
|
|
|
asmSrcPartition = "asm"
|
|
|
|
lSrcPartition = "l"
|
|
|
|
llSrcPartition = "ll"
|
|
|
|
cppSrcPartition = "cpp"
|
|
|
|
protoSrcPartition = "proto"
|
|
|
|
aidlSrcPartition = "aidl"
|
|
|
|
syspropSrcPartition = "sysprop"
|
2023-04-24 16:57:32 +02:00
|
|
|
|
|
|
|
yaccSrcPartition = "yacc"
|
|
|
|
|
|
|
|
rScriptSrcPartition = "renderScript"
|
2022-09-13 17:27:11 +02:00
|
|
|
|
|
|
|
stubsSuffix = "_stub_libs_current"
|
2021-10-19 15:45:48 +02:00
|
|
|
)
|
|
|
|
|
2021-05-24 21:41:47 +02:00
|
|
|
// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
|
2021-05-26 06:42:42 +02:00
|
|
|
// properties which apply to either the shared or static version of a cc_library module.
|
2021-05-24 21:41:47 +02:00
|
|
|
type staticOrSharedAttributes struct {
|
2022-08-16 19:10:31 +02:00
|
|
|
Srcs bazel.LabelListAttribute
|
|
|
|
Srcs_c bazel.LabelListAttribute
|
|
|
|
Srcs_as bazel.LabelListAttribute
|
|
|
|
Srcs_aidl bazel.LabelListAttribute
|
|
|
|
Hdrs bazel.LabelListAttribute
|
|
|
|
Copts bazel.StringListAttribute
|
2021-06-11 14:51:48 +02:00
|
|
|
|
2021-09-28 15:19:17 +02:00
|
|
|
Deps bazel.LabelListAttribute
|
|
|
|
Implementation_deps bazel.LabelListAttribute
|
|
|
|
Dynamic_deps bazel.LabelListAttribute
|
|
|
|
Implementation_dynamic_deps bazel.LabelListAttribute
|
|
|
|
Whole_archive_deps bazel.LabelListAttribute
|
|
|
|
Implementation_whole_archive_deps bazel.LabelListAttribute
|
2022-08-09 18:50:56 +02:00
|
|
|
Runtime_deps bazel.LabelListAttribute
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
|
|
|
|
System_dynamic_deps bazel.LabelListAttribute
|
2021-12-10 00:10:18 +01:00
|
|
|
|
|
|
|
Enabled bazel.BoolAttribute
|
2022-03-02 00:44:08 +01:00
|
|
|
|
2022-12-08 00:45:30 +01:00
|
|
|
Native_coverage *bool
|
2022-05-18 00:13:28 +02:00
|
|
|
|
2023-03-24 14:46:36 +01:00
|
|
|
Apex_available []string
|
|
|
|
|
2023-04-14 20:25:24 +02:00
|
|
|
Features bazel.StringListAttribute
|
|
|
|
|
2022-03-02 00:44:08 +01:00
|
|
|
sdkAttributes
|
2022-10-21 16:42:24 +02:00
|
|
|
|
|
|
|
tidyAttributes
|
|
|
|
}
|
|
|
|
|
|
|
|
type tidyAttributes struct {
|
2023-03-14 19:05:28 +01:00
|
|
|
Tidy *string
|
2022-10-21 16:42:24 +02:00
|
|
|
Tidy_flags []string
|
|
|
|
Tidy_checks []string
|
|
|
|
Tidy_checks_as_errors []string
|
2022-10-25 21:47:17 +02:00
|
|
|
Tidy_disabled_srcs bazel.LabelListAttribute
|
2022-11-02 19:17:15 +01:00
|
|
|
Tidy_timeout_srcs bazel.LabelListAttribute
|
2022-10-21 16:42:24 +02:00
|
|
|
}
|
|
|
|
|
2022-10-25 21:47:17 +02:00
|
|
|
func (m *Module) convertTidyAttributes(ctx android.BaseMutatorContext, moduleAttrs *tidyAttributes) {
|
2022-10-21 16:42:24 +02:00
|
|
|
for _, f := range m.features {
|
|
|
|
if tidy, ok := f.(*tidyFeature); ok {
|
2023-03-14 19:05:28 +01:00
|
|
|
var tidyAttr *string
|
|
|
|
if tidy.Properties.Tidy != nil {
|
|
|
|
if *tidy.Properties.Tidy {
|
|
|
|
tidyAttr = proptools.StringPtr("local")
|
|
|
|
} else {
|
|
|
|
tidyAttr = proptools.StringPtr("never")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moduleAttrs.Tidy = tidyAttr
|
2022-10-21 16:42:24 +02:00
|
|
|
moduleAttrs.Tidy_flags = tidy.Properties.Tidy_flags
|
|
|
|
moduleAttrs.Tidy_checks = tidy.Properties.Tidy_checks
|
|
|
|
moduleAttrs.Tidy_checks_as_errors = tidy.Properties.Tidy_checks_as_errors
|
|
|
|
}
|
2022-10-25 21:47:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
archVariantProps := m.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
|
|
|
|
for axis, configToProps := range archVariantProps {
|
2022-12-30 02:11:49 +01:00
|
|
|
for cfg, _props := range configToProps {
|
2022-10-25 21:47:17 +02:00
|
|
|
if archProps, ok := _props.(*BaseCompilerProperties); ok {
|
|
|
|
archDisabledSrcs := android.BazelLabelForModuleSrc(ctx, archProps.Tidy_disabled_srcs)
|
2022-12-30 02:11:49 +01:00
|
|
|
moduleAttrs.Tidy_disabled_srcs.SetSelectValue(axis, cfg, archDisabledSrcs)
|
2022-11-02 19:17:15 +01:00
|
|
|
archTimeoutSrcs := android.BazelLabelForModuleSrc(ctx, archProps.Tidy_timeout_srcs)
|
2022-12-30 02:11:49 +01:00
|
|
|
moduleAttrs.Tidy_timeout_srcs.SetSelectValue(axis, cfg, archTimeoutSrcs)
|
2022-10-25 21:47:17 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-21 16:42:24 +02:00
|
|
|
}
|
2021-04-29 10:15:13 +02:00
|
|
|
}
|
|
|
|
|
2022-02-04 22:01:20 +01:00
|
|
|
// groupSrcsByExtension partitions `srcs` into groups based on file extension.
|
2021-11-02 07:40:51 +01:00
|
|
|
func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
|
2021-09-20 18:55:02 +02:00
|
|
|
// Convert filegroup dependencies into extension-specific filegroups filtered in the filegroup.bzl
|
|
|
|
// macro.
|
|
|
|
addSuffixForFilegroup := func(suffix string) bazel.LabelMapper {
|
2022-08-16 19:10:31 +02:00
|
|
|
return func(otherModuleCtx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
|
|
|
|
|
|
|
|
m, exists := otherModuleCtx.ModuleFromName(label.OriginalModuleName)
|
2021-09-28 15:19:17 +02:00
|
|
|
labelStr := label.Label
|
2022-08-16 19:10:31 +02:00
|
|
|
if !exists || !android.IsFilegroup(otherModuleCtx, m) {
|
|
|
|
return labelStr, false
|
|
|
|
}
|
2022-09-01 20:54:47 +02:00
|
|
|
// If the filegroup is already converted to aidl_library or proto_library,
|
|
|
|
// skip creating _c_srcs, _as_srcs, _cpp_srcs filegroups
|
|
|
|
fg, _ := m.(android.FileGroupAsLibrary)
|
|
|
|
if fg.ShouldConvertToAidlLibrary(ctx) || fg.ShouldConvertToProtoLibrary(ctx) {
|
2021-09-28 15:19:17 +02:00
|
|
|
return labelStr, false
|
2021-06-02 13:10:02 +02:00
|
|
|
}
|
2021-09-28 15:19:17 +02:00
|
|
|
return labelStr + suffix, true
|
2021-07-21 20:34:58 +02:00
|
|
|
}
|
2021-06-02 13:10:02 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 18:55:02 +02:00
|
|
|
// TODO(b/190006308): Handle language detection of sources in a Bazel rule.
|
2022-02-04 22:01:20 +01:00
|
|
|
labels := bazel.LabelPartitions{
|
|
|
|
protoSrcPartition: android.ProtoSrcLabelPartition,
|
2021-12-08 21:25:06 +01:00
|
|
|
cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
|
|
|
|
asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
|
2022-07-30 00:58:33 +02:00
|
|
|
asmSrcPartition: bazel.LabelPartition{Extensions: []string{".asm"}},
|
2022-08-16 19:10:31 +02:00
|
|
|
aidlSrcPartition: android.AidlSrcLabelPartition,
|
2022-05-13 22:55:35 +02:00
|
|
|
// TODO(http://b/231968910): If there is ever a filegroup target that
|
|
|
|
// contains .l or .ll files we will need to find a way to add a
|
|
|
|
// LabelMapper for these that identifies these filegroups and
|
|
|
|
// converts them appropriately
|
2023-04-24 16:57:32 +02:00
|
|
|
lSrcPartition: bazel.LabelPartition{Extensions: []string{".l"}},
|
|
|
|
llSrcPartition: bazel.LabelPartition{Extensions: []string{".ll"}},
|
|
|
|
rScriptSrcPartition: bazel.LabelPartition{Extensions: []string{".fs", ".rscript"}},
|
2021-09-20 18:55:02 +02:00
|
|
|
// C++ is the "catch-all" group, and comprises generated sources because we don't
|
|
|
|
// know the language of these sources until the genrule is executed.
|
2022-09-06 21:31:25 +02:00
|
|
|
cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
|
|
|
|
syspropSrcPartition: bazel.LabelPartition{Extensions: []string{".sysprop"}},
|
2023-05-10 01:58:52 +02:00
|
|
|
yaccSrcPartition: bazel.LabelPartition{Extensions: []string{".y", "yy"}},
|
2022-02-04 22:01:20 +01:00
|
|
|
}
|
2021-06-02 13:10:02 +02:00
|
|
|
|
2022-02-04 22:01:20 +01:00
|
|
|
return bazel.PartitionLabelListAttribute(ctx, &srcs, labels)
|
2021-06-02 13:10:02 +02:00
|
|
|
}
|
|
|
|
|
2021-09-01 23:22:09 +02:00
|
|
|
// bp2BuildParseLibProps returns the attributes for a variant of a cc_library.
|
2021-11-02 07:40:51 +01:00
|
|
|
func bp2BuildParseLibProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) staticOrSharedAttributes {
|
2021-04-29 10:15:13 +02:00
|
|
|
lib, ok := module.compiler.(*libraryDecorator)
|
|
|
|
if !ok {
|
2021-05-24 21:41:47 +02:00
|
|
|
return staticOrSharedAttributes{}
|
2021-04-29 10:15:13 +02:00
|
|
|
}
|
2021-09-01 23:22:09 +02:00
|
|
|
return bp2buildParseStaticOrSharedProps(ctx, module, lib, isStatic)
|
|
|
|
}
|
2021-04-29 10:15:13 +02:00
|
|
|
|
2021-09-01 23:22:09 +02:00
|
|
|
// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
|
2021-11-02 07:40:51 +01:00
|
|
|
func bp2BuildParseSharedProps(ctx android.BazelConversionPathContext, module *Module) staticOrSharedAttributes {
|
2021-09-01 23:22:09 +02:00
|
|
|
return bp2BuildParseLibProps(ctx, module, false)
|
2021-04-29 10:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
|
2021-11-02 07:40:51 +01:00
|
|
|
func bp2BuildParseStaticProps(ctx android.BazelConversionPathContext, module *Module) staticOrSharedAttributes {
|
2021-09-01 23:22:09 +02:00
|
|
|
return bp2BuildParseLibProps(ctx, module, true)
|
2021-05-24 21:41:47 +02:00
|
|
|
}
|
|
|
|
|
2021-09-22 21:52:58 +02:00
|
|
|
type depsPartition struct {
|
|
|
|
export bazel.LabelList
|
|
|
|
implementation bazel.LabelList
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
type bazelLabelForDepsFn func(android.BazelConversionPathContext, []string) bazel.LabelList
|
2021-09-22 21:52:58 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func maybePartitionExportedAndImplementationsDeps(ctx android.BazelConversionPathContext, exportsDeps bool, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition {
|
2021-10-04 19:55:44 +02:00
|
|
|
if !exportsDeps {
|
|
|
|
return depsPartition{
|
|
|
|
implementation: fn(ctx, allDeps),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 21:52:58 +02:00
|
|
|
implementation, export := android.FilterList(allDeps, exportedDeps)
|
|
|
|
|
|
|
|
return depsPartition{
|
|
|
|
export: fn(ctx, export),
|
|
|
|
implementation: fn(ctx, implementation),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
type bazelLabelForDepsExcludesFn func(android.BazelConversionPathContext, []string, []string) bazel.LabelList
|
2021-09-22 21:52:58 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func maybePartitionExportedAndImplementationsDepsExcludes(ctx android.BazelConversionPathContext, exportsDeps bool, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition {
|
2021-10-04 19:55:44 +02:00
|
|
|
if !exportsDeps {
|
|
|
|
return depsPartition{
|
|
|
|
implementation: fn(ctx, allDeps, excludes),
|
|
|
|
}
|
|
|
|
}
|
2021-09-22 21:52:58 +02:00
|
|
|
implementation, export := android.FilterList(allDeps, exportedDeps)
|
|
|
|
|
|
|
|
return depsPartition{
|
|
|
|
export: fn(ctx, export, excludes),
|
|
|
|
implementation: fn(ctx, implementation, excludes),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 17:04:04 +02:00
|
|
|
func bp2BuildPropParseHelper(ctx android.ArchVariantContext, module *Module, propsType interface{}, parseFunc func(axis bazel.ConfigurationAxis, config string, props interface{})) {
|
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, propsType) {
|
2022-12-30 02:11:49 +01:00
|
|
|
for cfg, props := range configToProps {
|
|
|
|
parseFunc(axis, cfg, props)
|
2022-09-01 17:04:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 22:36:39 +02:00
|
|
|
// Parses properties common to static and shared libraries. Also used for prebuilt libraries.
|
2023-03-24 14:46:36 +01:00
|
|
|
func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
|
2021-08-11 16:46:06 +02:00
|
|
|
attrs := staticOrSharedAttributes{}
|
2021-05-06 22:23:19 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
|
2023-04-14 20:25:24 +02:00
|
|
|
attrs.Copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag, filterOutHiddenVisibility))
|
2021-06-11 14:51:48 +02:00
|
|
|
attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs))
|
2021-09-20 21:14:39 +02:00
|
|
|
attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs))
|
2021-09-22 21:52:58 +02:00
|
|
|
|
2021-10-04 19:55:44 +02:00
|
|
|
staticDeps := maybePartitionExportedAndImplementationsDeps(ctx, true, props.Static_libs, props.Export_static_lib_headers, bazelLabelForStaticDeps)
|
2021-09-22 21:52:58 +02:00
|
|
|
attrs.Deps.SetSelectValue(axis, config, staticDeps.export)
|
|
|
|
attrs.Implementation_deps.SetSelectValue(axis, config, staticDeps.implementation)
|
|
|
|
|
2021-10-04 19:55:44 +02:00
|
|
|
sharedDeps := maybePartitionExportedAndImplementationsDeps(ctx, true, props.Shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDeps)
|
2021-09-22 21:52:58 +02:00
|
|
|
attrs.Dynamic_deps.SetSelectValue(axis, config, sharedDeps.export)
|
|
|
|
attrs.Implementation_dynamic_deps.SetSelectValue(axis, config, sharedDeps.implementation)
|
|
|
|
|
|
|
|
attrs.Whole_archive_deps.SetSelectValue(axis, config, bazelLabelForWholeDeps(ctx, props.Whole_static_libs))
|
2021-12-10 00:10:18 +01:00
|
|
|
attrs.Enabled.SetSelectValue(axis, config, props.Enabled)
|
2021-05-26 06:42:42 +02:00
|
|
|
}
|
2021-08-11 16:46:06 +02:00
|
|
|
// system_dynamic_deps distinguishes between nil/empty list behavior:
|
|
|
|
// nil -> use default values
|
|
|
|
// empty list -> no values specified
|
|
|
|
attrs.System_dynamic_deps.ForceSpecifyEmptyList = true
|
2021-04-29 10:15:13 +02:00
|
|
|
|
2023-03-24 14:46:36 +01:00
|
|
|
var apexAvailable []string
|
2021-05-26 06:42:42 +02:00
|
|
|
if isStatic {
|
2023-03-24 14:46:36 +01:00
|
|
|
apexAvailable = lib.StaticProperties.Static.Apex_available
|
2022-04-21 22:04:42 +02:00
|
|
|
bp2BuildPropParseHelper(ctx, module, &StaticProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if staticOrSharedProps, ok := props.(*StaticProperties); ok {
|
|
|
|
setAttrs(axis, config, staticOrSharedProps.Static)
|
2021-05-26 06:42:42 +02:00
|
|
|
}
|
2022-04-21 22:04:42 +02:00
|
|
|
})
|
2021-05-26 06:42:42 +02:00
|
|
|
} else {
|
2023-03-24 14:46:36 +01:00
|
|
|
apexAvailable = lib.SharedProperties.Shared.Apex_available
|
2022-04-21 22:04:42 +02:00
|
|
|
bp2BuildPropParseHelper(ctx, module, &SharedProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if staticOrSharedProps, ok := props.(*SharedProperties); ok {
|
|
|
|
setAttrs(axis, config, staticOrSharedProps.Shared)
|
2021-05-26 06:42:42 +02:00
|
|
|
}
|
2022-04-21 22:04:42 +02:00
|
|
|
})
|
2021-04-29 10:15:13 +02:00
|
|
|
}
|
2021-05-26 06:42:42 +02:00
|
|
|
|
2021-10-19 15:45:48 +02:00
|
|
|
partitionedSrcs := groupSrcsByExtension(ctx, attrs.Srcs)
|
|
|
|
attrs.Srcs = partitionedSrcs[cppSrcPartition]
|
|
|
|
attrs.Srcs_c = partitionedSrcs[cSrcPartition]
|
|
|
|
attrs.Srcs_as = partitionedSrcs[asSrcPartition]
|
2021-06-02 13:10:02 +02:00
|
|
|
|
2023-04-12 21:05:49 +02:00
|
|
|
attrs.Apex_available = android.ConvertApexAvailableToTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), apexAvailable)
|
2023-03-24 14:46:36 +01:00
|
|
|
|
2023-04-14 20:25:24 +02:00
|
|
|
attrs.Features.Append(convertHiddenVisibilityToFeatureStaticOrShared(ctx, module, isStatic))
|
|
|
|
|
2021-09-28 15:19:17 +02:00
|
|
|
if !partitionedSrcs[protoSrcPartition].IsEmpty() {
|
|
|
|
// TODO(b/208815215): determine whether this is used and add support if necessary
|
|
|
|
ctx.ModuleErrorf("Migrating static/shared only proto srcs is not currently supported")
|
|
|
|
}
|
|
|
|
|
2021-05-26 06:42:42 +02:00
|
|
|
return attrs
|
2021-04-29 10:15:13 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 09:02:34 +02:00
|
|
|
// Convenience struct to hold all attributes parsed from prebuilt properties.
|
|
|
|
type prebuiltAttributes struct {
|
2022-04-07 22:36:39 +02:00
|
|
|
Src bazel.LabelAttribute
|
|
|
|
Enabled bazel.BoolAttribute
|
2021-05-14 09:02:34 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 17:04:04 +02:00
|
|
|
func parseSrc(ctx android.BazelConversionPathContext, srcLabelAttribute *bazel.LabelAttribute, axis bazel.ConfigurationAxis, config string, srcs []string) {
|
|
|
|
srcFileError := func() {
|
|
|
|
ctx.ModuleErrorf("parseSrc: Expected at most one source file for %s %s\n", axis, config)
|
2022-04-07 22:36:39 +02:00
|
|
|
}
|
2022-09-01 17:04:04 +02:00
|
|
|
if len(srcs) > 1 {
|
|
|
|
srcFileError()
|
|
|
|
return
|
|
|
|
} else if len(srcs) == 0 {
|
|
|
|
return
|
2022-04-07 22:36:39 +02:00
|
|
|
}
|
2022-09-01 17:04:04 +02:00
|
|
|
if srcLabelAttribute.SelectValue(axis, config) != nil {
|
|
|
|
srcFileError()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
srcLabelAttribute.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, srcs[0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package
|
|
|
|
func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) prebuiltAttributes {
|
2022-04-07 22:36:39 +02:00
|
|
|
|
2022-09-01 17:04:04 +02:00
|
|
|
var srcLabelAttribute bazel.LabelAttribute
|
2022-04-07 22:36:39 +02:00
|
|
|
bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if prebuiltLinkerProperties, ok := props.(*prebuiltLinkerProperties); ok {
|
2022-09-01 17:04:04 +02:00
|
|
|
parseSrc(ctx, &srcLabelAttribute, axis, config, prebuiltLinkerProperties.Srcs)
|
2022-04-07 22:36:39 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var enabledLabelAttribute bazel.BoolAttribute
|
|
|
|
parseAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
|
|
|
|
if props.Enabled != nil {
|
|
|
|
enabledLabelAttribute.SetSelectValue(axis, config, props.Enabled)
|
|
|
|
}
|
2022-09-01 17:04:04 +02:00
|
|
|
parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs)
|
2022-04-07 22:36:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if isStatic {
|
|
|
|
bp2BuildPropParseHelper(ctx, module, &StaticProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if staticProperties, ok := props.(*StaticProperties); ok {
|
|
|
|
parseAttrs(axis, config, staticProperties.Static)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
bp2BuildPropParseHelper(ctx, module, &SharedProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if sharedProperties, ok := props.(*SharedProperties); ok {
|
|
|
|
parseAttrs(axis, config, sharedProperties.Shared)
|
|
|
|
}
|
|
|
|
})
|
2021-05-14 09:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return prebuiltAttributes{
|
2022-04-07 22:36:39 +02:00
|
|
|
Src: srcLabelAttribute,
|
|
|
|
Enabled: enabledLabelAttribute,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 17:04:04 +02:00
|
|
|
func bp2BuildParsePrebuiltBinaryProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes {
|
|
|
|
var srcLabelAttribute bazel.LabelAttribute
|
|
|
|
bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if props, ok := props.(*prebuiltLinkerProperties); ok {
|
|
|
|
parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs)
|
2022-04-07 22:36:39 +02:00
|
|
|
}
|
2022-09-01 17:04:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return prebuiltAttributes{
|
|
|
|
Src: srcLabelAttribute,
|
2021-05-14 09:02:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-06 01:46:39 +01:00
|
|
|
func bp2BuildParsePrebuiltObjectProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes {
|
|
|
|
var srcLabelAttribute bazel.LabelAttribute
|
|
|
|
bp2BuildPropParseHelper(ctx, module, &prebuiltObjectProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if props, ok := props.(*prebuiltObjectProperties); ok {
|
|
|
|
parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return prebuiltAttributes{
|
|
|
|
Src: srcLabelAttribute,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
type baseAttributes struct {
|
|
|
|
compilerAttributes
|
|
|
|
linkerAttributes
|
2021-09-28 15:19:17 +02:00
|
|
|
|
2022-10-28 18:48:18 +02:00
|
|
|
// A combination of compilerAttributes.features and linkerAttributes.features, as well as sanitizer features
|
2022-08-22 23:31:04 +02:00
|
|
|
features bazel.StringListAttribute
|
2021-09-28 15:19:17 +02:00
|
|
|
protoDependency *bazel.LabelAttribute
|
2022-08-16 19:10:31 +02:00
|
|
|
aidlDependency *bazel.LabelAttribute
|
2022-12-08 00:45:30 +01:00
|
|
|
Native_coverage *bool
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
|
2021-04-09 12:43:12 +02:00
|
|
|
// Convenience struct to hold all attributes parsed from compiler properties.
|
|
|
|
type compilerAttributes struct {
|
2021-05-25 18:10:58 +02:00
|
|
|
// Options for all languages
|
|
|
|
copts bazel.StringListAttribute
|
|
|
|
// Assembly options and sources
|
|
|
|
asFlags bazel.StringListAttribute
|
|
|
|
asSrcs bazel.LabelListAttribute
|
2022-07-30 00:58:33 +02:00
|
|
|
asmSrcs bazel.LabelListAttribute
|
2021-05-25 18:10:58 +02:00
|
|
|
// C options and sources
|
|
|
|
conlyFlags bazel.StringListAttribute
|
|
|
|
cSrcs bazel.LabelListAttribute
|
|
|
|
// C++ options and sources
|
|
|
|
cppFlags bazel.StringListAttribute
|
2021-04-13 09:14:55 +02:00
|
|
|
srcs bazel.LabelListAttribute
|
2021-08-10 17:58:07 +02:00
|
|
|
|
2023-06-22 22:23:53 +02:00
|
|
|
// xsd config sources
|
|
|
|
xsdInSrcs bazel.StringListAttribute
|
|
|
|
|
2022-05-13 22:55:35 +02:00
|
|
|
// Lex sources and options
|
|
|
|
lSrcs bazel.LabelListAttribute
|
|
|
|
llSrcs bazel.LabelListAttribute
|
|
|
|
lexopts bazel.StringListAttribute
|
|
|
|
|
2022-09-06 21:31:25 +02:00
|
|
|
// Sysprop sources
|
|
|
|
syspropSrcs bazel.LabelListAttribute
|
|
|
|
|
2023-05-10 01:58:52 +02:00
|
|
|
// Yacc sources
|
|
|
|
yaccSrc *bazel.LabelAttribute
|
|
|
|
yaccFlags bazel.StringListAttribute
|
|
|
|
yaccGenLocationHeader bazel.BoolAttribute
|
|
|
|
yaccGenPositionHeader bazel.BoolAttribute
|
|
|
|
|
2023-04-24 16:57:32 +02:00
|
|
|
rsSrcs bazel.LabelListAttribute
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
hdrs bazel.LabelListAttribute
|
|
|
|
|
2021-08-10 17:58:07 +02:00
|
|
|
rtti bazel.BoolAttribute
|
2021-10-11 19:44:33 +02:00
|
|
|
|
|
|
|
// Not affected by arch variants
|
|
|
|
stl *string
|
2021-11-29 23:52:41 +01:00
|
|
|
cStd *string
|
2021-10-11 19:44:33 +02:00
|
|
|
cppStd *string
|
2021-09-10 16:07:07 +02:00
|
|
|
|
|
|
|
localIncludes bazel.StringListAttribute
|
|
|
|
absoluteIncludes bazel.StringListAttribute
|
2021-09-28 15:19:17 +02:00
|
|
|
|
2021-12-10 20:28:20 +01:00
|
|
|
includes BazelIncludes
|
|
|
|
|
2023-04-24 16:57:32 +02:00
|
|
|
protoSrcs bazel.LabelListAttribute
|
|
|
|
aidlSrcs bazel.LabelListAttribute
|
|
|
|
rscriptSrcs bazel.LabelListAttribute
|
2022-01-07 15:55:29 +01:00
|
|
|
|
|
|
|
stubsSymbolFile *string
|
|
|
|
stubsVersions bazel.StringListAttribute
|
2022-08-22 23:31:04 +02:00
|
|
|
|
|
|
|
features bazel.StringListAttribute
|
2022-02-24 00:39:59 +01:00
|
|
|
|
2023-05-26 20:03:39 +02:00
|
|
|
stem bazel.StringAttribute
|
2022-02-24 00:39:59 +01:00
|
|
|
suffix bazel.StringAttribute
|
2022-11-28 17:15:23 +01:00
|
|
|
|
|
|
|
fdoProfile bazel.LabelAttribute
|
2021-04-09 12:43:12 +02:00
|
|
|
}
|
|
|
|
|
2021-12-16 20:19:32 +01:00
|
|
|
type filterOutFn func(string) bool
|
|
|
|
|
2023-04-14 20:25:24 +02:00
|
|
|
// filterOutHiddenVisibility removes the flag specifying hidden visibility as
|
|
|
|
// this flag is converted to a toolchain feature
|
|
|
|
func filterOutHiddenVisibility(flag string) bool {
|
|
|
|
return flag == config.VisibilityHiddenFlag
|
|
|
|
}
|
|
|
|
|
2021-12-16 20:19:32 +01:00
|
|
|
func filterOutStdFlag(flag string) bool {
|
|
|
|
return strings.HasPrefix(flag, "-std=")
|
|
|
|
}
|
|
|
|
|
2022-05-17 00:56:04 +02:00
|
|
|
func filterOutClangUnknownCflags(flag string) bool {
|
|
|
|
for _, f := range config.ClangUnknownCflags {
|
|
|
|
if f == flag {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-09-20 20:58:01 +02:00
|
|
|
func parseCommandLineFlags(soongFlags []string, filterOut ...filterOutFn) []string {
|
2021-10-19 19:56:10 +02:00
|
|
|
var result []string
|
|
|
|
for _, flag := range soongFlags {
|
2022-05-17 00:56:04 +02:00
|
|
|
skipFlag := false
|
|
|
|
for _, filter := range filterOut {
|
|
|
|
if filter != nil && filter(flag) {
|
|
|
|
skipFlag = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if skipFlag {
|
2021-12-16 20:19:32 +01:00
|
|
|
continue
|
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
// Soong's cflags can contain spaces, like `-include header.h`. For
|
|
|
|
// Bazel's copts, split them up to be compatible with the
|
|
|
|
// no_copts_tokenization feature.
|
2022-09-20 20:58:01 +02:00
|
|
|
result = append(result, strings.Split(flag, " ")...)
|
2021-05-25 18:10:58 +02:00
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
return result
|
|
|
|
}
|
2021-05-25 18:10:58 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, config string, props *BaseCompilerProperties) {
|
2021-10-19 19:56:10 +02:00
|
|
|
// If there's arch specific srcs or exclude_srcs, generate a select entry for it.
|
|
|
|
// TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.
|
2023-06-22 22:23:53 +02:00
|
|
|
srcsList, xsdList, ok := parseSrcs(ctx, props)
|
|
|
|
|
|
|
|
if ok {
|
2021-10-19 19:56:10 +02:00
|
|
|
ca.srcs.SetSelectValue(axis, config, srcsList)
|
|
|
|
}
|
2023-06-22 22:23:53 +02:00
|
|
|
if len(xsdList) > 0 {
|
|
|
|
ca.xsdInSrcs.SetSelectValue(axis, config, xsdList)
|
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
|
|
|
|
localIncludeDirs := props.Local_include_dirs
|
|
|
|
if axis == bazel.NoConfigAxis {
|
2021-11-29 23:52:41 +01:00
|
|
|
ca.cStd, ca.cppStd = bp2buildResolveCppStdValue(props.C_std, props.Cpp_std, props.Gnu_extensions)
|
2021-10-19 19:56:10 +02:00
|
|
|
if includeBuildDirectory(props.Include_build_directory) {
|
|
|
|
localIncludeDirs = append(localIncludeDirs, ".")
|
2021-10-11 20:15:51 +02:00
|
|
|
}
|
2021-04-23 11:17:24 +02:00
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
ca.absoluteIncludes.SetSelectValue(axis, config, props.Include_dirs)
|
|
|
|
ca.localIncludes.SetSelectValue(axis, config, localIncludeDirs)
|
2021-10-11 19:44:33 +02:00
|
|
|
|
2022-08-22 23:31:04 +02:00
|
|
|
instructionSet := proptools.StringDefault(props.Instruction_set, "")
|
|
|
|
if instructionSet == "arm" {
|
2023-05-15 20:00:59 +02:00
|
|
|
ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm"})
|
2022-08-22 23:31:04 +02:00
|
|
|
} else if instructionSet != "" && instructionSet != "thumb" {
|
|
|
|
ctx.ModuleErrorf("Unknown value for instruction_set: %s", instructionSet)
|
|
|
|
}
|
|
|
|
|
2021-12-16 20:19:32 +01:00
|
|
|
// In Soong, cflags occur on the command line before -std=<val> flag, resulting in the value being
|
|
|
|
// overridden. In Bazel we always allow overriding, via flags; however, this can cause
|
|
|
|
// incompatibilities, so we remove "-std=" flags from Cflag properties while leaving it in other
|
|
|
|
// cases.
|
2023-04-14 20:25:24 +02:00
|
|
|
ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag, filterOutClangUnknownCflags, filterOutHiddenVisibility))
|
2022-09-20 20:58:01 +02:00
|
|
|
ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags, nil))
|
|
|
|
ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags, filterOutClangUnknownCflags))
|
|
|
|
ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags, filterOutClangUnknownCflags))
|
2021-10-19 19:56:10 +02:00
|
|
|
ca.rtti.SetSelectValue(axis, config, props.Rtti)
|
|
|
|
}
|
2021-07-13 17:47:44 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func (ca *compilerAttributes) convertStlProps(ctx android.ArchVariantContext, module *Module) {
|
2022-04-21 22:04:42 +02:00
|
|
|
bp2BuildPropParseHelper(ctx, module, &StlProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if stlProps, ok := props.(*StlProperties); ok {
|
|
|
|
if stlProps.Stl == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ca.stl == nil {
|
2022-05-12 17:42:33 +02:00
|
|
|
stl := deduplicateStlInput(*stlProps.Stl)
|
|
|
|
ca.stl = &stl
|
2022-04-21 22:04:42 +02:00
|
|
|
} else if ca.stl != stlProps.Stl {
|
|
|
|
ctx.ModuleErrorf("Unsupported conversion: module with different stl for different variants: %s and %s", *ca.stl, stlProps.Stl)
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-21 22:04:42 +02:00
|
|
|
})
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
2021-08-11 16:46:06 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func (ca *compilerAttributes) convertProductVariables(ctx android.BazelConversionPathContext, productVariableProps android.ProductConfigProperties) {
|
2021-10-19 19:56:10 +02:00
|
|
|
productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{
|
|
|
|
"Cflags": &ca.copts,
|
|
|
|
"Asflags": &ca.asFlags,
|
2023-05-01 22:49:52 +02:00
|
|
|
"Cppflags": &ca.cppFlags,
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
for propName, attr := range productVarPropNameToAttribute {
|
2021-11-15 13:28:43 +01:00
|
|
|
if productConfigProps, exists := productVariableProps[propName]; exists {
|
|
|
|
for productConfigProp, prop := range productConfigProps {
|
|
|
|
flags, ok := prop.([]string)
|
2021-10-19 19:56:10 +02:00
|
|
|
if !ok {
|
|
|
|
ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName))
|
|
|
|
}
|
2023-04-26 19:52:24 +02:00
|
|
|
newFlags, _ := bazel.TryVariableSubstitutions(flags, productConfigProp.Name())
|
2021-11-15 13:28:43 +01:00
|
|
|
attr.SetSelectValue(productConfigProp.ConfigurationAxis(), productConfigProp.SelectKey(), newFlags)
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
2021-04-05 12:35:13 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, implementationHdrs bazel.LabelListAttribute) {
|
2021-10-19 19:56:10 +02:00
|
|
|
ca.srcs.ResolveExcludes()
|
|
|
|
partitionedSrcs := groupSrcsByExtension(ctx, ca.srcs)
|
2021-10-19 15:45:48 +02:00
|
|
|
|
2021-09-28 15:19:17 +02:00
|
|
|
ca.protoSrcs = partitionedSrcs[protoSrcPartition]
|
2022-08-16 19:10:31 +02:00
|
|
|
ca.aidlSrcs = partitionedSrcs[aidlSrcPartition]
|
2021-09-28 15:19:17 +02:00
|
|
|
|
2021-10-19 15:45:48 +02:00
|
|
|
for p, lla := range partitionedSrcs {
|
|
|
|
// if there are no sources, there is no need for headers
|
|
|
|
if lla.IsEmpty() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
lla.Append(implementationHdrs)
|
|
|
|
partitionedSrcs[p] = lla
|
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
ca.srcs = partitionedSrcs[cppSrcPartition]
|
|
|
|
ca.cSrcs = partitionedSrcs[cSrcPartition]
|
|
|
|
ca.asSrcs = partitionedSrcs[asSrcPartition]
|
2022-07-30 00:58:33 +02:00
|
|
|
ca.asmSrcs = partitionedSrcs[asmSrcPartition]
|
2022-05-13 22:55:35 +02:00
|
|
|
ca.lSrcs = partitionedSrcs[lSrcPartition]
|
|
|
|
ca.llSrcs = partitionedSrcs[llSrcPartition]
|
2023-05-10 01:58:52 +02:00
|
|
|
if yacc := partitionedSrcs[yaccSrcPartition]; !yacc.IsEmpty() {
|
|
|
|
if len(yacc.Value.Includes) > 1 {
|
|
|
|
ctx.PropertyErrorf("srcs", "Found multiple yacc (.y/.yy) files in library")
|
|
|
|
}
|
|
|
|
ca.yaccSrc = bazel.MakeLabelAttribute(yacc.Value.Includes[0].Label)
|
|
|
|
}
|
2022-09-06 21:31:25 +02:00
|
|
|
ca.syspropSrcs = partitionedSrcs[syspropSrcPartition]
|
2023-04-24 16:57:32 +02:00
|
|
|
ca.rscriptSrcs = partitionedSrcs[rScriptSrcPartition]
|
2021-10-19 15:45:48 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
ca.absoluteIncludes.DeduplicateAxesFromBase()
|
|
|
|
ca.localIncludes.DeduplicateAxesFromBase()
|
|
|
|
}
|
2021-04-05 12:35:13 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
// Parse srcs from an arch or OS's props value.
|
2023-06-22 22:23:53 +02:00
|
|
|
func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, []string, bool) {
|
2021-10-19 19:56:10 +02:00
|
|
|
anySrcs := false
|
|
|
|
// Add srcs-like dependencies such as generated files.
|
|
|
|
// First create a LabelList containing these dependencies, then merge the values with srcs.
|
2023-06-22 22:23:53 +02:00
|
|
|
genSrcs, xsd := android.PartitionXsdSrcs(ctx, props.Generated_sources)
|
2023-06-01 01:32:40 +02:00
|
|
|
generatedSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, genSrcs, props.Exclude_generated_sources)
|
2021-10-19 19:56:10 +02:00
|
|
|
if len(props.Generated_sources) > 0 || len(props.Exclude_generated_sources) > 0 {
|
|
|
|
anySrcs = true
|
2021-05-26 14:45:30 +02:00
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
|
|
|
|
allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, props.Srcs, props.Exclude_srcs)
|
2022-08-16 19:10:31 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 {
|
|
|
|
anySrcs = true
|
|
|
|
}
|
2022-08-16 19:10:31 +02:00
|
|
|
|
2023-06-22 22:23:53 +02:00
|
|
|
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), xsd, anySrcs
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
|
2022-05-26 05:19:37 +02:00
|
|
|
func bp2buildStdVal(std *string, prefix string, useGnu bool) *string {
|
|
|
|
defaultVal := prefix + "_std_default"
|
2021-11-29 23:52:41 +01:00
|
|
|
// If c{,pp}std properties are not specified, don't generate them in the BUILD file.
|
|
|
|
// Defaults are handled by the toolchain definition.
|
|
|
|
// However, if gnu_extensions is false, then the default gnu-to-c version must be specified.
|
2022-05-26 05:19:37 +02:00
|
|
|
stdVal := proptools.StringDefault(std, defaultVal)
|
|
|
|
if stdVal == "experimental" || stdVal == defaultVal {
|
|
|
|
if stdVal == "experimental" {
|
|
|
|
stdVal = prefix + "_std_experimental"
|
|
|
|
}
|
|
|
|
if !useGnu {
|
|
|
|
stdVal += "_no_gnu"
|
|
|
|
}
|
|
|
|
} else if !useGnu {
|
|
|
|
stdVal = gnuToCReplacer.Replace(stdVal)
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
2021-11-29 23:52:41 +01:00
|
|
|
|
2022-05-26 05:19:37 +02:00
|
|
|
if stdVal == defaultVal {
|
|
|
|
return nil
|
2021-12-01 16:09:34 +01:00
|
|
|
}
|
2022-05-26 05:19:37 +02:00
|
|
|
return &stdVal
|
|
|
|
}
|
|
|
|
|
|
|
|
func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) {
|
|
|
|
useGnu := useGnuExtensions(gnu_extensions)
|
2021-12-01 16:09:34 +01:00
|
|
|
|
2022-05-26 05:19:37 +02:00
|
|
|
return bp2buildStdVal(c_std, "c", useGnu), bp2buildStdVal(cpp_std, "cpp", useGnu)
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
|
2021-12-10 20:28:20 +01:00
|
|
|
// packageFromLabel extracts package from a fully-qualified or relative Label and whether the label
|
|
|
|
// is fully-qualified.
|
|
|
|
// e.g. fully-qualified "//a/b:foo" -> "a/b", true, relative: ":bar" -> ".", false
|
|
|
|
func packageFromLabel(label string) (string, bool) {
|
|
|
|
split := strings.Split(label, ":")
|
|
|
|
if len(split) != 2 {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
if split[0] == "" {
|
|
|
|
return ".", false
|
|
|
|
}
|
|
|
|
// remove leading "//"
|
|
|
|
return split[0][2:], true
|
|
|
|
}
|
|
|
|
|
|
|
|
// includesFromLabelList extracts relative/absolute includes from a bazel.LabelList>
|
|
|
|
func includesFromLabelList(labelList bazel.LabelList) (relative, absolute []string) {
|
|
|
|
for _, hdr := range labelList.Includes {
|
|
|
|
if pkg, hasPkg := packageFromLabel(hdr.Label); hasPkg {
|
|
|
|
absolute = append(absolute, pkg)
|
|
|
|
} else if pkg != "" {
|
|
|
|
relative = append(relative, pkg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return relative, absolute
|
|
|
|
}
|
|
|
|
|
2022-07-30 00:58:33 +02:00
|
|
|
type YasmAttributes struct {
|
|
|
|
Srcs bazel.LabelListAttribute
|
|
|
|
Flags bazel.StringListAttribute
|
|
|
|
Include_dirs bazel.StringListAttribute
|
|
|
|
}
|
|
|
|
|
|
|
|
func bp2BuildYasm(ctx android.Bp2buildMutatorContext, m *Module, ca compilerAttributes) *bazel.LabelAttribute {
|
|
|
|
if ca.asmSrcs.IsEmpty() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yasm needs the include directories from both local_includes and
|
|
|
|
// export_include_dirs. We don't care about actually exporting them from the
|
|
|
|
// yasm rule though, because they will also be present on the cc_ rule that
|
|
|
|
// wraps this yasm rule.
|
|
|
|
includes := ca.localIncludes.Clone()
|
|
|
|
bp2BuildPropParseHelper(ctx, m, &FlagExporterProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
|
|
|
|
if len(flagExporterProperties.Export_include_dirs) > 0 {
|
|
|
|
x := bazel.StringListAttribute{}
|
|
|
|
x.SetSelectValue(axis, config, flagExporterProperties.Export_include_dirs)
|
|
|
|
includes.Append(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx.CreateBazelTargetModule(
|
|
|
|
bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "yasm",
|
|
|
|
Bzl_load_location: "//build/bazel/rules/cc:yasm.bzl",
|
|
|
|
},
|
|
|
|
android.CommonAttributes{Name: m.Name() + "_yasm"},
|
|
|
|
&YasmAttributes{
|
|
|
|
Srcs: ca.asmSrcs,
|
|
|
|
Flags: ca.asFlags,
|
|
|
|
Include_dirs: *includes,
|
|
|
|
})
|
|
|
|
|
|
|
|
// We only want to add a dependency on the _yasm target if there are asm
|
|
|
|
// sources in the current configuration. If there are unconfigured asm
|
|
|
|
// sources, always add the dependency. Otherwise, add the dependency only
|
|
|
|
// on the configuration axes and values that had asm sources.
|
|
|
|
if len(ca.asmSrcs.Value.Includes) > 0 {
|
|
|
|
return bazel.MakeLabelAttribute(":" + m.Name() + "_yasm")
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := &bazel.LabelAttribute{}
|
|
|
|
for _, axis := range ca.asmSrcs.SortedConfigurationAxes() {
|
2022-12-30 02:11:49 +01:00
|
|
|
for cfg := range ca.asmSrcs.ConfigurableValues[axis] {
|
|
|
|
ret.SetSelectValue(axis, cfg, bazel.Label{Label: ":" + m.Name() + "_yasm"})
|
2022-07-30 00:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2022-01-07 15:55:29 +01:00
|
|
|
// bp2BuildParseBaseProps returns all compiler, linker, library attributes of a cc module..
|
2021-09-28 15:19:17 +02:00
|
|
|
func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) baseAttributes {
|
2021-10-19 19:56:10 +02:00
|
|
|
archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
|
|
|
|
archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{})
|
2022-01-07 15:55:29 +01:00
|
|
|
archVariantLibraryProperties := module.GetArchVariantProperties(ctx, &LibraryProperties{})
|
2021-10-19 19:56:10 +02:00
|
|
|
|
|
|
|
var implementationHdrs bazel.LabelListAttribute
|
|
|
|
|
|
|
|
axisToConfigs := map[bazel.ConfigurationAxis]map[string]bool{}
|
|
|
|
allAxesAndConfigs := func(cp android.ConfigurationAxisToArchVariantProperties) {
|
|
|
|
for axis, configMap := range cp {
|
|
|
|
if _, ok := axisToConfigs[axis]; !ok {
|
|
|
|
axisToConfigs[axis] = map[string]bool{}
|
|
|
|
}
|
2022-12-30 02:11:49 +01:00
|
|
|
for cfg := range configMap {
|
|
|
|
axisToConfigs[axis][cfg] = true
|
2021-05-06 19:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
allAxesAndConfigs(archVariantCompilerProps)
|
|
|
|
allAxesAndConfigs(archVariantLinkerProps)
|
2022-01-07 15:55:29 +01:00
|
|
|
allAxesAndConfigs(archVariantLibraryProperties)
|
2021-05-06 19:54:29 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
compilerAttrs := compilerAttributes{}
|
|
|
|
linkerAttrs := linkerAttributes{}
|
|
|
|
|
2023-04-28 17:21:25 +02:00
|
|
|
var aidlLibs bazel.LabelList
|
|
|
|
|
2023-01-26 23:30:44 +01:00
|
|
|
// Iterate through these axes in a deterministic order. This is required
|
|
|
|
// because processing certain dependencies may result in concatenating
|
|
|
|
// elements along other axes. (For example, processing NoConfig may result
|
|
|
|
// in elements being added to InApex). This is thus the only way to ensure
|
|
|
|
// that the order of entries in each list is in a predictable order.
|
|
|
|
for _, axis := range bazel.SortedConfigurationAxes(axisToConfigs) {
|
|
|
|
configs := axisToConfigs[axis]
|
2022-12-30 02:11:49 +01:00
|
|
|
for cfg := range configs {
|
2023-06-22 22:23:53 +02:00
|
|
|
var allHdrs, allHdrsXsd []string
|
2022-12-30 02:11:49 +01:00
|
|
|
if baseCompilerProps, ok := archVariantCompilerProps[axis][cfg].(*BaseCompilerProperties); ok {
|
2023-06-22 22:23:53 +02:00
|
|
|
allHdrs, allHdrsXsd = android.PartitionXsdSrcs(ctx, baseCompilerProps.Generated_headers)
|
2023-06-01 01:32:40 +02:00
|
|
|
|
2022-05-13 22:55:35 +02:00
|
|
|
if baseCompilerProps.Lex != nil {
|
2022-12-30 02:11:49 +01:00
|
|
|
compilerAttrs.lexopts.SetSelectValue(axis, cfg, baseCompilerProps.Lex.Flags)
|
2022-05-13 22:55:35 +02:00
|
|
|
}
|
2023-05-10 01:58:52 +02:00
|
|
|
if baseCompilerProps.Yacc != nil {
|
|
|
|
compilerAttrs.yaccFlags.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Flags)
|
|
|
|
compilerAttrs.yaccGenLocationHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_location_hh)
|
|
|
|
compilerAttrs.yaccGenPositionHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_position_hh)
|
|
|
|
}
|
2022-12-30 02:11:49 +01:00
|
|
|
(&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, cfg, baseCompilerProps)
|
2023-04-28 17:21:25 +02:00
|
|
|
aidlLibs.Append(android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Aidl.Libs))
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
|
2023-06-22 22:23:53 +02:00
|
|
|
var exportHdrs, exportHdrsXsd []string
|
2021-10-19 19:56:10 +02:00
|
|
|
|
2022-12-30 02:11:49 +01:00
|
|
|
if baseLinkerProps, ok := archVariantLinkerProps[axis][cfg].(*BaseLinkerProperties); ok {
|
2023-06-22 22:23:53 +02:00
|
|
|
exportHdrs, exportHdrsXsd = android.PartitionXsdSrcs(ctx, baseLinkerProps.Export_generated_headers)
|
2023-03-17 15:17:50 +01:00
|
|
|
(&linkerAttrs).bp2buildForAxisAndConfig(ctx, module, axis, cfg, baseLinkerProps)
|
2021-09-23 22:34:35 +02:00
|
|
|
}
|
2023-06-22 22:23:53 +02:00
|
|
|
|
|
|
|
// in the synthetic bp2build workspace, xsd sources are compiled to a static library
|
|
|
|
xsdList := compilerAttrs.xsdInSrcs.SelectValue(axis, cfg)
|
|
|
|
allHdrsXsd = android.FirstUniqueStrings(append(xsdList, allHdrsXsd...))
|
2021-10-19 19:56:10 +02:00
|
|
|
headers := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrs, exportHdrs, android.BazelLabelForModuleDeps)
|
2023-06-22 22:23:53 +02:00
|
|
|
xsdConfigLibs := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrsXsd, exportHdrsXsd, bazelLabelForXsdConfig)
|
|
|
|
|
2022-12-30 02:11:49 +01:00
|
|
|
implementationHdrs.SetSelectValue(axis, cfg, headers.implementation)
|
|
|
|
compilerAttrs.hdrs.SetSelectValue(axis, cfg, headers.export)
|
2021-12-10 20:28:20 +01:00
|
|
|
|
|
|
|
exportIncludes, exportAbsoluteIncludes := includesFromLabelList(headers.export)
|
2022-12-30 02:11:49 +01:00
|
|
|
compilerAttrs.includes.Includes.SetSelectValue(axis, cfg, exportIncludes)
|
|
|
|
compilerAttrs.includes.AbsoluteIncludes.SetSelectValue(axis, cfg, exportAbsoluteIncludes)
|
2021-12-10 20:28:20 +01:00
|
|
|
|
|
|
|
includes, absoluteIncludes := includesFromLabelList(headers.implementation)
|
2022-12-30 02:11:49 +01:00
|
|
|
currAbsoluteIncludes := compilerAttrs.absoluteIncludes.SelectValue(axis, cfg)
|
2021-12-10 20:28:20 +01:00
|
|
|
currAbsoluteIncludes = android.FirstUniqueStrings(append(currAbsoluteIncludes, absoluteIncludes...))
|
2022-08-16 19:10:31 +02:00
|
|
|
|
2022-12-30 02:11:49 +01:00
|
|
|
compilerAttrs.absoluteIncludes.SetSelectValue(axis, cfg, currAbsoluteIncludes)
|
2022-08-16 19:10:31 +02:00
|
|
|
|
2022-12-30 02:11:49 +01:00
|
|
|
currIncludes := compilerAttrs.localIncludes.SelectValue(axis, cfg)
|
2021-12-10 20:28:20 +01:00
|
|
|
currIncludes = android.FirstUniqueStrings(append(currIncludes, includes...))
|
2022-08-16 19:10:31 +02:00
|
|
|
|
2022-12-30 02:11:49 +01:00
|
|
|
compilerAttrs.localIncludes.SetSelectValue(axis, cfg, currIncludes)
|
2022-01-07 15:55:29 +01:00
|
|
|
|
2022-12-30 02:11:49 +01:00
|
|
|
if libraryProps, ok := archVariantLibraryProperties[axis][cfg].(*LibraryProperties); ok {
|
2022-01-07 15:55:29 +01:00
|
|
|
if axis == bazel.NoConfigAxis {
|
2023-04-20 15:13:25 +02:00
|
|
|
if libraryProps.Stubs.Symbol_file != nil {
|
|
|
|
compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file
|
|
|
|
versions := android.CopyOf(libraryProps.Stubs.Versions)
|
|
|
|
normalizeVersions(ctx, versions)
|
|
|
|
versions = addCurrentVersionIfNotPresent(versions)
|
|
|
|
compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, versions)
|
|
|
|
}
|
2022-01-07 15:55:29 +01:00
|
|
|
}
|
2023-05-26 20:03:39 +02:00
|
|
|
if stem := libraryProps.Stem; stem != nil {
|
|
|
|
compilerAttrs.stem.SetSelectValue(axis, cfg, stem)
|
|
|
|
}
|
2022-02-24 00:39:59 +01:00
|
|
|
if suffix := libraryProps.Suffix; suffix != nil {
|
2022-12-30 02:11:49 +01:00
|
|
|
compilerAttrs.suffix.SetSelectValue(axis, cfg, suffix)
|
2022-02-24 00:39:59 +01:00
|
|
|
}
|
2022-01-07 15:55:29 +01:00
|
|
|
}
|
2023-06-22 22:23:53 +02:00
|
|
|
|
|
|
|
if len(allHdrsXsd) > 0 {
|
|
|
|
wholeStaticLibs := linkerAttrs.implementationWholeArchiveDeps.SelectValue(axis, cfg)
|
|
|
|
(&wholeStaticLibs).Append(xsdConfigLibs.implementation)
|
|
|
|
linkerAttrs.implementationWholeArchiveDeps.SetSelectValue(axis, cfg, wholeStaticLibs)
|
|
|
|
wholeStaticLibs = linkerAttrs.wholeArchiveDeps.SelectValue(axis, cfg)
|
|
|
|
(&wholeStaticLibs).Append(xsdConfigLibs.export)
|
|
|
|
linkerAttrs.wholeArchiveDeps.SetSelectValue(axis, cfg, wholeStaticLibs)
|
|
|
|
}
|
2021-09-23 22:34:35 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-16 19:10:31 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
compilerAttrs.convertStlProps(ctx, module)
|
|
|
|
(&linkerAttrs).convertStripProps(ctx, module)
|
|
|
|
|
2022-12-08 00:45:30 +01:00
|
|
|
var nativeCoverage *bool
|
2022-05-18 00:13:28 +02:00
|
|
|
if module.coverage != nil && module.coverage.Properties.Native_coverage != nil &&
|
|
|
|
!Bool(module.coverage.Properties.Native_coverage) {
|
2022-12-08 00:45:30 +01:00
|
|
|
nativeCoverage = BoolPtr(false)
|
2022-05-18 00:13:28 +02:00
|
|
|
}
|
|
|
|
|
2023-03-08 21:29:50 +01:00
|
|
|
productVariableProps := android.ProductVariableProperties(ctx, ctx.Module())
|
2021-10-19 19:56:10 +02:00
|
|
|
|
|
|
|
(&compilerAttrs).convertProductVariables(ctx, productVariableProps)
|
|
|
|
(&linkerAttrs).convertProductVariables(ctx, productVariableProps)
|
|
|
|
|
|
|
|
(&compilerAttrs).finalize(ctx, implementationHdrs)
|
2021-12-14 18:21:22 +01:00
|
|
|
(&linkerAttrs).finalize(ctx)
|
2021-10-19 19:56:10 +02:00
|
|
|
|
2022-07-30 00:58:33 +02:00
|
|
|
(&compilerAttrs.srcs).Add(bp2BuildYasm(ctx, module, compilerAttrs))
|
|
|
|
|
2021-09-28 15:19:17 +02:00
|
|
|
protoDep := bp2buildProto(ctx, module, compilerAttrs.protoSrcs)
|
|
|
|
|
|
|
|
// bp2buildProto will only set wholeStaticLib or implementationWholeStaticLib, but we don't know
|
|
|
|
// which. This will add the newly generated proto library to the appropriate attribute and nothing
|
|
|
|
// to the other
|
|
|
|
(&linkerAttrs).wholeArchiveDeps.Add(protoDep.wholeStaticLib)
|
|
|
|
(&linkerAttrs).implementationWholeArchiveDeps.Add(protoDep.implementationWholeStaticLib)
|
2022-08-29 23:46:58 +02:00
|
|
|
|
2023-04-28 17:21:25 +02:00
|
|
|
aidlDep := bp2buildCcAidlLibrary(
|
|
|
|
ctx, module,
|
|
|
|
compilerAttrs.aidlSrcs,
|
|
|
|
bazel.LabelListAttribute{
|
|
|
|
Value: aidlLibs,
|
|
|
|
},
|
|
|
|
linkerAttrs,
|
2023-04-28 17:21:25 +02:00
|
|
|
compilerAttrs,
|
2023-04-28 17:21:25 +02:00
|
|
|
)
|
2022-08-29 23:46:58 +02:00
|
|
|
if aidlDep != nil {
|
|
|
|
if lib, ok := module.linker.(*libraryDecorator); ok {
|
|
|
|
if proptools.Bool(lib.Properties.Aidl.Export_aidl_headers) {
|
|
|
|
(&linkerAttrs).wholeArchiveDeps.Add(aidlDep)
|
|
|
|
} else {
|
|
|
|
(&linkerAttrs).implementationWholeArchiveDeps.Add(aidlDep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 15:19:17 +02:00
|
|
|
|
2023-05-10 01:58:52 +02:00
|
|
|
// Create a cc_yacc_static_library if srcs contains .y/.yy files
|
|
|
|
// This internal target will produce an .a file that will be statically linked to the parent library
|
|
|
|
if yaccDep := bp2buildCcYaccLibrary(ctx, compilerAttrs, linkerAttrs); yaccDep != nil {
|
|
|
|
(&linkerAttrs).implementationWholeArchiveDeps.Add(yaccDep)
|
|
|
|
}
|
|
|
|
|
2022-05-13 22:55:35 +02:00
|
|
|
convertedLSrcs := bp2BuildLex(ctx, module.Name(), compilerAttrs)
|
|
|
|
(&compilerAttrs).srcs.Add(&convertedLSrcs.srcName)
|
|
|
|
(&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName)
|
|
|
|
|
2022-11-28 17:15:23 +01:00
|
|
|
if module.afdo != nil && module.afdo.Properties.Afdo {
|
|
|
|
fdoProfileDep := bp2buildFdoProfile(ctx, module)
|
|
|
|
if fdoProfileDep != nil {
|
|
|
|
(&compilerAttrs).fdoProfile.SetValue(*fdoProfileDep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-06 21:31:25 +02:00
|
|
|
if !compilerAttrs.syspropSrcs.IsEmpty() {
|
|
|
|
(&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs))
|
|
|
|
}
|
|
|
|
|
2023-01-04 20:06:54 +01:00
|
|
|
linkerAttrs.wholeArchiveDeps.Prepend = true
|
|
|
|
linkerAttrs.deps.Prepend = true
|
|
|
|
compilerAttrs.localIncludes.Prepend = true
|
|
|
|
compilerAttrs.absoluteIncludes.Prepend = true
|
|
|
|
compilerAttrs.hdrs.Prepend = true
|
|
|
|
|
2023-04-24 16:57:32 +02:00
|
|
|
convertedRsSrcs, rsAbsIncludes, rsLocalIncludes := bp2buildRScript(ctx, module, compilerAttrs)
|
|
|
|
(&compilerAttrs).srcs.Add(&convertedRsSrcs)
|
|
|
|
(&compilerAttrs).absoluteIncludes.Append(rsAbsIncludes)
|
|
|
|
(&compilerAttrs).localIncludes.Append(rsLocalIncludes)
|
|
|
|
(&compilerAttrs).localIncludes.Value = android.FirstUniqueStrings(compilerAttrs.localIncludes.Value)
|
|
|
|
|
2022-10-28 18:48:18 +02:00
|
|
|
features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module))
|
2023-02-06 22:58:30 +01:00
|
|
|
features = features.Append(bp2buildLtoFeatures(ctx, module))
|
2023-04-14 20:25:24 +02:00
|
|
|
features = features.Append(convertHiddenVisibilityToFeatureBase(ctx, module))
|
2022-08-22 23:31:04 +02:00
|
|
|
features.DeduplicateAxesFromBase()
|
|
|
|
|
2022-12-12 23:26:34 +01:00
|
|
|
addMuslSystemDynamicDeps(ctx, linkerAttrs)
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
return baseAttributes{
|
|
|
|
compilerAttrs,
|
|
|
|
linkerAttrs,
|
2022-08-22 23:31:04 +02:00
|
|
|
*features,
|
2021-09-28 15:19:17 +02:00
|
|
|
protoDep.protoDep,
|
2022-08-16 19:10:31 +02:00
|
|
|
aidlDep,
|
2022-12-08 00:45:30 +01:00
|
|
|
nativeCoverage,
|
2022-08-16 19:10:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-10 01:58:52 +02:00
|
|
|
type ccYaccLibraryAttributes struct {
|
|
|
|
Src bazel.LabelAttribute
|
|
|
|
Flags bazel.StringListAttribute
|
|
|
|
Gen_location_hh bazel.BoolAttribute
|
|
|
|
Gen_position_hh bazel.BoolAttribute
|
|
|
|
Local_includes bazel.StringListAttribute
|
|
|
|
Implementation_deps bazel.LabelListAttribute
|
|
|
|
Implementation_dynamic_deps bazel.LabelListAttribute
|
|
|
|
}
|
|
|
|
|
|
|
|
func bp2buildCcYaccLibrary(ctx android.Bp2buildMutatorContext, ca compilerAttributes, la linkerAttributes) *bazel.LabelAttribute {
|
|
|
|
if ca.yaccSrc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
yaccLibraryLabel := ctx.Module().Name() + "_yacc"
|
|
|
|
ctx.CreateBazelTargetModule(
|
|
|
|
bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "cc_yacc_static_library",
|
|
|
|
Bzl_load_location: "//build/bazel/rules/cc:cc_yacc_library.bzl",
|
|
|
|
},
|
|
|
|
android.CommonAttributes{
|
|
|
|
Name: yaccLibraryLabel,
|
|
|
|
},
|
|
|
|
&ccYaccLibraryAttributes{
|
|
|
|
Src: *ca.yaccSrc,
|
|
|
|
Flags: ca.yaccFlags,
|
|
|
|
Gen_location_hh: ca.yaccGenLocationHeader,
|
|
|
|
Gen_position_hh: ca.yaccGenPositionHeader,
|
|
|
|
Local_includes: ca.localIncludes,
|
|
|
|
Implementation_deps: la.implementationDeps,
|
|
|
|
Implementation_dynamic_deps: la.implementationDynamicDeps,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
yaccLibrary := &bazel.LabelAttribute{
|
|
|
|
Value: &bazel.Label{
|
|
|
|
Label: ":" + yaccLibraryLabel,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return yaccLibrary
|
|
|
|
}
|
|
|
|
|
2022-12-12 23:26:34 +01:00
|
|
|
// As a workaround for b/261657184, we are manually adding the default value
|
|
|
|
// of system_dynamic_deps for the linux_musl os.
|
|
|
|
// TODO: Solve this properly
|
|
|
|
func addMuslSystemDynamicDeps(ctx android.Bp2buildMutatorContext, attrs linkerAttributes) {
|
|
|
|
systemDynamicDeps := attrs.systemDynamicDeps.SelectValue(bazel.OsConfigurationAxis, "linux_musl")
|
|
|
|
if attrs.systemDynamicDeps.HasAxisSpecificValues(bazel.OsConfigurationAxis) && systemDynamicDeps.IsNil() {
|
|
|
|
attrs.systemDynamicDeps.SetSelectValue(bazel.OsConfigurationAxis, "linux_musl", android.BazelLabelForModuleDeps(ctx, config.MuslDefaultSharedLibraries))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 17:15:23 +01:00
|
|
|
type fdoProfileAttributes struct {
|
|
|
|
Absolute_path_profile string
|
|
|
|
}
|
|
|
|
|
|
|
|
func bp2buildFdoProfile(
|
|
|
|
ctx android.Bp2buildMutatorContext,
|
|
|
|
m *Module,
|
|
|
|
) *bazel.Label {
|
|
|
|
for _, project := range globalAfdoProfileProjects {
|
2022-12-09 18:03:52 +01:00
|
|
|
// Ensure handcrafted BUILD file exists in the project
|
|
|
|
BUILDPath := android.ExistentPathForSource(ctx, project, "BUILD")
|
|
|
|
if BUILDPath.Valid() {
|
|
|
|
// We handcraft a BUILD file with fdo_profile targets that use the existing profiles in the project
|
|
|
|
// This implementation is assuming that every afdo profile in globalAfdoProfileProjects already has
|
|
|
|
// an associated fdo_profile target declared in the same package.
|
|
|
|
// TODO(b/260714900): Handle arch-specific afdo profiles (e.g. `<module-name>-arm<64>.afdo`)
|
|
|
|
path := android.ExistentPathForSource(ctx, project, m.Name()+".afdo")
|
|
|
|
if path.Valid() {
|
|
|
|
// FIXME: Some profiles only exist internally and are not released to AOSP.
|
|
|
|
// When generated BUILD files are checked in, we'll run into merge conflict.
|
|
|
|
// The cc_library_shared target in AOSP won't have reference to an fdo_profile target because
|
|
|
|
// the profile doesn't exist. Internally, the same cc_library_shared target will
|
|
|
|
// have reference to the fdo_profile.
|
|
|
|
// For more context, see b/258682955#comment2
|
|
|
|
fdoProfileLabel := "//" + strings.TrimSuffix(project, "/") + ":" + m.Name()
|
|
|
|
return &bazel.Label{
|
|
|
|
Label: fdoProfileLabel,
|
|
|
|
}
|
2022-11-28 17:15:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-16 19:10:31 +02:00
|
|
|
func bp2buildCcAidlLibrary(
|
|
|
|
ctx android.Bp2buildMutatorContext,
|
|
|
|
m *Module,
|
2023-04-28 17:21:25 +02:00
|
|
|
aidlSrcs bazel.LabelListAttribute,
|
|
|
|
aidlLibs bazel.LabelListAttribute,
|
2022-09-17 00:27:29 +02:00
|
|
|
linkerAttrs linkerAttributes,
|
2023-04-28 17:21:25 +02:00
|
|
|
compilerAttrs compilerAttributes,
|
2022-08-16 19:10:31 +02:00
|
|
|
) *bazel.LabelAttribute {
|
2023-04-28 17:21:25 +02:00
|
|
|
var aidlLibsFromSrcs, aidlFiles bazel.LabelListAttribute
|
|
|
|
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
|
|
|
|
|
|
|
|
if !aidlSrcs.IsEmpty() {
|
|
|
|
aidlLibsFromSrcs, aidlFiles = aidlSrcs.Partition(func(src bazel.Label) bool {
|
2022-09-14 17:40:24 +02:00
|
|
|
if fg, ok := android.ToFileGroupAsLibrary(ctx, src.OriginalModuleName); ok &&
|
|
|
|
fg.ShouldConvertToAidlLibrary(ctx) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
2022-08-16 19:10:31 +02:00
|
|
|
|
2023-04-28 17:21:25 +02:00
|
|
|
if !aidlFiles.IsEmpty() {
|
2022-09-14 17:40:24 +02:00
|
|
|
aidlLibName := m.Name() + "_aidl_library"
|
|
|
|
ctx.CreateBazelTargetModule(
|
|
|
|
bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "aidl_library",
|
2023-03-31 15:47:28 +02:00
|
|
|
Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl",
|
2022-09-14 17:40:24 +02:00
|
|
|
},
|
2023-04-28 17:21:25 +02:00
|
|
|
android.CommonAttributes{
|
|
|
|
Name: aidlLibName,
|
2023-03-23 16:51:49 +01:00
|
|
|
Tags: apexAvailableTags,
|
2022-09-14 17:40:24 +02:00
|
|
|
},
|
2023-04-28 17:21:25 +02:00
|
|
|
&aidlLibraryAttributes{
|
|
|
|
Srcs: aidlFiles,
|
|
|
|
},
|
2022-09-14 17:40:24 +02:00
|
|
|
)
|
2023-04-28 17:21:25 +02:00
|
|
|
aidlLibsFromSrcs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
|
2022-09-14 17:40:24 +02:00
|
|
|
}
|
2023-04-28 17:21:25 +02:00
|
|
|
}
|
2022-08-16 19:10:31 +02:00
|
|
|
|
2023-04-28 17:21:25 +02:00
|
|
|
allAidlLibs := aidlLibs.Clone()
|
|
|
|
allAidlLibs.Append(aidlLibsFromSrcs)
|
2022-09-17 00:27:29 +02:00
|
|
|
|
2023-04-28 17:21:25 +02:00
|
|
|
if !allAidlLibs.IsEmpty() {
|
|
|
|
ccAidlLibrarylabel := m.Name() + "_cc_aidl_library"
|
|
|
|
// Since parent cc_library already has these dependencies, we can add them as implementation
|
|
|
|
// deps so that they don't re-export
|
|
|
|
implementationDeps := linkerAttrs.deps.Clone()
|
|
|
|
implementationDeps.Append(linkerAttrs.implementationDeps)
|
|
|
|
implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone()
|
|
|
|
implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps)
|
|
|
|
|
|
|
|
sdkAttrs := bp2BuildParseSdkAttributes(m)
|
|
|
|
|
2023-04-28 17:21:25 +02:00
|
|
|
exportedIncludes := bp2BuildParseExportedIncludes(ctx, m, &compilerAttrs.includes)
|
|
|
|
includeAttrs := includesAttributes{
|
|
|
|
Export_includes: exportedIncludes.Includes,
|
|
|
|
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
|
|
|
|
Export_system_includes: exportedIncludes.SystemIncludes,
|
|
|
|
Local_includes: compilerAttrs.localIncludes,
|
|
|
|
Absolute_includes: compilerAttrs.absoluteIncludes,
|
|
|
|
}
|
|
|
|
|
2023-04-28 17:21:25 +02:00
|
|
|
ctx.CreateBazelTargetModule(
|
|
|
|
bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "cc_aidl_library",
|
|
|
|
Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl",
|
|
|
|
},
|
|
|
|
android.CommonAttributes{Name: ccAidlLibrarylabel},
|
|
|
|
&ccAidlLibraryAttributes{
|
|
|
|
Deps: *allAidlLibs,
|
|
|
|
Implementation_deps: *implementationDeps,
|
|
|
|
Implementation_dynamic_deps: *implementationDynamicDeps,
|
|
|
|
Tags: apexAvailableTags,
|
|
|
|
sdkAttributes: sdkAttrs,
|
2023-04-28 17:21:25 +02:00
|
|
|
includesAttributes: includeAttrs,
|
2023-04-28 17:21:25 +02:00
|
|
|
},
|
|
|
|
)
|
|
|
|
label := &bazel.LabelAttribute{
|
|
|
|
Value: &bazel.Label{
|
|
|
|
Label: ":" + ccAidlLibrarylabel,
|
|
|
|
},
|
2022-09-14 17:40:24 +02:00
|
|
|
}
|
2023-04-28 17:21:25 +02:00
|
|
|
return label
|
2022-08-16 19:10:31 +02:00
|
|
|
}
|
|
|
|
|
2022-09-14 17:40:24 +02:00
|
|
|
return nil
|
2021-04-09 12:43:12 +02:00
|
|
|
}
|
|
|
|
|
2022-03-02 00:44:08 +01:00
|
|
|
func bp2BuildParseSdkAttributes(module *Module) sdkAttributes {
|
2022-04-07 22:36:39 +02:00
|
|
|
return sdkAttributes{
|
|
|
|
Sdk_version: module.Properties.Sdk_version,
|
2022-03-02 00:44:08 +01:00
|
|
|
Min_sdk_version: module.Properties.Min_sdk_version,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type sdkAttributes struct {
|
|
|
|
Sdk_version *string
|
|
|
|
Min_sdk_version *string
|
|
|
|
}
|
|
|
|
|
2021-04-09 12:43:12 +02:00
|
|
|
// Convenience struct to hold all attributes parsed from linker properties.
|
|
|
|
type linkerAttributes struct {
|
2021-12-14 18:21:22 +01:00
|
|
|
deps bazel.LabelListAttribute
|
|
|
|
implementationDeps bazel.LabelListAttribute
|
|
|
|
dynamicDeps bazel.LabelListAttribute
|
|
|
|
implementationDynamicDeps bazel.LabelListAttribute
|
2022-08-09 18:50:56 +02:00
|
|
|
runtimeDeps bazel.LabelListAttribute
|
2021-12-14 18:21:22 +01:00
|
|
|
wholeArchiveDeps bazel.LabelListAttribute
|
|
|
|
implementationWholeArchiveDeps bazel.LabelListAttribute
|
|
|
|
systemDynamicDeps bazel.LabelListAttribute
|
|
|
|
usedSystemDynamicDepAsDynamicDep map[string]bool
|
2021-09-22 21:52:58 +02:00
|
|
|
|
2021-12-10 13:22:53 +01:00
|
|
|
useVersionLib bazel.BoolAttribute
|
2021-06-09 09:18:37 +02:00
|
|
|
linkopts bazel.StringListAttribute
|
2021-10-04 19:54:37 +02:00
|
|
|
additionalLinkerInputs bazel.LabelListAttribute
|
2021-06-09 09:18:37 +02:00
|
|
|
stripKeepSymbols bazel.BoolAttribute
|
|
|
|
stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
|
|
|
|
stripKeepSymbolsList bazel.StringListAttribute
|
|
|
|
stripAll bazel.BoolAttribute
|
|
|
|
stripNone bazel.BoolAttribute
|
2021-10-06 16:32:26 +02:00
|
|
|
features bazel.StringListAttribute
|
2021-05-10 05:55:51 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 18:21:22 +01:00
|
|
|
var (
|
|
|
|
soongSystemSharedLibs = []string{"libc", "libm", "libdl"}
|
2022-09-16 15:01:29 +02:00
|
|
|
versionLib = "libbuildversion"
|
2021-12-14 18:21:22 +01:00
|
|
|
)
|
|
|
|
|
2022-09-16 22:17:48 +02:00
|
|
|
// resolveTargetApex re-adds the shared and static libs in target.apex.exclude_shared|static_libs props to non-apex variant
|
|
|
|
// since all libs are already excluded by default
|
2023-01-25 18:07:43 +01:00
|
|
|
func (la *linkerAttributes) resolveTargetApexProp(ctx android.BazelConversionPathContext, props *BaseLinkerProperties) {
|
|
|
|
excludeSharedLibs := bazelLabelForSharedDeps(ctx, props.Target.Apex.Exclude_shared_libs)
|
|
|
|
sharedExcludes := bazel.LabelList{Excludes: excludeSharedLibs.Includes}
|
|
|
|
sharedExcludesLabelList := bazel.LabelListAttribute{}
|
|
|
|
sharedExcludesLabelList.SetSelectValue(bazel.InApexAxis, bazel.InApex, sharedExcludes)
|
|
|
|
|
|
|
|
la.dynamicDeps.Append(sharedExcludesLabelList)
|
|
|
|
la.implementationDynamicDeps.Append(sharedExcludesLabelList)
|
|
|
|
|
|
|
|
excludeStaticLibs := bazelLabelForStaticDeps(ctx, props.Target.Apex.Exclude_static_libs)
|
|
|
|
staticExcludes := bazel.LabelList{Excludes: excludeStaticLibs.Includes}
|
|
|
|
staticExcludesLabelList := bazel.LabelListAttribute{}
|
|
|
|
staticExcludesLabelList.SetSelectValue(bazel.InApexAxis, bazel.InApex, staticExcludes)
|
|
|
|
|
|
|
|
la.deps.Append(staticExcludesLabelList)
|
|
|
|
la.implementationDeps.Append(staticExcludesLabelList)
|
2022-09-16 22:17:48 +02:00
|
|
|
}
|
|
|
|
|
2023-03-17 15:17:50 +01:00
|
|
|
func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, module *Module, axis bazel.ConfigurationAxis, config string, props *BaseLinkerProperties) {
|
|
|
|
isBinary := module.Binary()
|
2021-10-19 19:56:10 +02:00
|
|
|
// Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module
|
|
|
|
var axisFeatures []string
|
2021-09-22 21:52:58 +02:00
|
|
|
|
2022-03-21 14:03:29 +01:00
|
|
|
wholeStaticLibs := android.FirstUniqueStrings(props.Whole_static_libs)
|
2022-09-16 15:01:29 +02:00
|
|
|
staticLibs := android.FirstUniqueStrings(android.RemoveListFromList(props.Static_libs, wholeStaticLibs))
|
|
|
|
if axis == bazel.NoConfigAxis {
|
|
|
|
la.useVersionLib.SetSelectValue(axis, config, props.Use_version_lib)
|
|
|
|
if proptools.Bool(props.Use_version_lib) {
|
|
|
|
versionLibAlreadyInDeps := android.InList(versionLib, wholeStaticLibs)
|
|
|
|
// remove from static libs so there is no duplicate dependency
|
|
|
|
_, staticLibs = android.RemoveFromList(versionLib, staticLibs)
|
|
|
|
// only add the dep if it is not in progress
|
|
|
|
if !versionLibAlreadyInDeps {
|
2023-04-25 01:37:18 +02:00
|
|
|
wholeStaticLibs = append(wholeStaticLibs, versionLib)
|
2022-09-16 15:01:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
// Excludes to parallel Soong:
|
|
|
|
// https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
|
2022-09-16 15:01:29 +02:00
|
|
|
la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs))
|
2022-03-21 14:03:29 +01:00
|
|
|
|
2022-09-16 22:17:48 +02:00
|
|
|
staticDeps := maybePartitionExportedAndImplementationsDepsExcludes(
|
|
|
|
ctx,
|
|
|
|
!isBinary,
|
|
|
|
staticLibs,
|
2023-01-25 18:07:43 +01:00
|
|
|
props.Exclude_static_libs,
|
2022-09-16 22:17:48 +02:00
|
|
|
props.Export_static_lib_headers,
|
|
|
|
bazelLabelForStaticDepsExcludes,
|
|
|
|
)
|
2021-09-22 21:52:58 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
headerLibs := android.FirstUniqueStrings(props.Header_libs)
|
|
|
|
hDeps := maybePartitionExportedAndImplementationsDeps(ctx, !isBinary, headerLibs, props.Export_header_lib_headers, bazelLabelForHeaderDeps)
|
2021-03-24 15:04:33 +01:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
(&hDeps.export).Append(staticDeps.export)
|
|
|
|
la.deps.SetSelectValue(axis, config, hDeps.export)
|
2021-06-09 09:18:37 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
(&hDeps.implementation).Append(staticDeps.implementation)
|
|
|
|
la.implementationDeps.SetSelectValue(axis, config, hDeps.implementation)
|
2021-10-06 16:32:26 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
systemSharedLibs := props.System_shared_libs
|
|
|
|
// systemSharedLibs distinguishes between nil/empty list behavior:
|
|
|
|
// nil -> use default values
|
|
|
|
// empty list -> no values specified
|
|
|
|
if len(systemSharedLibs) > 0 {
|
|
|
|
systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs)
|
|
|
|
}
|
|
|
|
la.systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
|
2021-06-02 22:02:22 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
sharedLibs := android.FirstUniqueStrings(props.Shared_libs)
|
2021-12-14 18:21:22 +01:00
|
|
|
excludeSharedLibs := props.Exclude_shared_libs
|
|
|
|
usedSystem := android.FilterListPred(sharedLibs, func(s string) bool {
|
|
|
|
return android.InList(s, soongSystemSharedLibs) && !android.InList(s, excludeSharedLibs)
|
|
|
|
})
|
|
|
|
for _, el := range usedSystem {
|
|
|
|
if la.usedSystemDynamicDepAsDynamicDep == nil {
|
|
|
|
la.usedSystemDynamicDepAsDynamicDep = map[string]bool{}
|
|
|
|
}
|
|
|
|
la.usedSystemDynamicDepAsDynamicDep[el] = true
|
|
|
|
}
|
|
|
|
|
2022-09-16 22:17:48 +02:00
|
|
|
sharedDeps := maybePartitionExportedAndImplementationsDepsExcludes(
|
|
|
|
ctx,
|
|
|
|
!isBinary,
|
|
|
|
sharedLibs,
|
2023-01-25 18:07:43 +01:00
|
|
|
props.Exclude_shared_libs,
|
2022-09-16 22:17:48 +02:00
|
|
|
props.Export_shared_lib_headers,
|
|
|
|
bazelLabelForSharedDepsExcludes,
|
|
|
|
)
|
2021-10-19 19:56:10 +02:00
|
|
|
la.dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
|
|
|
|
la.implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
|
2023-01-25 18:07:43 +01:00
|
|
|
la.resolveTargetApexProp(ctx, props)
|
2022-09-16 22:17:48 +02:00
|
|
|
|
2022-07-27 09:22:06 +02:00
|
|
|
if axis == bazel.NoConfigAxis || (axis == bazel.OsConfigurationAxis && config == bazel.OsAndroid) {
|
2023-02-21 21:05:26 +01:00
|
|
|
// If a dependency in la.implementationDynamicDeps or la.dynamicDeps has stubs, its
|
|
|
|
// stub variant should be used when the dependency is linked in a APEX. The
|
|
|
|
// dependencies in NoConfigAxis and OsConfigurationAxis/OsAndroid are grouped by
|
|
|
|
// having stubs or not, so Bazel select() statement can be used to choose
|
|
|
|
// source/stub variants of them.
|
2023-03-17 15:17:50 +01:00
|
|
|
apexAvailable := module.ApexAvailable()
|
2023-04-24 02:07:38 +02:00
|
|
|
setStubsForDynamicDeps(ctx, axis, config, apexAvailable, sharedDeps.export, &la.dynamicDeps, 0, false)
|
|
|
|
setStubsForDynamicDeps(ctx, axis, config, apexAvailable, sharedDeps.implementation, &la.implementationDynamicDeps, 1, false)
|
|
|
|
if len(systemSharedLibs) > 0 {
|
|
|
|
setStubsForDynamicDeps(ctx, axis, config, apexAvailable, bazelLabelForSharedDeps(ctx, systemSharedLibs), &la.systemDynamicDeps, 2, true)
|
|
|
|
}
|
2022-07-27 09:22:06 +02:00
|
|
|
}
|
2021-09-22 21:52:58 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
if !BoolDefault(props.Pack_relocations, packRelocationsDefault) {
|
|
|
|
axisFeatures = append(axisFeatures, "disable_pack_relocations")
|
|
|
|
}
|
2021-05-19 12:49:02 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
if Bool(props.Allow_undefined_symbols) {
|
|
|
|
axisFeatures = append(axisFeatures, "-no_undefined_symbols")
|
|
|
|
}
|
2021-10-06 16:32:26 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
var linkerFlags []string
|
|
|
|
if len(props.Ldflags) > 0 {
|
2022-02-04 21:39:00 +01:00
|
|
|
linkerFlags = append(linkerFlags, proptools.NinjaEscapeList(props.Ldflags)...)
|
2021-10-19 19:56:10 +02:00
|
|
|
// binaries remove static flag if -shared is in the linker flags
|
|
|
|
if isBinary && android.InList("-shared", linkerFlags) {
|
|
|
|
axisFeatures = append(axisFeatures, "-static_flag")
|
|
|
|
}
|
|
|
|
}
|
2022-09-20 20:58:01 +02:00
|
|
|
|
2023-01-30 23:53:04 +01:00
|
|
|
if !props.libCrt() {
|
|
|
|
axisFeatures = append(axisFeatures, "-use_libcrt")
|
|
|
|
}
|
|
|
|
if !props.crt() {
|
|
|
|
axisFeatures = append(axisFeatures, "-link_crt")
|
|
|
|
}
|
|
|
|
|
2022-09-20 20:58:01 +02:00
|
|
|
// This must happen before the addition of flags for Version Script and
|
|
|
|
// Dynamic List, as these flags must be split on spaces and those must not
|
|
|
|
linkerFlags = parseCommandLineFlags(linkerFlags, filterOutClangUnknownCflags)
|
|
|
|
|
2022-09-27 03:46:01 +02:00
|
|
|
additionalLinkerInputs := bazel.LabelList{}
|
2021-10-19 19:56:10 +02:00
|
|
|
if props.Version_script != nil {
|
|
|
|
label := android.BazelLabelForModuleSrcSingle(ctx, *props.Version_script)
|
2022-09-27 03:46:01 +02:00
|
|
|
additionalLinkerInputs.Add(&label)
|
2021-10-19 19:56:10 +02:00
|
|
|
linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--version-script,$(location %s)", label.Label))
|
2023-05-19 16:51:41 +02:00
|
|
|
axisFeatures = append(axisFeatures, "android_cfi_exports_map")
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
2022-04-27 19:49:34 +02:00
|
|
|
|
|
|
|
if props.Dynamic_list != nil {
|
|
|
|
label := android.BazelLabelForModuleSrcSingle(ctx, *props.Dynamic_list)
|
2022-09-27 03:46:01 +02:00
|
|
|
additionalLinkerInputs.Add(&label)
|
2022-04-27 19:49:34 +02:00
|
|
|
linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--dynamic-list,$(location %s)", label.Label))
|
|
|
|
}
|
|
|
|
|
2022-09-27 03:46:01 +02:00
|
|
|
la.additionalLinkerInputs.SetSelectValue(axis, config, additionalLinkerInputs)
|
2023-05-15 20:35:36 +02:00
|
|
|
if axis == bazel.OsConfigurationAxis && (config == bazel.OsDarwin || config == bazel.OsLinux || config == bazel.OsWindows) {
|
|
|
|
linkerFlags = append(linkerFlags, props.Host_ldlibs...)
|
|
|
|
}
|
2022-09-20 20:58:01 +02:00
|
|
|
la.linkopts.SetSelectValue(axis, config, linkerFlags)
|
2021-10-06 16:32:26 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
if axisFeatures != nil {
|
|
|
|
la.features.SetSelectValue(axis, config, axisFeatures)
|
|
|
|
}
|
2022-08-09 18:50:56 +02:00
|
|
|
|
|
|
|
runtimeDeps := android.BazelLabelForModuleDepsExcludes(ctx, props.Runtime_libs, props.Exclude_runtime_libs)
|
|
|
|
if !runtimeDeps.IsEmpty() {
|
|
|
|
la.runtimeDeps.SetSelectValue(axis, config, runtimeDeps)
|
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
2021-10-06 16:32:26 +02:00
|
|
|
|
2023-03-17 04:02:32 +01:00
|
|
|
var (
|
|
|
|
apiSurfaceModuleLibCurrentPackage = "@api_surfaces//" + android.ModuleLibApi.String() + "/current:"
|
|
|
|
)
|
|
|
|
|
2023-03-17 15:17:50 +01:00
|
|
|
func availableToSameApexes(a, b []string) bool {
|
|
|
|
if len(a) == 0 && len(b) == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
differ, _, _ := android.ListSetDifference(a, b)
|
|
|
|
return !differ
|
|
|
|
}
|
|
|
|
|
2023-04-20 00:31:54 +02:00
|
|
|
var (
|
2023-05-04 19:15:44 +02:00
|
|
|
apiDomainConfigSettingKey = android.NewOnceKey("apiDomainConfigSettingKey")
|
|
|
|
apiDomainConfigSettingLock sync.Mutex
|
2023-04-20 00:31:54 +02:00
|
|
|
)
|
|
|
|
|
2023-05-04 19:15:44 +02:00
|
|
|
func getApiDomainConfigSettingMap(config android.Config) *map[string]bool {
|
|
|
|
return config.Once(apiDomainConfigSettingKey, func() interface{} {
|
2023-04-20 00:31:54 +02:00
|
|
|
return &map[string]bool{}
|
|
|
|
}).(*map[string]bool)
|
|
|
|
}
|
|
|
|
|
2023-05-04 19:15:44 +02:00
|
|
|
var (
|
|
|
|
testApexNameToApiDomain = map[string]string{
|
|
|
|
"test_broken_com.android.art": "com.android.art",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-05-08 20:33:16 +02:00
|
|
|
// GetApiDomain returns the canonical name of the apex. This is synonymous to the apex_name definition.
|
|
|
|
// https://cs.android.com/android/_/android/platform/build/soong/+/e3f0281b8897da1fe23b2f4f3a05f1dc87bcc902:apex/prebuilt.go;l=81-83;drc=2dc7244af985a6ad701b22f1271e606cabba527f;bpv=1;bpt=0
|
|
|
|
// For test apexes, it uses a naming convention heuristic to determine the api domain.
|
|
|
|
// TODO (b/281548611): Move this build/soong/android
|
|
|
|
func GetApiDomain(apexName string) string {
|
2023-05-04 19:15:44 +02:00
|
|
|
if apiDomain, exists := testApexNameToApiDomain[apexName]; exists {
|
|
|
|
return apiDomain
|
|
|
|
}
|
|
|
|
// Remove `test_` prefix
|
|
|
|
return strings.TrimPrefix(apexName, "test_")
|
|
|
|
}
|
|
|
|
|
2023-04-20 00:31:54 +02:00
|
|
|
// Create a config setting for this apex in build/bazel/rules/apex
|
|
|
|
// The use case for this is stub/impl selection in cc libraries
|
|
|
|
// Long term, these config_setting(s) should be colocated with the respective apex definitions.
|
|
|
|
// Note that this is an anti-pattern: The config_setting should be created from the apex definition
|
|
|
|
// and not from a cc_library.
|
|
|
|
// This anti-pattern is needed today since not all apexes have been allowlisted.
|
|
|
|
func createInApexConfigSetting(ctx android.TopDownMutatorContext, apexName string) {
|
|
|
|
if apexName == android.AvailableToPlatform || apexName == android.AvailableToAnyApex {
|
|
|
|
// These correspond to android-non_apex and android-in_apex
|
|
|
|
return
|
|
|
|
}
|
2023-05-04 19:15:44 +02:00
|
|
|
apiDomainConfigSettingLock.Lock()
|
|
|
|
defer apiDomainConfigSettingLock.Unlock()
|
2023-04-20 00:31:54 +02:00
|
|
|
|
|
|
|
// Return if a config_setting has already been created
|
2023-05-08 20:33:16 +02:00
|
|
|
apiDomain := GetApiDomain(apexName)
|
2023-05-04 19:15:44 +02:00
|
|
|
acsm := getApiDomainConfigSettingMap(ctx.Config())
|
|
|
|
if _, exists := (*acsm)[apiDomain]; exists {
|
2023-04-20 00:31:54 +02:00
|
|
|
return
|
|
|
|
}
|
2023-05-04 19:15:44 +02:00
|
|
|
(*acsm)[apiDomain] = true
|
2023-04-20 00:31:54 +02:00
|
|
|
|
|
|
|
csa := bazel.ConfigSettingAttributes{
|
|
|
|
Flag_values: bazel.StringMapAttribute{
|
2023-05-04 19:15:44 +02:00
|
|
|
"//build/bazel/rules/apex:api_domain": apiDomain,
|
2023-04-20 00:31:54 +02:00
|
|
|
},
|
2023-05-04 19:15:44 +02:00
|
|
|
// Constraint this to android
|
|
|
|
Constraint_values: bazel.MakeLabelListAttribute(
|
|
|
|
bazel.MakeLabelList(
|
|
|
|
[]bazel.Label{
|
|
|
|
bazel.Label{Label: "//build/bazel/platforms/os:android"},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2023-04-20 00:31:54 +02:00
|
|
|
}
|
|
|
|
ca := android.CommonAttributes{
|
2023-05-04 19:15:44 +02:00
|
|
|
Name: apiDomain,
|
2023-04-20 00:31:54 +02:00
|
|
|
}
|
|
|
|
ctx.CreateBazelConfigSetting(
|
|
|
|
csa,
|
|
|
|
ca,
|
|
|
|
"build/bazel/rules/apex",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func inApexConfigSetting(apexAvailable string) string {
|
|
|
|
if apexAvailable == android.AvailableToPlatform {
|
2023-04-18 08:20:40 +02:00
|
|
|
return bazel.AndroidPlatform
|
2023-04-20 00:31:54 +02:00
|
|
|
}
|
|
|
|
if apexAvailable == android.AvailableToAnyApex {
|
|
|
|
return bazel.AndroidAndInApex
|
|
|
|
}
|
2023-05-08 20:33:16 +02:00
|
|
|
apiDomain := GetApiDomain(apexAvailable)
|
2023-05-04 19:15:44 +02:00
|
|
|
return "//build/bazel/rules/apex:" + apiDomain
|
2023-04-20 00:31:54 +02:00
|
|
|
}
|
|
|
|
|
2023-04-18 08:20:40 +02:00
|
|
|
// Inputs to stub vs impl selection.
|
|
|
|
type stubSelectionInfo struct {
|
|
|
|
// Label of the implementation library (e.g. //bionic/libc:libc)
|
|
|
|
impl bazel.Label
|
|
|
|
// Axis containing the implementation library
|
|
|
|
axis bazel.ConfigurationAxis
|
|
|
|
// Axis key containing the implementation library
|
|
|
|
config string
|
|
|
|
// API domain of the apex
|
|
|
|
// For test apexes (test_com.android.foo), this will be the source apex (com.android.foo)
|
|
|
|
apiDomain string
|
|
|
|
// List of dep labels
|
|
|
|
dynamicDeps *bazel.LabelListAttribute
|
|
|
|
// Boolean value for determining if the dep is in the same api domain
|
|
|
|
// If false, the label will be rewritten to to the stub label
|
|
|
|
sameApiDomain bool
|
|
|
|
}
|
2023-03-17 15:17:50 +01:00
|
|
|
|
2023-04-18 08:20:40 +02:00
|
|
|
func useStubOrImplInApexWithName(ssi stubSelectionInfo) {
|
|
|
|
lib := ssi.impl
|
|
|
|
if !ssi.sameApiDomain {
|
|
|
|
lib = bazel.Label{
|
|
|
|
Label: apiSurfaceModuleLibCurrentPackage + strings.TrimPrefix(lib.OriginalModuleName, ":"),
|
2023-02-21 21:05:26 +01:00
|
|
|
}
|
|
|
|
}
|
2023-04-18 08:20:40 +02:00
|
|
|
// Create a select statement specific to this apex
|
|
|
|
inApexSelectValue := ssi.dynamicDeps.SelectValue(bazel.OsAndInApexAxis, inApexConfigSetting(ssi.apiDomain))
|
|
|
|
(&inApexSelectValue).Append(bazel.MakeLabelList([]bazel.Label{lib}))
|
|
|
|
ssi.dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, inApexConfigSetting(ssi.apiDomain), bazel.FirstUniqueBazelLabelList(inApexSelectValue))
|
|
|
|
// Delete the library from the common config for this apex
|
|
|
|
implDynamicDeps := ssi.dynamicDeps.SelectValue(ssi.axis, ssi.config)
|
|
|
|
implDynamicDeps = bazel.SubtractBazelLabelList(implDynamicDeps, bazel.MakeLabelList([]bazel.Label{ssi.impl}))
|
|
|
|
ssi.dynamicDeps.SetSelectValue(ssi.axis, ssi.config, implDynamicDeps)
|
|
|
|
if ssi.axis == bazel.NoConfigAxis {
|
|
|
|
// Set defaults. Defaults (i.e. host) should use impl and not stubs.
|
|
|
|
defaultSelectValue := ssi.dynamicDeps.SelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey)
|
|
|
|
(&defaultSelectValue).Append(bazel.MakeLabelList([]bazel.Label{ssi.impl}))
|
|
|
|
ssi.dynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.FirstUniqueBazelLabelList(defaultSelectValue))
|
2023-02-21 21:05:26 +01:00
|
|
|
}
|
2023-04-18 08:20:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func setStubsForDynamicDeps(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis,
|
|
|
|
config string, apexAvailable []string, dynamicLibs bazel.LabelList, dynamicDeps *bazel.LabelListAttribute, ind int, buildNonApexWithStubs bool) {
|
2023-04-20 00:31:54 +02:00
|
|
|
|
|
|
|
// Create a config_setting for each apex_available.
|
|
|
|
// This will be used to select impl of a dep if dep is available to the same apex.
|
|
|
|
for _, aa := range apexAvailable {
|
|
|
|
createInApexConfigSetting(ctx.(android.TopDownMutatorContext), aa)
|
|
|
|
}
|
|
|
|
|
2023-04-18 08:20:40 +02:00
|
|
|
apiDomainForSelects := []string{}
|
|
|
|
for _, apex := range apexAvailable {
|
|
|
|
apiDomainForSelects = append(apiDomainForSelects, GetApiDomain(apex))
|
|
|
|
}
|
|
|
|
// Always emit a select statement for the platform variant.
|
|
|
|
// This ensures that b build //foo --config=android works
|
|
|
|
// Soong always creates a platform variant even when the library might not be available to platform.
|
|
|
|
if !android.InList(android.AvailableToPlatform, apiDomainForSelects) {
|
|
|
|
apiDomainForSelects = append(apiDomainForSelects, android.AvailableToPlatform)
|
|
|
|
}
|
|
|
|
apiDomainForSelects = android.SortedUniqueStrings(apiDomainForSelects)
|
|
|
|
|
|
|
|
// Create a select for each apex this library could be included in.
|
|
|
|
for _, l := range dynamicLibs.Includes {
|
|
|
|
dep, _ := ctx.ModuleFromName(l.OriginalModuleName)
|
|
|
|
if c, ok := dep.(*Module); !ok || !c.HasStubsVariants() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// TODO (b/280339069): Decrease the verbosity of the generated BUILD files
|
|
|
|
for _, apiDomain := range apiDomainForSelects {
|
|
|
|
var sameApiDomain bool
|
|
|
|
if apiDomain == android.AvailableToPlatform {
|
|
|
|
// Platform variants in Soong use equality of apex_available for stub/impl selection.
|
|
|
|
// https://cs.android.com/android/_/android/platform/build/soong/+/316b0158fe57ee7764235923e7c6f3d530da39c6:cc/cc.go;l=3393-3404;drc=176271a426496fa2688efe2b40d5c74340c63375;bpv=1;bpt=0
|
|
|
|
// One of the factors behind this design choice is cc_test
|
|
|
|
// Tests only have a platform variant, and using equality of apex_available ensures
|
|
|
|
// that tests of an apex library gets its implementation and not stubs.
|
|
|
|
// TODO (b/280343104): Discuss if we can drop this special handling for platform variants.
|
|
|
|
sameApiDomain = availableToSameApexes(apexAvailable, dep.(*Module).ApexAvailable())
|
2023-05-04 19:27:30 +02:00
|
|
|
if linkable, ok := ctx.Module().(LinkableInterface); ok && linkable.Bootstrap() {
|
|
|
|
sameApiDomain = true
|
|
|
|
}
|
2023-04-18 08:20:40 +02:00
|
|
|
} else {
|
|
|
|
sameApiDomain = android.InList(apiDomain, dep.(*Module).ApexAvailable())
|
|
|
|
}
|
|
|
|
ssi := stubSelectionInfo{
|
|
|
|
impl: l,
|
|
|
|
axis: axis,
|
|
|
|
config: config,
|
|
|
|
apiDomain: apiDomain,
|
|
|
|
dynamicDeps: dynamicDeps,
|
|
|
|
sameApiDomain: sameApiDomain,
|
|
|
|
}
|
|
|
|
useStubOrImplInApexWithName(ssi)
|
|
|
|
}
|
|
|
|
}
|
2023-02-21 21:05:26 +01:00
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func (la *linkerAttributes) convertStripProps(ctx android.BazelConversionPathContext, module *Module) {
|
2022-04-21 22:04:42 +02:00
|
|
|
bp2BuildPropParseHelper(ctx, module, &StripProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if stripProperties, ok := props.(*StripProperties); ok {
|
|
|
|
la.stripKeepSymbols.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols)
|
|
|
|
la.stripKeepSymbolsList.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_list)
|
|
|
|
la.stripKeepSymbolsAndDebugFrame.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_and_debug_frame)
|
|
|
|
la.stripAll.SetSelectValue(axis, config, stripProperties.Strip.All)
|
|
|
|
la.stripNone.SetSelectValue(axis, config, stripProperties.Strip.None)
|
2021-06-02 22:02:22 +02:00
|
|
|
}
|
2022-04-21 22:04:42 +02:00
|
|
|
})
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
2021-06-02 22:02:22 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func (la *linkerAttributes) convertProductVariables(ctx android.BazelConversionPathContext, productVariableProps android.ProductConfigProperties) {
|
2021-09-17 13:38:09 +02:00
|
|
|
|
2021-06-02 22:02:22 +02:00
|
|
|
type productVarDep struct {
|
|
|
|
// the name of the corresponding excludes field, if one exists
|
|
|
|
excludesField string
|
|
|
|
// reference to the bazel attribute that should be set for the given product variable config
|
|
|
|
attribute *bazel.LabelListAttribute
|
2021-06-11 00:20:06 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
depResolutionFunc func(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList
|
2021-06-02 22:02:22 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 08:27:01 +02:00
|
|
|
// an intermediate attribute that holds Header_libs info, and will be appended to
|
|
|
|
// implementationDeps at the end, to solve the confliction that both header_libs
|
|
|
|
// and static_libs use implementationDeps.
|
|
|
|
var headerDeps bazel.LabelListAttribute
|
|
|
|
|
2021-06-02 22:02:22 +02:00
|
|
|
productVarToDepFields := map[string]productVarDep{
|
|
|
|
// product variables do not support exclude_shared_libs
|
2021-11-02 07:40:51 +01:00
|
|
|
"Shared_libs": {attribute: &la.implementationDynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes},
|
|
|
|
"Static_libs": {"Exclude_static_libs", &la.implementationDeps, bazelLabelForStaticDepsExcludes},
|
|
|
|
"Whole_static_libs": {"Exclude_static_libs", &la.wholeArchiveDeps, bazelLabelForWholeDepsExcludes},
|
2022-08-30 08:27:01 +02:00
|
|
|
"Header_libs": {attribute: &headerDeps, depResolutionFunc: bazelLabelForHeaderDepsExcludes},
|
2021-06-02 22:02:22 +02:00
|
|
|
}
|
2021-05-27 08:15:54 +02:00
|
|
|
|
2021-06-02 22:02:22 +02:00
|
|
|
for name, dep := range productVarToDepFields {
|
|
|
|
props, exists := productVariableProps[name]
|
|
|
|
excludeProps, excludesExists := productVariableProps[dep.excludesField]
|
2022-12-30 02:11:49 +01:00
|
|
|
// if neither an include nor excludes property exists, then skip it
|
2021-06-02 22:02:22 +02:00
|
|
|
if !exists && !excludesExists {
|
|
|
|
continue
|
|
|
|
}
|
2021-11-15 13:28:43 +01:00
|
|
|
// Collect all the configurations that an include or exclude property exists for.
|
|
|
|
// We want to iterate all configurations rather than either the include or exclude because, for a
|
|
|
|
// particular configuration, we may have either only an include or an exclude to handle.
|
2023-04-26 19:52:24 +02:00
|
|
|
productConfigProps := make(map[android.ProductConfigOrSoongConfigProperty]bool, len(props)+len(excludeProps))
|
2021-11-15 13:28:43 +01:00
|
|
|
for p := range props {
|
|
|
|
productConfigProps[p] = true
|
2021-06-02 22:02:22 +02:00
|
|
|
}
|
2021-11-15 13:28:43 +01:00
|
|
|
for p := range excludeProps {
|
|
|
|
productConfigProps[p] = true
|
2021-06-02 22:02:22 +02:00
|
|
|
}
|
|
|
|
|
2021-11-15 13:28:43 +01:00
|
|
|
for productConfigProp := range productConfigProps {
|
|
|
|
prop, includesExists := props[productConfigProp]
|
|
|
|
excludesProp, excludesExists := excludeProps[productConfigProp]
|
2021-06-02 22:02:22 +02:00
|
|
|
var includes, excludes []string
|
|
|
|
var ok bool
|
|
|
|
// if there was no includes/excludes property, casting fails and that's expected
|
2021-11-15 13:28:43 +01:00
|
|
|
if includes, ok = prop.([]string); includesExists && !ok {
|
2021-06-02 22:02:22 +02:00
|
|
|
ctx.ModuleErrorf("Could not convert product variable %s property", name)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-11-15 13:28:43 +01:00
|
|
|
if excludes, ok = excludesProp.([]string); excludesExists && !ok {
|
2021-06-02 22:02:22 +02:00
|
|
|
ctx.ModuleErrorf("Could not convert product variable %s property", dep.excludesField)
|
|
|
|
}
|
2021-06-11 00:20:06 +02:00
|
|
|
|
2021-11-17 13:14:41 +01:00
|
|
|
dep.attribute.EmitEmptyList = productConfigProp.AlwaysEmit()
|
2021-11-15 13:28:43 +01:00
|
|
|
dep.attribute.SetSelectValue(
|
|
|
|
productConfigProp.ConfigurationAxis(),
|
|
|
|
productConfigProp.SelectKey(),
|
|
|
|
dep.depResolutionFunc(ctx, android.FirstUniqueStrings(includes), excludes),
|
|
|
|
)
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:27:01 +02:00
|
|
|
la.implementationDeps.Append(headerDeps)
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
|
2021-12-14 18:21:22 +01:00
|
|
|
func (la *linkerAttributes) finalize(ctx android.BazelConversionPathContext) {
|
|
|
|
// if system dynamic deps have the default value, any use of a system dynamic library used will
|
|
|
|
// result in duplicate library errors for bionic OSes. Here, we explicitly exclude those libraries
|
2022-08-04 19:57:35 +02:00
|
|
|
// from bionic OSes and the no config case as these libraries only build for bionic OSes.
|
2021-12-14 18:21:22 +01:00
|
|
|
if la.systemDynamicDeps.IsNil() && len(la.usedSystemDynamicDepAsDynamicDep) > 0 {
|
2023-03-01 01:02:16 +01:00
|
|
|
toRemove := bazelLabelForSharedDeps(ctx, android.SortedKeys(la.usedSystemDynamicDepAsDynamicDep))
|
2022-08-04 19:57:35 +02:00
|
|
|
la.dynamicDeps.Exclude(bazel.NoConfigAxis, "", toRemove)
|
2021-12-14 18:21:22 +01:00
|
|
|
la.dynamicDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove)
|
|
|
|
la.dynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
|
2022-09-13 17:27:11 +02:00
|
|
|
la.implementationDynamicDeps.Exclude(bazel.NoConfigAxis, "", toRemove)
|
2021-12-14 18:21:22 +01:00
|
|
|
la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "android", toRemove)
|
|
|
|
la.implementationDynamicDeps.Exclude(bazel.OsConfigurationAxis, "linux_bionic", toRemove)
|
2022-09-13 17:27:11 +02:00
|
|
|
|
|
|
|
la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, toRemove)
|
|
|
|
stubsToRemove := make([]bazel.Label, 0, len(la.usedSystemDynamicDepAsDynamicDep))
|
|
|
|
for _, lib := range toRemove.Includes {
|
2023-03-17 04:02:32 +01:00
|
|
|
stubLabelInApiSurfaces := bazel.Label{
|
|
|
|
Label: apiSurfaceModuleLibCurrentPackage + lib.OriginalModuleName,
|
|
|
|
}
|
|
|
|
stubsToRemove = append(stubsToRemove, stubLabelInApiSurfaces)
|
2022-09-13 17:27:11 +02:00
|
|
|
}
|
2023-04-18 08:20:40 +02:00
|
|
|
// system libraries (e.g. libc, libm, libdl) belong the com.android.runtime api domain
|
|
|
|
// dedupe the stubs of these libraries from the other api domains (platform, other_apexes...)
|
|
|
|
for _, aa := range ctx.Module().(*Module).ApexAvailable() {
|
|
|
|
la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, inApexConfigSetting(aa), bazel.MakeLabelList(stubsToRemove))
|
|
|
|
}
|
|
|
|
la.implementationDynamicDeps.Exclude(bazel.OsAndInApexAxis, bazel.AndroidPlatform, bazel.MakeLabelList(stubsToRemove))
|
2021-12-14 18:21:22 +01:00
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
la.deps.ResolveExcludes()
|
|
|
|
la.implementationDeps.ResolveExcludes()
|
|
|
|
la.dynamicDeps.ResolveExcludes()
|
|
|
|
la.implementationDynamicDeps.ResolveExcludes()
|
|
|
|
la.wholeArchiveDeps.ResolveExcludes()
|
|
|
|
la.systemDynamicDeps.ForceSpecifyEmptyList = true
|
2021-12-14 18:21:22 +01:00
|
|
|
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}
|
|
|
|
|
2021-04-13 09:14:55 +02:00
|
|
|
// Relativize a list of root-relative paths with respect to the module's
|
|
|
|
// directory.
|
|
|
|
//
|
|
|
|
// include_dirs Soong prop are root-relative (b/183742505), but
|
|
|
|
// local_include_dirs, export_include_dirs and export_system_include_dirs are
|
|
|
|
// module dir relative. This function makes a list of paths entirely module dir
|
|
|
|
// relative.
|
|
|
|
//
|
|
|
|
// For the `include` attribute, Bazel wants the paths to be relative to the
|
|
|
|
// module.
|
|
|
|
func bp2BuildMakePathsRelativeToModule(ctx android.BazelConversionPathContext, paths []string) []string {
|
2021-04-06 22:06:21 +02:00
|
|
|
var relativePaths []string
|
|
|
|
for _, path := range paths {
|
2021-04-13 09:14:55 +02:00
|
|
|
// Semantics of filepath.Rel: join(ModuleDir, rel(ModuleDir, path)) == path
|
|
|
|
relativePath, err := filepath.Rel(ctx.ModuleDir(), path)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-04-06 22:06:21 +02:00
|
|
|
relativePaths = append(relativePaths, relativePath)
|
|
|
|
}
|
|
|
|
return relativePaths
|
|
|
|
}
|
|
|
|
|
2021-09-09 20:08:21 +02:00
|
|
|
// BazelIncludes contains information about -I and -isystem paths from a module converted to Bazel
|
|
|
|
// attributes.
|
|
|
|
type BazelIncludes struct {
|
2021-12-10 20:28:20 +01:00
|
|
|
AbsoluteIncludes bazel.StringListAttribute
|
|
|
|
Includes bazel.StringListAttribute
|
|
|
|
SystemIncludes bazel.StringListAttribute
|
2021-09-09 20:08:21 +02:00
|
|
|
}
|
|
|
|
|
2022-05-11 19:55:06 +02:00
|
|
|
func bp2BuildParseExportedIncludes(ctx android.BazelConversionPathContext, module *Module, includes *BazelIncludes) BazelIncludes {
|
2021-12-10 20:28:20 +01:00
|
|
|
var exported BazelIncludes
|
|
|
|
if includes != nil {
|
|
|
|
exported = *includes
|
|
|
|
} else {
|
|
|
|
exported = BazelIncludes{}
|
|
|
|
}
|
2022-12-10 01:08:54 +01:00
|
|
|
|
|
|
|
// cc library Export_include_dirs and Export_system_include_dirs are marked
|
|
|
|
// "variant_prepend" in struct tag, set their prepend property to true to make
|
|
|
|
// sure bp2build generates correct result.
|
|
|
|
exported.Includes.Prepend = true
|
|
|
|
exported.SystemIncludes.Prepend = true
|
|
|
|
|
2022-04-21 22:04:42 +02:00
|
|
|
bp2BuildPropParseHelper(ctx, module, &FlagExporterProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
|
|
|
|
if len(flagExporterProperties.Export_include_dirs) > 0 {
|
|
|
|
exported.Includes.SetSelectValue(axis, config, android.FirstUniqueStrings(append(exported.Includes.SelectValue(axis, config), flagExporterProperties.Export_include_dirs...)))
|
|
|
|
}
|
|
|
|
if len(flagExporterProperties.Export_system_include_dirs) > 0 {
|
|
|
|
exported.SystemIncludes.SetSelectValue(axis, config, android.FirstUniqueStrings(append(exported.SystemIncludes.SelectValue(axis, config), flagExporterProperties.Export_system_include_dirs...)))
|
2021-04-26 13:49:08 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-21 22:04:42 +02:00
|
|
|
})
|
2021-12-10 20:28:20 +01:00
|
|
|
exported.AbsoluteIncludes.DeduplicateAxesFromBase()
|
2021-09-09 20:08:21 +02:00
|
|
|
exported.Includes.DeduplicateAxesFromBase()
|
|
|
|
exported.SystemIncludes.DeduplicateAxesFromBase()
|
2021-04-26 13:49:08 +02:00
|
|
|
|
2021-09-09 20:08:21 +02:00
|
|
|
return exported
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
}
|
2021-09-20 21:14:39 +02:00
|
|
|
|
2022-09-06 21:31:25 +02:00
|
|
|
func BazelLabelNameForStaticModule(baseLabel string) string {
|
|
|
|
return baseLabel + "_bp2build_cc_library_static"
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForStaticModule(ctx android.BazelConversionPathContext, m blueprint.Module) string {
|
2021-09-20 21:14:39 +02:00
|
|
|
label := android.BazelModuleLabel(ctx, m)
|
2022-12-30 02:11:49 +01:00
|
|
|
if ccModule, ok := m.(*Module); ok && ccModule.typ() == fullLibrary {
|
2022-09-06 21:31:25 +02:00
|
|
|
return BazelLabelNameForStaticModule(label)
|
2021-09-20 21:14:39 +02:00
|
|
|
}
|
|
|
|
return label
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForSharedModule(ctx android.BazelConversionPathContext, m blueprint.Module) string {
|
2021-09-20 21:14:39 +02:00
|
|
|
// cc_library, at it's root name, propagates the shared library, which depends on the static
|
|
|
|
// library.
|
|
|
|
return android.BazelModuleLabel(ctx, m)
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForStaticWholeModuleDeps(ctx android.BazelConversionPathContext, m blueprint.Module) string {
|
2021-09-20 21:14:39 +02:00
|
|
|
label := bazelLabelForStaticModule(ctx, m)
|
|
|
|
if aModule, ok := m.(android.Module); ok {
|
|
|
|
if android.IsModulePrebuilt(aModule) {
|
|
|
|
label += "_alwayslink"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return label
|
|
|
|
}
|
|
|
|
|
2023-06-22 22:23:53 +02:00
|
|
|
// Replaces //a/b/my_xsd_config with //a/b/my_xsd_config-cpp
|
|
|
|
func xsdConfigCppTarget(ctx android.BazelConversionPathContext, mod blueprint.Module) string {
|
|
|
|
callback := func(xsd android.XsdConfigBp2buildTargets) string {
|
|
|
|
return xsd.CppBp2buildTargetName()
|
|
|
|
}
|
|
|
|
return android.XsdConfigBp2buildTarget(ctx, mod, callback)
|
|
|
|
}
|
|
|
|
|
|
|
|
func bazelLabelForXsdConfig(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
|
|
|
|
return android.BazelLabelForModuleDepsWithFn(ctx, modules, xsdConfigCppTarget)
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForWholeDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
|
2021-09-20 21:14:39 +02:00
|
|
|
return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticWholeModuleDeps)
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForWholeDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
|
2021-09-20 21:14:39 +02:00
|
|
|
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticWholeModuleDeps)
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForStaticDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
|
2021-09-20 21:14:39 +02:00
|
|
|
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticModule)
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForStaticDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
|
2021-09-20 21:14:39 +02:00
|
|
|
return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticModule)
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForSharedDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
|
2021-09-20 21:14:39 +02:00
|
|
|
return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForSharedModule)
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForHeaderDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
|
2021-09-20 21:14:39 +02:00
|
|
|
// This is not elegant, but bp2build's shared library targets only propagate
|
|
|
|
// their header information as part of the normal C++ provider.
|
|
|
|
return bazelLabelForSharedDeps(ctx, modules)
|
|
|
|
}
|
|
|
|
|
2022-08-30 08:27:01 +02:00
|
|
|
func bazelLabelForHeaderDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
|
|
|
|
// This is only used when product_variable header_libs is processed, to follow
|
|
|
|
// the pattern of depResolutionFunc
|
|
|
|
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bazelLabelForSharedDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
|
2021-09-20 21:14:39 +02:00
|
|
|
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
|
|
|
|
}
|
2021-10-04 19:55:44 +02:00
|
|
|
|
|
|
|
type binaryLinkerAttrs struct {
|
|
|
|
Linkshared *bool
|
2023-05-26 20:03:39 +02:00
|
|
|
Stem bazel.StringAttribute
|
2022-02-24 00:39:59 +01:00
|
|
|
Suffix bazel.StringAttribute
|
2021-10-04 19:55:44 +02:00
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bp2buildBinaryLinkerProps(ctx android.BazelConversionPathContext, m *Module) binaryLinkerAttrs {
|
2021-10-04 19:55:44 +02:00
|
|
|
attrs := binaryLinkerAttrs{}
|
2022-04-21 22:04:42 +02:00
|
|
|
bp2BuildPropParseHelper(ctx, m, &BinaryLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
linkerProps := props.(*BinaryLinkerProperties)
|
|
|
|
staticExecutable := linkerProps.Static_executable
|
|
|
|
if axis == bazel.NoConfigAxis {
|
|
|
|
if linkBinaryShared := !proptools.Bool(staticExecutable); !linkBinaryShared {
|
|
|
|
attrs.Linkshared = &linkBinaryShared
|
2021-10-04 19:55:44 +02:00
|
|
|
}
|
2022-04-21 22:04:42 +02:00
|
|
|
} else if staticExecutable != nil {
|
|
|
|
// TODO(b/202876379): Static_executable is arch-variant; however, linkshared is a
|
|
|
|
// nonconfigurable attribute. Only 4 AOSP modules use this feature, defer handling
|
|
|
|
ctx.ModuleErrorf("bp2build cannot migrate a module with arch/target-specific static_executable values")
|
2021-10-04 19:55:44 +02:00
|
|
|
}
|
2023-05-26 20:03:39 +02:00
|
|
|
if stem := linkerProps.Stem; stem != nil {
|
|
|
|
attrs.Stem.SetSelectValue(axis, config, stem)
|
|
|
|
}
|
2022-02-24 00:39:59 +01:00
|
|
|
if suffix := linkerProps.Suffix; suffix != nil {
|
|
|
|
attrs.Suffix.SetSelectValue(axis, config, suffix)
|
|
|
|
}
|
2022-04-21 22:04:42 +02:00
|
|
|
})
|
2021-10-04 19:55:44 +02:00
|
|
|
|
|
|
|
return attrs
|
|
|
|
}
|
2022-10-28 18:48:18 +02:00
|
|
|
|
|
|
|
func bp2buildSanitizerFeatures(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute {
|
|
|
|
sanitizerFeatures := bazel.StringListAttribute{}
|
|
|
|
bp2BuildPropParseHelper(ctx, m, &SanitizeProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
var features []string
|
|
|
|
if sanitizerProps, ok := props.(*SanitizeProperties); ok {
|
|
|
|
if sanitizerProps.Sanitize.Integer_overflow != nil && *sanitizerProps.Sanitize.Integer_overflow {
|
|
|
|
features = append(features, "ubsan_integer_overflow")
|
|
|
|
}
|
|
|
|
for _, sanitizer := range sanitizerProps.Sanitize.Misc_undefined {
|
|
|
|
features = append(features, "ubsan_"+sanitizer)
|
|
|
|
}
|
2023-06-12 21:18:28 +02:00
|
|
|
blocklist := sanitizerProps.Sanitize.Blocklist
|
|
|
|
if blocklist != nil {
|
|
|
|
// Format the blocklist name to be used in a feature name
|
|
|
|
blocklistFeatureSuffix := strings.Replace(strings.ToLower(*blocklist), ".", "_", -1)
|
|
|
|
features = append(features, "ubsan_blocklist_"+blocklistFeatureSuffix)
|
|
|
|
}
|
2023-06-16 22:15:45 +02:00
|
|
|
if sanitizerProps.Sanitize.Cfi != nil && !proptools.Bool(sanitizerProps.Sanitize.Cfi) {
|
|
|
|
features = append(features, "-android_cfi")
|
|
|
|
} else if proptools.Bool(sanitizerProps.Sanitize.Cfi) {
|
2023-03-28 22:47:10 +02:00
|
|
|
features = append(features, "android_cfi")
|
|
|
|
if proptools.Bool(sanitizerProps.Sanitize.Config.Cfi_assembly_support) {
|
|
|
|
features = append(features, "android_cfi_assembly_support")
|
|
|
|
}
|
|
|
|
}
|
2022-10-28 18:48:18 +02:00
|
|
|
sanitizerFeatures.SetSelectValue(axis, config, features)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return sanitizerFeatures
|
|
|
|
}
|
2023-02-06 22:58:30 +01:00
|
|
|
|
|
|
|
func bp2buildLtoFeatures(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute {
|
|
|
|
lto_feature_name := "android_thin_lto"
|
|
|
|
ltoBoolFeatures := bazel.BoolAttribute{}
|
|
|
|
bp2BuildPropParseHelper(ctx, m, <OProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
|
|
|
if ltoProps, ok := props.(*LTOProperties); ok {
|
|
|
|
thinProp := ltoProps.Lto.Thin != nil && *ltoProps.Lto.Thin
|
|
|
|
thinPropSetToFalse := ltoProps.Lto.Thin != nil && !*ltoProps.Lto.Thin
|
|
|
|
neverProp := ltoProps.Lto.Never != nil && *ltoProps.Lto.Never
|
|
|
|
if thinProp {
|
|
|
|
ltoBoolFeatures.SetSelectValue(axis, config, BoolPtr(true))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if neverProp || thinPropSetToFalse {
|
|
|
|
if thinProp {
|
|
|
|
ctx.ModuleErrorf("lto.thin and lto.never are mutually exclusive but were specified together")
|
|
|
|
} else {
|
|
|
|
ltoBoolFeatures.SetSelectValue(axis, config, BoolPtr(false))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ltoBoolFeatures.SetSelectValue(axis, config, nil)
|
|
|
|
})
|
|
|
|
|
|
|
|
props := m.GetArchVariantProperties(ctx, <OProperties{})
|
|
|
|
ltoStringFeatures, err := ltoBoolFeatures.ToStringListAttribute(func(boolPtr *bool, axis bazel.ConfigurationAxis, config string) []string {
|
|
|
|
if boolPtr == nil {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
if !*boolPtr {
|
|
|
|
return []string{"-" + lto_feature_name}
|
|
|
|
}
|
|
|
|
features := []string{lto_feature_name}
|
|
|
|
if ltoProps, ok := props[axis][config].(*LTOProperties); ok {
|
|
|
|
if ltoProps.Whole_program_vtables != nil && *ltoProps.Whole_program_vtables {
|
|
|
|
features = append(features, "android_thin_lto_whole_program_vtables")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return features
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("Error processing LTO attributes: %s", err)
|
|
|
|
}
|
|
|
|
return ltoStringFeatures
|
|
|
|
}
|
2023-04-14 20:25:24 +02:00
|
|
|
|
|
|
|
func convertHiddenVisibilityToFeatureBase(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute {
|
|
|
|
visibilityHiddenFeature := bazel.StringListAttribute{}
|
|
|
|
bp2BuildPropParseHelper(ctx, m, &BaseCompilerProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) {
|
|
|
|
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
|
|
|
convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, baseCompilerProps.Cflags)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return visibilityHiddenFeature
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertHiddenVisibilityToFeatureStaticOrShared(ctx android.BazelConversionPathContext, m *Module, isStatic bool) bazel.StringListAttribute {
|
|
|
|
visibilityHiddenFeature := bazel.StringListAttribute{}
|
|
|
|
if isStatic {
|
|
|
|
bp2BuildPropParseHelper(ctx, m, &StaticProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) {
|
|
|
|
if staticProps, ok := props.(*StaticProperties); ok {
|
|
|
|
convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, staticProps.Static.Cflags)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
bp2BuildPropParseHelper(ctx, m, &SharedProperties{}, func(axis bazel.ConfigurationAxis, configString string, props interface{}) {
|
|
|
|
if sharedProps, ok := props.(*SharedProperties); ok {
|
|
|
|
convertHiddenVisibilityToFeatureHelper(&visibilityHiddenFeature, axis, configString, sharedProps.Shared.Cflags)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return visibilityHiddenFeature
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertHiddenVisibilityToFeatureHelper(feature *bazel.StringListAttribute, axis bazel.ConfigurationAxis, configString string, cflags []string) {
|
|
|
|
if inList(config.VisibilityHiddenFlag, cflags) {
|
|
|
|
feature.SetSelectValue(axis, configString, []string{"visibility_hidden"})
|
|
|
|
}
|
|
|
|
}
|