Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package bazel |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Cole Faust | c843b99 | 2022-08-02 18:06:50 -0700 | [diff] [blame] | 19 | "math" |
| 20 | "sort" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 21 | "strings" |
| 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | // ArchType names in arch.go |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 26 | archArm = "arm" |
| 27 | archArm64 = "arm64" |
| 28 | archRiscv64 = "riscv64" |
| 29 | archX86 = "x86" |
| 30 | archX86_64 = "x86_64" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 31 | |
| 32 | // OsType names in arch.go |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 33 | OsAndroid = "android" |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 34 | OsDarwin = "darwin" |
| 35 | OsLinux = "linux_glibc" |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 36 | osLinuxMusl = "linux_musl" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 37 | osLinuxBionic = "linux_bionic" |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 38 | OsWindows = "windows" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 39 | |
| 40 | // Targets in arch.go |
| 41 | osArchAndroidArm = "android_arm" |
| 42 | osArchAndroidArm64 = "android_arm64" |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 43 | osArchAndroidRiscv64 = "android_riscv64" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 44 | osArchAndroidX86 = "android_x86" |
| 45 | osArchAndroidX86_64 = "android_x86_64" |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 46 | osArchDarwinArm64 = "darwin_arm64" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 47 | osArchDarwinX86_64 = "darwin_x86_64" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 48 | osArchLinuxX86 = "linux_glibc_x86" |
| 49 | osArchLinuxX86_64 = "linux_glibc_x86_64" |
Colin Cross | a9b2aac | 2022-06-15 17:25:51 -0700 | [diff] [blame] | 50 | osArchLinuxMuslArm = "linux_musl_arm" |
| 51 | osArchLinuxMuslArm64 = "linux_musl_arm64" |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 52 | osArchLinuxMuslX86 = "linux_musl_x86" |
| 53 | osArchLinuxMuslX86_64 = "linux_musl_x86_64" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 54 | osArchLinuxBionicArm64 = "linux_bionic_arm64" |
| 55 | osArchLinuxBionicX86_64 = "linux_bionic_x86_64" |
| 56 | osArchWindowsX86 = "windows_x86" |
| 57 | osArchWindowsX86_64 = "windows_x86_64" |
| 58 | |
| 59 | // This is the string representation of the default condition wherever a |
| 60 | // configurable attribute is used in a select statement, i.e. |
| 61 | // //conditions:default for Bazel. |
| 62 | // |
| 63 | // This is consistently named "conditions_default" to mirror the Soong |
| 64 | // config variable default key in an Android.bp file, although there's no |
| 65 | // integration with Soong config variables (yet). |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 66 | ConditionsDefaultConfigKey = "conditions_default" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 67 | |
| 68 | ConditionsDefaultSelectKey = "//conditions:default" |
| 69 | |
| 70 | productVariableBazelPackage = "//build/bazel/product_variables" |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 71 | |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 72 | AndroidAndInApex = "android-in_apex" |
| 73 | AndroidPlatform = "system" |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 74 | |
| 75 | InApex = "in_apex" |
| 76 | NonApex = "non_apex" |
Alix | c0dac52 | 2023-05-04 21:20:16 +0000 | [diff] [blame] | 77 | |
| 78 | ErrorproneDisabled = "errorprone_disabled" |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 79 | ) |
| 80 | |
Cole Faust | c843b99 | 2022-08-02 18:06:50 -0700 | [diff] [blame] | 81 | func PowerSetWithoutEmptySet[T any](items []T) [][]T { |
| 82 | resultSize := int(math.Pow(2, float64(len(items)))) |
| 83 | powerSet := make([][]T, 0, resultSize-1) |
| 84 | for i := 1; i < resultSize; i++ { |
| 85 | combination := make([]T, 0) |
| 86 | for j := 0; j < len(items); j++ { |
| 87 | if (i>>j)%2 == 1 { |
| 88 | combination = append(combination, items[j]) |
| 89 | } |
| 90 | } |
| 91 | powerSet = append(powerSet, combination) |
| 92 | } |
| 93 | return powerSet |
| 94 | } |
| 95 | |
| 96 | func createPlatformArchMap() map[string]string { |
| 97 | // Copy of archFeatures from android/arch_list.go because the bazel |
| 98 | // package can't access the android package |
| 99 | archFeatures := map[string][]string{ |
| 100 | "arm": { |
| 101 | "neon", |
| 102 | }, |
| 103 | "arm64": { |
| 104 | "dotprod", |
| 105 | }, |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 106 | "riscv64": {}, |
Cole Faust | c843b99 | 2022-08-02 18:06:50 -0700 | [diff] [blame] | 107 | "x86": { |
| 108 | "ssse3", |
| 109 | "sse4", |
| 110 | "sse4_1", |
| 111 | "sse4_2", |
| 112 | "aes_ni", |
| 113 | "avx", |
| 114 | "avx2", |
| 115 | "avx512", |
| 116 | "popcnt", |
| 117 | "movbe", |
| 118 | }, |
| 119 | "x86_64": { |
| 120 | "ssse3", |
| 121 | "sse4", |
| 122 | "sse4_1", |
| 123 | "sse4_2", |
| 124 | "aes_ni", |
| 125 | "avx", |
| 126 | "avx2", |
| 127 | "avx512", |
| 128 | "popcnt", |
| 129 | }, |
| 130 | } |
| 131 | result := make(map[string]string) |
| 132 | for arch, allFeatures := range archFeatures { |
| 133 | result[arch] = "//build/bazel/platforms/arch:" + arch |
| 134 | // Sometimes we want to select on multiple features being active, so |
| 135 | // add the power set of all possible features to the map. More details |
| 136 | // in android.ModuleBase.GetArchVariantProperties |
| 137 | for _, features := range PowerSetWithoutEmptySet(allFeatures) { |
| 138 | sort.Strings(features) |
| 139 | archFeaturesName := arch + "-" + strings.Join(features, "-") |
| 140 | result[archFeaturesName] = "//build/bazel/platforms/arch/variants:" + archFeaturesName |
| 141 | } |
| 142 | } |
| 143 | result[ConditionsDefaultConfigKey] = ConditionsDefaultSelectKey |
| 144 | return result |
| 145 | } |
| 146 | |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 147 | var ( |
| 148 | // These are the list of OSes and architectures with a Bazel config_setting |
| 149 | // and constraint value equivalent. These exist in arch.go, but the android |
| 150 | // package depends on the bazel package, so a cyclic dependency prevents |
| 151 | // using those variables here. |
| 152 | |
| 153 | // A map of architectures to the Bazel label of the constraint_value |
| 154 | // for the @platforms//cpu:cpu constraint_setting |
Cole Faust | c843b99 | 2022-08-02 18:06:50 -0700 | [diff] [blame] | 155 | platformArchMap = createPlatformArchMap() |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 156 | |
| 157 | // A map of target operating systems to the Bazel label of the |
| 158 | // constraint_value for the @platforms//os:os constraint_setting |
| 159 | platformOsMap = map[string]string{ |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 160 | OsAndroid: "//build/bazel/platforms/os:android", |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 161 | OsDarwin: "//build/bazel/platforms/os:darwin", |
| 162 | OsLinux: "//build/bazel/platforms/os:linux_glibc", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 163 | osLinuxMusl: "//build/bazel/platforms/os:linux_musl", |
| 164 | osLinuxBionic: "//build/bazel/platforms/os:linux_bionic", |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 165 | OsWindows: "//build/bazel/platforms/os:windows", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 166 | ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map. |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | platformOsArchMap = map[string]string{ |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 170 | osArchAndroidArm: "//build/bazel/platforms/os_arch:android_arm", |
| 171 | osArchAndroidArm64: "//build/bazel/platforms/os_arch:android_arm64", |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 172 | osArchAndroidRiscv64: "//build/bazel/platforms/os_arch:android_riscv64", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 173 | osArchAndroidX86: "//build/bazel/platforms/os_arch:android_x86", |
| 174 | osArchAndroidX86_64: "//build/bazel/platforms/os_arch:android_x86_64", |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 175 | osArchDarwinArm64: "//build/bazel/platforms/os_arch:darwin_arm64", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 176 | osArchDarwinX86_64: "//build/bazel/platforms/os_arch:darwin_x86_64", |
| 177 | osArchLinuxX86: "//build/bazel/platforms/os_arch:linux_glibc_x86", |
| 178 | osArchLinuxX86_64: "//build/bazel/platforms/os_arch:linux_glibc_x86_64", |
Colin Cross | a9b2aac | 2022-06-15 17:25:51 -0700 | [diff] [blame] | 179 | osArchLinuxMuslArm: "//build/bazel/platforms/os_arch:linux_musl_arm", |
| 180 | osArchLinuxMuslArm64: "//build/bazel/platforms/os_arch:linux_musl_arm64", |
Chris Parsons | 51f8c39 | 2021-08-03 21:01:05 -0400 | [diff] [blame] | 181 | osArchLinuxMuslX86: "//build/bazel/platforms/os_arch:linux_musl_x86", |
| 182 | osArchLinuxMuslX86_64: "//build/bazel/platforms/os_arch:linux_musl_x86_64", |
| 183 | osArchLinuxBionicArm64: "//build/bazel/platforms/os_arch:linux_bionic_arm64", |
| 184 | osArchLinuxBionicX86_64: "//build/bazel/platforms/os_arch:linux_bionic_x86_64", |
| 185 | osArchWindowsX86: "//build/bazel/platforms/os_arch:windows_x86", |
| 186 | osArchWindowsX86_64: "//build/bazel/platforms/os_arch:windows_x86_64", |
| 187 | ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map. |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 188 | } |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 189 | |
| 190 | // Map where keys are OsType names, and values are slices containing the archs |
| 191 | // that that OS supports. |
| 192 | // These definitions copied from arch.go. |
| 193 | // TODO(cparsons): Source from arch.go; this task is nontrivial, as it currently results |
| 194 | // in a cyclic dependency. |
| 195 | osToArchMap = map[string][]string{ |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 196 | OsAndroid: {archArm, archArm64, archRiscv64, archX86, archX86_64}, |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 197 | OsLinux: {archX86, archX86_64}, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 198 | osLinuxMusl: {archX86, archX86_64}, |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 199 | OsDarwin: {archArm64, archX86_64}, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 200 | osLinuxBionic: {archArm64, archX86_64}, |
| 201 | // TODO(cparsons): According to arch.go, this should contain archArm, archArm64, as well. |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 202 | OsWindows: {archX86, archX86_64}, |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 203 | } |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 204 | |
| 205 | osAndInApexMap = map[string]string{ |
| 206 | AndroidAndInApex: "//build/bazel/rules/apex:android-in_apex", |
Spandan Das | 6d4d9da | 2023-04-18 06:20:40 +0000 | [diff] [blame] | 207 | AndroidPlatform: "//build/bazel/rules/apex:system", |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 208 | OsDarwin: "//build/bazel/platforms/os:darwin", |
| 209 | OsLinux: "//build/bazel/platforms/os:linux_glibc", |
Liz Kammer | ffc17e4 | 2022-11-23 09:42:05 -0500 | [diff] [blame] | 210 | osLinuxMusl: "//build/bazel/platforms/os:linux_musl", |
| 211 | osLinuxBionic: "//build/bazel/platforms/os:linux_bionic", |
Spandan Das | fb04c41 | 2023-05-15 18:35:36 +0000 | [diff] [blame] | 212 | OsWindows: "//build/bazel/platforms/os:windows", |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 213 | ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, |
| 214 | } |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 215 | |
| 216 | inApexMap = map[string]string{ |
| 217 | InApex: "//build/bazel/rules/apex:in_apex", |
| 218 | NonApex: "//build/bazel/rules/apex:non_apex", |
| 219 | ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, |
| 220 | } |
Alix | c0dac52 | 2023-05-04 21:20:16 +0000 | [diff] [blame] | 221 | |
| 222 | errorProneMap = map[string]string{ |
| 223 | ErrorproneDisabled: "//build/bazel/rules/java/errorprone:errorprone_globally_disabled", |
| 224 | ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, |
| 225 | } |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 226 | ) |
| 227 | |
| 228 | // basic configuration types |
| 229 | type configurationType int |
| 230 | |
| 231 | const ( |
| 232 | noConfig configurationType = iota |
| 233 | arch |
| 234 | os |
| 235 | osArch |
| 236 | productVariables |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 237 | osAndInApex |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 238 | inApex |
Alix | c0dac52 | 2023-05-04 21:20:16 +0000 | [diff] [blame] | 239 | errorProneDisabled |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 240 | ) |
| 241 | |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 242 | func osArchString(os string, arch string) string { |
| 243 | return fmt.Sprintf("%s_%s", os, arch) |
| 244 | } |
| 245 | |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 246 | func (ct configurationType) String() string { |
| 247 | return map[configurationType]string{ |
Alix | c0dac52 | 2023-05-04 21:20:16 +0000 | [diff] [blame] | 248 | noConfig: "no_config", |
| 249 | arch: "arch", |
| 250 | os: "os", |
| 251 | osArch: "arch_os", |
| 252 | productVariables: "product_variables", |
| 253 | osAndInApex: "os_in_apex", |
| 254 | inApex: "in_apex", |
| 255 | errorProneDisabled: "errorprone_disabled", |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 256 | }[ct] |
| 257 | } |
| 258 | |
| 259 | func (ct configurationType) validateConfig(config string) { |
| 260 | switch ct { |
| 261 | case noConfig: |
| 262 | if config != "" { |
| 263 | panic(fmt.Errorf("Cannot specify config with %s, but got %s", ct, config)) |
| 264 | } |
| 265 | case arch: |
| 266 | if _, ok := platformArchMap[config]; !ok { |
| 267 | panic(fmt.Errorf("Unknown arch: %s", config)) |
| 268 | } |
| 269 | case os: |
| 270 | if _, ok := platformOsMap[config]; !ok { |
| 271 | panic(fmt.Errorf("Unknown os: %s", config)) |
| 272 | } |
| 273 | case osArch: |
| 274 | if _, ok := platformOsArchMap[config]; !ok { |
| 275 | panic(fmt.Errorf("Unknown os+arch: %s", config)) |
| 276 | } |
| 277 | case productVariables: |
| 278 | // do nothing |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 279 | case osAndInApex: |
Spandan Das | 4242f10 | 2023-04-19 22:31:54 +0000 | [diff] [blame] | 280 | // do nothing |
| 281 | // this axis can contain additional per-apex keys |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 282 | case inApex: |
| 283 | if _, ok := inApexMap[config]; !ok { |
| 284 | panic(fmt.Errorf("Unknown in_apex config: %s", config)) |
| 285 | } |
Alix | c0dac52 | 2023-05-04 21:20:16 +0000 | [diff] [blame] | 286 | case errorProneDisabled: |
| 287 | if _, ok := errorProneMap[config]; !ok { |
| 288 | panic(fmt.Errorf("Unknown errorprone config: %s", config)) |
| 289 | } |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 290 | default: |
| 291 | panic(fmt.Errorf("Unrecognized ConfigurationType %d", ct)) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | // SelectKey returns the Bazel select key for a given configurationType and config string. |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 296 | func (ca ConfigurationAxis) SelectKey(config string) string { |
| 297 | ca.validateConfig(config) |
| 298 | switch ca.configurationType { |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 299 | case noConfig: |
| 300 | panic(fmt.Errorf("SelectKey is unnecessary for noConfig ConfigurationType ")) |
| 301 | case arch: |
| 302 | return platformArchMap[config] |
| 303 | case os: |
| 304 | return platformOsMap[config] |
| 305 | case osArch: |
| 306 | return platformOsArchMap[config] |
| 307 | case productVariables: |
Cole Faust | 150f9a5 | 2023-04-26 10:52:24 -0700 | [diff] [blame] | 308 | if config == ConditionsDefaultConfigKey { |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 309 | return ConditionsDefaultSelectKey |
| 310 | } |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 311 | return fmt.Sprintf("%s:%s", productVariableBazelPackage, config) |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 312 | case osAndInApex: |
Spandan Das | 4242f10 | 2023-04-19 22:31:54 +0000 | [diff] [blame] | 313 | if ret, exists := osAndInApexMap[config]; exists { |
| 314 | return ret |
| 315 | } |
| 316 | return config |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 317 | case inApex: |
| 318 | return inApexMap[config] |
Alix | c0dac52 | 2023-05-04 21:20:16 +0000 | [diff] [blame] | 319 | case errorProneDisabled: |
| 320 | return errorProneMap[config] |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 321 | default: |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 322 | panic(fmt.Errorf("Unrecognized ConfigurationType %d", ca.configurationType)) |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | var ( |
| 327 | // Indicating there is no configuration axis |
| 328 | NoConfigAxis = ConfigurationAxis{configurationType: noConfig} |
| 329 | // An axis for architecture-specific configurations |
| 330 | ArchConfigurationAxis = ConfigurationAxis{configurationType: arch} |
| 331 | // An axis for os-specific configurations |
| 332 | OsConfigurationAxis = ConfigurationAxis{configurationType: os} |
| 333 | // An axis for arch+os-specific configurations |
| 334 | OsArchConfigurationAxis = ConfigurationAxis{configurationType: osArch} |
Wei Li | 81852ca | 2022-07-27 00:22:06 -0700 | [diff] [blame] | 335 | // An axis for os+in_apex-specific configurations |
| 336 | OsAndInApexAxis = ConfigurationAxis{configurationType: osAndInApex} |
Vinh Tran | 85fb07c | 2022-09-16 16:17:48 -0400 | [diff] [blame] | 337 | // An axis for in_apex-specific configurations |
| 338 | InApexAxis = ConfigurationAxis{configurationType: inApex} |
Alix | c0dac52 | 2023-05-04 21:20:16 +0000 | [diff] [blame] | 339 | |
| 340 | ErrorProneAxis = ConfigurationAxis{configurationType: errorProneDisabled} |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 341 | ) |
| 342 | |
| 343 | // ProductVariableConfigurationAxis returns an axis for the given product variable |
Cole Faust | 150f9a5 | 2023-04-26 10:52:24 -0700 | [diff] [blame] | 344 | func ProductVariableConfigurationAxis(archVariant bool, variable string) ConfigurationAxis { |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 345 | return ConfigurationAxis{ |
| 346 | configurationType: productVariables, |
| 347 | subType: variable, |
Cole Faust | 150f9a5 | 2023-04-26 10:52:24 -0700 | [diff] [blame] | 348 | archVariant: archVariant, |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
| 352 | // ConfigurationAxis is an independent axis for configuration, there should be no overlap between |
| 353 | // elements within an axis. |
| 354 | type ConfigurationAxis struct { |
| 355 | configurationType |
| 356 | // some configuration types (e.g. productVariables) have multiple independent axes, subType helps |
| 357 | // distinguish between them without needing to list all 17 product variables. |
| 358 | subType string |
Cole Faust | 150f9a5 | 2023-04-26 10:52:24 -0700 | [diff] [blame] | 359 | |
| 360 | archVariant bool |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | func (ca *ConfigurationAxis) less(other ConfigurationAxis) bool { |
Chris Parsons | 7b3289b | 2023-01-26 17:30:44 -0500 | [diff] [blame] | 364 | if ca.configurationType == other.configurationType { |
| 365 | return ca.subType < other.subType |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 366 | } |
Chris Parsons | 7b3289b | 2023-01-26 17:30:44 -0500 | [diff] [blame] | 367 | return ca.configurationType < other.configurationType |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 368 | } |