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
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
package cc
|
|
|
|
|
|
|
|
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"
|
2021-05-13 21:13:04 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/bazel"
|
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 (
|
|
|
|
cSrcPartition = "c"
|
|
|
|
asSrcPartition = "as"
|
|
|
|
cppSrcPartition = "cpp"
|
|
|
|
)
|
|
|
|
|
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 {
|
2021-06-11 14:51:48 +02:00
|
|
|
Srcs bazel.LabelListAttribute
|
|
|
|
Srcs_c bazel.LabelListAttribute
|
|
|
|
Srcs_as bazel.LabelListAttribute
|
2021-10-19 19:56:10 +02:00
|
|
|
Hdrs bazel.LabelListAttribute
|
2021-06-11 14:51:48 +02:00
|
|
|
Copts bazel.StringListAttribute
|
|
|
|
|
2021-09-22 21:52:58 +02:00
|
|
|
Deps bazel.LabelListAttribute
|
|
|
|
Implementation_deps bazel.LabelListAttribute
|
|
|
|
Dynamic_deps bazel.LabelListAttribute
|
|
|
|
Implementation_dynamic_deps bazel.LabelListAttribute
|
|
|
|
Whole_archive_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-04-29 10:15:13 +02:00
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
|
2021-06-02 13:10:02 +02:00
|
|
|
// Check that a module is a filegroup type named <label>.
|
|
|
|
isFilegroupNamed := func(m android.Module, fullLabel string) bool {
|
|
|
|
if ctx.OtherModuleType(m) != "filegroup" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
labelParts := strings.Split(fullLabel, ":")
|
|
|
|
if len(labelParts) > 2 {
|
|
|
|
// There should not be more than one colon in a label.
|
2021-09-20 18:55:02 +02:00
|
|
|
ctx.ModuleErrorf("%s is not a valid Bazel label for a filegroup", fullLabel)
|
2021-06-02 13:10:02 +02:00
|
|
|
}
|
2021-09-20 18:55:02 +02:00
|
|
|
return m.Name() == labelParts[len(labelParts)-1]
|
2021-06-02 13:10:02 +02:00
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
return func(ctx bazel.OtherModuleContext, label string) (string, bool) {
|
|
|
|
m, exists := ctx.ModuleFromName(label)
|
|
|
|
if !exists {
|
|
|
|
return label, false
|
2021-06-02 13:10:02 +02:00
|
|
|
}
|
2021-07-21 20:34:58 +02:00
|
|
|
aModule, _ := m.(android.Module)
|
2021-09-20 18:55:02 +02:00
|
|
|
if !isFilegroupNamed(aModule, label) {
|
|
|
|
return label, false
|
2021-06-02 13:10:02 +02:00
|
|
|
}
|
2021-09-20 18:55:02 +02:00
|
|
|
return label + 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.
|
|
|
|
partitioned := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{
|
2021-10-19 15:45:48 +02:00
|
|
|
cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
|
|
|
|
asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
|
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.
|
2021-10-19 15:45:48 +02:00
|
|
|
cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
|
2021-09-20 18:55:02 +02:00
|
|
|
})
|
2021-06-02 13:10:02 +02:00
|
|
|
|
2021-10-19 15:45:48 +02:00
|
|
|
return partitioned
|
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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +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) {
|
2021-06-11 14:51:48 +02:00
|
|
|
attrs.Copts.SetSelectValue(axis, config, props.Cflags)
|
|
|
|
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-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
|
|
|
|
2021-05-26 06:42:42 +02:00
|
|
|
if isStatic {
|
2021-05-21 14:37:59 +02:00
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &StaticProperties{}) {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
if staticOrSharedProps, ok := props.(*StaticProperties); ok {
|
|
|
|
setAttrs(axis, config, staticOrSharedProps.Static)
|
2021-05-26 06:42:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-05-21 14:37:59 +02:00
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &SharedProperties{}) {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
if staticOrSharedProps, ok := props.(*SharedProperties); ok {
|
|
|
|
setAttrs(axis, config, staticOrSharedProps.Shared)
|
2021-05-26 06:42: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
|
|
|
|
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 {
|
|
|
|
Src bazel.LabelAttribute
|
|
|
|
}
|
|
|
|
|
2021-09-01 23:22:09 +02:00
|
|
|
// NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package
|
2021-11-02 07:40:51 +01:00
|
|
|
func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes {
|
2021-05-14 09:02:34 +02:00
|
|
|
var srcLabelAttribute bazel.LabelAttribute
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltLinkerProperties{}) {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
if prebuiltLinkerProperties, ok := props.(*prebuiltLinkerProperties); ok {
|
2021-05-14 09:02:34 +02:00
|
|
|
if len(prebuiltLinkerProperties.Srcs) > 1 {
|
2021-05-21 14:37:59 +02:00
|
|
|
ctx.ModuleErrorf("Bp2BuildParsePrebuiltLibraryProps: Expected at most once source file for %s %s\n", axis, config)
|
|
|
|
continue
|
|
|
|
} else if len(prebuiltLinkerProperties.Srcs) == 0 {
|
|
|
|
continue
|
2021-05-14 09:02:34 +02:00
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
src := android.BazelLabelForModuleSrcSingle(ctx, prebuiltLinkerProperties.Srcs[0])
|
|
|
|
srcLabelAttribute.SetSelectValue(axis, config, src)
|
2021-05-14 09:02:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return prebuiltAttributes{
|
|
|
|
Src: srcLabelAttribute,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
type baseAttributes struct {
|
|
|
|
compilerAttributes
|
|
|
|
linkerAttributes
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// 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
|
|
|
|
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-04-09 12:43:12 +02:00
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
func parseCommandLineFlags(soongFlags []string) []string {
|
|
|
|
var result []string
|
|
|
|
for _, flag := range soongFlags {
|
|
|
|
// 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.
|
|
|
|
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.
|
|
|
|
if srcsList, ok := parseSrcs(ctx, props); ok {
|
|
|
|
ca.srcs.SetSelectValue(axis, config, srcsList)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags))
|
|
|
|
ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags))
|
|
|
|
ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags))
|
|
|
|
ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags))
|
|
|
|
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) {
|
2021-10-19 19:56:10 +02:00
|
|
|
stlPropsByArch := module.GetArchVariantProperties(ctx, &StlProperties{})
|
|
|
|
for _, configToProps := range stlPropsByArch {
|
|
|
|
for _, props := range configToProps {
|
|
|
|
if stlProps, ok := props.(*StlProperties); ok {
|
|
|
|
if stlProps.Stl == nil {
|
|
|
|
continue
|
2021-08-11 16:46:06 +02:00
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
if ca.stl == nil {
|
|
|
|
ca.stl = stlProps.Stl
|
|
|
|
} 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-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,
|
|
|
|
"CppFlags": &ca.cppFlags,
|
|
|
|
}
|
|
|
|
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))
|
|
|
|
}
|
2021-11-15 13:28:43 +01:00
|
|
|
newFlags, _ := bazel.TryVariableSubstitutions(flags, productConfigProp.Name)
|
|
|
|
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
|
|
|
|
|
|
|
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]
|
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.
|
2021-11-02 07:40:51 +01:00
|
|
|
func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, 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.
|
|
|
|
generatedSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, props.Generated_sources, props.Exclude_generated_sources)
|
|
|
|
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)
|
|
|
|
if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 {
|
|
|
|
anySrcs = true
|
|
|
|
}
|
|
|
|
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedSrcsLabelList), anySrcs
|
|
|
|
}
|
|
|
|
|
2021-11-29 23:52:41 +01:00
|
|
|
func bp2buildResolveCppStdValue(c_std *string, cpp_std *string, gnu_extensions *bool) (*string, *string) {
|
|
|
|
var cStdVal, cppStdVal string
|
|
|
|
// 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.
|
2021-10-19 19:56:10 +02:00
|
|
|
if cpp_std != nil {
|
2021-11-29 23:52:41 +01:00
|
|
|
cppStdVal = parseCppStd(cpp_std)
|
|
|
|
} else if gnu_extensions != nil && !*gnu_extensions {
|
|
|
|
cppStdVal = "c++17"
|
|
|
|
}
|
|
|
|
if c_std != nil {
|
|
|
|
cStdVal = parseCStd(c_std)
|
2021-10-19 19:56:10 +02:00
|
|
|
} else if gnu_extensions != nil && !*gnu_extensions {
|
2021-11-29 23:52:41 +01:00
|
|
|
cStdVal = "c99"
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
2021-11-29 23:52:41 +01:00
|
|
|
|
|
|
|
cStdVal, cppStdVal = maybeReplaceGnuToC(gnu_extensions, cStdVal, cppStdVal)
|
|
|
|
return &cStdVal, &cppStdVal
|
2021-10-19 19:56:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
|
2021-11-02 07:40:51 +01:00
|
|
|
func bp2BuildParseBaseProps(ctx android.BazelConversionPathContext, module *Module) baseAttributes {
|
2021-10-19 19:56:10 +02:00
|
|
|
archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
|
|
|
|
archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{})
|
|
|
|
|
|
|
|
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{}
|
|
|
|
}
|
|
|
|
for config, _ := range configMap {
|
|
|
|
axisToConfigs[axis][config] = true
|
2021-05-06 19:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
allAxesAndConfigs(archVariantCompilerProps)
|
|
|
|
allAxesAndConfigs(archVariantLinkerProps)
|
2021-05-06 19:54:29 +02:00
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
compilerAttrs := compilerAttributes{}
|
|
|
|
linkerAttrs := linkerAttributes{}
|
|
|
|
|
|
|
|
for axis, configs := range axisToConfigs {
|
|
|
|
for config, _ := range configs {
|
|
|
|
var allHdrs []string
|
|
|
|
if baseCompilerProps, ok := archVariantCompilerProps[axis][config].(*BaseCompilerProperties); ok {
|
|
|
|
allHdrs = baseCompilerProps.Generated_headers
|
|
|
|
|
|
|
|
(&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, config, baseCompilerProps)
|
|
|
|
}
|
|
|
|
|
|
|
|
var exportHdrs []string
|
|
|
|
|
|
|
|
if baseLinkerProps, ok := archVariantLinkerProps[axis][config].(*BaseLinkerProperties); ok {
|
|
|
|
exportHdrs = baseLinkerProps.Export_generated_headers
|
|
|
|
|
|
|
|
(&linkerAttrs).bp2buildForAxisAndConfig(ctx, module.Binary(), axis, config, baseLinkerProps)
|
2021-09-23 22:34:35 +02:00
|
|
|
}
|
2021-10-19 19:56:10 +02:00
|
|
|
headers := maybePartitionExportedAndImplementationsDeps(ctx, !module.Binary(), allHdrs, exportHdrs, android.BazelLabelForModuleDeps)
|
|
|
|
implementationHdrs.SetSelectValue(axis, config, headers.implementation)
|
|
|
|
compilerAttrs.hdrs.SetSelectValue(axis, config, headers.export)
|
2021-09-23 22:34:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 19:56:10 +02:00
|
|
|
compilerAttrs.convertStlProps(ctx, module)
|
|
|
|
(&linkerAttrs).convertStripProps(ctx, module)
|
|
|
|
|
|
|
|
productVariableProps := android.ProductVariableProperties(ctx)
|
|
|
|
|
|
|
|
(&compilerAttrs).convertProductVariables(ctx, productVariableProps)
|
|
|
|
(&linkerAttrs).convertProductVariables(ctx, productVariableProps)
|
|
|
|
|
|
|
|
(&compilerAttrs).finalize(ctx, implementationHdrs)
|
|
|
|
(&linkerAttrs).finalize()
|
|
|
|
|
|
|
|
return baseAttributes{
|
|
|
|
compilerAttrs,
|
|
|
|
linkerAttrs,
|
2021-04-09 12:43:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience struct to hold all attributes parsed from linker properties.
|
|
|
|
type linkerAttributes struct {
|
2021-09-22 21:52:58 +02:00
|
|
|
deps bazel.LabelListAttribute
|
|
|
|
implementationDeps bazel.LabelListAttribute
|
|
|
|
dynamicDeps bazel.LabelListAttribute
|
|
|
|
implementationDynamicDeps bazel.LabelListAttribute
|
|
|
|
wholeArchiveDeps bazel.LabelListAttribute
|
|
|
|
systemDynamicDeps bazel.LabelListAttribute
|
|
|
|
|
2021-09-17 13:38:09 +02:00
|
|
|
linkCrt bazel.BoolAttribute
|
2021-06-09 09:18:37 +02:00
|
|
|
useLibcrt bazel.BoolAttribute
|
|
|
|
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-11-02 07:40:51 +01:00
|
|
|
func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, isBinary bool, axis bazel.ConfigurationAxis, config string, props *BaseLinkerProperties) {
|
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
|
|
|
|
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
|
|
|
|
staticLibs := android.FirstUniqueStrings(props.Static_libs)
|
|
|
|
staticDeps := maybePartitionExportedAndImplementationsDepsExcludes(ctx, !isBinary, staticLibs, props.Exclude_static_libs, 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
|
|
|
wholeStaticLibs := android.FirstUniqueStrings(props.Whole_static_libs)
|
|
|
|
la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs))
|
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
|
|
|
|
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)
|
|
|
|
sharedDeps := maybePartitionExportedAndImplementationsDepsExcludes(ctx, !isBinary, sharedLibs, props.Exclude_shared_libs, props.Export_shared_lib_headers, bazelLabelForSharedDepsExcludes)
|
|
|
|
la.dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
|
|
|
|
la.implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
|
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 {
|
|
|
|
linkerFlags = append(linkerFlags, props.Ldflags...)
|
|
|
|
// binaries remove static flag if -shared is in the linker flags
|
|
|
|
if isBinary && android.InList("-shared", linkerFlags) {
|
|
|
|
axisFeatures = append(axisFeatures, "-static_flag")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if props.Version_script != nil {
|
|
|
|
label := android.BazelLabelForModuleSrcSingle(ctx, *props.Version_script)
|
|
|
|
la.additionalLinkerInputs.SetSelectValue(axis, config, bazel.LabelList{Includes: []bazel.Label{label}})
|
|
|
|
linkerFlags = append(linkerFlags, fmt.Sprintf("-Wl,--version-script,$(location %s)", label.Label))
|
|
|
|
}
|
|
|
|
la.linkopts.SetSelectValue(axis, config, linkerFlags)
|
|
|
|
la.useLibcrt.SetSelectValue(axis, config, props.libCrt())
|
|
|
|
|
|
|
|
// it's very unlikely for nocrt to be arch variant, so bp2build doesn't support it.
|
|
|
|
if props.crt() != nil {
|
|
|
|
if axis == bazel.NoConfigAxis {
|
|
|
|
la.linkCrt.SetSelectValue(axis, config, props.crt())
|
|
|
|
} else if axis == bazel.ArchConfigurationAxis {
|
|
|
|
ctx.ModuleErrorf("nocrt is not supported for arch variants")
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
}
|
2021-10-06 16:32:26 +02:00
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func (la *linkerAttributes) convertStripProps(ctx android.BazelConversionPathContext, module *Module) {
|
2021-10-19 19:56:10 +02:00
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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},
|
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]
|
|
|
|
// if neither an include or excludes property exists, then skip it
|
|
|
|
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.
|
|
|
|
productConfigProps := make(map[android.ProductConfigProperty]bool, len(props)+len(excludeProps))
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
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-10-19 19:56:10 +02:00
|
|
|
func (la *linkerAttributes) finalize() {
|
|
|
|
la.deps.ResolveExcludes()
|
|
|
|
la.implementationDeps.ResolveExcludes()
|
|
|
|
la.dynamicDeps.ResolveExcludes()
|
|
|
|
la.implementationDynamicDeps.ResolveExcludes()
|
|
|
|
la.wholeArchiveDeps.ResolveExcludes()
|
|
|
|
la.systemDynamicDeps.ForceSpecifyEmptyList = true
|
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 {
|
|
|
|
Includes bazel.StringListAttribute
|
|
|
|
SystemIncludes bazel.StringListAttribute
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:40:51 +01:00
|
|
|
func bp2BuildParseExportedIncludes(ctx android.BazelConversionPathContext, module *Module) BazelIncludes {
|
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
|
|
|
libraryDecorator := module.linker.(*libraryDecorator)
|
2021-05-14 09:02:34 +02:00
|
|
|
return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator)
|
|
|
|
}
|
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-09 20:08:21 +02:00
|
|
|
// Bp2buildParseExportedIncludesForPrebuiltLibrary returns a BazelIncludes with Bazel-ified values
|
|
|
|
// to export includes from the underlying module's properties.
|
2021-11-02 07:40:51 +01:00
|
|
|
func Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx android.BazelConversionPathContext, module *Module) BazelIncludes {
|
2021-05-14 09:02:34 +02:00
|
|
|
prebuiltLibraryLinker := module.linker.(*prebuiltLibraryLinker)
|
|
|
|
libraryDecorator := prebuiltLibraryLinker.libraryDecorator
|
|
|
|
return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator)
|
|
|
|
}
|
|
|
|
|
|
|
|
// bp2BuildParseExportedIncludes creates a string list attribute contains the
|
|
|
|
// exported included directories of a module.
|
2021-11-02 07:40:51 +01:00
|
|
|
func bp2BuildParseExportedIncludesHelper(ctx android.BazelConversionPathContext, module *Module, libraryDecorator *libraryDecorator) BazelIncludes {
|
2021-09-09 20:08:21 +02:00
|
|
|
exported := BazelIncludes{}
|
2021-05-21 14:37:59 +02:00
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &FlagExporterProperties{}) {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
|
2021-09-09 20:08:21 +02:00
|
|
|
if len(flagExporterProperties.Export_include_dirs) > 0 {
|
|
|
|
exported.Includes.SetSelectValue(axis, config, flagExporterProperties.Export_include_dirs)
|
|
|
|
}
|
|
|
|
if len(flagExporterProperties.Export_system_include_dirs) > 0 {
|
|
|
|
exported.SystemIncludes.SetSelectValue(axis, config, flagExporterProperties.Export_system_include_dirs)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-04-26 13:49:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
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)
|
|
|
|
if aModule, ok := m.(android.Module); ok {
|
|
|
|
if ctx.OtherModuleType(aModule) == "cc_library" && !android.GenerateCcLibraryStaticOnly(m.Name()) {
|
|
|
|
label += "_bp2build_cc_library_static"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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{}
|
|
|
|
archVariantProps := m.GetArchVariantProperties(ctx, &BinaryLinkerProperties{})
|
|
|
|
for axis, configToProps := range archVariantProps {
|
|
|
|
for _, p := range configToProps {
|
|
|
|
props := p.(*BinaryLinkerProperties)
|
|
|
|
staticExecutable := props.Static_executable
|
|
|
|
if axis == bazel.NoConfigAxis {
|
|
|
|
if linkBinaryShared := !proptools.Bool(staticExecutable); !linkBinaryShared {
|
|
|
|
attrs.Linkshared = &linkBinaryShared
|
|
|
|
}
|
|
|
|
} 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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return attrs
|
|
|
|
}
|