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 14:18:33 +08: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 (
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/bazel"
|
2021-04-13 15:14:55 +08:00
|
|
|
"path/filepath"
|
2021-05-12 12:33:00 +08:00
|
|
|
"strings"
|
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 14:18:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// bp2build functions and helpers for converting cc_* modules to Bazel.
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.DepsBp2BuildMutators(RegisterDepsBp2Build)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterDepsBp2Build(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("cc_bp2build_deps", depsBp2BuildMutator)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A naive deps mutator to add deps on all modules across all combinations of
|
|
|
|
// target props for cc modules. This is needed to make module -> bazel label
|
|
|
|
// resolution work in the bp2build mutator later. This is probably
|
|
|
|
// the wrong way to do it, but it works.
|
|
|
|
//
|
|
|
|
// TODO(jingwen): can we create a custom os mutator in depsBp2BuildMutator to do this?
|
|
|
|
func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
module, ok := ctx.Module().(*Module)
|
|
|
|
if !ok {
|
|
|
|
// Not a cc module
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !module.ConvertWithBp2build(ctx) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var allDeps []string
|
|
|
|
|
|
|
|
for _, p := range module.GetTargetProperties(&BaseLinkerProperties{}) {
|
|
|
|
// arch specific linker props
|
|
|
|
if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
|
|
|
|
allDeps = append(allDeps, baseLinkerProps.Header_libs...)
|
|
|
|
allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
|
2021-04-13 15:14:55 +08:00
|
|
|
allDeps = append(allDeps, baseLinkerProps.Static_libs...)
|
|
|
|
allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:00:01 +08:00
|
|
|
for _, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
|
2021-04-13 15:14:55 +08:00
|
|
|
// arch specific linker props
|
|
|
|
if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
|
|
|
|
allDeps = append(allDeps, baseLinkerProps.Header_libs...)
|
|
|
|
allDeps = append(allDeps, baseLinkerProps.Export_header_lib_headers...)
|
|
|
|
allDeps = append(allDeps, baseLinkerProps.Static_libs...)
|
|
|
|
allDeps = append(allDeps, baseLinkerProps.Whole_static_libs...)
|
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 14:18:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 16:15:13 +08:00
|
|
|
// Deps in the static: { .. } and shared: { .. } props of a cc_library.
|
|
|
|
if lib, ok := module.compiler.(*libraryDecorator); ok {
|
|
|
|
allDeps = append(allDeps, lib.SharedProperties.Shared.Static_libs...)
|
|
|
|
allDeps = append(allDeps, lib.SharedProperties.Shared.Whole_static_libs...)
|
|
|
|
allDeps = append(allDeps, lib.SharedProperties.Shared.Shared_libs...)
|
|
|
|
allDeps = append(allDeps, lib.SharedProperties.Shared.System_shared_libs...)
|
|
|
|
|
|
|
|
allDeps = append(allDeps, lib.StaticProperties.Static.Static_libs...)
|
|
|
|
allDeps = append(allDeps, lib.StaticProperties.Static.Whole_static_libs...)
|
|
|
|
allDeps = append(allDeps, lib.StaticProperties.Static.Shared_libs...)
|
|
|
|
allDeps = append(allDeps, lib.StaticProperties.Static.System_shared_libs...)
|
|
|
|
}
|
|
|
|
|
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 14:18:33 +08:00
|
|
|
ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)
|
|
|
|
}
|
|
|
|
|
2021-04-29 16:15:13 +08:00
|
|
|
type sharedAttributes struct {
|
2021-05-07 04:23:19 +08:00
|
|
|
copts bazel.StringListAttribute
|
|
|
|
srcs bazel.LabelListAttribute
|
|
|
|
staticDeps bazel.LabelListAttribute
|
|
|
|
dynamicDeps bazel.LabelListAttribute
|
|
|
|
wholeArchiveDeps bazel.LabelListAttribute
|
2021-04-29 16:15:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
|
|
|
|
func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) sharedAttributes {
|
|
|
|
lib, ok := module.compiler.(*libraryDecorator)
|
|
|
|
if !ok {
|
|
|
|
return sharedAttributes{}
|
|
|
|
}
|
|
|
|
|
2021-05-07 04:23:19 +08:00
|
|
|
copts := bazel.StringListAttribute{Value: lib.SharedProperties.Shared.Cflags}
|
2021-04-29 16:15:13 +08:00
|
|
|
|
2021-05-07 04:23:19 +08:00
|
|
|
srcs := bazel.LabelListAttribute{
|
|
|
|
Value: android.BazelLabelForModuleSrc(ctx, lib.SharedProperties.Shared.Srcs)}
|
|
|
|
|
|
|
|
staticDeps := bazel.LabelListAttribute{
|
|
|
|
Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Static_libs)}
|
|
|
|
|
|
|
|
dynamicDeps := bazel.LabelListAttribute{
|
|
|
|
Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Shared_libs)}
|
|
|
|
|
|
|
|
wholeArchiveDeps := bazel.LabelListAttribute{
|
|
|
|
Value: android.BazelLabelForModuleDeps(ctx, lib.SharedProperties.Shared.Whole_static_libs)}
|
2021-04-29 16:15:13 +08:00
|
|
|
|
|
|
|
return sharedAttributes{
|
2021-05-07 04:23:19 +08:00
|
|
|
copts: copts,
|
|
|
|
srcs: srcs,
|
|
|
|
staticDeps: staticDeps,
|
|
|
|
dynamicDeps: dynamicDeps,
|
|
|
|
wholeArchiveDeps: wholeArchiveDeps,
|
2021-04-29 16:15:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type staticAttributes struct {
|
2021-05-07 04:23:19 +08:00
|
|
|
copts bazel.StringListAttribute
|
|
|
|
srcs bazel.LabelListAttribute
|
|
|
|
staticDeps bazel.LabelListAttribute
|
|
|
|
dynamicDeps bazel.LabelListAttribute
|
|
|
|
wholeArchiveDeps bazel.LabelListAttribute
|
2021-04-29 16:15:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
|
|
|
|
func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticAttributes {
|
|
|
|
lib, ok := module.compiler.(*libraryDecorator)
|
|
|
|
if !ok {
|
|
|
|
return staticAttributes{}
|
|
|
|
}
|
|
|
|
|
2021-05-07 04:23:19 +08:00
|
|
|
copts := bazel.StringListAttribute{Value: lib.StaticProperties.Static.Cflags}
|
|
|
|
|
|
|
|
srcs := bazel.LabelListAttribute{
|
|
|
|
Value: android.BazelLabelForModuleSrc(ctx, lib.StaticProperties.Static.Srcs)}
|
|
|
|
|
|
|
|
staticDeps := bazel.LabelListAttribute{
|
|
|
|
Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Static_libs)}
|
|
|
|
|
|
|
|
dynamicDeps := bazel.LabelListAttribute{
|
|
|
|
Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Shared_libs)}
|
|
|
|
|
|
|
|
wholeArchiveDeps := bazel.LabelListAttribute{
|
|
|
|
Value: android.BazelLabelForModuleDeps(ctx, lib.StaticProperties.Static.Whole_static_libs)}
|
2021-04-29 16:15:13 +08:00
|
|
|
|
|
|
|
return staticAttributes{
|
2021-05-07 04:23:19 +08:00
|
|
|
copts: copts,
|
|
|
|
srcs: srcs,
|
|
|
|
staticDeps: staticDeps,
|
|
|
|
dynamicDeps: dynamicDeps,
|
|
|
|
wholeArchiveDeps: wholeArchiveDeps,
|
2021-04-29 16:15:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 18:43:12 +08:00
|
|
|
// Convenience struct to hold all attributes parsed from compiler properties.
|
|
|
|
type compilerAttributes struct {
|
2021-04-13 15:14:55 +08:00
|
|
|
copts bazel.StringListAttribute
|
|
|
|
srcs bazel.LabelListAttribute
|
|
|
|
includes bazel.StringListAttribute
|
2021-04-09 18:43:12 +08:00
|
|
|
}
|
|
|
|
|
2021-03-24 22:04:33 +08:00
|
|
|
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
|
2021-04-09 18:43:12 +08:00
|
|
|
func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {
|
2021-04-27 13:54:20 +08:00
|
|
|
var srcs bazel.LabelListAttribute
|
2021-04-09 18:43:12 +08:00
|
|
|
var copts bazel.StringListAttribute
|
2021-03-24 22:04:33 +08:00
|
|
|
|
2021-04-13 15:14:55 +08:00
|
|
|
// Creates the -I flag for a directory, while making the directory relative
|
|
|
|
// to the exec root for Bazel to work.
|
|
|
|
includeFlag := func(dir string) string {
|
|
|
|
// filepath.Join canonicalizes the path, i.e. it takes care of . or .. elements.
|
|
|
|
return "-I" + filepath.Join(ctx.ModuleDir(), dir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the list of copts.
|
|
|
|
parseCopts := func(baseCompilerProps *BaseCompilerProperties) []string {
|
2021-05-12 12:33:00 +08:00
|
|
|
var copts []string
|
2021-05-12 13:04:58 +08:00
|
|
|
for _, flag := range append(baseCompilerProps.Cflags, baseCompilerProps.Cppflags...) {
|
2021-05-12 12:33:00 +08: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.
|
|
|
|
copts = append(copts, strings.Split(flag, " ")...)
|
|
|
|
}
|
2021-04-13 15:14:55 +08:00
|
|
|
for _, dir := range parseLocalIncludeDirs(baseCompilerProps) {
|
|
|
|
copts = append(copts, includeFlag(dir))
|
|
|
|
}
|
|
|
|
return copts
|
2021-03-24 22:04:33 +08:00
|
|
|
}
|
|
|
|
|
2021-04-23 17:17:24 +08:00
|
|
|
// baseSrcs contain the list of src files that are used for every configuration.
|
|
|
|
var baseSrcs []string
|
|
|
|
// baseExcludeSrcs contain the list of src files that are excluded for every configuration.
|
|
|
|
var baseExcludeSrcs []string
|
|
|
|
// baseSrcsLabelList is a clone of the base srcs LabelList, used for computing the
|
|
|
|
// arch or os specific srcs later.
|
|
|
|
var baseSrcsLabelList bazel.LabelList
|
|
|
|
|
|
|
|
// Parse srcs from an arch or OS's props value, taking the base srcs and
|
|
|
|
// exclude srcs into account.
|
|
|
|
parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList {
|
|
|
|
// Combine the base srcs and arch-specific srcs
|
|
|
|
allSrcs := append(baseSrcs, baseCompilerProps.Srcs...)
|
|
|
|
// Combine the base exclude_srcs and configuration-specific exclude_srcs
|
|
|
|
allExcludeSrcs := append(baseExcludeSrcs, baseCompilerProps.Exclude_srcs...)
|
|
|
|
return android.BazelLabelForModuleSrcExcludes(ctx, allSrcs, allExcludeSrcs)
|
|
|
|
}
|
|
|
|
|
2021-04-05 18:35:13 +08:00
|
|
|
for _, props := range module.compiler.compilerProps() {
|
|
|
|
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
2021-04-13 15:14:55 +08:00
|
|
|
srcs.Value = parseSrcs(baseCompilerProps)
|
|
|
|
copts.Value = parseCopts(baseCompilerProps)
|
2021-04-23 17:17:24 +08:00
|
|
|
|
|
|
|
// Used for arch-specific srcs later.
|
|
|
|
baseSrcs = baseCompilerProps.Srcs
|
|
|
|
baseExcludeSrcs = baseCompilerProps.Exclude_srcs
|
|
|
|
baseSrcsLabelList = parseSrcs(baseCompilerProps)
|
2021-04-05 18:35:13 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 17:17:24 +08: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 15:14:55 +08:00
|
|
|
if c, ok := module.compiler.(*baseCompiler); ok && c.includeBuildDirectory() {
|
|
|
|
copts.Value = append(copts.Value, includeFlag("."))
|
|
|
|
} else if c, ok := module.compiler.(*libraryDecorator); ok && c.includeBuildDirectory() {
|
|
|
|
copts.Value = append(copts.Value, includeFlag("."))
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:00:01 +08:00
|
|
|
for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {
|
2021-04-05 18:35:13 +08:00
|
|
|
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
2021-04-23 17:17:24 +08: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 len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 {
|
|
|
|
srcsList := parseSrcs(baseCompilerProps)
|
|
|
|
srcs.SetValueForArch(arch.Name, srcsList)
|
|
|
|
// The base srcs value should not contain any arch-specific excludes.
|
|
|
|
srcs.Value = bazel.SubtractBazelLabelList(srcs.Value, bazel.LabelList{Includes: srcsList.Excludes})
|
|
|
|
}
|
|
|
|
|
2021-04-13 15:14:55 +08:00
|
|
|
copts.SetValueForArch(arch.Name, parseCopts(baseCompilerProps))
|
2021-04-05 18:35:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 17:17:24 +08:00
|
|
|
// After going through all archs, delete the duplicate files in the arch
|
|
|
|
// values that are already in the base srcs.Value.
|
2021-05-05 15:00:01 +08:00
|
|
|
for arch, props := range module.GetArchProperties(ctx, &BaseCompilerProperties{}) {
|
2021-04-23 17:17:24 +08:00
|
|
|
if _, ok := props.(*BaseCompilerProperties); ok {
|
|
|
|
srcs.SetValueForArch(arch.Name, bazel.SubtractBazelLabelList(srcs.GetValueForArch(arch.Name), srcs.Value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that the srcs.Value list is finalized, compare it with the original
|
|
|
|
// list, and put the difference into the default condition for the arch
|
|
|
|
// select.
|
|
|
|
defaultsSrcs := bazel.SubtractBazelLabelList(baseSrcsLabelList, srcs.Value)
|
|
|
|
// TODO(b/186153868): handle the case with multiple variant types, e.g. when arch and os are both used.
|
|
|
|
srcs.SetValueForArch(bazel.CONDITIONS_DEFAULT, defaultsSrcs)
|
|
|
|
|
|
|
|
// Handle OS specific props.
|
2021-04-05 18:35:13 +08:00
|
|
|
for os, props := range module.GetTargetProperties(&BaseCompilerProperties{}) {
|
|
|
|
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
2021-04-13 15:14:55 +08:00
|
|
|
srcsList := parseSrcs(baseCompilerProps)
|
2021-04-23 17:17:24 +08:00
|
|
|
// TODO(b/186153868): add support for os-specific srcs and exclude_srcs
|
|
|
|
srcs.SetValueForOS(os.Name, bazel.SubtractBazelLabelList(srcsList, baseSrcsLabelList))
|
2021-04-13 15:14:55 +08:00
|
|
|
copts.SetValueForOS(os.Name, parseCopts(baseCompilerProps))
|
2021-04-05 18:35:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 18:43:12 +08:00
|
|
|
return compilerAttributes{
|
|
|
|
srcs: srcs,
|
|
|
|
copts: copts,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience struct to hold all attributes parsed from linker properties.
|
|
|
|
type linkerAttributes struct {
|
2021-05-07 04:23:19 +08:00
|
|
|
deps bazel.LabelListAttribute
|
|
|
|
dynamicDeps bazel.LabelListAttribute
|
|
|
|
wholeArchiveDeps bazel.LabelListAttribute
|
|
|
|
linkopts bazel.StringListAttribute
|
|
|
|
versionScript bazel.LabelAttribute
|
2021-04-05 18:35:13 +08:00
|
|
|
}
|
|
|
|
|
2021-05-10 11:55:51 +08: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 21:35:09 +08: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 14:18:33 +08:00
|
|
|
// configurable attribute values.
|
2021-04-09 18:43:12 +08:00
|
|
|
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
|
2021-03-24 22:04:33 +08:00
|
|
|
var deps bazel.LabelListAttribute
|
2021-05-06 14:40:33 +08:00
|
|
|
var dynamicDeps bazel.LabelListAttribute
|
2021-05-07 04:23:19 +08:00
|
|
|
var wholeArchiveDeps bazel.LabelListAttribute
|
2021-03-24 22:04:33 +08:00
|
|
|
var linkopts bazel.StringListAttribute
|
2021-04-30 21:35:09 +08:00
|
|
|
var versionScript bazel.LabelAttribute
|
2021-03-24 22:04:33 +08: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 14:18:33 +08:00
|
|
|
for _, linkerProps := range module.linker.linkerProps() {
|
|
|
|
if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok {
|
|
|
|
libs := baseLinkerProps.Header_libs
|
|
|
|
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
|
2021-04-13 15:14:55 +08:00
|
|
|
libs = append(libs, baseLinkerProps.Static_libs...)
|
2021-05-07 04:23:19 +08:00
|
|
|
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
|
2021-04-13 15:14:55 +08:00
|
|
|
libs = android.SortedUniqueStrings(libs)
|
|
|
|
deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))
|
2021-05-10 11:55:51 +08:00
|
|
|
linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps)
|
2021-05-07 04:23:19 +08:00
|
|
|
wholeArchiveDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
|
2021-04-30 21:35:09 +08:00
|
|
|
|
|
|
|
if baseLinkerProps.Version_script != nil {
|
2021-05-05 15:00:01 +08:00
|
|
|
versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)
|
2021-04-30 21:35:09 +08:00
|
|
|
}
|
2021-05-06 14:40:33 +08:00
|
|
|
|
|
|
|
sharedLibs := baseLinkerProps.Shared_libs
|
|
|
|
dynamicDeps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, sharedLibs))
|
|
|
|
|
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 14:18:33 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-05 15:00:01 +08:00
|
|
|
for arch, p := range module.GetArchProperties(ctx, &BaseLinkerProperties{}) {
|
2021-03-24 22:04:33 +08:00
|
|
|
if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
|
|
|
|
libs := baseLinkerProps.Header_libs
|
|
|
|
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
|
2021-04-13 15:14:55 +08:00
|
|
|
libs = append(libs, baseLinkerProps.Static_libs...)
|
2021-05-07 04:23:19 +08:00
|
|
|
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
|
2021-03-24 22:04:33 +08:00
|
|
|
libs = android.SortedUniqueStrings(libs)
|
|
|
|
deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs))
|
2021-05-10 11:55:51 +08:00
|
|
|
linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps))
|
2021-05-07 04:23:19 +08:00
|
|
|
wholeArchiveDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
|
2021-05-06 14:40:33 +08:00
|
|
|
|
2021-05-05 15:00:01 +08:00
|
|
|
if baseLinkerProps.Version_script != nil {
|
|
|
|
versionScript.SetValueForArch(arch.Name,
|
|
|
|
android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
|
|
|
|
}
|
2021-05-11 06:41:51 +08:00
|
|
|
|
|
|
|
sharedLibs := baseLinkerProps.Shared_libs
|
|
|
|
dynamicDeps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
|
2021-03-24 22:04:33 +08: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 14:18:33 +08:00
|
|
|
for os, p := range module.GetTargetProperties(&BaseLinkerProperties{}) {
|
|
|
|
if baseLinkerProps, ok := p.(*BaseLinkerProperties); ok {
|
|
|
|
libs := baseLinkerProps.Header_libs
|
|
|
|
libs = append(libs, baseLinkerProps.Export_header_lib_headers...)
|
2021-04-13 15:14:55 +08:00
|
|
|
libs = append(libs, baseLinkerProps.Static_libs...)
|
2021-05-07 04:23:19 +08:00
|
|
|
wholeArchiveLibs := baseLinkerProps.Whole_static_libs
|
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 14:18:33 +08:00
|
|
|
libs = android.SortedUniqueStrings(libs)
|
2021-05-07 04:23:19 +08:00
|
|
|
wholeArchiveDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, wholeArchiveLibs))
|
2021-03-24 22:04:33 +08:00
|
|
|
deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs))
|
2021-05-06 14:40:33 +08:00
|
|
|
|
2021-05-10 11:55:51 +08:00
|
|
|
linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps))
|
2021-05-06 14:40:33 +08:00
|
|
|
|
|
|
|
sharedLibs := baseLinkerProps.Shared_libs
|
|
|
|
dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))
|
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 14:18:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 18:43:12 +08:00
|
|
|
return linkerAttributes{
|
2021-05-07 04:23:19 +08:00
|
|
|
deps: deps,
|
|
|
|
dynamicDeps: dynamicDeps,
|
|
|
|
wholeArchiveDeps: wholeArchiveDeps,
|
|
|
|
linkopts: linkopts,
|
|
|
|
versionScript: versionScript,
|
2021-04-09 18:43:12 +08: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 14:18:33 +08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:14:55 +08: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-07 04:06:21 +08:00
|
|
|
var relativePaths []string
|
|
|
|
for _, path := range paths {
|
2021-04-13 15:14:55 +08: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-07 04:06:21 +08:00
|
|
|
relativePaths = append(relativePaths, relativePath)
|
|
|
|
}
|
|
|
|
return relativePaths
|
|
|
|
}
|
|
|
|
|
2021-04-13 15:14:55 +08:00
|
|
|
// bp2BuildParseExportedIncludes creates a string list attribute contains the
|
2021-04-27 13:54:20 +08:00
|
|
|
// exported included directories of a module.
|
|
|
|
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 14:18:33 +08:00
|
|
|
libraryDecorator := module.linker.(*libraryDecorator)
|
|
|
|
|
2021-04-13 15:14:55 +08: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 14:18:33 +08:00
|
|
|
includeDirs := libraryDecorator.flagExporter.Properties.Export_system_include_dirs
|
|
|
|
includeDirs = append(includeDirs, libraryDecorator.flagExporter.Properties.Export_include_dirs...)
|
2021-04-07 04:06:21 +08: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 14:18:33 +08:00
|
|
|
|
2021-05-05 15:00:01 +08:00
|
|
|
for arch, props := range module.GetArchProperties(ctx, &FlagExporterProperties{}) {
|
2021-04-07 04:06:21 +08:00
|
|
|
if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
|
|
|
|
archIncludeDirs := flagExporterProperties.Export_system_include_dirs
|
|
|
|
archIncludeDirs = append(archIncludeDirs, flagExporterProperties.Export_include_dirs...)
|
|
|
|
|
|
|
|
// To avoid duplicate includes when base includes + arch includes are combined
|
2021-04-26 19:49:08 +08:00
|
|
|
// FIXME: This doesn't take conflicts between arch and os includes into account
|
2021-04-07 04:06:21 +08:00
|
|
|
archIncludeDirs = bazel.SubtractStrings(archIncludeDirs, includeDirs)
|
|
|
|
|
|
|
|
if len(archIncludeDirs) > 0 {
|
|
|
|
includeDirsAttribute.SetValueForArch(arch.Name, archIncludeDirs)
|
|
|
|
}
|
|
|
|
}
|
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 14:18:33 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 19:49:08 +08:00
|
|
|
for os, props := range module.GetTargetProperties(&FlagExporterProperties{}) {
|
|
|
|
if flagExporterProperties, ok := props.(*FlagExporterProperties); ok {
|
|
|
|
osIncludeDirs := flagExporterProperties.Export_system_include_dirs
|
|
|
|
osIncludeDirs = append(osIncludeDirs, flagExporterProperties.Export_include_dirs...)
|
|
|
|
|
|
|
|
// To avoid duplicate includes when base includes + os includes are combined
|
|
|
|
// FIXME: This doesn't take conflicts between arch and os includes into account
|
|
|
|
osIncludeDirs = bazel.SubtractStrings(osIncludeDirs, includeDirs)
|
|
|
|
|
|
|
|
if len(osIncludeDirs) > 0 {
|
|
|
|
includeDirsAttribute.SetValueForOS(os.Name, osIncludeDirs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 13:54:20 +08: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 14:18:33 +08:00
|
|
|
}
|