blob: e808eb4f32fd89f2aa965ed351ef135ed4bf306d [file] [log] [blame]
Colin Cross7f64b6d2015-07-09 13:57:48 -07001// 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 Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross7f64b6d2015-07-09 13:57:48 -070016
17import (
18 "fmt"
19 "reflect"
Dan Willemsen490fd492015-11-24 17:53:15 -080020 "runtime"
Colin Cross7f64b6d2015-07-09 13:57:48 -070021 "strings"
22
Colin Cross7f64b6d2015-07-09 13:57:48 -070023 "github.com/google/blueprint/proptools"
24)
25
26func init() {
Paul Duffine7a055c2021-03-07 15:46:33 +000027 registerVariableBuildComponents(InitRegistrationContext)
28}
29
30func registerVariableBuildComponents(ctx RegistrationContext) {
31 ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
Colin Crosseabaedd2020-02-06 17:01:55 -080032 ctx.BottomUp("variable", VariableMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070033 })
Colin Cross7f64b6d2015-07-09 13:57:48 -070034}
35
Paul Duffine7a055c2021-03-07 15:46:33 +000036var PrepareForTestWithVariables = FixtureRegisterWithContext(registerVariableBuildComponents)
37
Colin Cross7f64b6d2015-07-09 13:57:48 -070038type variableProperties struct {
39 Product_variables struct {
Dan Willemsen47cf66b2015-09-16 16:48:54 -070040 Platform_sdk_version struct {
41 Asflags []string
Colin Crossceeff0f2017-05-08 13:43:00 -070042 Cflags []string
Dan Willemsen9fe14102021-07-13 21:52:04 -070043 Cmd *string
Dan Willemsen47cf66b2015-09-16 16:48:54 -070044 }
Colin Cross83163192015-12-01 16:31:16 -080045
Yuntao Xu402e9b02021-08-09 15:44:44 -070046 Platform_sdk_version_or_codename struct {
47 Java_resource_dirs []string
48 }
49
Anton Hanssonb021bf82021-08-27 17:35:40 +010050 Platform_sdk_extension_version struct {
51 Cmd *string
52 }
53
Dan Willemsen9fe14102021-07-13 21:52:04 -070054 Platform_version_name struct {
55 Base_dir *string
56 }
57
Steven Morelanda48df2b2024-06-03 22:29:38 +000058 Shipping_api_level struct {
59 Cflags []string
60 }
61
Colin Cross83163192015-12-01 16:31:16 -080062 // unbundled_build is a catch-all property to annotate modules that don't build in one or
63 // more unbundled branches, usually due to dependencies missing from the manifest.
64 Unbundled_build struct {
Cole Fausta963b942024-04-11 17:43:00 -070065 Enabled proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"`
Colin Cross83163192015-12-01 16:31:16 -080066 } `android:"arch_variant"`
Dan Willemsen496e3952016-01-05 14:27:55 -080067
Jeongik Chaf08e59c2023-02-09 10:47:59 +090068 // similar to `Unbundled_build`, but `Always_use_prebuilt_sdks` means that it uses prebuilt
69 // sdk specifically.
70 Always_use_prebuilt_sdks struct {
Cole Fausta963b942024-04-11 17:43:00 -070071 Enabled proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"`
Jeongik Chaf08e59c2023-02-09 10:47:59 +090072 } `android:"arch_variant"`
73
Christopher Ferrisa5a6b9c2024-04-23 17:17:49 -070074 Malloc_low_memory struct {
Christopher Ferrisc71193a2019-12-16 09:55:10 -080075 Cflags []string `android:"arch_variant"`
76 Shared_libs []string `android:"arch_variant"`
77 Whole_static_libs []string `android:"arch_variant"`
Florian Mayerca2854e2024-01-16 16:42:34 -080078 Static_libs []string `android:"arch_variant"`
Christopher Ferrisc71193a2019-12-16 09:55:10 -080079 Exclude_static_libs []string `android:"arch_variant"`
Christopher Ferrisdea66172021-09-24 00:07:53 -070080 Srcs []string `android:"arch_variant"`
81 Header_libs []string `android:"arch_variant"`
Sasha Smundak61ebf8d2018-08-31 16:56:05 -070082 } `android:"arch_variant"`
Evgenii Stepanov8391efa2016-05-12 18:04:18 -070083
Quallenaugee96e6b72020-10-21 21:19:01 +020084 Malloc_low_memory_libc32 struct {
85 Cflags []string `android:"arch_variant"`
86 Shared_libs []string `android:"arch_variant"`
87 Whole_static_libs []string `android:"arch_variant"`
88 Static_libs []string `android:"arch_variant"`
89 Exclude_static_libs []string `android:"arch_variant"`
90 Srcs []string `android:"arch_variant"`
91 Header_libs []string `android:"arch_variant"`
92 } `android:"arch_variant"`
93
Evgenii Stepanov19ff3c92020-04-29 14:57:30 -070094 Malloc_zero_contents struct {
95 Cflags []string `android:"arch_variant"`
96 } `android:"arch_variant"`
97
98 Malloc_pattern_fill_contents struct {
99 Cflags []string `android:"arch_variant"`
100 } `android:"arch_variant"`
101
Evgenii Stepanov8391efa2016-05-12 18:04:18 -0700102 Safestack struct {
103 Cflags []string `android:"arch_variant"`
104 } `android:"arch_variant"`
Dan Willemsena6f7d152016-07-12 14:57:40 -0700105
Dan Willemsen1be35382016-07-25 17:42:18 -0700106 Binder32bit struct {
107 Cflags []string
108 }
Dan Willemsenfcebcd52016-09-22 14:49:10 -0700109
Colin Cross95436422017-05-04 13:57:05 -0700110 Override_rs_driver struct {
111 Cflags []string
112 }
113
Steven Morelandc2b9f062017-12-13 14:06:20 -0800114 // treble_linker_namespaces is true when the system/vendor linker namespace separation is
115 // enabled.
116 Treble_linker_namespaces struct {
117 Cflags []string
118 }
Steven Morelandc2b9f062017-12-13 14:06:20 -0800119 // enforce_vintf_manifest is true when a device is required to have a vintf manifest.
120 Enforce_vintf_manifest struct {
121 Cflags []string
122 }
123
Jihoon Kangcbcad7c2023-06-01 22:31:52 +0000124 Build_from_text_stub struct {
125 Static_libs []string
126 Exclude_static_libs []string
127 }
128
Colin Cross6bc59ef2016-12-08 09:46:35 -0800129 // debuggable is true for eng and userdebug builds, and can be used to turn on additional
130 // debugging features that don't significantly impact runtime behavior. userdebug builds
131 // are used for dogfooding and performance testing, and should be as similar to user builds
132 // as possible.
Dan Willemsenfcebcd52016-09-22 14:49:10 -0700133 Debuggable struct {
Jim Tang91483242024-09-10 18:04:28 +0800134 Apk *string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700135 Cflags []string
136 Cppflags []string
137 Init_rc []string
138 Required []string
139 Host_required []string
140 Target_required []string
Philip Cuadra328e0bf2020-10-19 22:01:29 -0700141 Strip struct {
142 All *bool
143 Keep_symbols *bool
144 Keep_symbols_and_debug_frame *bool
145 }
Herbert Xue38178322024-07-16 17:28:15 +0800146 Static_libs []string
147 Exclude_static_libs []string
148 Whole_static_libs []string
149 Shared_libs []string
150 Jni_libs []string
Jiyong Park16e77a92021-08-30 18:43:19 +0900151
152 Cmdline []string
Inseob Kimf5ed3002022-01-07 19:17:29 +0900153
Jay Aliomer2599d1d2021-09-23 15:49:54 -0400154 Srcs []string
155 Exclude_srcs []string
Cole Fausted940002023-08-15 11:59:24 -0700156 Cmd *string
Jiyong Park62532d72024-04-12 16:16:28 +0900157
158 Deps []string
Dan Willemsenfcebcd52016-09-22 14:49:10 -0700159 }
Colin Cross6bc59ef2016-12-08 09:46:35 -0800160
Usta Shresthac725f472022-01-11 02:44:21 -0500161 // eng is true for -eng builds, and can be used to turn on additional heavyweight debugging
Colin Cross6bc59ef2016-12-08 09:46:35 -0800162 // features.
163 Eng struct {
164 Cflags []string
165 Cppflags []string
dianlujitao7f280d22022-02-20 23:57:22 +0800166 Init_rc []string
John Reck1d2b7ee2018-07-11 11:01:59 -0700167 Lto struct {
168 Never *bool
169 }
Colin Cross3273cc22018-10-26 23:58:42 -0700170 Sanitize struct {
171 Address *bool
172 }
Felka Changf13642e2019-06-21 20:58:27 +0800173 Optimize struct {
174 Enabled *bool
175 }
Colin Cross6bc59ef2016-12-08 09:46:35 -0800176 }
Colin Crossb2123aa2017-05-05 13:37:11 -0700177
Dmitry Shmidtdba54192017-08-23 14:58:37 -0700178 Uml struct {
179 Cppflags []string
180 }
Risanea004dd2017-11-27 18:14:46 +0900181
182 Arc struct {
Satoshi Niwa54f48262020-12-18 09:53:26 +0900183 Cflags []string `android:"arch_variant"`
184 Exclude_srcs []string `android:"arch_variant"`
Jasmine Chenacace422021-03-05 00:56:40 +0800185 Header_libs []string `android:"arch_variant"`
Satoshi Niwa54f48262020-12-18 09:53:26 +0900186 Include_dirs []string `android:"arch_variant"`
187 Shared_libs []string `android:"arch_variant"`
188 Static_libs []string `android:"arch_variant"`
189 Srcs []string `android:"arch_variant"`
190 Whole_static_libs []string `android:"arch_variant"`
191 } `android:"arch_variant"`
Roland Levillain2879d412019-08-13 15:00:18 +0100192
Colin Crossd9a121b2020-01-27 13:26:42 -0800193 Native_coverage struct {
Colin Cross2b10ba02020-02-05 16:23:21 -0800194 Src *string `android:"arch_variant"`
Colin Crossd9a121b2020-01-27 13:26:42 -0800195 Srcs []string `android:"arch_variant"`
196 Exclude_srcs []string `android:"arch_variant"`
197 } `android:"arch_variant"`
Devin Moorec381e102023-07-06 22:03:58 +0000198
199 // release_aidl_use_unfrozen is "true" when a device can
200 // use the unfrozen versions of AIDL interfaces.
201 Release_aidl_use_unfrozen struct {
Kiyoung Kima0523da2024-08-19 10:15:30 +0900202 Cflags []string
203 Cmd *string
204 Required []string
205 Vintf_fragment_modules []string
Devin Moorec381e102023-07-06 22:03:58 +0000206 }
Colin Cross83163192015-12-01 16:31:16 -0800207 } `android:"arch_variant"`
Colin Cross7f64b6d2015-07-09 13:57:48 -0700208}
209
Colin Cross6961a492020-02-06 16:57:45 -0800210var defaultProductVariables interface{} = variableProperties{}
Colin Cross7f64b6d2015-07-09 13:57:48 -0700211
Cole Faustf8231dd2023-04-21 17:37:11 -0700212type ProductVariables struct {
Dan Willemsen174978c2016-05-11 00:27:49 -0700213 // Suffix to add to generated Makefiles
214 Make_suffix *string `json:",omitempty"`
215
Inseob Kim2da72af2024-06-18 11:09:12 +0900216 BuildId *string `json:",omitempty"`
217 BuildFingerprintFile *string `json:",omitempty"`
218 BuildNumberFile *string `json:",omitempty"`
219 BuildHostnameFile *string `json:",omitempty"`
220 BuildThumbprintFile *string `json:",omitempty"`
221 DisplayBuildNumber *bool `json:",omitempty"`
Nan Zhang581fd212018-01-10 16:06:12 -0800222
Linus Tufvessonba270c52024-04-12 13:06:22 +0200223 Platform_display_version_name *string `json:",omitempty"`
224 Platform_version_name *string `json:",omitempty"`
225 Platform_sdk_version *int `json:",omitempty"`
226 Platform_sdk_codename *string `json:",omitempty"`
227 Platform_sdk_version_or_codename *string `json:",omitempty"`
228 Platform_sdk_final *bool `json:",omitempty"`
229 Platform_sdk_extension_version *int `json:",omitempty"`
230 Platform_base_sdk_extension_version *int `json:",omitempty"`
231 Platform_version_active_codenames []string `json:",omitempty"`
232 Platform_version_all_preview_codenames []string `json:",omitempty"`
233 Platform_systemsdk_versions []string `json:",omitempty"`
234 Platform_security_patch *string `json:",omitempty"`
235 Platform_preview_sdk_version *string `json:",omitempty"`
236 Platform_base_os *string `json:",omitempty"`
237 Platform_version_last_stable *string `json:",omitempty"`
238 Platform_version_known_codenames *string `json:",omitempty"`
Colin Cross4225f652015-09-17 14:33:42 -0700239
Jeongik Cha219141c2020-08-06 23:00:37 +0900240 DeviceName *string `json:",omitempty"`
Jackeagledeb65ac2024-09-04 22:10:51 -0400241 BlissDeviceName *string `json:",omitempty"`
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000242 DeviceProduct *string `json:",omitempty"`
Jeongik Cha219141c2020-08-06 23:00:37 +0900243 DeviceArch *string `json:",omitempty"`
244 DeviceArchVariant *string `json:",omitempty"`
245 DeviceCpuVariant *string `json:",omitempty"`
246 DeviceAbi []string `json:",omitempty"`
247 DeviceVndkVersion *string `json:",omitempty"`
248 DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"`
249 DeviceSystemSdkVersions []string `json:",omitempty"`
Juan Yescas05d4d902023-04-07 10:35:35 -0700250 DeviceMaxPageSizeSupported *string `json:",omitempty"`
Vilas Bhatb3d2d222023-12-04 22:51:20 +0000251 DeviceNoBionicPageSizeMacro *bool `json:",omitempty"`
Colin Cross4225f652015-09-17 14:33:42 -0700252
Justin Yun41cbb5e2023-11-29 17:58:16 +0900253 VendorApiLevel *string `json:",omitempty"`
254
Colin Crossa74ca042019-01-31 14:31:51 -0800255 DeviceSecondaryArch *string `json:",omitempty"`
256 DeviceSecondaryArchVariant *string `json:",omitempty"`
257 DeviceSecondaryCpuVariant *string `json:",omitempty"`
258 DeviceSecondaryAbi []string `json:",omitempty"`
Colin Cross4225f652015-09-17 14:33:42 -0700259
dimitry8d6dde82019-07-11 10:23:53 +0200260 NativeBridgeArch *string `json:",omitempty"`
261 NativeBridgeArchVariant *string `json:",omitempty"`
262 NativeBridgeCpuVariant *string `json:",omitempty"`
263 NativeBridgeAbi []string `json:",omitempty"`
264 NativeBridgeRelativePath *string `json:",omitempty"`
dimitry1f33e402019-03-26 12:39:31 +0100265
dimitry8d6dde82019-07-11 10:23:53 +0200266 NativeBridgeSecondaryArch *string `json:",omitempty"`
267 NativeBridgeSecondaryArchVariant *string `json:",omitempty"`
268 NativeBridgeSecondaryCpuVariant *string `json:",omitempty"`
269 NativeBridgeSecondaryAbi []string `json:",omitempty"`
270 NativeBridgeSecondaryRelativePath *string `json:",omitempty"`
dimitry1f33e402019-03-26 12:39:31 +0100271
Colin Cross4225f652015-09-17 14:33:42 -0700272 HostArch *string `json:",omitempty"`
273 HostSecondaryArch *string `json:",omitempty"`
Colin Cross528d67e2021-07-23 22:23:07 +0000274 HostMusl *bool `json:",omitempty"`
Dan Willemsen490fd492015-11-24 17:53:15 -0800275
276 CrossHost *string `json:",omitempty"`
277 CrossHostArch *string `json:",omitempty"`
278 CrossHostSecondaryArch *string `json:",omitempty"`
Colin Cross83163192015-12-01 16:31:16 -0800279
Jeongik Chacee5ba92021-02-19 12:11:51 +0900280 DeviceResourceOverlays []string `json:",omitempty"`
281 ProductResourceOverlays []string `json:",omitempty"`
282 EnforceRROTargets []string `json:",omitempty"`
Colin Crossa74ca042019-01-31 14:31:51 -0800283 EnforceRROExcludedOverlays []string `json:",omitempty"`
Colin Crossface4e42017-10-30 17:32:15 -0700284
Colin Crossa74ca042019-01-31 14:31:51 -0800285 AAPTCharacteristics *string `json:",omitempty"`
286 AAPTConfig []string `json:",omitempty"`
287 AAPTPreferredConfig *string `json:",omitempty"`
288 AAPTPrebuiltDPI []string `json:",omitempty"`
Colin Crossface4e42017-10-30 17:32:15 -0700289
Justin Yun635e7882024-07-04 14:50:57 +0900290 DefaultAppCertificate *string `json:",omitempty"`
291 ExtraOtaKeys []string `json:",omitempty"`
292 ExtraOtaRecoveryKeys []string `json:",omitempty"`
293 MainlineSepolicyDevCertificates *string `json:",omitempty"`
Colin Cross61ae0b72017-12-01 17:16:02 -0800294
Colin Crossface4e42017-10-30 17:32:15 -0700295 AppsDefaultVersionName *string `json:",omitempty"`
296
Cole Faust701ca252021-11-23 19:02:08 -0800297 Allow_missing_dependencies *bool `json:",omitempty"`
298 Unbundled_build *bool `json:",omitempty"`
299 Unbundled_build_apps []string `json:",omitempty"`
300 Unbundled_build_image *bool `json:",omitempty"`
301 Always_use_prebuilt_sdks *bool `json:",omitempty"`
302 Skip_boot_jars_check *bool `json:",omitempty"`
Christopher Ferrisa5a6b9c2024-04-23 17:17:49 -0700303 Malloc_low_memory *bool `json:",omitempty"`
Quallenaugee96e6b72020-10-21 21:19:01 +0200304 Malloc_low_memory_libc32 *bool `json:",omitempty"`
Cole Faust701ca252021-11-23 19:02:08 -0800305 Malloc_zero_contents *bool `json:",omitempty"`
306 Malloc_pattern_fill_contents *bool `json:",omitempty"`
307 Safestack *bool `json:",omitempty"`
308 HostStaticBinaries *bool `json:",omitempty"`
309 Binder32bit *bool `json:",omitempty"`
310 UseGoma *bool `json:",omitempty"`
Taylor Santiago3c16e612024-05-30 14:41:31 -0700311 UseABFS *bool `json:",omitempty"`
Cole Faust701ca252021-11-23 19:02:08 -0800312 UseRBE *bool `json:",omitempty"`
313 UseRBEJAVAC *bool `json:",omitempty"`
314 UseRBER8 *bool `json:",omitempty"`
315 UseRBED8 *bool `json:",omitempty"`
316 Debuggable *bool `json:",omitempty"`
317 Eng *bool `json:",omitempty"`
318 Treble_linker_namespaces *bool `json:",omitempty"`
319 Enforce_vintf_manifest *bool `json:",omitempty"`
320 Uml *bool `json:",omitempty"`
321 Arc *bool `json:",omitempty"`
322 MinimizeJavaDebugInfo *bool `json:",omitempty"`
Jihoon Kangcbcad7c2023-06-01 22:31:52 +0000323 Build_from_text_stub *bool `json:",omitempty"`
Colin Cross16b23492016-01-06 14:41:07 -0800324
Inseob Kim8fa54da2024-03-19 16:48:59 +0900325 BuildType *string `json:",omitempty"`
326
Logan Chien4fcea3d2018-11-20 11:59:08 +0800327 Check_elf_files *bool `json:",omitempty"`
328
Colin Cross5a0dcd52018-10-05 14:20:06 -0700329 UncompressPrivAppDex *bool `json:",omitempty"`
330 ModulesLoadedByPrivilegedModules []string `json:",omitempty"`
Colin Cross43f08db2018-11-12 10:13:39 -0800331
satayevd604b212021-07-21 14:23:52 +0100332 BootJars ConfiguredJarList `json:",omitempty"`
333 ApexBootJars ConfiguredJarList `json:",omitempty"`
Vladimir Markoe8b00d62018-12-21 15:54:16 +0000334
Colin Crossa74ca042019-01-31 14:31:51 -0800335 IntegerOverflowExcludePaths []string `json:",omitempty"`
Ivan Lozano5f595532017-07-13 14:46:05 -0700336
Colin Crossa74ca042019-01-31 14:31:51 -0800337 EnableCFI *bool `json:",omitempty"`
338 CFIExcludePaths []string `json:",omitempty"`
339 CFIIncludePaths []string `json:",omitempty"`
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700340
Kostya Kortchinskyd5275c82019-02-01 08:42:56 -0800341 DisableScudo *bool `json:",omitempty"`
342
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -0800343 MemtagHeapExcludePaths []string `json:",omitempty"`
344 MemtagHeapAsyncIncludePaths []string `json:",omitempty"`
345 MemtagHeapSyncIncludePaths []string `json:",omitempty"`
346
Hang Lua98aab92023-03-17 13:17:22 +0800347 HWASanIncludePaths []string `json:",omitempty"`
Tomislav Novakf734f002023-08-22 10:51:44 -0700348 HWASanExcludePaths []string `json:",omitempty"`
Hang Lua98aab92023-03-17 13:17:22 +0800349
Justin Yund5f6c822019-06-25 16:47:17 +0900350 VendorPath *string `json:",omitempty"`
351 OdmPath *string `json:",omitempty"`
352 ProductPath *string `json:",omitempty"`
353 SystemExtPath *string `json:",omitempty"`
Dan Willemsen4353bc42016-12-05 17:16:02 -0800354
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700355 ClangTidy *bool `json:",omitempty"`
356 TidyChecks *string `json:",omitempty"`
357
Roland Levillainada12702020-06-09 13:07:36 +0100358 JavaCoveragePaths []string `json:",omitempty"`
359 JavaCoverageExcludePaths []string `json:",omitempty"`
360
Pirama Arumuga Nainarb37ae582022-01-26 22:14:32 -0800361 GcovCoverage *bool `json:",omitempty"`
362 ClangCoverage *bool `json:",omitempty"`
363 NativeCoveragePaths []string `json:",omitempty"`
364 NativeCoverageExcludePaths []string `json:",omitempty"`
365 ClangCoverageContinuousMode *bool `json:",omitempty"`
Dan Willemsen581341d2017-02-09 16:16:31 -0800366
Colin Cross1a6acd42020-06-16 17:51:46 -0700367 // Set by NewConfig
Liz Kammer09f947d2021-05-12 14:51:49 -0400368 Native_coverage *bool `json:",omitempty"`
Colin Cross1a6acd42020-06-16 17:51:46 -0700369
Colin Cross23ae82a2016-11-02 14:34:39 -0700370 SanitizeHost []string `json:",omitempty"`
371 SanitizeDevice []string `json:",omitempty"`
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700372 SanitizeDeviceDiag []string `json:",omitempty"`
Colin Cross23ae82a2016-11-02 14:34:39 -0700373 SanitizeDeviceArch []string `json:",omitempty"`
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800374
375 ArtUseReadBarrier *bool `json:",omitempty"`
Jack He8cc71432016-12-08 15:45:07 -0800376
377 BtConfigIncludeDir *string `json:",omitempty"`
Colin Cross95436422017-05-04 13:57:05 -0700378
379 Override_rs_driver *string `json:",omitempty"`
Jiyong Parkd773eb32017-07-03 13:18:12 +0900380
381 DeviceKernelHeaders []string `json:",omitempty"`
Justin Yun71549282017-11-17 12:10:28 +0900382
Jan Altensenedb11d82020-09-10 15:21:40 +0200383 TargetSpecificHeaderPath *string `json:",omitempty"`
384
Justin Yun71549282017-11-17 12:10:28 +0900385 ExtraVndkVersions []string `json:",omitempty"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800386
387 NamespacesToExport []string `json:",omitempty"`
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -0800388
Vinh Tran7a8362c2022-11-01 15:33:51 -0400389 PgoAdditionalProfileDirs []string `json:",omitempty"`
Dan Willemsen0fe78662018-03-26 12:41:18 -0700390
Inseob Kim5eb7ee92022-04-27 10:30:34 +0900391 MultitreeUpdateMeta bool `json:",omitempty"`
392
Inseob Kim6077b232023-08-31 16:49:59 +0900393 BoardVendorSepolicyDirs []string `json:",omitempty"`
394 BoardOdmSepolicyDirs []string `json:",omitempty"`
395 SystemExtPublicSepolicyDirs []string `json:",omitempty"`
396 SystemExtPrivateSepolicyDirs []string `json:",omitempty"`
397 BoardSepolicyM4Defs []string `json:",omitempty"`
Tri Vo35a51432018-03-25 20:00:00 -0700398
Herbert Xue0fc8abe2024-08-21 13:03:01 +0800399 BoardPlatform *string `json:",omitempty"`
Inseob Kim16ebd5a2020-12-09 23:08:17 +0900400 BoardSepolicyVers *string `json:",omitempty"`
401 PlatformSepolicyVersion *string `json:",omitempty"`
402
Inseob Kim1a0afcc2022-02-14 23:10:51 +0900403 SystemExtSepolicyPrebuiltApiDir *string `json:",omitempty"`
404 ProductSepolicyPrebuiltApiDir *string `json:",omitempty"`
405
Inseob Kim843f6642022-01-07 09:11:23 +0900406 PlatformSepolicyCompatVersions []string `json:",omitempty"`
407
Cole Faust46f6e2f2024-06-20 12:57:43 -0700408 VendorVars map[string]map[string]string `json:",omitempty"`
409 VendorVarTypes map[string]map[string]string `json:",omitempty"`
Colin Cross395f2cf2018-10-24 16:10:32 -0700410
Dan Albertd05ba002021-04-13 15:55:47 -0700411 Ndk_abis *bool `json:",omitempty"`
Jiyong Park8fd61922018-11-08 02:50:25 +0900412
Dennis Shene2ed70c2023-01-11 14:15:43 +0000413 TrimmedApex *bool `json:",omitempty"`
Jiyong Park4da07972021-01-05 21:01:11 +0900414 ForceApexSymlinkOptimization *bool `json:",omitempty"`
415 CompressedApex *bool `json:",omitempty"`
416 Aml_abis *bool `json:",omitempty"`
Colin Cross43f08db2018-11-12 10:13:39 -0800417
418 DexpreoptGlobalConfig *string `json:",omitempty"`
Jiyong Park7f67f482019-01-05 12:57:48 +0900419
Inseob Kim7b85eeb2021-03-23 20:52:24 +0900420 WithDexpreopt bool `json:",omitempty"`
421
Jiakai Zhang4d90da22023-07-12 16:51:48 +0100422 ManifestPackageNameOverrides []string `json:",omitempty"`
423 CertificateOverrides []string `json:",omitempty"`
424 PackageNameOverrides []string `json:",omitempty"`
425 ConfiguredJarLocationOverrides []string `json:",omitempty"`
Jeongik Chac9464142019-01-07 12:07:27 +0900426
Albert Martineefabcf2022-03-21 20:11:16 +0000427 ApexGlobalMinSdkVersionOverride *string `json:",omitempty"`
428
Jeongik Chac9464142019-01-07 12:07:27 +0900429 EnforceSystemCertificate *bool `json:",omitempty"`
Colin Cross440e0d02020-06-11 11:32:11 -0700430 EnforceSystemCertificateAllowList []string `json:",omitempty"`
Colin Cross8faf8fc2019-01-16 15:15:52 -0800431
Colin Crossf24a22a2019-01-31 14:12:44 -0800432 ProductHiddenAPIStubs []string `json:",omitempty"`
433 ProductHiddenAPIStubsSystem []string `json:",omitempty"`
434 ProductHiddenAPIStubsTest []string `json:",omitempty"`
Dan Willemsen71c74602019-04-10 12:27:35 -0700435
Inseob Kim0866b002019-04-15 20:21:29 +0900436 ProductPublicSepolicyDirs []string `json:",omitempty"`
437 ProductPrivateSepolicyDirs []string `json:",omitempty"`
Inseob Kim0866b002019-04-15 20:21:29 +0900438
Dan Willemsen54879d12019-04-18 10:08:46 -0700439 TargetFSConfigGen []string `json:",omitempty"`
Colin Cross50ddcc42019-05-16 12:28:22 -0700440
Justin Yun2cc42502024-09-11 14:10:20 +0900441 UseSoongSystemImage *bool `json:",omitempty"`
442 ProductSoongDefinedSystemImage *string `json:",omitempty"`
443
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900444 EnforceProductPartitionInterface *bool `json:",omitempty"`
Jooyung Han3ab2c3e2019-12-05 16:27:44 +0900445
JaeMan Parkff715562020-10-19 17:25:58 +0900446 EnforceInterPartitionJavaSdkLibrary *bool `json:",omitempty"`
447 InterPartitionJavaLibraryAllowList []string `json:",omitempty"`
448
Yifan Hong82db7352020-01-21 16:12:26 -0800449 BoardUsesRecoveryAsBoot *bool `json:",omitempty"`
Yifan Hong97365ee2020-07-29 09:51:57 -0700450
Yifan Hong42bef8d2020-08-05 14:36:09 -0700451 BoardKernelBinaries []string `json:",omitempty"`
452 BoardKernelModuleInterfaceVersions []string `json:",omitempty"`
Yifan Hongdd8dacc2020-10-21 15:40:17 -0700453
454 BoardMoveRecoveryResourcesToVendorBoot *bool `json:",omitempty"`
Bill Peckhambae47492021-01-08 09:34:44 -0800455
456 PrebuiltHiddenApiDir *string `json:",omitempty"`
Inseob Kim60c32f02020-12-21 22:53:05 +0900457
Steven Morelanda48df2b2024-06-03 22:29:38 +0000458 Shipping_api_level *string `json:",omitempty"`
Inseob Kim0cac7b42021-02-03 18:16:46 +0900459
Cole Faustded79602023-09-05 17:48:11 -0700460 BuildBrokenPluginValidation []string `json:",omitempty"`
461 BuildBrokenClangAsFlags bool `json:",omitempty"`
462 BuildBrokenClangCFlags bool `json:",omitempty"`
463 BuildBrokenClangProperty bool `json:",omitempty"`
464 GenruleSandboxing *bool `json:",omitempty"`
465 BuildBrokenEnforceSyspropOwner bool `json:",omitempty"`
466 BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"`
Cole Faustded79602023-09-05 17:48:11 -0700467 BuildBrokenVendorPropertyNamespace bool `json:",omitempty"`
468 BuildBrokenIncorrectPartitionImages bool `json:",omitempty"`
469 BuildBrokenInputDirModules []string `json:",omitempty"`
Jiyong Park3bb99242024-01-04 23:21:26 +0000470 BuildBrokenDontCheckSystemSdk bool `json:",omitempty"`
Inseob Kim2da72af2024-06-18 11:09:12 +0900471 BuildBrokenDupSysprop bool `json:",omitempty"`
Inseob Kim67e5add192021-03-17 18:05:33 +0900472
Jiakai Zhang48203e32023-06-02 23:42:21 +0100473 BuildWarningBadOptionalUsesLibsAllowlist []string `json:",omitempty"`
474
Hridya Valsaraju5a5c7d52021-04-02 16:45:24 -0700475 BuildDebugfsRestrictionsEnabled bool `json:",omitempty"`
476
Inseob Kim67e5add192021-03-17 18:05:33 +0900477 RequiresInsecureExecmemForSwiftshader bool `json:",omitempty"`
478
479 SelinuxIgnoreNeverallows bool `json:",omitempty"`
480
Devin Moorec381e102023-07-06 22:03:58 +0000481 Release_aidl_use_unfrozen *bool `json:",omitempty"`
482
Inseob Kima10ef272021-09-15 03:04:53 +0000483 SepolicyFreezeTestExtraDirs []string `json:",omitempty"`
484 SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"`
Jiyong Parkd163d4d2021-10-12 16:47:43 +0900485
486 GenerateAidlNdkPlatformBackend bool `json:",omitempty"`
Christopher Ferris98f10222022-07-13 23:16:52 -0700487
488 IgnorePrefer32OnDevice bool `json:",omitempty"`
Spandan Dasc5763832022-11-08 18:42:16 +0000489
Sam Delmerico98a73292023-02-21 11:50:29 -0500490 SourceRootDirs []string `json:",omitempty"`
Vinh Tran44cb78c2023-03-09 22:07:19 -0500491
492 AfdoProfiles []string `json:",omitempty"`
Wei Lic642d682023-05-04 09:06:06 -0700493
Inseob Kim8fa54da2024-03-19 16:48:59 +0900494 ProductManufacturer string `json:",omitempty"`
495 ProductBrand string `json:",omitempty"`
Joe Onoratofee845a2023-05-09 08:14:14 -0700496
Yu Liueebb2592023-10-12 20:31:27 -0700497 ReleaseVersion string `json:",omitempty"`
498 ReleaseAconfigValueSets []string `json:",omitempty"`
Kiyoung Kime623c582023-07-06 16:43:44 +0900499
Zhi Dou3f65a412023-08-10 21:47:40 +0000500 ReleaseAconfigFlagDefaultPermission string `json:",omitempty"`
501
Alyssa Ketpreechasawat34ab8792023-10-06 07:01:22 +0000502 ReleaseDefaultModuleBuildFromSource *bool `json:",omitempty"`
503
Inseob Kim5bac3b62023-08-25 21:29:46 +0900504 CheckVendorSeappViolations *bool `json:",omitempty"`
Cole Faustb4cb0c82023-09-14 15:16:58 -0700505
Inseob Kime4e85d52023-10-25 23:53:58 +0900506 BuildFlags map[string]string `json:",omitempty"`
Jihoon Kangc1b04d62023-11-16 19:07:04 +0000507
Cole Faust751a4a52024-05-21 16:51:59 -0700508 BuildFlagTypes map[string]string `json:",omitempty"`
509
Jihoon Kangc1b04d62023-11-16 19:07:04 +0000510 BuildFromSourceStub *bool `json:",omitempty"`
Spandan Das8ab28dd2024-02-17 03:31:45 +0000511
Spandan Das0d24ade2024-03-08 04:20:15 +0000512 BuildIgnoreApexContributionContents *bool `json:",omitempty"`
Jihoon Kangb36fc542024-02-22 19:35:26 +0000513
514 HiddenapiExportableStubs *bool `json:",omitempty"`
Jihoon Kang35349462024-02-22 19:52:46 +0000515
516 ExportRuntimeApis *bool `json:",omitempty"`
Yu Liu67a28422024-03-05 00:36:31 +0000517
518 AconfigContainerValidation string `json:",omitempty"`
Inseob Kim8fa54da2024-03-19 16:48:59 +0900519
520 ProductLocales []string `json:",omitempty"`
521
522 ProductDefaultWifiChannels []string `json:",omitempty"`
523
524 BoardUseVbmetaDigestInFingerprint *bool `json:",omitempty"`
525
526 OemProperties []string `json:",omitempty"`
Jackeagledeb65ac2024-09-04 22:10:51 -0400527 BlissDevice []string `json:",omitempty"`
Kiyoung Kim881e4652024-07-08 11:02:23 +0900528
529 ArtTargetIncludeDebugBuild *bool `json:",omitempty"`
Inseob Kimd8538e52024-07-31 02:00:41 +0000530
Inseob Kimacf91742024-08-05 12:51:05 +0900531 SystemPropFiles []string `json:",omitempty"`
532 SystemExtPropFiles []string `json:",omitempty"`
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900533 ProductPropFiles []string `json:",omitempty"`
Inseob Kim9a22c7e2024-08-26 15:58:09 +0900534 OdmPropFiles []string `json:",omitempty"`
Inseob Kim6bd92d52024-07-31 02:01:03 +0000535
536 EnableUffdGc *string `json:",omitempty"`
Bill Yang3b3aac02024-09-05 09:22:09 +0000537
538 BoardAvbEnable *bool `json:",omitempty"`
539 BoardAvbSystemAddHashtreeFooterArgs []string `json:",omitempty"`
540 DeviceFrameworkCompatibilityMatrixFile []string `json:",omitempty"`
541 DeviceProductCompatibilityMatrixFile []string `json:",omitempty"`
Cole Faustcb193ec2023-09-20 16:01:18 -0700542}
543
Cole Faust11edf552023-10-13 11:32:14 -0700544type PartitionQualifiedVariablesType struct {
545 BuildingImage bool `json:",omitempty"`
546 BoardErofsCompressor string `json:",omitempty"`
547 BoardErofsCompressHints string `json:",omitempty"`
548 BoardErofsPclusterSize string `json:",omitempty"`
549 BoardExtfsInodeCount string `json:",omitempty"`
550 BoardExtfsRsvPct string `json:",omitempty"`
551 BoardF2fsSloadCompressFlags string `json:",omitempty"`
552 BoardFileSystemCompress string `json:",omitempty"`
553 BoardFileSystemType string `json:",omitempty"`
554 BoardJournalSize string `json:",omitempty"`
555 BoardPartitionReservedSize string `json:",omitempty"`
556 BoardPartitionSize string `json:",omitempty"`
557 BoardSquashfsBlockSize string `json:",omitempty"`
558 BoardSquashfsCompressor string `json:",omitempty"`
559 BoardSquashfsCompressorOpt string `json:",omitempty"`
560 BoardSquashfsDisable4kAlign string `json:",omitempty"`
561 ProductBaseFsPath string `json:",omitempty"`
562 ProductHeadroom string `json:",omitempty"`
563 ProductVerityPartition string `json:",omitempty"`
564
565 BoardAvbAddHashtreeFooterArgs string `json:",omitempty"`
566 BoardAvbKeyPath string `json:",omitempty"`
567 BoardAvbAlgorithm string `json:",omitempty"`
568 BoardAvbRollbackIndex string `json:",omitempty"`
569 BoardAvbRollbackIndexLocation string `json:",omitempty"`
570}
571
Cole Faustcb193ec2023-09-20 16:01:18 -0700572type PartitionVariables struct {
573 ProductDirectory string `json:",omitempty"`
Cole Faust11edf552023-10-13 11:32:14 -0700574 PartitionQualifiedVariables map[string]PartitionQualifiedVariablesType
575 TargetUserimagesUseExt2 bool `json:",omitempty"`
576 TargetUserimagesUseExt3 bool `json:",omitempty"`
577 TargetUserimagesUseExt4 bool `json:",omitempty"`
Cole Faustcb193ec2023-09-20 16:01:18 -0700578
579 TargetUserimagesSparseExtDisabled bool `json:",omitempty"`
580 TargetUserimagesSparseErofsDisabled bool `json:",omitempty"`
581 TargetUserimagesSparseSquashfsDisabled bool `json:",omitempty"`
582 TargetUserimagesSparseF2fsDisabled bool `json:",omitempty"`
583
Yi-Yo Chiang939fe1a2023-11-24 14:58:50 +0800584 BoardErofsCompressor string `json:",omitempty"`
585 BoardErofsCompressorHints string `json:",omitempty"`
586 BoardErofsPclusterSize string `json:",omitempty"`
587 BoardErofsShareDupBlocks string `json:",omitempty"`
588 BoardErofsUseLegacyCompression string `json:",omitempty"`
589 BoardExt4ShareDupBlocks string `json:",omitempty"`
590 BoardFlashLogicalBlockSize string `json:",omitempty"`
591 BoardFlashEraseBlockSize string `json:",omitempty"`
592 BoardUsesRecoveryAsBoot bool `json:",omitempty"`
593 ProductUseDynamicPartitionSize bool `json:",omitempty"`
594 CopyImagesForTargetFilesZip bool `json:",omitempty"`
Cole Faustb5055392023-09-27 13:44:40 -0700595
596 BoardAvbEnable bool `json:",omitempty"`
Cole Faust11edf552023-10-13 11:32:14 -0700597
598 ProductPackages []string `json:",omitempty"`
Colin Crossa6bc19e2015-09-16 13:53:42 -0700599}
600
601func boolPtr(v bool) *bool {
602 return &v
Colin Cross485e5722015-08-27 13:28:01 -0700603}
604
Dan Willemsen47cf66b2015-09-16 16:48:54 -0700605func intPtr(v int) *int {
606 return &v
607}
608
Colin Cross4225f652015-09-17 14:33:42 -0700609func stringPtr(v string) *string {
610 return &v
611}
612
Cole Faustf8231dd2023-04-21 17:37:11 -0700613func (v *ProductVariables) SetDefaultConfig() {
614 *v = ProductVariables{
Colin Cross2a2e0db2020-02-21 16:55:46 -0800615 BuildNumberFile: stringPtr("build_number.txt"),
Dan Willemsenb6d171b2019-04-07 09:41:44 -0700616
Dan Albert8c7a9942023-03-27 20:34:01 +0000617 Platform_version_name: stringPtr("S"),
618 Platform_base_sdk_extension_version: intPtr(30),
619 Platform_sdk_version: intPtr(30),
620 Platform_sdk_codename: stringPtr("S"),
621 Platform_sdk_final: boolPtr(false),
622 Platform_version_active_codenames: []string{"S"},
623 Platform_version_all_preview_codenames: []string{"S"},
Dan Willemsencbf9e822017-11-13 14:34:56 -0800624
Vilas Bhatb3d2d222023-12-04 22:51:20 +0000625 HostArch: stringPtr("x86_64"),
626 HostSecondaryArch: stringPtr("x86"),
627 DeviceName: stringPtr("generic_arm64"),
628 DeviceProduct: stringPtr("aosp_arm-eng"),
629 DeviceArch: stringPtr("arm64"),
630 DeviceArchVariant: stringPtr("armv8-a"),
631 DeviceCpuVariant: stringPtr("generic"),
632 DeviceAbi: []string{"arm64-v8a"},
633 DeviceSecondaryArch: stringPtr("arm"),
634 DeviceSecondaryArchVariant: stringPtr("armv8-a"),
635 DeviceSecondaryCpuVariant: stringPtr("generic"),
636 DeviceSecondaryAbi: []string{"armeabi-v7a", "armeabi"},
637 DeviceMaxPageSizeSupported: stringPtr("4096"),
638 DeviceNoBionicPageSizeMacro: boolPtr(false),
Colin Crossface4e42017-10-30 17:32:15 -0700639
Colin Crossa74ca042019-01-31 14:31:51 -0800640 AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
Colin Crossface4e42017-10-30 17:32:15 -0700641 AAPTPreferredConfig: stringPtr("xhdpi"),
642 AAPTCharacteristics: stringPtr("nosdcard"),
Colin Crossa74ca042019-01-31 14:31:51 -0800643 AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
Colin Crossface4e42017-10-30 17:32:15 -0700644
Christopher Ferrisa5a6b9c2024-04-23 17:17:49 -0700645 Malloc_low_memory: boolPtr(false),
Quallenaugee96e6b72020-10-21 21:19:01 +0200646 Malloc_low_memory_libc32: boolPtr(false),
Steven Morelandd1342012020-07-30 20:38:49 +0000647 Malloc_zero_contents: boolPtr(true),
Evgenii Stepanov19ff3c92020-04-29 14:57:30 -0700648 Malloc_pattern_fill_contents: boolPtr(false),
649 Safestack: boolPtr(false),
Dennis Shene2ed70c2023-01-11 14:15:43 +0000650 TrimmedApex: boolPtr(false),
Jihoon Kangcbcad7c2023-06-01 22:31:52 +0000651 Build_from_text_stub: boolPtr(false),
Lukacs T. Berki720b3962021-03-17 13:34:30 +0100652
satayevd604b212021-07-21 14:23:52 +0100653 BootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
654 ApexBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
Colin Cross485e5722015-08-27 13:28:01 -0700655 }
Dan Willemsen490fd492015-11-24 17:53:15 -0800656
657 if runtime.GOOS == "linux" {
658 v.CrossHost = stringPtr("windows")
659 v.CrossHostArch = stringPtr("x86")
Dan Willemsen07cd0512016-02-03 23:16:33 -0800660 v.CrossHostSecondaryArch = stringPtr("x86_64")
Dan Willemsen490fd492015-11-24 17:53:15 -0800661 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700662}
663
Joe Onorato3fefc232023-12-04 17:35:15 +0000664func (this *ProductVariables) GetBuildFlagBool(flag string) bool {
665 val, ok := this.BuildFlags[flag]
666 if !ok {
667 return false
668 }
669 return val == "true"
670}
671
Colin Crosseabaedd2020-02-06 17:01:55 -0800672func VariableMutator(mctx BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700673 var module Module
Colin Cross7f64b6d2015-07-09 13:57:48 -0700674 var ok bool
Colin Cross635c3b02016-05-18 15:37:25 -0700675 if module, ok = mctx.Module().(Module); !ok {
Colin Cross7f64b6d2015-07-09 13:57:48 -0700676 return
677 }
678
679 // TODO: depend on config variable, create variants, propagate variants up tree
680 a := module.base()
Colin Cross18c46802019-09-24 22:19:02 -0700681
682 if a.variableProperties == nil {
683 return
684 }
685
686 variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
Colin Cross7f64b6d2015-07-09 13:57:48 -0700687
Colin Cross0cec3122021-01-20 11:27:32 -0800688 productVariables := reflect.ValueOf(mctx.Config().productVariables)
689
Colin Cross7f64b6d2015-07-09 13:57:48 -0700690 for i := 0; i < variableValues.NumField(); i++ {
691 variableValue := variableValues.Field(i)
Colin Cross485e5722015-08-27 13:28:01 -0700692 name := variableValues.Type().Field(i).Name
693 property := "product_variables." + proptools.PropertyNameForField(name)
Colin Cross7f64b6d2015-07-09 13:57:48 -0700694
Colin Crossa6bc19e2015-09-16 13:53:42 -0700695 // Check that the variable was set for the product
Colin Cross0cec3122021-01-20 11:27:32 -0800696 val := productVariables.FieldByName(name)
Colin Crossa6bc19e2015-09-16 13:53:42 -0700697 if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() {
698 continue
Colin Cross7f64b6d2015-07-09 13:57:48 -0700699 }
Colin Crossa6bc19e2015-09-16 13:53:42 -0700700
701 val = val.Elem()
702
703 // For bools, check that the value is true
704 if val.Kind() == reflect.Bool && val.Bool() == false {
705 continue
706 }
707
708 // Check if any properties were set for the module
Colin Cross6961a492020-02-06 16:57:45 -0800709 if variableValue.IsZero() {
Colin Crossa6bc19e2015-09-16 13:53:42 -0700710 continue
711 }
Colin Crossa6bc19e2015-09-16 13:53:42 -0700712 a.setVariableProperties(mctx, property, variableValue, val.Interface())
Colin Cross7f64b6d2015-07-09 13:57:48 -0700713 }
714}
715
Colin Cross4157e882019-06-06 16:57:04 -0700716func (m *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext,
Colin Cross7f64b6d2015-07-09 13:57:48 -0700717 prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) {
718
Colin Cross7e0eaf12017-05-05 16:16:24 -0700719 printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue)
Colin Cross7f64b6d2015-07-09 13:57:48 -0700720
Usta851a3272022-01-05 23:42:33 -0500721 err := proptools.AppendMatchingProperties(m.GetProperties(),
Colin Cross06a931b2015-10-28 17:23:31 -0700722 productVariablePropertyValue.Addr().Interface(), nil)
723 if err != nil {
724 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
725 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
726 } else {
727 panic(err)
728 }
729 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700730}
731
Colin Cross7e0eaf12017-05-05 16:16:24 -0700732func printfIntoPropertiesError(ctx BottomUpMutatorContext, prefix string,
733 productVariablePropertyValue reflect.Value, i int, err error) {
734
735 field := productVariablePropertyValue.Type().Field(i).Name
736 property := prefix + "." + proptools.PropertyNameForField(field)
737 ctx.PropertyErrorf(property, "%s", err)
738}
739
740func printfIntoProperties(ctx BottomUpMutatorContext, prefix string,
741 productVariablePropertyValue reflect.Value, variableValue interface{}) {
742
Colin Cross7f64b6d2015-07-09 13:57:48 -0700743 for i := 0; i < productVariablePropertyValue.NumField(); i++ {
744 propertyValue := productVariablePropertyValue.Field(i)
Colin Crossdd0dbe62015-12-02 15:24:38 -0800745 kind := propertyValue.Kind()
746 if kind == reflect.Ptr {
747 if propertyValue.IsNil() {
748 continue
749 }
750 propertyValue = propertyValue.Elem()
751 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700752 switch propertyValue.Kind() {
753 case reflect.String:
Colin Cross7e0eaf12017-05-05 16:16:24 -0700754 err := printfIntoProperty(propertyValue, variableValue)
755 if err != nil {
756 printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
757 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700758 case reflect.Slice:
759 for j := 0; j < propertyValue.Len(); j++ {
Colin Cross7e0eaf12017-05-05 16:16:24 -0700760 err := printfIntoProperty(propertyValue.Index(j), variableValue)
761 if err != nil {
762 printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
763 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700764 }
Colin Crossdd0dbe62015-12-02 15:24:38 -0800765 case reflect.Bool:
766 // Nothing
Colin Cross7f64b6d2015-07-09 13:57:48 -0700767 case reflect.Struct:
Colin Cross7e0eaf12017-05-05 16:16:24 -0700768 printfIntoProperties(ctx, prefix, propertyValue, variableValue)
Colin Cross7f64b6d2015-07-09 13:57:48 -0700769 default:
770 panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind()))
771 }
772 }
773}
774
Colin Cross7e0eaf12017-05-05 16:16:24 -0700775func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) error {
Colin Cross7f64b6d2015-07-09 13:57:48 -0700776 s := propertyValue.String()
Colin Cross7e0eaf12017-05-05 16:16:24 -0700777
778 count := strings.Count(s, "%")
779 if count == 0 {
780 return nil
781 }
782
783 if count > 1 {
784 return fmt.Errorf("product variable properties only support a single '%%'")
785 }
786
Colin Cross7f64b6d2015-07-09 13:57:48 -0700787 if strings.Contains(s, "%d") {
788 switch v := variableValue.(type) {
789 case int:
Colin Cross7e0eaf12017-05-05 16:16:24 -0700790 // Nothing
Colin Cross7f64b6d2015-07-09 13:57:48 -0700791 case bool:
792 if v {
Colin Cross7e0eaf12017-05-05 16:16:24 -0700793 variableValue = 1
794 } else {
795 variableValue = 0
Colin Cross7f64b6d2015-07-09 13:57:48 -0700796 }
797 default:
Colin Cross7e0eaf12017-05-05 16:16:24 -0700798 return fmt.Errorf("unsupported type %T for %%d", variableValue)
Colin Cross7f64b6d2015-07-09 13:57:48 -0700799 }
Colin Cross7e0eaf12017-05-05 16:16:24 -0700800 } else if strings.Contains(s, "%s") {
801 switch variableValue.(type) {
802 case string:
803 // Nothing
804 default:
805 return fmt.Errorf("unsupported type %T for %%s", variableValue)
806 }
807 } else {
808 return fmt.Errorf("unsupported %% in product variable property")
Colin Cross7f64b6d2015-07-09 13:57:48 -0700809 }
Colin Cross7e0eaf12017-05-05 16:16:24 -0700810
811 propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, variableValue)))
812
813 return nil
Colin Cross7f64b6d2015-07-09 13:57:48 -0700814}
Colin Cross18c46802019-09-24 22:19:02 -0700815
816var variablePropTypeMap OncePer
817
818// sliceToTypeArray takes a slice of property structs and returns a reflection created array containing the
819// reflect.Types of each property struct. The result can be used as a key in a map.
820func sliceToTypeArray(s []interface{}) interface{} {
821 // Create an array using reflection whose length is the length of the input slice
822 ret := reflect.New(reflect.ArrayOf(len(s), reflect.TypeOf(reflect.TypeOf(0)))).Elem()
823 for i, e := range s {
824 ret.Index(i).Set(reflect.ValueOf(reflect.TypeOf(e)))
825 }
826 return ret.Interface()
827}
828
Colin Crosseabaedd2020-02-06 17:01:55 -0800829func initProductVariableModule(m Module) {
830 base := m.base()
831
832 // Allow tests to override the default product variables
833 if base.variableProperties == nil {
834 base.variableProperties = defaultProductVariables
835 }
836 // Filter the product variables properties to the ones that exist on this module
837 base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
838 if base.variableProperties != nil {
839 m.AddProperties(base.variableProperties)
840 }
841}
842
Colin Cross18c46802019-09-24 22:19:02 -0700843// createVariableProperties takes the list of property structs for a module and returns a property struct that
844// contains the product variable properties that exist in the property structs, or nil if there are none. It
845// caches the result.
846func createVariableProperties(moduleTypeProps []interface{}, productVariables interface{}) interface{} {
847 // Convert the moduleTypeProps to an array of reflect.Types that can be used as a key in the OncePer.
848 key := sliceToTypeArray(moduleTypeProps)
849
850 // Use the variablePropTypeMap OncePer to cache the result for each set of property struct types.
851 typ, _ := variablePropTypeMap.Once(NewCustomOnceKey(key), func() interface{} {
852 // Compute the filtered property struct type.
853 return createVariablePropertiesType(moduleTypeProps, productVariables)
854 }).(reflect.Type)
855
856 if typ == nil {
857 return nil
858 }
859
860 // Create a new pointer to a filtered property struct.
861 return reflect.New(typ).Interface()
862}
863
864// createVariablePropertiesType creates a new type that contains only the product variable properties that exist in
865// a list of property structs.
866func createVariablePropertiesType(moduleTypeProps []interface{}, productVariables interface{}) reflect.Type {
867 typ, _ := proptools.FilterPropertyStruct(reflect.TypeOf(productVariables),
868 func(field reflect.StructField, prefix string) (bool, reflect.StructField) {
869 // Filter function, returns true if the field should be in the resulting struct
870 if prefix == "" {
871 // Keep the top level Product_variables field
872 return true, field
873 }
874 _, rest := splitPrefix(prefix)
875 if rest == "" {
876 // Keep the 2nd level field (i.e. Product_variables.Eng)
877 return true, field
878 }
879
880 // Strip off the first 2 levels of the prefix
881 _, prefix = splitPrefix(rest)
882
883 for _, p := range moduleTypeProps {
884 if fieldExistsByNameRecursive(reflect.TypeOf(p).Elem(), prefix, field.Name) {
885 // Keep any fields that exist in one of the property structs
886 return true, field
887 }
888 }
889
890 return false, field
891 })
892 return typ
893}
894
895func splitPrefix(prefix string) (first, rest string) {
896 index := strings.IndexByte(prefix, '.')
897 if index == -1 {
898 return prefix, ""
899 }
900 return prefix[:index], prefix[index+1:]
901}
902
903func fieldExistsByNameRecursive(t reflect.Type, prefix, name string) bool {
904 if t.Kind() != reflect.Struct {
905 panic(fmt.Errorf("fieldExistsByNameRecursive can only be called on a reflect.Struct"))
906 }
907
908 if prefix != "" {
909 split := strings.SplitN(prefix, ".", 2)
910 firstPrefix := split[0]
911 rest := ""
912 if len(split) > 1 {
913 rest = split[1]
914 }
915 f, exists := t.FieldByName(firstPrefix)
916 if !exists {
917 return false
918 }
919 ft := f.Type
920 if ft.Kind() == reflect.Ptr {
921 ft = ft.Elem()
922 }
923 if ft.Kind() != reflect.Struct {
924 panic(fmt.Errorf("field %q in %q is not a struct", firstPrefix, t))
925 }
926 return fieldExistsByNameRecursive(ft, rest, name)
927 } else {
928 _, exists := t.FieldByName(name)
929 return exists
930 }
931}