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