2021-05-21 14:37:59 +02: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 bazel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-08-03 03:06:50 +02:00
|
|
|
"math"
|
|
|
|
"sort"
|
2021-05-21 14:37:59 +02:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// ArchType names in arch.go
|
2022-07-15 03:10:34 +02:00
|
|
|
archArm = "arm"
|
|
|
|
archArm64 = "arm64"
|
|
|
|
archRiscv64 = "riscv64"
|
|
|
|
archX86 = "x86"
|
|
|
|
archX86_64 = "x86_64"
|
2021-05-21 14:37:59 +02:00
|
|
|
|
|
|
|
// OsType names in arch.go
|
2022-07-27 09:22:06 +02:00
|
|
|
OsAndroid = "android"
|
2023-05-15 20:35:36 +02:00
|
|
|
OsDarwin = "darwin"
|
|
|
|
OsLinux = "linux_glibc"
|
2021-07-24 00:23:07 +02:00
|
|
|
osLinuxMusl = "linux_musl"
|
2021-05-21 14:37:59 +02:00
|
|
|
osLinuxBionic = "linux_bionic"
|
2023-05-15 20:35:36 +02:00
|
|
|
OsWindows = "windows"
|
2021-05-21 14:37:59 +02:00
|
|
|
|
|
|
|
// Targets in arch.go
|
|
|
|
osArchAndroidArm = "android_arm"
|
|
|
|
osArchAndroidArm64 = "android_arm64"
|
2022-07-15 03:10:34 +02:00
|
|
|
osArchAndroidRiscv64 = "android_riscv64"
|
2021-05-21 14:37:59 +02:00
|
|
|
osArchAndroidX86 = "android_x86"
|
|
|
|
osArchAndroidX86_64 = "android_x86_64"
|
2021-10-19 09:22:06 +02:00
|
|
|
osArchDarwinArm64 = "darwin_arm64"
|
2021-05-21 14:37:59 +02:00
|
|
|
osArchDarwinX86_64 = "darwin_x86_64"
|
|
|
|
osArchLinuxX86 = "linux_glibc_x86"
|
|
|
|
osArchLinuxX86_64 = "linux_glibc_x86_64"
|
2022-06-16 02:25:51 +02:00
|
|
|
osArchLinuxMuslArm = "linux_musl_arm"
|
|
|
|
osArchLinuxMuslArm64 = "linux_musl_arm64"
|
2021-07-24 00:23:07 +02:00
|
|
|
osArchLinuxMuslX86 = "linux_musl_x86"
|
|
|
|
osArchLinuxMuslX86_64 = "linux_musl_x86_64"
|
2021-05-21 14:37:59 +02:00
|
|
|
osArchLinuxBionicArm64 = "linux_bionic_arm64"
|
|
|
|
osArchLinuxBionicX86_64 = "linux_bionic_x86_64"
|
|
|
|
osArchWindowsX86 = "windows_x86"
|
|
|
|
osArchWindowsX86_64 = "windows_x86_64"
|
|
|
|
|
|
|
|
// This is the string representation of the default condition wherever a
|
|
|
|
// configurable attribute is used in a select statement, i.e.
|
|
|
|
// //conditions:default for Bazel.
|
|
|
|
//
|
|
|
|
// This is consistently named "conditions_default" to mirror the Soong
|
|
|
|
// config variable default key in an Android.bp file, although there's no
|
|
|
|
// integration with Soong config variables (yet).
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
ConditionsDefaultConfigKey = "conditions_default"
|
2021-05-21 14:37:59 +02:00
|
|
|
|
|
|
|
ConditionsDefaultSelectKey = "//conditions:default"
|
|
|
|
|
|
|
|
productVariableBazelPackage = "//build/bazel/product_variables"
|
2022-07-27 09:22:06 +02:00
|
|
|
|
2023-04-18 08:20:40 +02:00
|
|
|
AndroidAndInApex = "android-in_apex"
|
|
|
|
AndroidPlatform = "system"
|
2022-09-16 22:17:48 +02:00
|
|
|
|
|
|
|
InApex = "in_apex"
|
|
|
|
NonApex = "non_apex"
|
2023-05-04 23:20:16 +02:00
|
|
|
|
|
|
|
ErrorproneDisabled = "errorprone_disabled"
|
2021-05-21 14:37:59 +02:00
|
|
|
)
|
|
|
|
|
2022-08-03 03:06:50 +02:00
|
|
|
func PowerSetWithoutEmptySet[T any](items []T) [][]T {
|
|
|
|
resultSize := int(math.Pow(2, float64(len(items))))
|
|
|
|
powerSet := make([][]T, 0, resultSize-1)
|
|
|
|
for i := 1; i < resultSize; i++ {
|
|
|
|
combination := make([]T, 0)
|
|
|
|
for j := 0; j < len(items); j++ {
|
|
|
|
if (i>>j)%2 == 1 {
|
|
|
|
combination = append(combination, items[j])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
powerSet = append(powerSet, combination)
|
|
|
|
}
|
|
|
|
return powerSet
|
|
|
|
}
|
|
|
|
|
|
|
|
func createPlatformArchMap() map[string]string {
|
|
|
|
// Copy of archFeatures from android/arch_list.go because the bazel
|
|
|
|
// package can't access the android package
|
|
|
|
archFeatures := map[string][]string{
|
|
|
|
"arm": {
|
|
|
|
"neon",
|
|
|
|
},
|
|
|
|
"arm64": {
|
|
|
|
"dotprod",
|
|
|
|
},
|
2022-07-15 03:10:34 +02:00
|
|
|
"riscv64": {},
|
2022-08-03 03:06:50 +02:00
|
|
|
"x86": {
|
|
|
|
"ssse3",
|
|
|
|
"sse4",
|
|
|
|
"sse4_1",
|
|
|
|
"sse4_2",
|
|
|
|
"aes_ni",
|
|
|
|
"avx",
|
|
|
|
"avx2",
|
|
|
|
"avx512",
|
|
|
|
"popcnt",
|
|
|
|
"movbe",
|
|
|
|
},
|
|
|
|
"x86_64": {
|
|
|
|
"ssse3",
|
|
|
|
"sse4",
|
|
|
|
"sse4_1",
|
|
|
|
"sse4_2",
|
|
|
|
"aes_ni",
|
|
|
|
"avx",
|
|
|
|
"avx2",
|
|
|
|
"avx512",
|
|
|
|
"popcnt",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
result := make(map[string]string)
|
|
|
|
for arch, allFeatures := range archFeatures {
|
|
|
|
result[arch] = "//build/bazel/platforms/arch:" + arch
|
|
|
|
// Sometimes we want to select on multiple features being active, so
|
|
|
|
// add the power set of all possible features to the map. More details
|
|
|
|
// in android.ModuleBase.GetArchVariantProperties
|
|
|
|
for _, features := range PowerSetWithoutEmptySet(allFeatures) {
|
|
|
|
sort.Strings(features)
|
|
|
|
archFeaturesName := arch + "-" + strings.Join(features, "-")
|
|
|
|
result[archFeaturesName] = "//build/bazel/platforms/arch/variants:" + archFeaturesName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result[ConditionsDefaultConfigKey] = ConditionsDefaultSelectKey
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
var (
|
|
|
|
// These are the list of OSes and architectures with a Bazel config_setting
|
|
|
|
// and constraint value equivalent. These exist in arch.go, but the android
|
|
|
|
// package depends on the bazel package, so a cyclic dependency prevents
|
|
|
|
// using those variables here.
|
|
|
|
|
|
|
|
// A map of architectures to the Bazel label of the constraint_value
|
|
|
|
// for the @platforms//cpu:cpu constraint_setting
|
2022-08-03 03:06:50 +02:00
|
|
|
platformArchMap = createPlatformArchMap()
|
2021-05-21 14:37:59 +02:00
|
|
|
|
|
|
|
// A map of target operating systems to the Bazel label of the
|
|
|
|
// constraint_value for the @platforms//os:os constraint_setting
|
|
|
|
platformOsMap = map[string]string{
|
2022-07-27 09:22:06 +02:00
|
|
|
OsAndroid: "//build/bazel/platforms/os:android",
|
2023-05-15 20:35:36 +02:00
|
|
|
OsDarwin: "//build/bazel/platforms/os:darwin",
|
|
|
|
OsLinux: "//build/bazel/platforms/os:linux_glibc",
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
osLinuxMusl: "//build/bazel/platforms/os:linux_musl",
|
|
|
|
osLinuxBionic: "//build/bazel/platforms/os:linux_bionic",
|
2023-05-15 20:35:36 +02:00
|
|
|
OsWindows: "//build/bazel/platforms/os:windows",
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
platformOsArchMap = map[string]string{
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
osArchAndroidArm: "//build/bazel/platforms/os_arch:android_arm",
|
|
|
|
osArchAndroidArm64: "//build/bazel/platforms/os_arch:android_arm64",
|
2022-07-15 03:10:34 +02:00
|
|
|
osArchAndroidRiscv64: "//build/bazel/platforms/os_arch:android_riscv64",
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
osArchAndroidX86: "//build/bazel/platforms/os_arch:android_x86",
|
|
|
|
osArchAndroidX86_64: "//build/bazel/platforms/os_arch:android_x86_64",
|
2021-10-19 09:22:06 +02:00
|
|
|
osArchDarwinArm64: "//build/bazel/platforms/os_arch:darwin_arm64",
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
osArchDarwinX86_64: "//build/bazel/platforms/os_arch:darwin_x86_64",
|
|
|
|
osArchLinuxX86: "//build/bazel/platforms/os_arch:linux_glibc_x86",
|
|
|
|
osArchLinuxX86_64: "//build/bazel/platforms/os_arch:linux_glibc_x86_64",
|
2022-06-16 02:25:51 +02:00
|
|
|
osArchLinuxMuslArm: "//build/bazel/platforms/os_arch:linux_musl_arm",
|
|
|
|
osArchLinuxMuslArm64: "//build/bazel/platforms/os_arch:linux_musl_arm64",
|
bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.
Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.
As a related fix, supports static struct for cc_library_static.
Also, removes some elements from the bp2build denylist.
Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-04 03:01:05 +02:00
|
|
|
osArchLinuxMuslX86: "//build/bazel/platforms/os_arch:linux_musl_x86",
|
|
|
|
osArchLinuxMuslX86_64: "//build/bazel/platforms/os_arch:linux_musl_x86_64",
|
|
|
|
osArchLinuxBionicArm64: "//build/bazel/platforms/os_arch:linux_bionic_arm64",
|
|
|
|
osArchLinuxBionicX86_64: "//build/bazel/platforms/os_arch:linux_bionic_x86_64",
|
|
|
|
osArchWindowsX86: "//build/bazel/platforms/os_arch:windows_x86",
|
|
|
|
osArchWindowsX86_64: "//build/bazel/platforms/os_arch:windows_x86_64",
|
|
|
|
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|
2021-12-10 00:10:18 +01:00
|
|
|
|
|
|
|
// Map where keys are OsType names, and values are slices containing the archs
|
|
|
|
// that that OS supports.
|
|
|
|
// These definitions copied from arch.go.
|
|
|
|
// TODO(cparsons): Source from arch.go; this task is nontrivial, as it currently results
|
|
|
|
// in a cyclic dependency.
|
|
|
|
osToArchMap = map[string][]string{
|
2022-07-15 03:10:34 +02:00
|
|
|
OsAndroid: {archArm, archArm64, archRiscv64, archX86, archX86_64},
|
2023-05-15 20:35:36 +02:00
|
|
|
OsLinux: {archX86, archX86_64},
|
2021-12-10 00:10:18 +01:00
|
|
|
osLinuxMusl: {archX86, archX86_64},
|
2023-05-15 20:35:36 +02:00
|
|
|
OsDarwin: {archArm64, archX86_64},
|
2021-12-10 00:10:18 +01:00
|
|
|
osLinuxBionic: {archArm64, archX86_64},
|
|
|
|
// TODO(cparsons): According to arch.go, this should contain archArm, archArm64, as well.
|
2023-05-15 20:35:36 +02:00
|
|
|
OsWindows: {archX86, archX86_64},
|
2021-12-10 00:10:18 +01:00
|
|
|
}
|
2022-07-27 09:22:06 +02:00
|
|
|
|
|
|
|
osAndInApexMap = map[string]string{
|
|
|
|
AndroidAndInApex: "//build/bazel/rules/apex:android-in_apex",
|
2023-04-18 08:20:40 +02:00
|
|
|
AndroidPlatform: "//build/bazel/rules/apex:system",
|
2023-05-15 20:35:36 +02:00
|
|
|
OsDarwin: "//build/bazel/platforms/os:darwin",
|
|
|
|
OsLinux: "//build/bazel/platforms/os:linux_glibc",
|
2022-11-23 15:42:05 +01:00
|
|
|
osLinuxMusl: "//build/bazel/platforms/os:linux_musl",
|
|
|
|
osLinuxBionic: "//build/bazel/platforms/os:linux_bionic",
|
2023-05-15 20:35:36 +02:00
|
|
|
OsWindows: "//build/bazel/platforms/os:windows",
|
2022-07-27 09:22:06 +02:00
|
|
|
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey,
|
|
|
|
}
|
2022-09-16 22:17:48 +02:00
|
|
|
|
|
|
|
inApexMap = map[string]string{
|
|
|
|
InApex: "//build/bazel/rules/apex:in_apex",
|
|
|
|
NonApex: "//build/bazel/rules/apex:non_apex",
|
|
|
|
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey,
|
|
|
|
}
|
2023-05-04 23:20:16 +02:00
|
|
|
|
|
|
|
errorProneMap = map[string]string{
|
|
|
|
ErrorproneDisabled: "//build/bazel/rules/java/errorprone:errorprone_globally_disabled",
|
|
|
|
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey,
|
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// basic configuration types
|
|
|
|
type configurationType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
noConfig configurationType = iota
|
|
|
|
arch
|
|
|
|
os
|
|
|
|
osArch
|
|
|
|
productVariables
|
2022-07-27 09:22:06 +02:00
|
|
|
osAndInApex
|
2022-09-16 22:17:48 +02:00
|
|
|
inApex
|
2023-05-04 23:20:16 +02:00
|
|
|
errorProneDisabled
|
2021-05-21 14:37:59 +02:00
|
|
|
)
|
|
|
|
|
2021-12-10 00:10:18 +01:00
|
|
|
func osArchString(os string, arch string) string {
|
|
|
|
return fmt.Sprintf("%s_%s", os, arch)
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
func (ct configurationType) String() string {
|
|
|
|
return map[configurationType]string{
|
2023-05-04 23:20:16 +02:00
|
|
|
noConfig: "no_config",
|
|
|
|
arch: "arch",
|
|
|
|
os: "os",
|
|
|
|
osArch: "arch_os",
|
|
|
|
productVariables: "product_variables",
|
|
|
|
osAndInApex: "os_in_apex",
|
|
|
|
inApex: "in_apex",
|
|
|
|
errorProneDisabled: "errorprone_disabled",
|
2021-05-21 14:37:59 +02:00
|
|
|
}[ct]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ct configurationType) validateConfig(config string) {
|
|
|
|
switch ct {
|
|
|
|
case noConfig:
|
|
|
|
if config != "" {
|
|
|
|
panic(fmt.Errorf("Cannot specify config with %s, but got %s", ct, config))
|
|
|
|
}
|
|
|
|
case arch:
|
|
|
|
if _, ok := platformArchMap[config]; !ok {
|
|
|
|
panic(fmt.Errorf("Unknown arch: %s", config))
|
|
|
|
}
|
|
|
|
case os:
|
|
|
|
if _, ok := platformOsMap[config]; !ok {
|
|
|
|
panic(fmt.Errorf("Unknown os: %s", config))
|
|
|
|
}
|
|
|
|
case osArch:
|
|
|
|
if _, ok := platformOsArchMap[config]; !ok {
|
|
|
|
panic(fmt.Errorf("Unknown os+arch: %s", config))
|
|
|
|
}
|
|
|
|
case productVariables:
|
|
|
|
// do nothing
|
2022-07-27 09:22:06 +02:00
|
|
|
case osAndInApex:
|
2023-04-20 00:31:54 +02:00
|
|
|
// do nothing
|
|
|
|
// this axis can contain additional per-apex keys
|
2022-09-16 22:17:48 +02:00
|
|
|
case inApex:
|
|
|
|
if _, ok := inApexMap[config]; !ok {
|
|
|
|
panic(fmt.Errorf("Unknown in_apex config: %s", config))
|
|
|
|
}
|
2023-05-04 23:20:16 +02:00
|
|
|
case errorProneDisabled:
|
|
|
|
if _, ok := errorProneMap[config]; !ok {
|
|
|
|
panic(fmt.Errorf("Unknown errorprone config: %s", config))
|
|
|
|
}
|
2021-05-21 14:37:59 +02:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationType %d", ct))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectKey returns the Bazel select key for a given configurationType and config string.
|
2021-11-02 17:43:57 +01:00
|
|
|
func (ca ConfigurationAxis) SelectKey(config string) string {
|
|
|
|
ca.validateConfig(config)
|
|
|
|
switch ca.configurationType {
|
2021-05-21 14:37:59 +02:00
|
|
|
case noConfig:
|
|
|
|
panic(fmt.Errorf("SelectKey is unnecessary for noConfig ConfigurationType "))
|
|
|
|
case arch:
|
|
|
|
return platformArchMap[config]
|
|
|
|
case os:
|
|
|
|
return platformOsMap[config]
|
|
|
|
case osArch:
|
|
|
|
return platformOsArchMap[config]
|
|
|
|
case productVariables:
|
2023-04-26 19:52:24 +02:00
|
|
|
if config == ConditionsDefaultConfigKey {
|
2021-05-21 14:37:59 +02:00
|
|
|
return ConditionsDefaultSelectKey
|
|
|
|
}
|
2021-11-02 17:43:57 +01:00
|
|
|
return fmt.Sprintf("%s:%s", productVariableBazelPackage, config)
|
2022-07-27 09:22:06 +02:00
|
|
|
case osAndInApex:
|
2023-04-20 00:31:54 +02:00
|
|
|
if ret, exists := osAndInApexMap[config]; exists {
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
return config
|
2022-09-16 22:17:48 +02:00
|
|
|
case inApex:
|
|
|
|
return inApexMap[config]
|
2023-05-04 23:20:16 +02:00
|
|
|
case errorProneDisabled:
|
|
|
|
return errorProneMap[config]
|
2021-05-21 14:37:59 +02:00
|
|
|
default:
|
2021-11-02 17:43:57 +01:00
|
|
|
panic(fmt.Errorf("Unrecognized ConfigurationType %d", ca.configurationType))
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Indicating there is no configuration axis
|
|
|
|
NoConfigAxis = ConfigurationAxis{configurationType: noConfig}
|
|
|
|
// An axis for architecture-specific configurations
|
|
|
|
ArchConfigurationAxis = ConfigurationAxis{configurationType: arch}
|
|
|
|
// An axis for os-specific configurations
|
|
|
|
OsConfigurationAxis = ConfigurationAxis{configurationType: os}
|
|
|
|
// An axis for arch+os-specific configurations
|
|
|
|
OsArchConfigurationAxis = ConfigurationAxis{configurationType: osArch}
|
2022-07-27 09:22:06 +02:00
|
|
|
// An axis for os+in_apex-specific configurations
|
|
|
|
OsAndInApexAxis = ConfigurationAxis{configurationType: osAndInApex}
|
2022-09-16 22:17:48 +02:00
|
|
|
// An axis for in_apex-specific configurations
|
|
|
|
InApexAxis = ConfigurationAxis{configurationType: inApex}
|
2023-05-04 23:20:16 +02:00
|
|
|
|
|
|
|
ErrorProneAxis = ConfigurationAxis{configurationType: errorProneDisabled}
|
2021-05-21 14:37:59 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// ProductVariableConfigurationAxis returns an axis for the given product variable
|
2023-04-26 19:52:24 +02:00
|
|
|
func ProductVariableConfigurationAxis(archVariant bool, variable string) ConfigurationAxis {
|
2021-05-21 14:37:59 +02:00
|
|
|
return ConfigurationAxis{
|
|
|
|
configurationType: productVariables,
|
|
|
|
subType: variable,
|
2023-04-26 19:52:24 +02:00
|
|
|
archVariant: archVariant,
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigurationAxis is an independent axis for configuration, there should be no overlap between
|
|
|
|
// elements within an axis.
|
|
|
|
type ConfigurationAxis struct {
|
|
|
|
configurationType
|
|
|
|
// some configuration types (e.g. productVariables) have multiple independent axes, subType helps
|
|
|
|
// distinguish between them without needing to list all 17 product variables.
|
|
|
|
subType string
|
2023-04-26 19:52:24 +02:00
|
|
|
|
|
|
|
archVariant bool
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ca *ConfigurationAxis) less(other ConfigurationAxis) bool {
|
2023-01-26 23:30:44 +01:00
|
|
|
if ca.configurationType == other.configurationType {
|
|
|
|
return ca.subType < other.subType
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|
2023-01-26 23:30:44 +01:00
|
|
|
return ca.configurationType < other.configurationType
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|