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-06-02 13:10:02 +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-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-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
|
|
|
|
Copts bazel.StringListAttribute
|
|
|
|
|
|
|
|
Static_deps bazel.LabelListAttribute
|
|
|
|
Dynamic_deps bazel.LabelListAttribute
|
|
|
|
Whole_archive_deps bazel.LabelListAttribute
|
2021-04-29 10:15:13 +02:00
|
|
|
}
|
|
|
|
|
2021-06-02 13:10:02 +02:00
|
|
|
func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) (cppSrcs, cSrcs, asSrcs bazel.LabelListAttribute) {
|
|
|
|
// Branch srcs into three language-specific groups.
|
|
|
|
// 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.
|
|
|
|
// TODO(b/190006308): Handle language detection of sources in a Bazel rule.
|
|
|
|
isCSrcOrFilegroup := func(s string) bool {
|
|
|
|
return strings.HasSuffix(s, ".c") || strings.HasSuffix(s, "_c_srcs")
|
|
|
|
}
|
|
|
|
|
|
|
|
isAsmSrcOrFilegroup := func(s string) bool {
|
|
|
|
return strings.HasSuffix(s, ".S") || strings.HasSuffix(s, ".s") || strings.HasSuffix(s, "_as_srcs")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
panic(fmt.Errorf("%s is not a valid Bazel label for a filegroup", fullLabel))
|
|
|
|
} else {
|
|
|
|
return m.Name() == labelParts[len(labelParts)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the filegroup dependencies into the extension-specific filegroups
|
|
|
|
// filtered in the filegroup.bzl macro.
|
|
|
|
cppFilegroup := func(label string) string {
|
2021-07-21 20:34:58 +02:00
|
|
|
m, exists := ctx.ModuleFromName(label)
|
|
|
|
if exists {
|
|
|
|
aModule, _ := m.(android.Module)
|
|
|
|
if isFilegroupNamed(aModule, label) {
|
2021-06-02 13:10:02 +02:00
|
|
|
label = label + "_cpp_srcs"
|
|
|
|
}
|
2021-07-21 20:34:58 +02:00
|
|
|
}
|
2021-06-02 13:10:02 +02:00
|
|
|
return label
|
|
|
|
}
|
|
|
|
cFilegroup := func(label string) string {
|
2021-07-21 20:34:58 +02:00
|
|
|
m, exists := ctx.ModuleFromName(label)
|
|
|
|
if exists {
|
|
|
|
aModule, _ := m.(android.Module)
|
|
|
|
if isFilegroupNamed(aModule, label) {
|
2021-06-02 13:10:02 +02:00
|
|
|
label = label + "_c_srcs"
|
|
|
|
}
|
2021-07-21 20:34:58 +02:00
|
|
|
}
|
2021-06-02 13:10:02 +02:00
|
|
|
return label
|
|
|
|
}
|
|
|
|
asFilegroup := func(label string) string {
|
2021-07-21 20:34:58 +02:00
|
|
|
m, exists := ctx.ModuleFromName(label)
|
|
|
|
if exists {
|
|
|
|
aModule, _ := m.(android.Module)
|
|
|
|
if isFilegroupNamed(aModule, label) {
|
2021-06-02 13:10:02 +02:00
|
|
|
label = label + "_as_srcs"
|
|
|
|
}
|
2021-07-21 20:34:58 +02:00
|
|
|
}
|
2021-06-02 13:10:02 +02:00
|
|
|
return label
|
|
|
|
}
|
|
|
|
|
|
|
|
cSrcs = bazel.MapLabelListAttribute(srcs, cFilegroup)
|
|
|
|
cSrcs = bazel.FilterLabelListAttribute(cSrcs, isCSrcOrFilegroup)
|
|
|
|
|
|
|
|
asSrcs = bazel.MapLabelListAttribute(srcs, asFilegroup)
|
|
|
|
asSrcs = bazel.FilterLabelListAttribute(asSrcs, isAsmSrcOrFilegroup)
|
|
|
|
|
|
|
|
cppSrcs = bazel.MapLabelListAttribute(srcs, cppFilegroup)
|
|
|
|
cppSrcs = bazel.SubtractBazelLabelListAttribute(cppSrcs, cSrcs)
|
|
|
|
cppSrcs = bazel.SubtractBazelLabelListAttribute(cppSrcs, asSrcs)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-29 10:15:13 +02:00
|
|
|
// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
|
2021-05-24 21:41:47 +02:00
|
|
|
func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) 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-05-26 06:42:42 +02:00
|
|
|
return bp2buildParseStaticOrSharedProps(ctx, module, lib, false)
|
2021-04-29 10:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
|
2021-05-24 21:41:47 +02:00
|
|
|
func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) 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-05-26 06:42:42 +02:00
|
|
|
return bp2buildParseStaticOrSharedProps(ctx, module, lib, true)
|
2021-05-24 21:41:47 +02:00
|
|
|
}
|
|
|
|
|
2021-05-26 06:42:42 +02:00
|
|
|
func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
|
|
|
|
var props StaticOrSharedProperties
|
|
|
|
if isStatic {
|
|
|
|
props = lib.StaticProperties.Static
|
|
|
|
} else {
|
|
|
|
props = lib.SharedProperties.Shared
|
|
|
|
}
|
2021-05-06 22:23:19 +02:00
|
|
|
|
2021-05-26 06:42:42 +02:00
|
|
|
attrs := staticOrSharedAttributes{
|
2021-06-11 14:51:48 +02:00
|
|
|
Copts: bazel.StringListAttribute{Value: props.Cflags},
|
|
|
|
Srcs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, props.Srcs)),
|
|
|
|
Static_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Static_libs)),
|
2021-07-13 17:47:44 +02:00
|
|
|
Dynamic_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, append(props.Shared_libs, props.System_shared_libs...))),
|
2021-06-11 14:51:48 +02:00
|
|
|
Whole_archive_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs)),
|
2021-05-26 06:42:42 +02:00
|
|
|
}
|
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))
|
|
|
|
attrs.Static_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Static_libs))
|
|
|
|
attrs.Dynamic_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Shared_libs))
|
|
|
|
attrs.Whole_archive_deps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs))
|
2021-05-26 06:42:42 +02:00
|
|
|
}
|
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-06-11 14:51:48 +02:00
|
|
|
cppSrcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, attrs.Srcs)
|
|
|
|
attrs.Srcs = cppSrcs
|
|
|
|
attrs.Srcs_c = cSrcs
|
|
|
|
attrs.Srcs_as = asSrcs
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func Bp2BuildParsePrebuiltLibraryProps(ctx android.TopDownMutatorContext, module *Module) prebuiltAttributes {
|
|
|
|
prebuiltLibraryLinker := module.linker.(*prebuiltLibraryLinker)
|
|
|
|
prebuiltLinker := prebuiltLibraryLinker.prebuiltLinker
|
|
|
|
|
|
|
|
var srcLabelAttribute bazel.LabelAttribute
|
|
|
|
|
|
|
|
if len(prebuiltLinker.properties.Srcs) > 1 {
|
|
|
|
ctx.ModuleErrorf("Bp2BuildParsePrebuiltLibraryProps: Expected at most once source file\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(prebuiltLinker.properties.Srcs) == 1 {
|
2021-05-21 14:37:59 +02:00
|
|
|
srcLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, prebuiltLinker.properties.Srcs[0]))
|
2021-05-14 09:02:34 +02:00
|
|
|
}
|
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-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-04-09 12:43:12 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 15:04:33 +01:00
|
|
|
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
|
2021-04-09 12:43:12 +02:00
|
|
|
func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {
|
2021-04-27 07:54:20 +02:00
|
|
|
var srcs bazel.LabelListAttribute
|
2021-04-09 12:43:12 +02:00
|
|
|
var copts bazel.StringListAttribute
|
2021-05-25 18:10:58 +02:00
|
|
|
var asFlags bazel.StringListAttribute
|
|
|
|
var conlyFlags bazel.StringListAttribute
|
|
|
|
var cppFlags bazel.StringListAttribute
|
2021-03-24 15:04:33 +01:00
|
|
|
|
2021-05-13 21:13:04 +02:00
|
|
|
// Creates the -I flags for a directory, while making the directory relative
|
2021-04-13 09:14:55 +02:00
|
|
|
// to the exec root for Bazel to work.
|
2021-05-13 21:13:04 +02:00
|
|
|
includeFlags := func(dir string) []string {
|
2021-04-13 09:14:55 +02:00
|
|
|
// filepath.Join canonicalizes the path, i.e. it takes care of . or .. elements.
|
2021-05-13 21:13:04 +02:00
|
|
|
moduleDirRootedPath := filepath.Join(ctx.ModuleDir(), dir)
|
|
|
|
return []string{
|
|
|
|
"-I" + moduleDirRootedPath,
|
|
|
|
// Include the bindir-rooted path (using make variable substitution). This most
|
|
|
|
// closely matches Bazel's native include path handling, which allows for dependency
|
|
|
|
// on generated headers in these directories.
|
|
|
|
// TODO(b/188084383): Handle local include directories in Bazel.
|
|
|
|
"-I$(BINDIR)/" + moduleDirRootedPath,
|
|
|
|
}
|
2021-04-13 09:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the list of module-relative include directories (-I).
|
|
|
|
parseLocalIncludeDirs := func(baseCompilerProps *BaseCompilerProperties) []string {
|
|
|
|
// include_dirs are root-relative, not module-relative.
|
|
|
|
includeDirs := bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Include_dirs)
|
|
|
|
return append(includeDirs, baseCompilerProps.Local_include_dirs...)
|
|
|
|
}
|
|
|
|
|
2021-05-25 18:10:58 +02:00
|
|
|
parseCommandLineFlags := func(soongFlags []string) []string {
|
|
|
|
var result []string
|
|
|
|
for _, flag := range soongFlags {
|
2021-05-12 06:33:00 +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.
|
2021-05-25 18:10:58 +02:00
|
|
|
result = append(result, strings.Split(flag, " ")...)
|
2021-05-12 06:33:00 +02:00
|
|
|
}
|
2021-05-25 18:10:58 +02:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-06-02 19:02:03 +02:00
|
|
|
// Parse srcs from an arch or OS's props value.
|
2021-04-23 11:17:24 +02:00
|
|
|
parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList {
|
2021-05-13 21:13:04 +02:00
|
|
|
// Add srcs-like dependencies such as generated files.
|
|
|
|
// First create a LabelList containing these dependencies, then merge the values with srcs.
|
|
|
|
generatedHdrsAndSrcs := baseCompilerProps.Generated_headers
|
|
|
|
generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, baseCompilerProps.Generated_sources...)
|
|
|
|
generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDeps(ctx, generatedHdrsAndSrcs)
|
|
|
|
|
2021-06-02 19:02:03 +02:00
|
|
|
allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, baseCompilerProps.Srcs, baseCompilerProps.Exclude_srcs)
|
2021-05-13 21:13:04 +02:00
|
|
|
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList)
|
2021-04-23 11:17:24 +02:00
|
|
|
}
|
|
|
|
|
2021-04-05 12:35:13 +02:00
|
|
|
for _, props := range module.compiler.compilerProps() {
|
|
|
|
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
2021-05-21 14:37:59 +02:00
|
|
|
srcs.SetValue(parseSrcs(baseCompilerProps))
|
2021-07-13 17:47:44 +02:00
|
|
|
copts.Value = parseCommandLineFlags(baseCompilerProps.Cflags)
|
2021-05-25 18:10:58 +02:00
|
|
|
asFlags.Value = parseCommandLineFlags(baseCompilerProps.Asflags)
|
|
|
|
conlyFlags.Value = parseCommandLineFlags(baseCompilerProps.Conlyflags)
|
|
|
|
cppFlags.Value = parseCommandLineFlags(baseCompilerProps.Cppflags)
|
2021-04-23 11:17:24 +02:00
|
|
|
|
2021-07-13 17:47:44 +02:00
|
|
|
for _, dir := range parseLocalIncludeDirs(baseCompilerProps) {
|
|
|
|
copts.Value = append(copts.Value, includeFlags(dir)...)
|
|
|
|
asFlags.Value = append(asFlags.Value, includeFlags(dir)...)
|
|
|
|
}
|
2021-04-05 12:35:13 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 11:17:24 +02:00
|
|
|
// Handle include_build_directory prop. If the property is true, then the
|
|
|
|
// target has access to all headers recursively in the package, and has
|
|
|
|
// "-I<module-dir>" in its copts.
|
2021-04-13 09:14:55 +02:00
|
|
|
if c, ok := module.compiler.(*baseCompiler); ok && c.includeBuildDirectory() {
|
2021-05-13 21:13:04 +02:00
|
|
|
copts.Value = append(copts.Value, includeFlags(".")...)
|
2021-07-13 17:47:44 +02:00
|
|
|
asFlags.Value = append(asFlags.Value, includeFlags(".")...)
|
2021-04-13 09:14:55 +02:00
|
|
|
} else if c, ok := module.compiler.(*libraryDecorator); ok && c.includeBuildDirectory() {
|
2021-05-13 21:13:04 +02:00
|
|
|
copts.Value = append(copts.Value, includeFlags(".")...)
|
2021-07-13 17:47:44 +02:00
|
|
|
asFlags.Value = append(asFlags.Value, includeFlags(".")...)
|
2021-04-13 09:14:55 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
|
|
|
|
|
|
|
|
for axis, configToProps := range archVariantCompilerProps {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
|
|
|
// 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 len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 {
|
|
|
|
srcsList := parseSrcs(baseCompilerProps)
|
|
|
|
srcs.SetSelectValue(axis, config, srcsList)
|
|
|
|
}
|
2021-04-23 11:17:24 +02:00
|
|
|
|
2021-07-13 17:47:44 +02:00
|
|
|
archVariantCopts := parseCommandLineFlags(baseCompilerProps.Cflags)
|
|
|
|
archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags)
|
|
|
|
for _, dir := range parseLocalIncludeDirs(baseCompilerProps) {
|
|
|
|
archVariantCopts = append(archVariantCopts, includeFlags(dir)...)
|
|
|
|
archVariantAsflags = append(archVariantAsflags, includeFlags(dir)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
copts.SetSelectValue(axis, config, archVariantCopts)
|
|
|
|
asFlags.SetSelectValue(axis, config, archVariantAsflags)
|
2021-05-21 14:37:59 +02:00
|
|
|
conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Conlyflags))
|
|
|
|
cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(baseCompilerProps.Cppflags))
|
|
|
|
}
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-02 19:02:03 +02:00
|
|
|
srcs.ResolveExcludes()
|
2021-04-05 12:35:13 +02:00
|
|
|
|
2021-05-26 14:45:30 +02:00
|
|
|
productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{
|
|
|
|
"Cflags": &copts,
|
|
|
|
"Asflags": &asFlags,
|
|
|
|
"CppFlags": &cppFlags,
|
|
|
|
}
|
2021-05-06 19:54:29 +02:00
|
|
|
productVariableProps := android.ProductVariableProperties(ctx)
|
2021-05-26 14:45:30 +02:00
|
|
|
for propName, attr := range productVarPropNameToAttribute {
|
|
|
|
if props, exists := productVariableProps[propName]; exists {
|
|
|
|
for _, prop := range props {
|
|
|
|
flags, ok := prop.Property.([]string)
|
|
|
|
if !ok {
|
|
|
|
ctx.ModuleErrorf("Could not convert product variable %s property", proptools.PropertyNameForField(propName))
|
|
|
|
}
|
|
|
|
newFlags, _ := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable)
|
2021-06-02 22:02:22 +02:00
|
|
|
attr.SetSelectValue(bazel.ProductVariableConfigurationAxis(prop.FullConfig), prop.FullConfig, newFlags)
|
2021-05-06 19:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-02 13:10:02 +02:00
|
|
|
srcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, srcs)
|
|
|
|
|
2021-04-09 12:43:12 +02:00
|
|
|
return compilerAttributes{
|
2021-05-25 18:10:58 +02:00
|
|
|
copts: copts,
|
|
|
|
srcs: srcs,
|
|
|
|
asFlags: asFlags,
|
|
|
|
asSrcs: asSrcs,
|
|
|
|
cSrcs: cSrcs,
|
|
|
|
conlyFlags: conlyFlags,
|
|
|
|
cppFlags: cppFlags,
|
2021-04-09 12:43:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience struct to hold all attributes parsed from linker properties.
|
|
|
|
type linkerAttributes struct {
|
2021-06-09 09:18:37 +02:00
|
|
|
deps bazel.LabelListAttribute
|
|
|
|
dynamicDeps bazel.LabelListAttribute
|
|
|
|
wholeArchiveDeps bazel.LabelListAttribute
|
|
|
|
exportedDeps bazel.LabelListAttribute
|
|
|
|
useLibcrt bazel.BoolAttribute
|
|
|
|
linkopts bazel.StringListAttribute
|
|
|
|
versionScript bazel.LabelAttribute
|
|
|
|
stripKeepSymbols bazel.BoolAttribute
|
|
|
|
stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
|
|
|
|
stripKeepSymbolsList bazel.StringListAttribute
|
|
|
|
stripAll bazel.BoolAttribute
|
|
|
|
stripNone bazel.BoolAttribute
|
2021-04-05 12:35:13 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 05:55:51 +02:00
|
|
|
// FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here
|
|
|
|
func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string {
|
|
|
|
flags := linkerProperties.Ldflags
|
|
|
|
if !BoolDefault(linkerProperties.Pack_relocations, true) {
|
|
|
|
flags = append(flags, "-Wl,--pack-dyn-relocs=none")
|
|
|
|
}
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2021-04-30 15:35:09 +02:00
|
|
|
// bp2BuildParseLinkerProps parses the linker properties of a module, including
|
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
|
|
|
// configurable attribute values.
|
2021-04-09 12:43:12 +02:00
|
|
|
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
|
2021-06-02 22:02:22 +02:00
|
|
|
var headerDeps bazel.LabelListAttribute
|
|
|
|
var staticDeps bazel.LabelListAttribute
|
2021-05-19 00:35:24 +02:00
|
|
|
var exportedDeps bazel.LabelListAttribute
|
2021-05-06 08:40:33 +02:00
|
|
|
var dynamicDeps bazel.LabelListAttribute
|
2021-05-06 22:23:19 +02:00
|
|
|
var wholeArchiveDeps bazel.LabelListAttribute
|
2021-03-24 15:04:33 +01:00
|
|
|
var linkopts bazel.StringListAttribute
|
2021-04-30 15:35:09 +02:00
|
|
|
var versionScript bazel.LabelAttribute
|
2021-06-03 19:43:01 +02:00
|
|
|
var useLibcrt bazel.BoolAttribute
|
2021-03-24 15:04:33 +01:00
|
|
|
|
2021-06-09 09:18:37 +02:00
|
|
|
var stripKeepSymbols bazel.BoolAttribute
|
|
|
|
var stripKeepSymbolsAndDebugFrame bazel.BoolAttribute
|
|
|
|
var stripKeepSymbolsList bazel.StringListAttribute
|
|
|
|
var stripAll bazel.BoolAttribute
|
|
|
|
var stripNone bazel.BoolAttribute
|
|
|
|
|
|
|
|
if libraryDecorator, ok := module.linker.(*libraryDecorator); ok {
|
|
|
|
stripProperties := libraryDecorator.stripper.StripProperties
|
|
|
|
stripKeepSymbols.Value = stripProperties.Strip.Keep_symbols
|
|
|
|
stripKeepSymbolsList.Value = stripProperties.Strip.Keep_symbols_list
|
|
|
|
stripKeepSymbolsAndDebugFrame.Value = stripProperties.Strip.Keep_symbols_and_debug_frame
|
|
|
|
stripAll.Value = stripProperties.Strip.All
|
|
|
|
stripNone.Value = stripProperties.Strip.None
|
|
|
|
}
|
|
|
|
|
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
if stripProperties, ok := props.(*StripProperties); ok {
|
|
|
|
stripKeepSymbols.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols)
|
|
|
|
stripKeepSymbolsList.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_list)
|
|
|
|
stripKeepSymbolsAndDebugFrame.SetSelectValue(axis, config, stripProperties.Strip.Keep_symbols_and_debug_frame)
|
|
|
|
stripAll.SetSelectValue(axis, config, stripProperties.Strip.All)
|
|
|
|
stripNone.SetSelectValue(axis, config, stripProperties.Strip.None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
for _, linkerProps := range module.linker.linkerProps() {
|
|
|
|
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
|
2021-06-02 22:02:22 +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(baseLinkerProps.Static_libs)
|
|
|
|
staticDeps.Value = android.BazelLabelForModuleDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs)
|
|
|
|
wholeArchiveLibs := android.FirstUniqueStrings(baseLinkerProps.Whole_static_libs)
|
2021-06-11 00:20:06 +02:00
|
|
|
wholeArchiveDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleWholeDepsExcludes(ctx, wholeArchiveLibs, baseLinkerProps.Exclude_static_libs))
|
2021-07-13 17:47:44 +02:00
|
|
|
// TODO(b/186024507): Handle system_shared_libs as its own attribute, so that the appropriate default
|
|
|
|
// may be supported.
|
|
|
|
sharedLibs := android.FirstUniqueStrings(append(baseLinkerProps.Shared_libs, baseLinkerProps.System_shared_libs...))
|
2021-06-02 22:02:22 +02:00
|
|
|
dynamicDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs))
|
|
|
|
|
|
|
|
headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs)
|
|
|
|
headerDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, headerLibs))
|
|
|
|
// TODO(b/188796939): also handle export_static_lib_headers, export_shared_lib_headers,
|
|
|
|
// export_generated_headers
|
|
|
|
exportedLibs := android.FirstUniqueStrings(baseLinkerProps.Export_header_lib_headers)
|
2021-05-19 00:35:24 +02:00
|
|
|
exportedDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, exportedLibs))
|
2021-04-30 15:35:09 +02:00
|
|
|
|
2021-06-02 22:02:22 +02:00
|
|
|
linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps)
|
2021-04-30 15:35:09 +02:00
|
|
|
if baseLinkerProps.Version_script != nil {
|
2021-05-21 14:37:59 +02:00
|
|
|
versionScript.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
|
2021-04-30 15:35:09 +02:00
|
|
|
}
|
2021-06-03 19:43:01 +02:00
|
|
|
useLibcrt.Value = baseLinkerProps.libCrt()
|
2021-05-06 08:40:33 +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
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
|
2021-06-02 22:02:22 +02:00
|
|
|
staticLibs := android.FirstUniqueStrings(baseLinkerProps.Static_libs)
|
|
|
|
staticDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDepsExcludes(ctx, staticLibs, baseLinkerProps.Exclude_static_libs))
|
|
|
|
wholeArchiveLibs := android.FirstUniqueStrings(baseLinkerProps.Whole_static_libs)
|
2021-06-11 00:20:06 +02:00
|
|
|
wholeArchiveDeps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDepsExcludes(ctx, wholeArchiveLibs, baseLinkerProps.Exclude_static_libs))
|
2021-07-13 17:47:44 +02:00
|
|
|
sharedLibs := android.FirstUniqueStrings(append(baseLinkerProps.Shared_libs, baseLinkerProps.System_shared_libs...))
|
2021-06-02 22:02:22 +02:00
|
|
|
dynamicDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDepsExcludes(ctx, sharedLibs, baseLinkerProps.Exclude_shared_libs))
|
|
|
|
|
|
|
|
headerLibs := android.FirstUniqueStrings(baseLinkerProps.Header_libs)
|
|
|
|
headerDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, headerLibs))
|
|
|
|
exportedLibs := android.FirstUniqueStrings(baseLinkerProps.Export_header_lib_headers)
|
2021-05-21 14:37:59 +02:00
|
|
|
exportedDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, exportedLibs))
|
2021-05-19 12:49:02 +02:00
|
|
|
|
2021-06-02 22:02:22 +02:00
|
|
|
linkopts.SetSelectValue(axis, config, getBp2BuildLinkerFlags(baseLinkerProps))
|
2021-05-27 08:15:54 +02:00
|
|
|
if baseLinkerProps.Version_script != nil {
|
2021-05-21 14:37:59 +02:00
|
|
|
versionScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
|
2021-05-27 08:15:54 +02:00
|
|
|
}
|
2021-06-03 19:43:01 +02:00
|
|
|
useLibcrt.SetSelectValue(axis, config, baseLinkerProps.libCrt())
|
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
|
|
|
|
|
|
|
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-06-11 00:20:06 +02:00
|
|
|
"Shared_libs": productVarDep{attribute: &dynamicDeps, depResolutionFunc: android.BazelLabelForModuleDepsExcludes},
|
|
|
|
"Static_libs": productVarDep{"Exclude_static_libs", &staticDeps, android.BazelLabelForModuleDepsExcludes},
|
|
|
|
"Whole_static_libs": productVarDep{"Exclude_static_libs", &wholeArchiveDeps, android.BazelLabelForModuleWholeDepsExcludes},
|
2021-06-02 22:02:22 +02:00
|
|
|
}
|
2021-05-27 08:15:54 +02:00
|
|
|
|
2021-06-02 22:02:22 +02:00
|
|
|
productVariableProps := android.ProductVariableProperties(ctx)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
// 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 only and include or only an exclude to handle
|
|
|
|
configs := make(map[string]bool, len(props)+len(excludeProps))
|
|
|
|
for config := range props {
|
|
|
|
configs[config] = true
|
|
|
|
}
|
|
|
|
for config := range excludeProps {
|
|
|
|
configs[config] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
for config := range configs {
|
|
|
|
prop, includesExists := props[config]
|
|
|
|
excludesProp, excludesExists := excludeProps[config]
|
|
|
|
var includes, excludes []string
|
|
|
|
var ok bool
|
|
|
|
// if there was no includes/excludes property, casting fails and that's expected
|
|
|
|
if includes, ok = prop.Property.([]string); includesExists && !ok {
|
|
|
|
ctx.ModuleErrorf("Could not convert product variable %s property", name)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-06-02 22:02:22 +02:00
|
|
|
if excludes, ok = excludesProp.Property.([]string); excludesExists && !ok {
|
|
|
|
ctx.ModuleErrorf("Could not convert product variable %s property", dep.excludesField)
|
|
|
|
}
|
2021-06-11 00:20:06 +02:00
|
|
|
|
|
|
|
dep.attribute.SetSelectValue(bazel.ProductVariableConfigurationAxis(config), config, 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-06-02 22:02:22 +02:00
|
|
|
staticDeps.ResolveExcludes()
|
|
|
|
dynamicDeps.ResolveExcludes()
|
|
|
|
wholeArchiveDeps.ResolveExcludes()
|
|
|
|
|
|
|
|
headerDeps.Append(staticDeps)
|
|
|
|
|
2021-04-09 12:43:12 +02:00
|
|
|
return linkerAttributes{
|
2021-06-02 22:02:22 +02:00
|
|
|
deps: headerDeps,
|
2021-05-19 00:35:24 +02:00
|
|
|
exportedDeps: exportedDeps,
|
2021-05-06 22:23:19 +02:00
|
|
|
dynamicDeps: dynamicDeps,
|
|
|
|
wholeArchiveDeps: wholeArchiveDeps,
|
|
|
|
linkopts: linkopts,
|
2021-06-03 19:43:01 +02:00
|
|
|
useLibcrt: useLibcrt,
|
2021-05-06 22:23:19 +02:00
|
|
|
versionScript: versionScript,
|
2021-06-09 09:18:37 +02:00
|
|
|
|
|
|
|
// Strip properties
|
|
|
|
stripKeepSymbols: stripKeepSymbols,
|
|
|
|
stripKeepSymbolsAndDebugFrame: stripKeepSymbolsAndDebugFrame,
|
|
|
|
stripKeepSymbolsList: stripKeepSymbolsList,
|
|
|
|
stripAll: stripAll,
|
|
|
|
stripNone: stripNone,
|
2021-04-09 12:43:12 +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-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-04-27 07:54:20 +02:00
|
|
|
func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) bazel.StringListAttribute {
|
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-05-14 09:02:34 +02:00
|
|
|
func Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx android.TopDownMutatorContext, module *Module) bazel.StringListAttribute {
|
|
|
|
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.
|
|
|
|
func bp2BuildParseExportedIncludesHelper(ctx android.TopDownMutatorContext, module *Module, libraryDecorator *libraryDecorator) bazel.StringListAttribute {
|
2021-04-13 09:14:55 +02:00
|
|
|
// Export_system_include_dirs and export_include_dirs are already module dir
|
|
|
|
// relative, so they don't need to be relativized like include_dirs, which
|
|
|
|
// are root-relative.
|
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
|
|
|
includeDirs := libraryDecorator.flagExporter.Properties.Export_system_include_dirs
|
|
|
|
includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...)
|
2021-04-06 22:06:21 +02:00
|
|
|
includeDirsAttribute := bazel.MakeStringListAttribute(includeDirs)
|
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-05-19 12:49:02 +02:00
|
|
|
getVariantIncludeDirs := func(includeDirs []string, flagExporterProperties *FlagExporterProperties) []string {
|
|
|
|
variantIncludeDirs := flagExporterProperties.Export_system_include_dirs
|
|
|
|
variantIncludeDirs = append(variantIncludeDirs, flagExporterProperties.Export_include_dirs...)
|
2021-04-06 22:06:21 +02:00
|
|
|
|
2021-05-19 12:49:02 +02:00
|
|
|
// To avoid duplicate includes when base includes + arch includes are combined
|
|
|
|
// TODO: This doesn't take conflicts between arch and os includes into account
|
|
|
|
variantIncludeDirs = bazel.SubtractStrings(variantIncludeDirs, includeDirs)
|
|
|
|
return variantIncludeDirs
|
|
|
|
}
|
2021-04-06 22:06:21 +02:00
|
|
|
|
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 {
|
|
|
|
archVariantIncludeDirs := getVariantIncludeDirs(includeDirs, flagExporterProperties)
|
|
|
|
if len(archVariantIncludeDirs) > 0 {
|
|
|
|
includeDirsAttribute.SetSelectValue(axis, config, archVariantIncludeDirs)
|
2021-05-19 12:49:02 +02:00
|
|
|
}
|
2021-04-26 13:49:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 07:54:20 +02:00
|
|
|
return includeDirsAttribute
|
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
|
|
|
}
|