Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "reflect" |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 20 | "runtime" |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 21 | "strings" |
| 22 | |
Cole Faust | 701ca25 | 2021-11-23 19:02:08 -0800 | [diff] [blame] | 23 | "android/soong/android/soongconfig" |
| 24 | "android/soong/bazel" |
| 25 | |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
| 27 | ) |
| 28 | |
| 29 | func init() { |
Paul Duffin | e7a055c | 2021-03-07 15:46:33 +0000 | [diff] [blame] | 30 | registerVariableBuildComponents(InitRegistrationContext) |
| 31 | } |
| 32 | |
| 33 | func registerVariableBuildComponents(ctx RegistrationContext) { |
| 34 | ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 35 | ctx.BottomUp("variable", VariableMutator).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 36 | }) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Paul Duffin | e7a055c | 2021-03-07 15:46:33 +0000 | [diff] [blame] | 39 | var PrepareForTestWithVariables = FixtureRegisterWithContext(registerVariableBuildComponents) |
| 40 | |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 41 | type variableProperties struct { |
| 42 | Product_variables struct { |
Dan Willemsen | 47cf66b | 2015-09-16 16:48:54 -0700 | [diff] [blame] | 43 | Platform_sdk_version struct { |
| 44 | Asflags []string |
Colin Cross | ceeff0f | 2017-05-08 13:43:00 -0700 | [diff] [blame] | 45 | Cflags []string |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 46 | Cmd *string |
Dan Willemsen | 47cf66b | 2015-09-16 16:48:54 -0700 | [diff] [blame] | 47 | } |
Colin Cross | 8316319 | 2015-12-01 16:31:16 -0800 | [diff] [blame] | 48 | |
Yuntao Xu | 402e9b0 | 2021-08-09 15:44:44 -0700 | [diff] [blame] | 49 | Platform_sdk_version_or_codename struct { |
| 50 | Java_resource_dirs []string |
| 51 | } |
| 52 | |
Anton Hansson | b021bf8 | 2021-08-27 17:35:40 +0100 | [diff] [blame] | 53 | Platform_sdk_extension_version struct { |
| 54 | Cmd *string |
| 55 | } |
| 56 | |
Dan Willemsen | 9fe1410 | 2021-07-13 21:52:04 -0700 | [diff] [blame] | 57 | Platform_version_name struct { |
| 58 | Base_dir *string |
| 59 | } |
| 60 | |
Colin Cross | 8316319 | 2015-12-01 16:31:16 -0800 | [diff] [blame] | 61 | // unbundled_build is a catch-all property to annotate modules that don't build in one or |
| 62 | // more unbundled branches, usually due to dependencies missing from the manifest. |
| 63 | Unbundled_build struct { |
| 64 | Enabled *bool `android:"arch_variant"` |
| 65 | } `android:"arch_variant"` |
Dan Willemsen | 496e395 | 2016-01-05 14:27:55 -0800 | [diff] [blame] | 66 | |
Dan Willemsen | 97cae01 | 2016-03-01 14:08:42 -0800 | [diff] [blame] | 67 | Malloc_not_svelte struct { |
Christopher Ferris | c71193a | 2019-12-16 09:55:10 -0800 | [diff] [blame] | 68 | Cflags []string `android:"arch_variant"` |
| 69 | Shared_libs []string `android:"arch_variant"` |
| 70 | Whole_static_libs []string `android:"arch_variant"` |
| 71 | Exclude_static_libs []string `android:"arch_variant"` |
Christopher Ferris | dea6617 | 2021-09-24 00:07:53 -0700 | [diff] [blame] | 72 | Srcs []string `android:"arch_variant"` |
| 73 | Header_libs []string `android:"arch_variant"` |
Sasha Smundak | 61ebf8d | 2018-08-31 16:56:05 -0700 | [diff] [blame] | 74 | } `android:"arch_variant"` |
Evgenii Stepanov | 8391efa | 2016-05-12 18:04:18 -0700 | [diff] [blame] | 75 | |
Quallenauge | bed769c | 2020-10-21 21:19:01 +0200 | [diff] [blame] | 76 | Malloc_not_svelte_libc32 struct { |
| 77 | Cflags []string `android:"arch_variant"` |
| 78 | Shared_libs []string `android:"arch_variant"` |
| 79 | Whole_static_libs []string `android:"arch_variant"` |
| 80 | Exclude_static_libs []string `android:"arch_variant"` |
| 81 | } `android:"arch_variant"` |
| 82 | |
Evgenii Stepanov | 19ff3c9 | 2020-04-29 14:57:30 -0700 | [diff] [blame] | 83 | Malloc_zero_contents struct { |
| 84 | Cflags []string `android:"arch_variant"` |
| 85 | } `android:"arch_variant"` |
| 86 | |
| 87 | Malloc_pattern_fill_contents struct { |
| 88 | Cflags []string `android:"arch_variant"` |
| 89 | } `android:"arch_variant"` |
| 90 | |
Evgenii Stepanov | 8391efa | 2016-05-12 18:04:18 -0700 | [diff] [blame] | 91 | Safestack struct { |
| 92 | Cflags []string `android:"arch_variant"` |
| 93 | } `android:"arch_variant"` |
Dan Willemsen | a6f7d15 | 2016-07-12 14:57:40 -0700 | [diff] [blame] | 94 | |
Dan Willemsen | 1be3538 | 2016-07-25 17:42:18 -0700 | [diff] [blame] | 95 | Binder32bit struct { |
| 96 | Cflags []string |
| 97 | } |
Dan Willemsen | fcebcd5 | 2016-09-22 14:49:10 -0700 | [diff] [blame] | 98 | |
Colin Cross | 9543642 | 2017-05-04 13:57:05 -0700 | [diff] [blame] | 99 | Override_rs_driver struct { |
| 100 | Cflags []string |
| 101 | } |
| 102 | |
Steven Moreland | c2b9f06 | 2017-12-13 14:06:20 -0800 | [diff] [blame] | 103 | // treble_linker_namespaces is true when the system/vendor linker namespace separation is |
| 104 | // enabled. |
| 105 | Treble_linker_namespaces struct { |
| 106 | Cflags []string |
| 107 | } |
Steven Moreland | c2b9f06 | 2017-12-13 14:06:20 -0800 | [diff] [blame] | 108 | // enforce_vintf_manifest is true when a device is required to have a vintf manifest. |
| 109 | Enforce_vintf_manifest struct { |
| 110 | Cflags []string |
| 111 | } |
| 112 | |
Colin Cross | 6bc59ef | 2016-12-08 09:46:35 -0800 | [diff] [blame] | 113 | // debuggable is true for eng and userdebug builds, and can be used to turn on additional |
| 114 | // debugging features that don't significantly impact runtime behavior. userdebug builds |
| 115 | // are used for dogfooding and performance testing, and should be as similar to user builds |
| 116 | // as possible. |
Dan Willemsen | fcebcd5 | 2016-09-22 14:49:10 -0700 | [diff] [blame] | 117 | Debuggable struct { |
Sasha Smundak | b6d2305 | 2019-04-01 18:37:36 -0700 | [diff] [blame] | 118 | Cflags []string |
| 119 | Cppflags []string |
| 120 | Init_rc []string |
| 121 | Required []string |
| 122 | Host_required []string |
| 123 | Target_required []string |
Philip Cuadra | 328e0bf | 2020-10-19 22:01:29 -0700 | [diff] [blame] | 124 | Strip struct { |
| 125 | All *bool |
| 126 | Keep_symbols *bool |
| 127 | Keep_symbols_and_debug_frame *bool |
| 128 | } |
Yifan Hong | 8f323ae | 2021-06-23 20:01:13 -0700 | [diff] [blame] | 129 | Static_libs []string |
| 130 | Whole_static_libs []string |
| 131 | Shared_libs []string |
Jiyong Park | 16e77a9 | 2021-08-30 18:43:19 +0900 | [diff] [blame] | 132 | |
| 133 | Cmdline []string |
Inseob Kim | f5ed300 | 2022-01-07 19:17:29 +0900 | [diff] [blame] | 134 | |
Jay Aliomer | 2599d1d | 2021-09-23 15:49:54 -0400 | [diff] [blame] | 135 | Srcs []string |
| 136 | Exclude_srcs []string |
Dan Willemsen | fcebcd5 | 2016-09-22 14:49:10 -0700 | [diff] [blame] | 137 | } |
Colin Cross | 6bc59ef | 2016-12-08 09:46:35 -0800 | [diff] [blame] | 138 | |
Usta Shrestha | c725f47 | 2022-01-11 02:44:21 -0500 | [diff] [blame] | 139 | // eng is true for -eng builds, and can be used to turn on additional heavyweight debugging |
Colin Cross | 6bc59ef | 2016-12-08 09:46:35 -0800 | [diff] [blame] | 140 | // features. |
| 141 | Eng struct { |
| 142 | Cflags []string |
| 143 | Cppflags []string |
dianlujitao | b65e8c7 | 2022-02-20 23:57:22 +0800 | [diff] [blame] | 144 | Init_rc []string |
John Reck | 1d2b7ee | 2018-07-11 11:01:59 -0700 | [diff] [blame] | 145 | Lto struct { |
| 146 | Never *bool |
| 147 | } |
Colin Cross | 3273cc2 | 2018-10-26 23:58:42 -0700 | [diff] [blame] | 148 | Sanitize struct { |
| 149 | Address *bool |
| 150 | } |
Felka Chang | f13642e | 2019-06-21 20:58:27 +0800 | [diff] [blame] | 151 | Optimize struct { |
| 152 | Enabled *bool |
| 153 | } |
Colin Cross | 6bc59ef | 2016-12-08 09:46:35 -0800 | [diff] [blame] | 154 | } |
Colin Cross | b2123aa | 2017-05-05 13:37:11 -0700 | [diff] [blame] | 155 | |
| 156 | Pdk struct { |
Colin Cross | 99967a7 | 2017-10-17 13:55:02 -0700 | [diff] [blame] | 157 | Enabled *bool `android:"arch_variant"` |
| 158 | } `android:"arch_variant"` |
Dmitry Shmidt | dba5419 | 2017-08-23 14:58:37 -0700 | [diff] [blame] | 159 | |
| 160 | Uml struct { |
| 161 | Cppflags []string |
| 162 | } |
Risan | ea004dd | 2017-11-27 18:14:46 +0900 | [diff] [blame] | 163 | |
| 164 | Arc struct { |
Satoshi Niwa | 54f4826 | 2020-12-18 09:53:26 +0900 | [diff] [blame] | 165 | Cflags []string `android:"arch_variant"` |
| 166 | Exclude_srcs []string `android:"arch_variant"` |
Jasmine Chen | acace42 | 2021-03-05 00:56:40 +0800 | [diff] [blame] | 167 | Header_libs []string `android:"arch_variant"` |
Satoshi Niwa | 54f4826 | 2020-12-18 09:53:26 +0900 | [diff] [blame] | 168 | Include_dirs []string `android:"arch_variant"` |
| 169 | Shared_libs []string `android:"arch_variant"` |
| 170 | Static_libs []string `android:"arch_variant"` |
| 171 | Srcs []string `android:"arch_variant"` |
| 172 | Whole_static_libs []string `android:"arch_variant"` |
| 173 | } `android:"arch_variant"` |
Roland Levillain | 2879d41 | 2019-08-13 15:00:18 +0100 | [diff] [blame] | 174 | |
| 175 | Flatten_apex struct { |
| 176 | Enabled *bool |
| 177 | } |
Peter Collingbourne | c66baf7 | 2019-10-29 11:00:15 -0700 | [diff] [blame] | 178 | |
Colin Cross | d9a121b | 2020-01-27 13:26:42 -0800 | [diff] [blame] | 179 | Native_coverage struct { |
Colin Cross | 2b10ba0 | 2020-02-05 16:23:21 -0800 | [diff] [blame] | 180 | Src *string `android:"arch_variant"` |
Colin Cross | d9a121b | 2020-01-27 13:26:42 -0800 | [diff] [blame] | 181 | Srcs []string `android:"arch_variant"` |
| 182 | Exclude_srcs []string `android:"arch_variant"` |
| 183 | } `android:"arch_variant"` |
Colin Cross | 8316319 | 2015-12-01 16:31:16 -0800 | [diff] [blame] | 184 | } `android:"arch_variant"` |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Colin Cross | 6961a49 | 2020-02-06 16:57:45 -0800 | [diff] [blame] | 187 | var defaultProductVariables interface{} = variableProperties{} |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 188 | |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 189 | type productVariables struct { |
Dan Willemsen | 174978c | 2016-05-11 00:27:49 -0700 | [diff] [blame] | 190 | // Suffix to add to generated Makefiles |
| 191 | Make_suffix *string `json:",omitempty"` |
| 192 | |
Colin Cross | 2a2e0db | 2020-02-21 16:55:46 -0800 | [diff] [blame] | 193 | BuildId *string `json:",omitempty"` |
| 194 | BuildNumberFile *string `json:",omitempty"` |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 195 | |
Colin Cross | 092c9da | 2019-04-02 22:56:43 -0700 | [diff] [blame] | 196 | Platform_version_name *string `json:",omitempty"` |
| 197 | Platform_sdk_version *int `json:",omitempty"` |
| 198 | Platform_sdk_codename *string `json:",omitempty"` |
Yuntao Xu | 402e9b0 | 2021-08-09 15:44:44 -0700 | [diff] [blame] | 199 | Platform_sdk_version_or_codename *string `json:",omitempty"` |
Colin Cross | 092c9da | 2019-04-02 22:56:43 -0700 | [diff] [blame] | 200 | Platform_sdk_final *bool `json:",omitempty"` |
Anton Hansson | b021bf8 | 2021-08-27 17:35:40 +0100 | [diff] [blame] | 201 | Platform_sdk_extension_version *int `json:",omitempty"` |
Anton Hansson | 97d0bae | 2022-02-16 16:15:10 +0000 | [diff] [blame] | 202 | Platform_base_sdk_extension_version *int `json:",omitempty"` |
Colin Cross | 092c9da | 2019-04-02 22:56:43 -0700 | [diff] [blame] | 203 | Platform_version_active_codenames []string `json:",omitempty"` |
Colin Cross | 092c9da | 2019-04-02 22:56:43 -0700 | [diff] [blame] | 204 | Platform_vndk_version *string `json:",omitempty"` |
| 205 | Platform_systemsdk_versions []string `json:",omitempty"` |
| 206 | Platform_security_patch *string `json:",omitempty"` |
| 207 | Platform_preview_sdk_version *string `json:",omitempty"` |
| 208 | Platform_min_supported_target_sdk_version *string `json:",omitempty"` |
| 209 | Platform_base_os *string `json:",omitempty"` |
Inseob Kim | c7c4746 | 2022-04-25 18:23:58 +0900 | [diff] [blame] | 210 | Platform_version_last_stable *string `json:",omitempty"` |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 211 | |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 212 | DeviceName *string `json:",omitempty"` |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 213 | DeviceProduct *string `json:",omitempty"` |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 214 | DeviceArch *string `json:",omitempty"` |
| 215 | DeviceArchVariant *string `json:",omitempty"` |
| 216 | DeviceCpuVariant *string `json:",omitempty"` |
| 217 | DeviceAbi []string `json:",omitempty"` |
| 218 | DeviceVndkVersion *string `json:",omitempty"` |
| 219 | DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"` |
| 220 | DeviceSystemSdkVersions []string `json:",omitempty"` |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 221 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 222 | RecoverySnapshotVersion *string `json:",omitempty"` |
| 223 | |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 224 | DeviceSecondaryArch *string `json:",omitempty"` |
| 225 | DeviceSecondaryArchVariant *string `json:",omitempty"` |
| 226 | DeviceSecondaryCpuVariant *string `json:",omitempty"` |
| 227 | DeviceSecondaryAbi []string `json:",omitempty"` |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 228 | |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 229 | NativeBridgeArch *string `json:",omitempty"` |
| 230 | NativeBridgeArchVariant *string `json:",omitempty"` |
| 231 | NativeBridgeCpuVariant *string `json:",omitempty"` |
| 232 | NativeBridgeAbi []string `json:",omitempty"` |
| 233 | NativeBridgeRelativePath *string `json:",omitempty"` |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 234 | |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 235 | NativeBridgeSecondaryArch *string `json:",omitempty"` |
| 236 | NativeBridgeSecondaryArchVariant *string `json:",omitempty"` |
| 237 | NativeBridgeSecondaryCpuVariant *string `json:",omitempty"` |
| 238 | NativeBridgeSecondaryAbi []string `json:",omitempty"` |
| 239 | NativeBridgeSecondaryRelativePath *string `json:",omitempty"` |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 240 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 241 | HostArch *string `json:",omitempty"` |
| 242 | HostSecondaryArch *string `json:",omitempty"` |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 243 | HostMusl *bool `json:",omitempty"` |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 244 | |
| 245 | CrossHost *string `json:",omitempty"` |
| 246 | CrossHostArch *string `json:",omitempty"` |
| 247 | CrossHostSecondaryArch *string `json:",omitempty"` |
Colin Cross | 8316319 | 2015-12-01 16:31:16 -0800 | [diff] [blame] | 248 | |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 249 | DeviceResourceOverlays []string `json:",omitempty"` |
| 250 | ProductResourceOverlays []string `json:",omitempty"` |
| 251 | EnforceRROTargets []string `json:",omitempty"` |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 252 | EnforceRROExcludedOverlays []string `json:",omitempty"` |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 253 | |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 254 | AAPTCharacteristics *string `json:",omitempty"` |
| 255 | AAPTConfig []string `json:",omitempty"` |
| 256 | AAPTPreferredConfig *string `json:",omitempty"` |
| 257 | AAPTPrebuiltDPI []string `json:",omitempty"` |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 258 | |
Colin Cross | 61ae0b7 | 2017-12-01 17:16:02 -0800 | [diff] [blame] | 259 | DefaultAppCertificate *string `json:",omitempty"` |
| 260 | |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 261 | AppsDefaultVersionName *string `json:",omitempty"` |
| 262 | |
Cole Faust | 701ca25 | 2021-11-23 19:02:08 -0800 | [diff] [blame] | 263 | Allow_missing_dependencies *bool `json:",omitempty"` |
| 264 | Unbundled_build *bool `json:",omitempty"` |
| 265 | Unbundled_build_apps []string `json:",omitempty"` |
| 266 | Unbundled_build_image *bool `json:",omitempty"` |
| 267 | Always_use_prebuilt_sdks *bool `json:",omitempty"` |
| 268 | Skip_boot_jars_check *bool `json:",omitempty"` |
| 269 | Malloc_not_svelte *bool `json:",omitempty"` |
Quallenauge | bed769c | 2020-10-21 21:19:01 +0200 | [diff] [blame] | 270 | Malloc_not_svelte_libc32 *bool `json:",omitempty"` |
Cole Faust | 701ca25 | 2021-11-23 19:02:08 -0800 | [diff] [blame] | 271 | Malloc_zero_contents *bool `json:",omitempty"` |
| 272 | Malloc_pattern_fill_contents *bool `json:",omitempty"` |
| 273 | Safestack *bool `json:",omitempty"` |
| 274 | HostStaticBinaries *bool `json:",omitempty"` |
| 275 | Binder32bit *bool `json:",omitempty"` |
| 276 | UseGoma *bool `json:",omitempty"` |
| 277 | UseRBE *bool `json:",omitempty"` |
| 278 | UseRBEJAVAC *bool `json:",omitempty"` |
| 279 | UseRBER8 *bool `json:",omitempty"` |
| 280 | UseRBED8 *bool `json:",omitempty"` |
| 281 | Debuggable *bool `json:",omitempty"` |
| 282 | Eng *bool `json:",omitempty"` |
| 283 | Treble_linker_namespaces *bool `json:",omitempty"` |
| 284 | Enforce_vintf_manifest *bool `json:",omitempty"` |
| 285 | Uml *bool `json:",omitempty"` |
| 286 | Arc *bool `json:",omitempty"` |
| 287 | MinimizeJavaDebugInfo *bool `json:",omitempty"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 288 | |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 289 | Check_elf_files *bool `json:",omitempty"` |
| 290 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 291 | UncompressPrivAppDex *bool `json:",omitempty"` |
| 292 | ModulesLoadedByPrivilegedModules []string `json:",omitempty"` |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 293 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 294 | BootJars ConfiguredJarList `json:",omitempty"` |
| 295 | ApexBootJars ConfiguredJarList `json:",omitempty"` |
Vladimir Marko | e8b00d6 | 2018-12-21 15:54:16 +0000 | [diff] [blame] | 296 | |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 297 | IntegerOverflowExcludePaths []string `json:",omitempty"` |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 298 | |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 299 | EnableCFI *bool `json:",omitempty"` |
| 300 | CFIExcludePaths []string `json:",omitempty"` |
| 301 | CFIIncludePaths []string `json:",omitempty"` |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 302 | |
Kostya Kortchinsky | d5275c8 | 2019-02-01 08:42:56 -0800 | [diff] [blame] | 303 | DisableScudo *bool `json:",omitempty"` |
| 304 | |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 305 | MemtagHeapExcludePaths []string `json:",omitempty"` |
| 306 | MemtagHeapAsyncIncludePaths []string `json:",omitempty"` |
| 307 | MemtagHeapSyncIncludePaths []string `json:",omitempty"` |
| 308 | |
Justin Yun | d5f6c82 | 2019-06-25 16:47:17 +0900 | [diff] [blame] | 309 | VendorPath *string `json:",omitempty"` |
| 310 | OdmPath *string `json:",omitempty"` |
| 311 | ProductPath *string `json:",omitempty"` |
| 312 | SystemExtPath *string `json:",omitempty"` |
Dan Willemsen | 4353bc4 | 2016-12-05 17:16:02 -0800 | [diff] [blame] | 313 | |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 314 | ClangTidy *bool `json:",omitempty"` |
| 315 | TidyChecks *string `json:",omitempty"` |
| 316 | |
Roland Levillain | ada1270 | 2020-06-09 13:07:36 +0100 | [diff] [blame] | 317 | JavaCoveragePaths []string `json:",omitempty"` |
| 318 | JavaCoverageExcludePaths []string `json:",omitempty"` |
| 319 | |
Pirama Arumuga Nainar | b37ae58 | 2022-01-26 22:14:32 -0800 | [diff] [blame] | 320 | GcovCoverage *bool `json:",omitempty"` |
| 321 | ClangCoverage *bool `json:",omitempty"` |
| 322 | NativeCoveragePaths []string `json:",omitempty"` |
| 323 | NativeCoverageExcludePaths []string `json:",omitempty"` |
| 324 | ClangCoverageContinuousMode *bool `json:",omitempty"` |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 325 | |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 326 | // Set by NewConfig |
Liz Kammer | 09f947d | 2021-05-12 14:51:49 -0400 | [diff] [blame] | 327 | Native_coverage *bool `json:",omitempty"` |
Colin Cross | 1a6acd4 | 2020-06-16 17:51:46 -0700 | [diff] [blame] | 328 | |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 329 | SanitizeHost []string `json:",omitempty"` |
| 330 | SanitizeDevice []string `json:",omitempty"` |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 331 | SanitizeDeviceDiag []string `json:",omitempty"` |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 332 | SanitizeDeviceArch []string `json:",omitempty"` |
Hiroshi Yamauchi | e2a1063 | 2016-12-19 13:44:41 -0800 | [diff] [blame] | 333 | |
| 334 | ArtUseReadBarrier *bool `json:",omitempty"` |
Jack He | 8cc7143 | 2016-12-08 15:45:07 -0800 | [diff] [blame] | 335 | |
| 336 | BtConfigIncludeDir *string `json:",omitempty"` |
Colin Cross | 9543642 | 2017-05-04 13:57:05 -0700 | [diff] [blame] | 337 | |
| 338 | Override_rs_driver *string `json:",omitempty"` |
Jiyong Park | d773eb3 | 2017-07-03 13:18:12 +0900 | [diff] [blame] | 339 | |
| 340 | DeviceKernelHeaders []string `json:",omitempty"` |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 341 | |
Jan Altensen | 3bebd4f | 2020-09-10 15:21:40 +0200 | [diff] [blame] | 342 | TargetSpecificHeaderPath *string `json:",omitempty"` |
| 343 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 344 | ExtraVndkVersions []string `json:",omitempty"` |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 345 | |
| 346 | NamespacesToExport []string `json:",omitempty"` |
Pirama Arumuga Nainar | 4954080 | 2018-01-29 23:11:42 -0800 | [diff] [blame] | 347 | |
Yi Kong | eb8efc9 | 2021-12-09 18:06:29 +0800 | [diff] [blame] | 348 | AfdoAdditionalProfileDirs []string `json:",omitempty"` |
| 349 | PgoAdditionalProfileDirs []string `json:",omitempty"` |
Dan Willemsen | 0fe7866 | 2018-03-26 12:41:18 -0700 | [diff] [blame] | 350 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 351 | VndkUseCoreVariant *bool `json:",omitempty"` |
| 352 | VndkSnapshotBuildArtifacts *bool `json:",omitempty"` |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 353 | |
Inseob Kim | 7cf1465 | 2021-01-06 23:06:52 +0900 | [diff] [blame] | 354 | DirectedVendorSnapshot bool `json:",omitempty"` |
| 355 | VendorSnapshotModules map[string]bool `json:",omitempty"` |
| 356 | |
Jose Galmes | 4c6895e | 2021-02-09 07:44:30 -0800 | [diff] [blame] | 357 | DirectedRecoverySnapshot bool `json:",omitempty"` |
| 358 | RecoverySnapshotModules map[string]bool `json:",omitempty"` |
| 359 | |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 360 | VendorSnapshotDirsIncluded []string `json:",omitempty"` |
| 361 | VendorSnapshotDirsExcluded []string `json:",omitempty"` |
| 362 | RecoverySnapshotDirsExcluded []string `json:",omitempty"` |
| 363 | RecoverySnapshotDirsIncluded []string `json:",omitempty"` |
Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 364 | HostFakeSnapshotEnabled bool `json:",omitempty"` |
Justin DeMartino | 383bfb3 | 2021-02-24 10:49:43 -0800 | [diff] [blame] | 365 | |
Inseob Kim | 0f46e7c | 2021-12-15 22:48:14 +0900 | [diff] [blame] | 366 | BoardVendorSepolicyDirs []string `json:",omitempty"` |
| 367 | BoardOdmSepolicyDirs []string `json:",omitempty"` |
| 368 | BoardReqdMaskPolicy []string `json:",omitempty"` |
| 369 | BoardPlatVendorPolicy []string `json:",omitempty"` |
| 370 | BoardSystemExtPublicPrebuiltDirs []string `json:",omitempty"` |
| 371 | BoardSystemExtPrivatePrebuiltDirs []string `json:",omitempty"` |
| 372 | BoardProductPublicPrebuiltDirs []string `json:",omitempty"` |
| 373 | BoardProductPrivatePrebuiltDirs []string `json:",omitempty"` |
| 374 | SystemExtPublicSepolicyDirs []string `json:",omitempty"` |
| 375 | SystemExtPrivateSepolicyDirs []string `json:",omitempty"` |
| 376 | BoardSepolicyM4Defs []string `json:",omitempty"` |
Tri Vo | 35a5143 | 2018-03-25 20:00:00 -0700 | [diff] [blame] | 377 | |
Inseob Kim | 16ebd5a | 2020-12-09 23:08:17 +0900 | [diff] [blame] | 378 | BoardSepolicyVers *string `json:",omitempty"` |
| 379 | PlatformSepolicyVersion *string `json:",omitempty"` |
Inseob Kim | a10ef27 | 2021-09-15 03:04:53 +0000 | [diff] [blame] | 380 | TotSepolicyVersion *string `json:",omitempty"` |
Inseob Kim | 16ebd5a | 2020-12-09 23:08:17 +0900 | [diff] [blame] | 381 | |
Inseob Kim | 1a0afcc | 2022-02-14 23:10:51 +0900 | [diff] [blame] | 382 | SystemExtSepolicyPrebuiltApiDir *string `json:",omitempty"` |
| 383 | ProductSepolicyPrebuiltApiDir *string `json:",omitempty"` |
| 384 | |
Inseob Kim | 843f664 | 2022-01-07 09:11:23 +0900 | [diff] [blame] | 385 | PlatformSepolicyCompatVersions []string `json:",omitempty"` |
| 386 | |
Dan Willemsen | 0fe7866 | 2018-03-26 12:41:18 -0700 | [diff] [blame] | 387 | VendorVars map[string]map[string]string `json:",omitempty"` |
Colin Cross | 395f2cf | 2018-10-24 16:10:32 -0700 | [diff] [blame] | 388 | |
Dan Albert | d05ba00 | 2021-04-13 15:55:47 -0700 | [diff] [blame] | 389 | Ndk_abis *bool `json:",omitempty"` |
Jiyong Park | 8fd6192 | 2018-11-08 02:50:25 +0900 | [diff] [blame] | 390 | |
Jiyong Park | 4da0797 | 2021-01-05 21:01:11 +0900 | [diff] [blame] | 391 | Flatten_apex *bool `json:",omitempty"` |
| 392 | ForceApexSymlinkOptimization *bool `json:",omitempty"` |
| 393 | CompressedApex *bool `json:",omitempty"` |
| 394 | Aml_abis *bool `json:",omitempty"` |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 395 | |
| 396 | DexpreoptGlobalConfig *string `json:",omitempty"` |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 397 | |
Inseob Kim | 7b85eeb | 2021-03-23 20:52:24 +0900 | [diff] [blame] | 398 | WithDexpreopt bool `json:",omitempty"` |
| 399 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 400 | ManifestPackageNameOverrides []string `json:",omitempty"` |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 401 | CertificateOverrides []string `json:",omitempty"` |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 402 | PackageNameOverrides []string `json:",omitempty"` |
Jeongik Cha | c946414 | 2019-01-07 12:07:27 +0900 | [diff] [blame] | 403 | |
Albert Martin | 55ccba2 | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 404 | ApexGlobalMinSdkVersionOverride *string `json:",omitempty"` |
| 405 | |
Jeongik Cha | c946414 | 2019-01-07 12:07:27 +0900 | [diff] [blame] | 406 | EnforceSystemCertificate *bool `json:",omitempty"` |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 407 | EnforceSystemCertificateAllowList []string `json:",omitempty"` |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 408 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 409 | ProductHiddenAPIStubs []string `json:",omitempty"` |
| 410 | ProductHiddenAPIStubsSystem []string `json:",omitempty"` |
| 411 | ProductHiddenAPIStubsTest []string `json:",omitempty"` |
Dan Willemsen | 71c7460 | 2019-04-10 12:27:35 -0700 | [diff] [blame] | 412 | |
Inseob Kim | 0866b00 | 2019-04-15 20:21:29 +0900 | [diff] [blame] | 413 | ProductPublicSepolicyDirs []string `json:",omitempty"` |
| 414 | ProductPrivateSepolicyDirs []string `json:",omitempty"` |
Inseob Kim | 0866b00 | 2019-04-15 20:21:29 +0900 | [diff] [blame] | 415 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 416 | ProductVndkVersion *string `json:",omitempty"` |
| 417 | |
Dan Willemsen | 54879d1 | 2019-04-18 10:08:46 -0700 | [diff] [blame] | 418 | TargetFSConfigGen []string `json:",omitempty"` |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 419 | |
| 420 | MissingUsesLibraries []string `json:",omitempty"` |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 421 | |
| 422 | EnforceProductPartitionInterface *bool `json:",omitempty"` |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 423 | |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 424 | EnforceInterPartitionJavaSdkLibrary *bool `json:",omitempty"` |
| 425 | InterPartitionJavaLibraryAllowList []string `json:",omitempty"` |
| 426 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 427 | InstallExtraFlattenedApexes *bool `json:",omitempty"` |
Yifan Hong | 82db735 | 2020-01-21 16:12:26 -0800 | [diff] [blame] | 428 | |
| 429 | BoardUsesRecoveryAsBoot *bool `json:",omitempty"` |
Yifan Hong | 97365ee | 2020-07-29 09:51:57 -0700 | [diff] [blame] | 430 | |
Yifan Hong | 42bef8d | 2020-08-05 14:36:09 -0700 | [diff] [blame] | 431 | BoardKernelBinaries []string `json:",omitempty"` |
| 432 | BoardKernelModuleInterfaceVersions []string `json:",omitempty"` |
Yifan Hong | dd8dacc | 2020-10-21 15:40:17 -0700 | [diff] [blame] | 433 | |
| 434 | BoardMoveRecoveryResourcesToVendorBoot *bool `json:",omitempty"` |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 435 | |
| 436 | PrebuiltHiddenApiDir *string `json:",omitempty"` |
Inseob Kim | 60c32f0 | 2020-12-21 22:53:05 +0900 | [diff] [blame] | 437 | |
| 438 | ShippingApiLevel *string `json:",omitempty"` |
Inseob Kim | 0cac7b4 | 2021-02-03 18:16:46 +0900 | [diff] [blame] | 439 | |
Liz Kammer | 619be46 | 2022-01-28 15:13:39 -0500 | [diff] [blame] | 440 | BuildBrokenEnforceSyspropOwner bool `json:",omitempty"` |
| 441 | BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"` |
| 442 | BuildBrokenVendorPropertyNamespace bool `json:",omitempty"` |
| 443 | BuildBrokenInputDirModules []string `json:",omitempty"` |
Inseob Kim | 67e5add | 2021-03-17 18:05:33 +0900 | [diff] [blame] | 444 | |
Hridya Valsaraju | 5a5c7d5 | 2021-04-02 16:45:24 -0700 | [diff] [blame] | 445 | BuildDebugfsRestrictionsEnabled bool `json:",omitempty"` |
| 446 | |
Inseob Kim | 67e5add | 2021-03-17 18:05:33 +0900 | [diff] [blame] | 447 | RequiresInsecureExecmemForSwiftshader bool `json:",omitempty"` |
| 448 | |
| 449 | SelinuxIgnoreNeverallows bool `json:",omitempty"` |
| 450 | |
| 451 | SepolicySplit bool `json:",omitempty"` |
Inseob Kim | a10ef27 | 2021-09-15 03:04:53 +0000 | [diff] [blame] | 452 | |
| 453 | SepolicyFreezeTestExtraDirs []string `json:",omitempty"` |
| 454 | SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"` |
Jiyong Park | d163d4d | 2021-10-12 16:47:43 +0900 | [diff] [blame] | 455 | |
| 456 | GenerateAidlNdkPlatformBackend bool `json:",omitempty"` |
Christopher Ferris | 3c0ae33 | 2022-07-13 23:16:52 -0700 | [diff] [blame] | 457 | |
| 458 | ForceMultilibFirstOnDevice bool `json:",omitempty"` |
Spandan Das | 8274777 | 2022-11-08 18:42:16 +0000 | [diff] [blame] | 459 | |
| 460 | IncludeTags []string `json:",omitempty"` |
Colin Cross | a6bc19e | 2015-09-16 13:53:42 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | func boolPtr(v bool) *bool { |
| 464 | return &v |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Dan Willemsen | 47cf66b | 2015-09-16 16:48:54 -0700 | [diff] [blame] | 467 | func intPtr(v int) *int { |
| 468 | return &v |
| 469 | } |
| 470 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 471 | func stringPtr(v string) *string { |
| 472 | return &v |
| 473 | } |
| 474 | |
Colin Cross | 2738597 | 2015-09-18 10:57:10 -0700 | [diff] [blame] | 475 | func (v *productVariables) SetDefaultConfig() { |
| 476 | *v = productVariables{ |
Colin Cross | 2a2e0db | 2020-02-21 16:55:46 -0800 | [diff] [blame] | 477 | BuildNumberFile: stringPtr("build_number.txt"), |
Dan Willemsen | b6d171b | 2019-04-07 09:41:44 -0700 | [diff] [blame] | 478 | |
Jiyong Park | 84d8a7e | 2020-09-25 13:44:51 +0900 | [diff] [blame] | 479 | Platform_version_name: stringPtr("S"), |
| 480 | Platform_sdk_version: intPtr(30), |
| 481 | Platform_sdk_codename: stringPtr("S"), |
Dan Willemsen | b6d171b | 2019-04-07 09:41:44 -0700 | [diff] [blame] | 482 | Platform_sdk_final: boolPtr(false), |
Jiyong Park | 84d8a7e | 2020-09-25 13:44:51 +0900 | [diff] [blame] | 483 | Platform_version_active_codenames: []string{"S"}, |
| 484 | Platform_vndk_version: stringPtr("S"), |
Dan Willemsen | cbf9e82 | 2017-11-13 14:34:56 -0800 | [diff] [blame] | 485 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 486 | HostArch: stringPtr("x86_64"), |
| 487 | HostSecondaryArch: stringPtr("x86"), |
Dan Willemsen | cbf9e82 | 2017-11-13 14:34:56 -0800 | [diff] [blame] | 488 | DeviceName: stringPtr("generic_arm64"), |
Trevor Radcliffe | 90727f4 | 2022-03-21 19:34:02 +0000 | [diff] [blame] | 489 | DeviceProduct: stringPtr("aosp_arm-eng"), |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 490 | DeviceArch: stringPtr("arm64"), |
Dan Willemsen | a91d127 | 2016-03-29 22:06:05 -0700 | [diff] [blame] | 491 | DeviceArchVariant: stringPtr("armv8-a"), |
Dan Willemsen | cbf9e82 | 2017-11-13 14:34:56 -0800 | [diff] [blame] | 492 | DeviceCpuVariant: stringPtr("generic"), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 493 | DeviceAbi: []string{"arm64-v8a"}, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 494 | DeviceSecondaryArch: stringPtr("arm"), |
Dan Willemsen | cbf9e82 | 2017-11-13 14:34:56 -0800 | [diff] [blame] | 495 | DeviceSecondaryArchVariant: stringPtr("armv8-a"), |
| 496 | DeviceSecondaryCpuVariant: stringPtr("generic"), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 497 | DeviceSecondaryAbi: []string{"armeabi-v7a", "armeabi"}, |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 498 | |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 499 | AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}, |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 500 | AAPTPreferredConfig: stringPtr("xhdpi"), |
| 501 | AAPTCharacteristics: stringPtr("nosdcard"), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 502 | AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"}, |
Colin Cross | face4e4 | 2017-10-30 17:32:15 -0700 | [diff] [blame] | 503 | |
Evgenii Stepanov | 19ff3c9 | 2020-04-29 14:57:30 -0700 | [diff] [blame] | 504 | Malloc_not_svelte: boolPtr(true), |
Quallenauge | bed769c | 2020-10-21 21:19:01 +0200 | [diff] [blame] | 505 | Malloc_not_svelte_libc32: boolPtr(true), |
Steven Moreland | d134201 | 2020-07-30 20:38:49 +0000 | [diff] [blame] | 506 | Malloc_zero_contents: boolPtr(true), |
Evgenii Stepanov | 19ff3c9 | 2020-04-29 14:57:30 -0700 | [diff] [blame] | 507 | Malloc_pattern_fill_contents: boolPtr(false), |
| 508 | Safestack: boolPtr(false), |
Lukacs T. Berki | 720b396 | 2021-03-17 13:34:30 +0100 | [diff] [blame] | 509 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 510 | BootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}}, |
| 511 | ApexBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}}, |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 512 | } |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 513 | |
| 514 | if runtime.GOOS == "linux" { |
| 515 | v.CrossHost = stringPtr("windows") |
| 516 | v.CrossHostArch = stringPtr("x86") |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 517 | v.CrossHostSecondaryArch = stringPtr("x86_64") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 518 | } |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 521 | // ProductConfigContext requires the access to the Module to get product config properties. |
| 522 | type ProductConfigContext interface { |
| 523 | Module() Module |
| 524 | } |
| 525 | |
| 526 | // ProductConfigProperty contains the information for a single property (may be a struct) paired |
| 527 | // with the appropriate ProductConfigVariable. |
| 528 | type ProductConfigProperty struct { |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 529 | // The name of the product variable, e.g. "safestack", "malloc_not_svelte", |
| 530 | // "board" |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 531 | Name string |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 532 | |
| 533 | // Namespace of the variable, if this is a soong_config_module_type variable |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 534 | // e.g. "acme", "ANDROID", "vendor_name" |
| 535 | Namespace string |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 536 | |
| 537 | // Unique configuration to identify this product config property (i.e. a |
| 538 | // primary key), as just using the product variable name is not sufficient. |
| 539 | // |
| 540 | // For product variables, this is the product variable name + optional |
| 541 | // archvariant information. e.g. |
| 542 | // |
| 543 | // product_variables: { |
| 544 | // foo: { |
| 545 | // cflags: ["-Dfoo"], |
| 546 | // }, |
| 547 | // }, |
| 548 | // |
| 549 | // FullConfig would be "foo". |
| 550 | // |
| 551 | // target: { |
| 552 | // android: { |
| 553 | // product_variables: { |
| 554 | // foo: { |
| 555 | // cflags: ["-Dfoo-android"], |
| 556 | // }, |
| 557 | // }, |
| 558 | // }, |
| 559 | // }, |
| 560 | // |
| 561 | // FullConfig would be "foo-android". |
| 562 | // |
| 563 | // For soong config variables, this is the namespace + product variable name |
| 564 | // + value of the variable, if applicable. The value can also be |
| 565 | // conditions_default. |
| 566 | // |
| 567 | // e.g. |
| 568 | // |
| 569 | // soong_config_variables: { |
| 570 | // feature1: { |
| 571 | // conditions_default: { |
| 572 | // cflags: ["-DDEFAULT1"], |
| 573 | // }, |
| 574 | // cflags: ["-DFEATURE1"], |
| 575 | // }, |
| 576 | // } |
| 577 | // |
| 578 | // where feature1 is created in the "acme" namespace, so FullConfig would be |
| 579 | // "acme__feature1" and "acme__feature1__conditions_default". |
| 580 | // |
| 581 | // e.g. |
| 582 | // |
| 583 | // soong_config_variables: { |
| 584 | // board: { |
| 585 | // soc_a: { |
| 586 | // cflags: ["-DSOC_A"], |
| 587 | // }, |
| 588 | // soc_b: { |
| 589 | // cflags: ["-DSOC_B"], |
| 590 | // }, |
| 591 | // soc_c: {}, |
| 592 | // conditions_default: { |
| 593 | // cflags: ["-DSOC_DEFAULT"] |
| 594 | // }, |
| 595 | // }, |
| 596 | // } |
| 597 | // |
| 598 | // where board is created in the "acme" namespace, so FullConfig would be |
| 599 | // "acme__board__soc_a", "acme__board__soc_b", and |
| 600 | // "acme__board__conditions_default" |
| 601 | FullConfig string |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 602 | } |
| 603 | |
Jingwen Chen | 58ff680 | 2021-11-17 12:14:41 +0000 | [diff] [blame] | 604 | func (p *ProductConfigProperty) AlwaysEmit() bool { |
| 605 | return p.Namespace != "" |
| 606 | } |
| 607 | |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 608 | func (p *ProductConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis { |
| 609 | if p.Namespace == "" { |
| 610 | return bazel.ProductVariableConfigurationAxis(p.FullConfig) |
| 611 | } else { |
| 612 | // Soong config variables can be uniquely identified by the namespace |
| 613 | // (e.g. acme, android) and the product variable name (e.g. board, size) |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 614 | return bazel.ProductVariableConfigurationAxis(p.Namespace + "__" + p.Name) |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 618 | // SelectKey returns the literal string that represents this variable in a BUILD |
| 619 | // select statement. |
| 620 | func (p *ProductConfigProperty) SelectKey() string { |
| 621 | if p.Namespace == "" { |
| 622 | return strings.ToLower(p.FullConfig) |
| 623 | } |
| 624 | |
| 625 | if p.FullConfig == bazel.ConditionsDefaultConfigKey { |
| 626 | return bazel.ConditionsDefaultConfigKey |
| 627 | } |
| 628 | |
| 629 | value := p.FullConfig |
| 630 | if value == p.Name { |
Sam Delmerico | 0e33c9d | 2022-01-07 20:39:21 +0000 | [diff] [blame] | 631 | value = "" |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 632 | } |
Sam Delmerico | 0e33c9d | 2022-01-07 20:39:21 +0000 | [diff] [blame] | 633 | |
| 634 | // e.g. acme__feature1, android__board__soc_a |
| 635 | selectKey := strings.ToLower(strings.Join([]string{p.Namespace, p.Name}, "__")) |
| 636 | if value != "" { |
| 637 | selectKey = strings.ToLower(strings.Join([]string{selectKey, value}, "__")) |
| 638 | } |
| 639 | |
| 640 | return selectKey |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | // ProductConfigProperties is a map of maps to group property values according |
| 644 | // their property name and the product config variable they're set under. |
| 645 | // |
| 646 | // The outer map key is the name of the property, like "cflags". |
| 647 | // |
| 648 | // The inner map key is a ProductConfigProperty, which is a struct of product |
| 649 | // variable name, namespace, and the "full configuration" of the product |
| 650 | // variable. |
| 651 | // |
| 652 | // e.g. product variable name: board, namespace: acme, full config: vendor_chip_foo |
| 653 | // |
| 654 | // The value of the map is the interface{} representing the value of the |
| 655 | // property, like ["-DDEFINES"] for cflags. |
| 656 | type ProductConfigProperties map[string]map[ProductConfigProperty]interface{} |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 657 | |
| 658 | // ProductVariableProperties returns a ProductConfigProperties containing only the properties which |
| 659 | // have been set for the module in the given context. |
Jingwen Chen | 55bc820 | 2021-11-02 06:40:51 +0000 | [diff] [blame] | 660 | func ProductVariableProperties(ctx BazelConversionPathContext) ProductConfigProperties { |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 661 | module := ctx.Module() |
| 662 | moduleBase := module.base() |
| 663 | |
| 664 | productConfigProperties := ProductConfigProperties{} |
| 665 | |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 666 | if moduleBase.variableProperties != nil { |
| 667 | productVariablesProperty := proptools.FieldNameForProperty("product_variables") |
| 668 | productVariableValues( |
| 669 | productVariablesProperty, |
| 670 | moduleBase.variableProperties, |
| 671 | "", |
| 672 | "", |
| 673 | &productConfigProperties) |
| 674 | |
| 675 | for _, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) { |
| 676 | for config, props := range configToProps { |
| 677 | // GetArchVariantProperties is creating an instance of the requested type |
| 678 | // and productVariablesValues expects an interface, so no need to cast |
| 679 | productVariableValues( |
| 680 | productVariablesProperty, |
| 681 | props, |
| 682 | "", |
| 683 | config, |
| 684 | &productConfigProperties) |
| 685 | } |
| 686 | } |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 687 | } |
| 688 | |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 689 | if m, ok := module.(Bazelable); ok && m.namespacedVariableProps() != nil { |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 690 | for namespace, namespacedVariableProps := range m.namespacedVariableProps() { |
| 691 | for _, namespacedVariableProp := range namespacedVariableProps { |
| 692 | productVariableValues( |
| 693 | soongconfig.SoongConfigProperty, |
| 694 | namespacedVariableProp, |
| 695 | namespace, |
| 696 | "", |
| 697 | &productConfigProperties) |
| 698 | } |
Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 699 | } |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame] | 700 | } |
| 701 | |
Jingwen Chen | 58ff680 | 2021-11-17 12:14:41 +0000 | [diff] [blame] | 702 | productConfigProperties.zeroValuesForNamespacedVariables() |
| 703 | |
Liz Kammer | e3e4a5f | 2021-05-10 11:39:53 -0400 | [diff] [blame] | 704 | return productConfigProperties |
| 705 | } |
| 706 | |
Jingwen Chen | 58ff680 | 2021-11-17 12:14:41 +0000 | [diff] [blame] | 707 | // zeroValuesForNamespacedVariables ensures that selects that contain __only__ |
| 708 | // conditions default values have zero values set for the other non-default |
| 709 | // values for that select statement. |
| 710 | // |
| 711 | // If the ProductConfigProperties map contains these items, as parsed from the .bp file: |
| 712 | // |
| 713 | // library_linking_strategy: { |
| 714 | // prefer_static: { |
| 715 | // static_libs: [ |
| 716 | // "lib_a", |
| 717 | // "lib_b", |
| 718 | // ], |
| 719 | // }, |
| 720 | // conditions_default: { |
| 721 | // shared_libs: [ |
| 722 | // "lib_a", |
| 723 | // "lib_b", |
| 724 | // ], |
| 725 | // }, |
| 726 | // }, |
| 727 | // |
| 728 | // Static_libs {Library_linking_strategy ANDROID prefer_static} [lib_a lib_b] |
| 729 | // Shared_libs {Library_linking_strategy ANDROID conditions_default} [lib_a lib_b] |
| 730 | // |
| 731 | // We need to add this: |
| 732 | // |
| 733 | // Shared_libs {Library_linking_strategy ANDROID prefer_static} [] |
| 734 | // |
| 735 | // so that the following gets generated for the "dynamic_deps" attribute, |
| 736 | // instead of putting lib_a and lib_b directly into dynamic_deps without a |
| 737 | // select: |
| 738 | // |
| 739 | // dynamic_deps = select({ |
| 740 | // "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": [], |
| 741 | // "//conditions:default": [ |
| 742 | // "//foo/bar:lib_a", |
| 743 | // "//foo/bar:lib_b", |
| 744 | // ], |
| 745 | // }), |
| 746 | func (props *ProductConfigProperties) zeroValuesForNamespacedVariables() { |
| 747 | // A map of product config properties to the zero values of their respective |
| 748 | // property value. |
| 749 | zeroValues := make(map[ProductConfigProperty]interface{}) |
| 750 | |
| 751 | // A map of prop names (e.g. cflags) to product config properties where the |
| 752 | // (prop name, ProductConfigProperty) tuple contains a non-conditions_default key. |
| 753 | // |
| 754 | // e.g. |
| 755 | // |
| 756 | // prefer_static: { |
| 757 | // static_libs: [ |
| 758 | // "lib_a", |
| 759 | // "lib_b", |
| 760 | // ], |
| 761 | // }, |
| 762 | // conditions_default: { |
| 763 | // shared_libs: [ |
| 764 | // "lib_a", |
| 765 | // "lib_b", |
| 766 | // ], |
| 767 | // }, |
| 768 | // |
| 769 | // The tuple of ("static_libs", prefer_static) would be in this map. |
| 770 | hasNonDefaultValue := make(map[string]map[ProductConfigProperty]bool) |
| 771 | |
| 772 | // Iterate over all added soong config variables. |
| 773 | for propName, v := range *props { |
| 774 | for p, intf := range v { |
| 775 | if p.Namespace == "" { |
| 776 | // If there's no namespace, this isn't a soong config variable, |
| 777 | // i.e. this is a product variable. product variables have no |
| 778 | // conditions_defaults, so skip them. |
| 779 | continue |
| 780 | } |
| 781 | if p.FullConfig == bazel.ConditionsDefaultConfigKey { |
| 782 | // Skip conditions_defaults. |
| 783 | continue |
| 784 | } |
| 785 | if hasNonDefaultValue[propName] == nil { |
| 786 | hasNonDefaultValue[propName] = make(map[ProductConfigProperty]bool) |
| 787 | hasNonDefaultValue[propName][p] = false |
| 788 | } |
| 789 | // Create the zero value of the variable. |
| 790 | if _, exists := zeroValues[p]; !exists { |
| 791 | zeroValue := reflect.Zero(reflect.ValueOf(intf).Type()).Interface() |
| 792 | if zeroValue == nil { |
| 793 | panic(fmt.Errorf("Expected non-nil zero value for product/config variable %+v\n", intf)) |
| 794 | } |
| 795 | zeroValues[p] = zeroValue |
| 796 | } |
| 797 | hasNonDefaultValue[propName][p] = true |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | for propName := range *props { |
| 802 | for p, zeroValue := range zeroValues { |
| 803 | // Ignore variables that already have a non-default value for that axis |
| 804 | if exists, _ := hasNonDefaultValue[propName][p]; !exists { |
| 805 | // fmt.Println(propName, p.Namespace, p.Name, p.FullConfig, zeroValue) |
| 806 | // Insert the zero value for this propname + product config value. |
| 807 | props.AddProductConfigProperty( |
| 808 | propName, |
| 809 | p.Namespace, |
| 810 | p.Name, |
| 811 | p.FullConfig, |
| 812 | zeroValue, |
| 813 | ) |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 819 | func (p *ProductConfigProperties) AddProductConfigProperty( |
| 820 | propertyName, namespace, productVariableName, config string, property interface{}) { |
| 821 | if (*p)[propertyName] == nil { |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 822 | (*p)[propertyName] = make(map[ProductConfigProperty]interface{}) |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 825 | productConfigProp := ProductConfigProperty{ |
| 826 | Namespace: namespace, // e.g. acme, android |
| 827 | Name: productVariableName, // e.g. size, feature1, feature2, FEATURE3, board |
| 828 | FullConfig: config, // e.g. size, feature1-x86, size__conditions_default |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 829 | } |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 830 | |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 831 | if existing, ok := (*p)[propertyName][productConfigProp]; ok && namespace != "" { |
| 832 | switch dst := existing.(type) { |
| 833 | case []string: |
| 834 | if src, ok := property.([]string); ok { |
| 835 | dst = append(dst, src...) |
| 836 | (*p)[propertyName][productConfigProp] = dst |
| 837 | } |
| 838 | default: |
Jingwen Chen | 58ff680 | 2021-11-17 12:14:41 +0000 | [diff] [blame] | 839 | panic(fmt.Errorf("TODO: handle merging value %s", existing)) |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 840 | } |
| 841 | } else { |
| 842 | (*p)[propertyName][productConfigProp] = property |
| 843 | } |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | var ( |
| 847 | conditionsDefaultField string = proptools.FieldNameForProperty(bazel.ConditionsDefaultConfigKey) |
| 848 | ) |
| 849 | |
| 850 | // maybeExtractConfigVarProp attempts to read this value as a config var struct |
| 851 | // wrapped by interfaces and ptrs. If it's not the right type, the second return |
| 852 | // value is false. |
| 853 | func maybeExtractConfigVarProp(v reflect.Value) (reflect.Value, bool) { |
| 854 | if v.Kind() == reflect.Interface { |
| 855 | // The conditions_default value can be either |
| 856 | // 1) an ptr to an interface of a struct (bool config variables and product variables) |
| 857 | // 2) an interface of 1) (config variables with nested structs, like string vars) |
| 858 | v = v.Elem() |
| 859 | } |
| 860 | if v.Kind() != reflect.Ptr { |
| 861 | return v, false |
| 862 | } |
| 863 | v = reflect.Indirect(v) |
| 864 | if v.Kind() == reflect.Interface { |
| 865 | // Extract the struct from the interface |
| 866 | v = v.Elem() |
| 867 | } |
| 868 | |
| 869 | if !v.IsValid() { |
| 870 | return v, false |
| 871 | } |
| 872 | |
| 873 | if v.Kind() != reflect.Struct { |
| 874 | return v, false |
| 875 | } |
| 876 | return v, true |
| 877 | } |
| 878 | |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 879 | func (productConfigProperties *ProductConfigProperties) AddProductConfigProperties(namespace, suffix string, variableValues reflect.Value) { |
| 880 | // variableValues can either be a product_variables or |
| 881 | // soong_config_variables struct. |
| 882 | // |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 883 | // Example of product_variables: |
| 884 | // |
| 885 | // product_variables: { |
| 886 | // malloc_not_svelte: { |
| 887 | // shared_libs: ["malloc_not_svelte_shared_lib"], |
| 888 | // whole_static_libs: ["malloc_not_svelte_whole_static_lib"], |
| 889 | // exclude_static_libs: [ |
| 890 | // "malloc_not_svelte_static_lib_excludes", |
| 891 | // "malloc_not_svelte_whole_static_lib_excludes", |
| 892 | // ], |
| 893 | // }, |
| 894 | // }, |
| 895 | // |
| 896 | // Example of soong_config_variables: |
| 897 | // |
| 898 | // soong_config_variables: { |
| 899 | // feature1: { |
| 900 | // conditions_default: { |
| 901 | // ... |
| 902 | // }, |
| 903 | // cflags: ... |
| 904 | // }, |
| 905 | // feature2: { |
| 906 | // cflags: ... |
| 907 | // conditions_default: { |
| 908 | // ... |
| 909 | // }, |
| 910 | // }, |
| 911 | // board: { |
| 912 | // soc_a: { |
| 913 | // ... |
| 914 | // }, |
| 915 | // soc_a: { |
| 916 | // ... |
| 917 | // }, |
| 918 | // soc_c: {}, |
| 919 | // conditions_default: { |
| 920 | // ... |
| 921 | // }, |
| 922 | // }, |
| 923 | // } |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 924 | for i := 0; i < variableValues.NumField(); i++ { |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 925 | // e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc. |
| 926 | productVariableName := variableValues.Type().Field(i).Name |
| 927 | |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 928 | variableValue := variableValues.Field(i) |
| 929 | // Check if any properties were set for the module |
| 930 | if variableValue.IsZero() { |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 931 | // e.g. feature1: {}, malloc_not_svelte: {} |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 932 | continue |
| 933 | } |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 934 | |
| 935 | // Unlike product variables, config variables require a few more |
| 936 | // indirections to extract the struct from the reflect.Value. |
| 937 | if v, ok := maybeExtractConfigVarProp(variableValue); ok { |
| 938 | variableValue = v |
| 939 | } |
| 940 | |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 941 | for j := 0; j < variableValue.NumField(); j++ { |
| 942 | property := variableValue.Field(j) |
| 943 | // If the property wasn't set, no need to pass it along |
| 944 | if property.IsZero() { |
| 945 | continue |
| 946 | } |
| 947 | |
| 948 | // e.g. Asflags, Cflags, Enabled, etc. |
| 949 | propertyName := variableValue.Type().Field(j).Name |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 950 | |
| 951 | if v, ok := maybeExtractConfigVarProp(property); ok { |
| 952 | // The field is a struct, which is used by: |
| 953 | // 1) soong_config_string_variables |
| 954 | // |
| 955 | // soc_a: { |
| 956 | // cflags: ..., |
| 957 | // } |
| 958 | // |
| 959 | // soc_b: { |
| 960 | // cflags: ..., |
| 961 | // } |
| 962 | // |
| 963 | // 2) conditions_default structs for all soong config variable types. |
| 964 | // |
| 965 | // conditions_default: { |
| 966 | // cflags: ..., |
| 967 | // static_libs: ... |
| 968 | // } |
| 969 | field := v |
| 970 | for k := 0; k < field.NumField(); k++ { |
| 971 | // Iterate over fields of this struct prop. |
| 972 | if field.Field(k).IsZero() { |
| 973 | continue |
| 974 | } |
Jingwen Chen | 25825ca | 2021-11-15 12:28:43 +0000 | [diff] [blame] | 975 | // config can also be "conditions_default". |
| 976 | config := proptools.PropertyNameForField(propertyName) |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 977 | actualPropertyName := field.Type().Field(k).Name |
| 978 | |
| 979 | productConfigProperties.AddProductConfigProperty( |
| 980 | actualPropertyName, // e.g. cflags, static_libs |
| 981 | namespace, // e.g. acme, android |
| 982 | productVariableName, // e.g. size, feature1, FEATURE2, board |
| 983 | config, |
| 984 | field.Field(k).Interface(), // e.g. ["-DDEFAULT"], ["foo", "bar"] |
| 985 | ) |
| 986 | } |
Jingwen Chen | 58ff680 | 2021-11-17 12:14:41 +0000 | [diff] [blame] | 987 | } else if property.Kind() != reflect.Interface { |
| 988 | // If not an interface, then this is not a conditions_default or |
| 989 | // a struct prop. That is, this is a regular product variable, |
| 990 | // or a bool/value config variable. |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 991 | config := productVariableName + suffix |
Jingwen Chen | a47f28d | 2021-11-02 16:43:57 +0000 | [diff] [blame] | 992 | productConfigProperties.AddProductConfigProperty( |
| 993 | propertyName, |
| 994 | namespace, |
| 995 | productVariableName, |
| 996 | config, |
| 997 | property.Interface(), |
| 998 | ) |
Liz Kammer | 47535c5 | 2021-06-02 16:02:22 -0400 | [diff] [blame] | 999 | } |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 1000 | } |
| 1001 | } |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
Jingwen Chen | 84817de | 2021-11-17 10:57:35 +0000 | [diff] [blame] | 1004 | // productVariableValues uses reflection to convert a property struct for |
| 1005 | // product_variables and soong_config_variables to structs that can be generated |
| 1006 | // as select statements. |
| 1007 | func productVariableValues( |
| 1008 | fieldName string, variableProps interface{}, namespace, suffix string, productConfigProperties *ProductConfigProperties) { |
| 1009 | if suffix != "" { |
| 1010 | suffix = "-" + suffix |
| 1011 | } |
| 1012 | |
| 1013 | // variableValues represent the product_variables or soong_config_variables struct. |
| 1014 | variableValues := reflect.ValueOf(variableProps).Elem().FieldByName(fieldName) |
| 1015 | productConfigProperties.AddProductConfigProperties(namespace, suffix, variableValues) |
| 1016 | } |
| 1017 | |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 1018 | func VariableMutator(mctx BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1019 | var module Module |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1020 | var ok bool |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1021 | if module, ok = mctx.Module().(Module); !ok { |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1022 | return |
| 1023 | } |
| 1024 | |
| 1025 | // TODO: depend on config variable, create variants, propagate variants up tree |
| 1026 | a := module.base() |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 1027 | |
| 1028 | if a.variableProperties == nil { |
| 1029 | return |
| 1030 | } |
| 1031 | |
| 1032 | variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables") |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1033 | |
Colin Cross | 0cec312 | 2021-01-20 11:27:32 -0800 | [diff] [blame] | 1034 | productVariables := reflect.ValueOf(mctx.Config().productVariables) |
| 1035 | |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1036 | for i := 0; i < variableValues.NumField(); i++ { |
| 1037 | variableValue := variableValues.Field(i) |
Colin Cross | 485e572 | 2015-08-27 13:28:01 -0700 | [diff] [blame] | 1038 | name := variableValues.Type().Field(i).Name |
| 1039 | property := "product_variables." + proptools.PropertyNameForField(name) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1040 | |
Colin Cross | a6bc19e | 2015-09-16 13:53:42 -0700 | [diff] [blame] | 1041 | // Check that the variable was set for the product |
Colin Cross | 0cec312 | 2021-01-20 11:27:32 -0800 | [diff] [blame] | 1042 | val := productVariables.FieldByName(name) |
Colin Cross | a6bc19e | 2015-09-16 13:53:42 -0700 | [diff] [blame] | 1043 | if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() { |
| 1044 | continue |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1045 | } |
Colin Cross | a6bc19e | 2015-09-16 13:53:42 -0700 | [diff] [blame] | 1046 | |
| 1047 | val = val.Elem() |
| 1048 | |
| 1049 | // For bools, check that the value is true |
| 1050 | if val.Kind() == reflect.Bool && val.Bool() == false { |
| 1051 | continue |
| 1052 | } |
| 1053 | |
| 1054 | // Check if any properties were set for the module |
Colin Cross | 6961a49 | 2020-02-06 16:57:45 -0800 | [diff] [blame] | 1055 | if variableValue.IsZero() { |
Colin Cross | a6bc19e | 2015-09-16 13:53:42 -0700 | [diff] [blame] | 1056 | continue |
| 1057 | } |
Colin Cross | a6bc19e | 2015-09-16 13:53:42 -0700 | [diff] [blame] | 1058 | a.setVariableProperties(mctx, property, variableValue, val.Interface()) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1059 | } |
| 1060 | } |
| 1061 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1062 | func (m *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext, |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1063 | prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) { |
| 1064 | |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1065 | printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1066 | |
Usta | 851a327 | 2022-01-05 23:42:33 -0500 | [diff] [blame] | 1067 | err := proptools.AppendMatchingProperties(m.GetProperties(), |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1068 | productVariablePropertyValue.Addr().Interface(), nil) |
| 1069 | if err != nil { |
| 1070 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 1071 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 1072 | } else { |
| 1073 | panic(err) |
| 1074 | } |
| 1075 | } |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1078 | func printfIntoPropertiesError(ctx BottomUpMutatorContext, prefix string, |
| 1079 | productVariablePropertyValue reflect.Value, i int, err error) { |
| 1080 | |
| 1081 | field := productVariablePropertyValue.Type().Field(i).Name |
| 1082 | property := prefix + "." + proptools.PropertyNameForField(field) |
| 1083 | ctx.PropertyErrorf(property, "%s", err) |
| 1084 | } |
| 1085 | |
| 1086 | func printfIntoProperties(ctx BottomUpMutatorContext, prefix string, |
| 1087 | productVariablePropertyValue reflect.Value, variableValue interface{}) { |
| 1088 | |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1089 | for i := 0; i < productVariablePropertyValue.NumField(); i++ { |
| 1090 | propertyValue := productVariablePropertyValue.Field(i) |
Colin Cross | dd0dbe6 | 2015-12-02 15:24:38 -0800 | [diff] [blame] | 1091 | kind := propertyValue.Kind() |
| 1092 | if kind == reflect.Ptr { |
| 1093 | if propertyValue.IsNil() { |
| 1094 | continue |
| 1095 | } |
| 1096 | propertyValue = propertyValue.Elem() |
| 1097 | } |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1098 | switch propertyValue.Kind() { |
| 1099 | case reflect.String: |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1100 | err := printfIntoProperty(propertyValue, variableValue) |
| 1101 | if err != nil { |
| 1102 | printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err) |
| 1103 | } |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1104 | case reflect.Slice: |
| 1105 | for j := 0; j < propertyValue.Len(); j++ { |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1106 | err := printfIntoProperty(propertyValue.Index(j), variableValue) |
| 1107 | if err != nil { |
| 1108 | printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err) |
| 1109 | } |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1110 | } |
Colin Cross | dd0dbe6 | 2015-12-02 15:24:38 -0800 | [diff] [blame] | 1111 | case reflect.Bool: |
| 1112 | // Nothing |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1113 | case reflect.Struct: |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1114 | printfIntoProperties(ctx, prefix, propertyValue, variableValue) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1115 | default: |
| 1116 | panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind())) |
| 1117 | } |
| 1118 | } |
| 1119 | } |
| 1120 | |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1121 | func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) error { |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1122 | s := propertyValue.String() |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1123 | |
| 1124 | count := strings.Count(s, "%") |
| 1125 | if count == 0 { |
| 1126 | return nil |
| 1127 | } |
| 1128 | |
| 1129 | if count > 1 { |
| 1130 | return fmt.Errorf("product variable properties only support a single '%%'") |
| 1131 | } |
| 1132 | |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1133 | if strings.Contains(s, "%d") { |
| 1134 | switch v := variableValue.(type) { |
| 1135 | case int: |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1136 | // Nothing |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1137 | case bool: |
| 1138 | if v { |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1139 | variableValue = 1 |
| 1140 | } else { |
| 1141 | variableValue = 0 |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1142 | } |
| 1143 | default: |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1144 | return fmt.Errorf("unsupported type %T for %%d", variableValue) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1145 | } |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1146 | } else if strings.Contains(s, "%s") { |
| 1147 | switch variableValue.(type) { |
| 1148 | case string: |
| 1149 | // Nothing |
| 1150 | default: |
| 1151 | return fmt.Errorf("unsupported type %T for %%s", variableValue) |
| 1152 | } |
| 1153 | } else { |
| 1154 | return fmt.Errorf("unsupported %% in product variable property") |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1155 | } |
Colin Cross | 7e0eaf1 | 2017-05-05 16:16:24 -0700 | [diff] [blame] | 1156 | |
| 1157 | propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, variableValue))) |
| 1158 | |
| 1159 | return nil |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 1160 | } |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 1161 | |
| 1162 | var variablePropTypeMap OncePer |
| 1163 | |
| 1164 | // sliceToTypeArray takes a slice of property structs and returns a reflection created array containing the |
| 1165 | // reflect.Types of each property struct. The result can be used as a key in a map. |
| 1166 | func sliceToTypeArray(s []interface{}) interface{} { |
| 1167 | // Create an array using reflection whose length is the length of the input slice |
| 1168 | ret := reflect.New(reflect.ArrayOf(len(s), reflect.TypeOf(reflect.TypeOf(0)))).Elem() |
| 1169 | for i, e := range s { |
| 1170 | ret.Index(i).Set(reflect.ValueOf(reflect.TypeOf(e))) |
| 1171 | } |
| 1172 | return ret.Interface() |
| 1173 | } |
| 1174 | |
Colin Cross | eabaedd | 2020-02-06 17:01:55 -0800 | [diff] [blame] | 1175 | func initProductVariableModule(m Module) { |
| 1176 | base := m.base() |
| 1177 | |
| 1178 | // Allow tests to override the default product variables |
| 1179 | if base.variableProperties == nil { |
| 1180 | base.variableProperties = defaultProductVariables |
| 1181 | } |
| 1182 | // Filter the product variables properties to the ones that exist on this module |
| 1183 | base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties) |
| 1184 | if base.variableProperties != nil { |
| 1185 | m.AddProperties(base.variableProperties) |
| 1186 | } |
| 1187 | } |
| 1188 | |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 1189 | // createVariableProperties takes the list of property structs for a module and returns a property struct that |
| 1190 | // contains the product variable properties that exist in the property structs, or nil if there are none. It |
| 1191 | // caches the result. |
| 1192 | func createVariableProperties(moduleTypeProps []interface{}, productVariables interface{}) interface{} { |
| 1193 | // Convert the moduleTypeProps to an array of reflect.Types that can be used as a key in the OncePer. |
| 1194 | key := sliceToTypeArray(moduleTypeProps) |
| 1195 | |
| 1196 | // Use the variablePropTypeMap OncePer to cache the result for each set of property struct types. |
| 1197 | typ, _ := variablePropTypeMap.Once(NewCustomOnceKey(key), func() interface{} { |
| 1198 | // Compute the filtered property struct type. |
| 1199 | return createVariablePropertiesType(moduleTypeProps, productVariables) |
| 1200 | }).(reflect.Type) |
| 1201 | |
| 1202 | if typ == nil { |
| 1203 | return nil |
| 1204 | } |
| 1205 | |
| 1206 | // Create a new pointer to a filtered property struct. |
| 1207 | return reflect.New(typ).Interface() |
| 1208 | } |
| 1209 | |
| 1210 | // createVariablePropertiesType creates a new type that contains only the product variable properties that exist in |
| 1211 | // a list of property structs. |
| 1212 | func createVariablePropertiesType(moduleTypeProps []interface{}, productVariables interface{}) reflect.Type { |
| 1213 | typ, _ := proptools.FilterPropertyStruct(reflect.TypeOf(productVariables), |
| 1214 | func(field reflect.StructField, prefix string) (bool, reflect.StructField) { |
| 1215 | // Filter function, returns true if the field should be in the resulting struct |
| 1216 | if prefix == "" { |
| 1217 | // Keep the top level Product_variables field |
| 1218 | return true, field |
| 1219 | } |
| 1220 | _, rest := splitPrefix(prefix) |
| 1221 | if rest == "" { |
| 1222 | // Keep the 2nd level field (i.e. Product_variables.Eng) |
| 1223 | return true, field |
| 1224 | } |
| 1225 | |
| 1226 | // Strip off the first 2 levels of the prefix |
| 1227 | _, prefix = splitPrefix(rest) |
| 1228 | |
| 1229 | for _, p := range moduleTypeProps { |
| 1230 | if fieldExistsByNameRecursive(reflect.TypeOf(p).Elem(), prefix, field.Name) { |
| 1231 | // Keep any fields that exist in one of the property structs |
| 1232 | return true, field |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | return false, field |
| 1237 | }) |
| 1238 | return typ |
| 1239 | } |
| 1240 | |
| 1241 | func splitPrefix(prefix string) (first, rest string) { |
| 1242 | index := strings.IndexByte(prefix, '.') |
| 1243 | if index == -1 { |
| 1244 | return prefix, "" |
| 1245 | } |
| 1246 | return prefix[:index], prefix[index+1:] |
| 1247 | } |
| 1248 | |
| 1249 | func fieldExistsByNameRecursive(t reflect.Type, prefix, name string) bool { |
| 1250 | if t.Kind() != reflect.Struct { |
| 1251 | panic(fmt.Errorf("fieldExistsByNameRecursive can only be called on a reflect.Struct")) |
| 1252 | } |
| 1253 | |
| 1254 | if prefix != "" { |
| 1255 | split := strings.SplitN(prefix, ".", 2) |
| 1256 | firstPrefix := split[0] |
| 1257 | rest := "" |
| 1258 | if len(split) > 1 { |
| 1259 | rest = split[1] |
| 1260 | } |
| 1261 | f, exists := t.FieldByName(firstPrefix) |
| 1262 | if !exists { |
| 1263 | return false |
| 1264 | } |
| 1265 | ft := f.Type |
| 1266 | if ft.Kind() == reflect.Ptr { |
| 1267 | ft = ft.Elem() |
| 1268 | } |
| 1269 | if ft.Kind() != reflect.Struct { |
| 1270 | panic(fmt.Errorf("field %q in %q is not a struct", firstPrefix, t)) |
| 1271 | } |
| 1272 | return fieldExistsByNameRecursive(ft, rest, name) |
| 1273 | } else { |
| 1274 | _, exists := t.FieldByName(name) |
| 1275 | return exists |
| 1276 | } |
| 1277 | } |