blob: f7392d1c5e85dab2dafa1e1ce1f4d3ff22e54869 [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 Cross8a962802024-10-09 15:29:27 -070032 ctx.BottomUp("variable", VariableMutator)
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
Evgenii Stepanov19ff3c92020-04-29 14:57:30 -070084 Malloc_zero_contents struct {
85 Cflags []string `android:"arch_variant"`
86 } `android:"arch_variant"`
87
88 Malloc_pattern_fill_contents struct {
89 Cflags []string `android:"arch_variant"`
90 } `android:"arch_variant"`
91
Evgenii Stepanov8391efa2016-05-12 18:04:18 -070092 Safestack struct {
93 Cflags []string `android:"arch_variant"`
94 } `android:"arch_variant"`
Dan Willemsena6f7d152016-07-12 14:57:40 -070095
Dan Willemsen1be35382016-07-25 17:42:18 -070096 Binder32bit struct {
97 Cflags []string
98 }
Dan Willemsenfcebcd52016-09-22 14:49:10 -070099
Colin Cross95436422017-05-04 13:57:05 -0700100 Override_rs_driver struct {
101 Cflags []string
102 }
103
Steven Morelandc2b9f062017-12-13 14:06:20 -0800104 // treble_linker_namespaces is true when the system/vendor linker namespace separation is
105 // enabled.
106 Treble_linker_namespaces struct {
107 Cflags []string
108 }
Steven Morelandc2b9f062017-12-13 14:06:20 -0800109 // enforce_vintf_manifest is true when a device is required to have a vintf manifest.
110 Enforce_vintf_manifest struct {
111 Cflags []string
112 }
113
Jihoon Kangcbcad7c2023-06-01 22:31:52 +0000114 Build_from_text_stub struct {
115 Static_libs []string
116 Exclude_static_libs []string
117 }
118
Colin Cross6bc59ef2016-12-08 09:46:35 -0800119 // debuggable is true for eng and userdebug builds, and can be used to turn on additional
120 // debugging features that don't significantly impact runtime behavior. userdebug builds
121 // are used for dogfooding and performance testing, and should be as similar to user builds
122 // as possible.
Dan Willemsenfcebcd52016-09-22 14:49:10 -0700123 Debuggable struct {
Jim Tang91483242024-09-10 18:04:28 +0800124 Apk *string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700125 Cflags []string
126 Cppflags []string
127 Init_rc []string
128 Required []string
129 Host_required []string
130 Target_required []string
Philip Cuadra328e0bf2020-10-19 22:01:29 -0700131 Strip struct {
132 All *bool
133 Keep_symbols *bool
134 Keep_symbols_and_debug_frame *bool
135 }
Herbert Xue38178322024-07-16 17:28:15 +0800136 Static_libs []string
137 Exclude_static_libs []string
138 Whole_static_libs []string
139 Shared_libs []string
140 Jni_libs []string
Jiyong Park16e77a92021-08-30 18:43:19 +0900141
142 Cmdline []string
Inseob Kimf5ed3002022-01-07 19:17:29 +0900143
Jay Aliomer2599d1d2021-09-23 15:49:54 -0400144 Srcs []string
145 Exclude_srcs []string
Cole Fausted940002023-08-15 11:59:24 -0700146 Cmd *string
Jiyong Park62532d72024-04-12 16:16:28 +0900147
148 Deps []string
Dan Willemsenfcebcd52016-09-22 14:49:10 -0700149 }
Colin Cross6bc59ef2016-12-08 09:46:35 -0800150
Usta Shresthac725f472022-01-11 02:44:21 -0500151 // eng is true for -eng builds, and can be used to turn on additional heavyweight debugging
Colin Cross6bc59ef2016-12-08 09:46:35 -0800152 // features.
153 Eng struct {
154 Cflags []string
155 Cppflags []string
John Reck1d2b7ee2018-07-11 11:01:59 -0700156 Lto struct {
157 Never *bool
158 }
Colin Cross3273cc22018-10-26 23:58:42 -0700159 Sanitize struct {
160 Address *bool
161 }
Felka Changf13642e2019-06-21 20:58:27 +0800162 Optimize struct {
163 Enabled *bool
164 }
Colin Cross6bc59ef2016-12-08 09:46:35 -0800165 }
Colin Crossb2123aa2017-05-05 13:37:11 -0700166
Dmitry Shmidtdba54192017-08-23 14:58:37 -0700167 Uml struct {
168 Cppflags []string
169 }
Risanea004dd2017-11-27 18:14:46 +0900170
171 Arc struct {
Satoshi Niwa54f48262020-12-18 09:53:26 +0900172 Cflags []string `android:"arch_variant"`
173 Exclude_srcs []string `android:"arch_variant"`
Jasmine Chenacace422021-03-05 00:56:40 +0800174 Header_libs []string `android:"arch_variant"`
Satoshi Niwa54f48262020-12-18 09:53:26 +0900175 Include_dirs []string `android:"arch_variant"`
176 Shared_libs []string `android:"arch_variant"`
177 Static_libs []string `android:"arch_variant"`
178 Srcs []string `android:"arch_variant"`
179 Whole_static_libs []string `android:"arch_variant"`
180 } `android:"arch_variant"`
Roland Levillain2879d412019-08-13 15:00:18 +0100181
Colin Crossd9a121b2020-01-27 13:26:42 -0800182 Native_coverage struct {
Colin Cross2b10ba02020-02-05 16:23:21 -0800183 Src *string `android:"arch_variant"`
Colin Crossd9a121b2020-01-27 13:26:42 -0800184 Srcs []string `android:"arch_variant"`
185 Exclude_srcs []string `android:"arch_variant"`
186 } `android:"arch_variant"`
Devin Moorec381e102023-07-06 22:03:58 +0000187
188 // release_aidl_use_unfrozen is "true" when a device can
189 // use the unfrozen versions of AIDL interfaces.
190 Release_aidl_use_unfrozen struct {
Kiyoung Kima0523da2024-08-19 10:15:30 +0900191 Cflags []string
192 Cmd *string
193 Required []string
194 Vintf_fragment_modules []string
Devin Moorec381e102023-07-06 22:03:58 +0000195 }
kellyhung1e613d22024-07-29 12:56:51 +0000196 SelinuxIgnoreNeverallows struct {
197 Required []string
198 }
Colin Cross83163192015-12-01 16:31:16 -0800199 } `android:"arch_variant"`
Colin Cross7f64b6d2015-07-09 13:57:48 -0700200}
201
Colin Cross6961a492020-02-06 16:57:45 -0800202var defaultProductVariables interface{} = variableProperties{}
Colin Cross7f64b6d2015-07-09 13:57:48 -0700203
Cole Faustf8231dd2023-04-21 17:37:11 -0700204type ProductVariables struct {
Dan Willemsen174978c2016-05-11 00:27:49 -0700205 // Suffix to add to generated Makefiles
206 Make_suffix *string `json:",omitempty"`
207
Inseob Kim2da72af2024-06-18 11:09:12 +0900208 BuildId *string `json:",omitempty"`
209 BuildFingerprintFile *string `json:",omitempty"`
210 BuildNumberFile *string `json:",omitempty"`
211 BuildHostnameFile *string `json:",omitempty"`
212 BuildThumbprintFile *string `json:",omitempty"`
213 DisplayBuildNumber *bool `json:",omitempty"`
Nan Zhang581fd212018-01-10 16:06:12 -0800214
Linus Tufvessonba270c52024-04-12 13:06:22 +0200215 Platform_display_version_name *string `json:",omitempty"`
216 Platform_version_name *string `json:",omitempty"`
217 Platform_sdk_version *int `json:",omitempty"`
218 Platform_sdk_codename *string `json:",omitempty"`
219 Platform_sdk_version_or_codename *string `json:",omitempty"`
220 Platform_sdk_final *bool `json:",omitempty"`
221 Platform_sdk_extension_version *int `json:",omitempty"`
222 Platform_base_sdk_extension_version *int `json:",omitempty"`
223 Platform_version_active_codenames []string `json:",omitempty"`
224 Platform_version_all_preview_codenames []string `json:",omitempty"`
225 Platform_systemsdk_versions []string `json:",omitempty"`
226 Platform_security_patch *string `json:",omitempty"`
227 Platform_preview_sdk_version *string `json:",omitempty"`
228 Platform_base_os *string `json:",omitempty"`
229 Platform_version_last_stable *string `json:",omitempty"`
230 Platform_version_known_codenames *string `json:",omitempty"`
Colin Cross4225f652015-09-17 14:33:42 -0700231
Jeongik Cha219141c2020-08-06 23:00:37 +0900232 DeviceName *string `json:",omitempty"`
Trevor Radcliffe90727f42022-03-21 19:34:02 +0000233 DeviceProduct *string `json:",omitempty"`
Jeongik Cha219141c2020-08-06 23:00:37 +0900234 DeviceArch *string `json:",omitempty"`
235 DeviceArchVariant *string `json:",omitempty"`
236 DeviceCpuVariant *string `json:",omitempty"`
237 DeviceAbi []string `json:",omitempty"`
238 DeviceVndkVersion *string `json:",omitempty"`
239 DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"`
240 DeviceSystemSdkVersions []string `json:",omitempty"`
Juan Yescas05d4d902023-04-07 10:35:35 -0700241 DeviceMaxPageSizeSupported *string `json:",omitempty"`
Vilas Bhatb3d2d222023-12-04 22:51:20 +0000242 DeviceNoBionicPageSizeMacro *bool `json:",omitempty"`
Colin Cross4225f652015-09-17 14:33:42 -0700243
Justin Yun41cbb5e2023-11-29 17:58:16 +0900244 VendorApiLevel *string `json:",omitempty"`
245
Colin Crossa74ca042019-01-31 14:31:51 -0800246 DeviceSecondaryArch *string `json:",omitempty"`
247 DeviceSecondaryArchVariant *string `json:",omitempty"`
248 DeviceSecondaryCpuVariant *string `json:",omitempty"`
249 DeviceSecondaryAbi []string `json:",omitempty"`
Colin Cross4225f652015-09-17 14:33:42 -0700250
dimitry8d6dde82019-07-11 10:23:53 +0200251 NativeBridgeArch *string `json:",omitempty"`
252 NativeBridgeArchVariant *string `json:",omitempty"`
253 NativeBridgeCpuVariant *string `json:",omitempty"`
254 NativeBridgeAbi []string `json:",omitempty"`
255 NativeBridgeRelativePath *string `json:",omitempty"`
dimitry1f33e402019-03-26 12:39:31 +0100256
dimitry8d6dde82019-07-11 10:23:53 +0200257 NativeBridgeSecondaryArch *string `json:",omitempty"`
258 NativeBridgeSecondaryArchVariant *string `json:",omitempty"`
259 NativeBridgeSecondaryCpuVariant *string `json:",omitempty"`
260 NativeBridgeSecondaryAbi []string `json:",omitempty"`
261 NativeBridgeSecondaryRelativePath *string `json:",omitempty"`
dimitry1f33e402019-03-26 12:39:31 +0100262
Colin Cross4225f652015-09-17 14:33:42 -0700263 HostArch *string `json:",omitempty"`
264 HostSecondaryArch *string `json:",omitempty"`
Colin Cross528d67e2021-07-23 22:23:07 +0000265 HostMusl *bool `json:",omitempty"`
Dan Willemsen490fd492015-11-24 17:53:15 -0800266
267 CrossHost *string `json:",omitempty"`
268 CrossHostArch *string `json:",omitempty"`
269 CrossHostSecondaryArch *string `json:",omitempty"`
Colin Cross83163192015-12-01 16:31:16 -0800270
Jeongik Chacee5ba92021-02-19 12:11:51 +0900271 DeviceResourceOverlays []string `json:",omitempty"`
272 ProductResourceOverlays []string `json:",omitempty"`
273 EnforceRROTargets []string `json:",omitempty"`
Colin Crossa74ca042019-01-31 14:31:51 -0800274 EnforceRROExcludedOverlays []string `json:",omitempty"`
Colin Crossface4e42017-10-30 17:32:15 -0700275
Colin Crossa74ca042019-01-31 14:31:51 -0800276 AAPTCharacteristics *string `json:",omitempty"`
277 AAPTConfig []string `json:",omitempty"`
278 AAPTPreferredConfig *string `json:",omitempty"`
279 AAPTPrebuiltDPI []string `json:",omitempty"`
Colin Crossface4e42017-10-30 17:32:15 -0700280
Justin Yun635e7882024-07-04 14:50:57 +0900281 DefaultAppCertificate *string `json:",omitempty"`
282 ExtraOtaKeys []string `json:",omitempty"`
283 ExtraOtaRecoveryKeys []string `json:",omitempty"`
284 MainlineSepolicyDevCertificates *string `json:",omitempty"`
Colin Cross61ae0b72017-12-01 17:16:02 -0800285
Colin Crossface4e42017-10-30 17:32:15 -0700286 AppsDefaultVersionName *string `json:",omitempty"`
287
Cole Faust701ca252021-11-23 19:02:08 -0800288 Allow_missing_dependencies *bool `json:",omitempty"`
289 Unbundled_build *bool `json:",omitempty"`
290 Unbundled_build_apps []string `json:",omitempty"`
291 Unbundled_build_image *bool `json:",omitempty"`
292 Always_use_prebuilt_sdks *bool `json:",omitempty"`
293 Skip_boot_jars_check *bool `json:",omitempty"`
Christopher Ferrisa5a6b9c2024-04-23 17:17:49 -0700294 Malloc_low_memory *bool `json:",omitempty"`
Cole Faust701ca252021-11-23 19:02:08 -0800295 Malloc_zero_contents *bool `json:",omitempty"`
296 Malloc_pattern_fill_contents *bool `json:",omitempty"`
297 Safestack *bool `json:",omitempty"`
298 HostStaticBinaries *bool `json:",omitempty"`
299 Binder32bit *bool `json:",omitempty"`
300 UseGoma *bool `json:",omitempty"`
Taylor Santiago3c16e612024-05-30 14:41:31 -0700301 UseABFS *bool `json:",omitempty"`
Cole Faust701ca252021-11-23 19:02:08 -0800302 UseRBE *bool `json:",omitempty"`
303 UseRBEJAVAC *bool `json:",omitempty"`
304 UseRBER8 *bool `json:",omitempty"`
305 UseRBED8 *bool `json:",omitempty"`
306 Debuggable *bool `json:",omitempty"`
307 Eng *bool `json:",omitempty"`
308 Treble_linker_namespaces *bool `json:",omitempty"`
309 Enforce_vintf_manifest *bool `json:",omitempty"`
310 Uml *bool `json:",omitempty"`
311 Arc *bool `json:",omitempty"`
312 MinimizeJavaDebugInfo *bool `json:",omitempty"`
Jihoon Kangcbcad7c2023-06-01 22:31:52 +0000313 Build_from_text_stub *bool `json:",omitempty"`
Colin Cross16b23492016-01-06 14:41:07 -0800314
Inseob Kim8fa54da2024-03-19 16:48:59 +0900315 BuildType *string `json:",omitempty"`
316
Logan Chien4fcea3d2018-11-20 11:59:08 +0800317 Check_elf_files *bool `json:",omitempty"`
318
Colin Cross5a0dcd52018-10-05 14:20:06 -0700319 UncompressPrivAppDex *bool `json:",omitempty"`
320 ModulesLoadedByPrivilegedModules []string `json:",omitempty"`
Colin Cross43f08db2018-11-12 10:13:39 -0800321
satayevd604b212021-07-21 14:23:52 +0100322 BootJars ConfiguredJarList `json:",omitempty"`
323 ApexBootJars ConfiguredJarList `json:",omitempty"`
Vladimir Markoe8b00d62018-12-21 15:54:16 +0000324
Colin Crossa74ca042019-01-31 14:31:51 -0800325 IntegerOverflowExcludePaths []string `json:",omitempty"`
Ivan Lozano5f595532017-07-13 14:46:05 -0700326
Colin Crossa74ca042019-01-31 14:31:51 -0800327 EnableCFI *bool `json:",omitempty"`
328 CFIExcludePaths []string `json:",omitempty"`
329 CFIIncludePaths []string `json:",omitempty"`
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700330
Kostya Kortchinskyd5275c82019-02-01 08:42:56 -0800331 DisableScudo *bool `json:",omitempty"`
332
Evgenii Stepanov4beaa0c2021-01-05 16:41:26 -0800333 MemtagHeapExcludePaths []string `json:",omitempty"`
334 MemtagHeapAsyncIncludePaths []string `json:",omitempty"`
335 MemtagHeapSyncIncludePaths []string `json:",omitempty"`
336
Hang Lua98aab92023-03-17 13:17:22 +0800337 HWASanIncludePaths []string `json:",omitempty"`
Tomislav Novakf734f002023-08-22 10:51:44 -0700338 HWASanExcludePaths []string `json:",omitempty"`
Hang Lua98aab92023-03-17 13:17:22 +0800339
Spandan Dase3b65312024-10-22 00:27:27 +0000340 VendorPath *string `json:",omitempty"`
341 BuildingVendorImage *bool `json:",omitempty"`
342 OdmPath *string `json:",omitempty"`
343 ProductPath *string `json:",omitempty"`
344 SystemExtPath *string `json:",omitempty"`
Dan Willemsen4353bc42016-12-05 17:16:02 -0800345
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700346 ClangTidy *bool `json:",omitempty"`
347 TidyChecks *string `json:",omitempty"`
348
Roland Levillainada12702020-06-09 13:07:36 +0100349 JavaCoveragePaths []string `json:",omitempty"`
350 JavaCoverageExcludePaths []string `json:",omitempty"`
351
Pirama Arumuga Nainarb37ae582022-01-26 22:14:32 -0800352 GcovCoverage *bool `json:",omitempty"`
353 ClangCoverage *bool `json:",omitempty"`
354 NativeCoveragePaths []string `json:",omitempty"`
355 NativeCoverageExcludePaths []string `json:",omitempty"`
356 ClangCoverageContinuousMode *bool `json:",omitempty"`
Dan Willemsen581341d2017-02-09 16:16:31 -0800357
Colin Cross1a6acd42020-06-16 17:51:46 -0700358 // Set by NewConfig
Liz Kammer09f947d2021-05-12 14:51:49 -0400359 Native_coverage *bool `json:",omitempty"`
Colin Cross1a6acd42020-06-16 17:51:46 -0700360
Colin Cross23ae82a2016-11-02 14:34:39 -0700361 SanitizeHost []string `json:",omitempty"`
362 SanitizeDevice []string `json:",omitempty"`
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700363 SanitizeDeviceDiag []string `json:",omitempty"`
Colin Cross23ae82a2016-11-02 14:34:39 -0700364 SanitizeDeviceArch []string `json:",omitempty"`
Hiroshi Yamauchie2a10632016-12-19 13:44:41 -0800365
366 ArtUseReadBarrier *bool `json:",omitempty"`
Jack He8cc71432016-12-08 15:45:07 -0800367
368 BtConfigIncludeDir *string `json:",omitempty"`
Colin Cross95436422017-05-04 13:57:05 -0700369
370 Override_rs_driver *string `json:",omitempty"`
Jiyong Parkd773eb32017-07-03 13:18:12 +0900371
372 DeviceKernelHeaders []string `json:",omitempty"`
Justin Yun71549282017-11-17 12:10:28 +0900373
374 ExtraVndkVersions []string `json:",omitempty"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800375
376 NamespacesToExport []string `json:",omitempty"`
Pirama Arumuga Nainar49540802018-01-29 23:11:42 -0800377
Vinh Tran7a8362c2022-11-01 15:33:51 -0400378 PgoAdditionalProfileDirs []string `json:",omitempty"`
Dan Willemsen0fe78662018-03-26 12:41:18 -0700379
Inseob Kim5eb7ee92022-04-27 10:30:34 +0900380 MultitreeUpdateMeta bool `json:",omitempty"`
381
Inseob Kim6077b232023-08-31 16:49:59 +0900382 BoardVendorSepolicyDirs []string `json:",omitempty"`
383 BoardOdmSepolicyDirs []string `json:",omitempty"`
384 SystemExtPublicSepolicyDirs []string `json:",omitempty"`
385 SystemExtPrivateSepolicyDirs []string `json:",omitempty"`
386 BoardSepolicyM4Defs []string `json:",omitempty"`
Tri Vo35a51432018-03-25 20:00:00 -0700387
Herbert Xue0fc8abe2024-08-21 13:03:01 +0800388 BoardPlatform *string `json:",omitempty"`
Inseob Kim16ebd5a2020-12-09 23:08:17 +0900389 BoardSepolicyVers *string `json:",omitempty"`
390 PlatformSepolicyVersion *string `json:",omitempty"`
391
Inseob Kim1a0afcc2022-02-14 23:10:51 +0900392 SystemExtSepolicyPrebuiltApiDir *string `json:",omitempty"`
393 ProductSepolicyPrebuiltApiDir *string `json:",omitempty"`
394
Inseob Kim843f6642022-01-07 09:11:23 +0900395 PlatformSepolicyCompatVersions []string `json:",omitempty"`
396
Cole Faust46f6e2f2024-06-20 12:57:43 -0700397 VendorVars map[string]map[string]string `json:",omitempty"`
398 VendorVarTypes map[string]map[string]string `json:",omitempty"`
Colin Cross395f2cf2018-10-24 16:10:32 -0700399
Dan Albertd05ba002021-04-13 15:55:47 -0700400 Ndk_abis *bool `json:",omitempty"`
Jiyong Park8fd61922018-11-08 02:50:25 +0900401
Dennis Shene2ed70c2023-01-11 14:15:43 +0000402 TrimmedApex *bool `json:",omitempty"`
Jiyong Park4da07972021-01-05 21:01:11 +0900403 ForceApexSymlinkOptimization *bool `json:",omitempty"`
404 CompressedApex *bool `json:",omitempty"`
405 Aml_abis *bool `json:",omitempty"`
Colin Cross43f08db2018-11-12 10:13:39 -0800406
407 DexpreoptGlobalConfig *string `json:",omitempty"`
Jiyong Park7f67f482019-01-05 12:57:48 +0900408
Inseob Kim7b85eeb2021-03-23 20:52:24 +0900409 WithDexpreopt bool `json:",omitempty"`
410
Jiakai Zhang4d90da22023-07-12 16:51:48 +0100411 ManifestPackageNameOverrides []string `json:",omitempty"`
412 CertificateOverrides []string `json:",omitempty"`
413 PackageNameOverrides []string `json:",omitempty"`
414 ConfiguredJarLocationOverrides []string `json:",omitempty"`
Jeongik Chac9464142019-01-07 12:07:27 +0900415
Albert Martineefabcf2022-03-21 20:11:16 +0000416 ApexGlobalMinSdkVersionOverride *string `json:",omitempty"`
417
Jeongik Chac9464142019-01-07 12:07:27 +0900418 EnforceSystemCertificate *bool `json:",omitempty"`
Colin Cross440e0d02020-06-11 11:32:11 -0700419 EnforceSystemCertificateAllowList []string `json:",omitempty"`
Colin Cross8faf8fc2019-01-16 15:15:52 -0800420
Colin Crossf24a22a2019-01-31 14:12:44 -0800421 ProductHiddenAPIStubs []string `json:",omitempty"`
422 ProductHiddenAPIStubsSystem []string `json:",omitempty"`
423 ProductHiddenAPIStubsTest []string `json:",omitempty"`
Dan Willemsen71c74602019-04-10 12:27:35 -0700424
Inseob Kim0866b002019-04-15 20:21:29 +0900425 ProductPublicSepolicyDirs []string `json:",omitempty"`
426 ProductPrivateSepolicyDirs []string `json:",omitempty"`
Inseob Kim0866b002019-04-15 20:21:29 +0900427
Dan Willemsen54879d12019-04-18 10:08:46 -0700428 TargetFSConfigGen []string `json:",omitempty"`
Colin Cross50ddcc42019-05-16 12:28:22 -0700429
Justin Yun2cc42502024-09-11 14:10:20 +0900430 UseSoongSystemImage *bool `json:",omitempty"`
431 ProductSoongDefinedSystemImage *string `json:",omitempty"`
432
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900433 EnforceProductPartitionInterface *bool `json:",omitempty"`
Jooyung Han3ab2c3e2019-12-05 16:27:44 +0900434
Yifan Hong82db7352020-01-21 16:12:26 -0800435 BoardUsesRecoveryAsBoot *bool `json:",omitempty"`
Yifan Hong97365ee2020-07-29 09:51:57 -0700436
Yifan Hong42bef8d2020-08-05 14:36:09 -0700437 BoardKernelBinaries []string `json:",omitempty"`
438 BoardKernelModuleInterfaceVersions []string `json:",omitempty"`
Yifan Hongdd8dacc2020-10-21 15:40:17 -0700439
440 BoardMoveRecoveryResourcesToVendorBoot *bool `json:",omitempty"`
Bill Peckhambae47492021-01-08 09:34:44 -0800441
442 PrebuiltHiddenApiDir *string `json:",omitempty"`
Inseob Kim60c32f02020-12-21 22:53:05 +0900443
Steven Morelanda48df2b2024-06-03 22:29:38 +0000444 Shipping_api_level *string `json:",omitempty"`
Inseob Kim0cac7b42021-02-03 18:16:46 +0900445
Cole Faustded79602023-09-05 17:48:11 -0700446 BuildBrokenPluginValidation []string `json:",omitempty"`
447 BuildBrokenClangAsFlags bool `json:",omitempty"`
448 BuildBrokenClangCFlags bool `json:",omitempty"`
449 BuildBrokenClangProperty bool `json:",omitempty"`
450 GenruleSandboxing *bool `json:",omitempty"`
451 BuildBrokenEnforceSyspropOwner bool `json:",omitempty"`
452 BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"`
Cole Faustded79602023-09-05 17:48:11 -0700453 BuildBrokenVendorPropertyNamespace bool `json:",omitempty"`
454 BuildBrokenIncorrectPartitionImages bool `json:",omitempty"`
455 BuildBrokenInputDirModules []string `json:",omitempty"`
Jiyong Park3bb99242024-01-04 23:21:26 +0000456 BuildBrokenDontCheckSystemSdk bool `json:",omitempty"`
Inseob Kim2da72af2024-06-18 11:09:12 +0900457 BuildBrokenDupSysprop bool `json:",omitempty"`
Inseob Kim67e5add192021-03-17 18:05:33 +0900458
Jiakai Zhang48203e32023-06-02 23:42:21 +0100459 BuildWarningBadOptionalUsesLibsAllowlist []string `json:",omitempty"`
460
Hridya Valsaraju5a5c7d52021-04-02 16:45:24 -0700461 BuildDebugfsRestrictionsEnabled bool `json:",omitempty"`
462
Inseob Kim67e5add192021-03-17 18:05:33 +0900463 RequiresInsecureExecmemForSwiftshader bool `json:",omitempty"`
464
465 SelinuxIgnoreNeverallows bool `json:",omitempty"`
466
Devin Moorec381e102023-07-06 22:03:58 +0000467 Release_aidl_use_unfrozen *bool `json:",omitempty"`
468
Inseob Kima10ef272021-09-15 03:04:53 +0000469 SepolicyFreezeTestExtraDirs []string `json:",omitempty"`
470 SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"`
Jiyong Parkd163d4d2021-10-12 16:47:43 +0900471
472 GenerateAidlNdkPlatformBackend bool `json:",omitempty"`
Christopher Ferris98f10222022-07-13 23:16:52 -0700473
474 IgnorePrefer32OnDevice bool `json:",omitempty"`
Spandan Dasc5763832022-11-08 18:42:16 +0000475
Sam Delmerico98a73292023-02-21 11:50:29 -0500476 SourceRootDirs []string `json:",omitempty"`
Vinh Tran44cb78c2023-03-09 22:07:19 -0500477
478 AfdoProfiles []string `json:",omitempty"`
Wei Lic642d682023-05-04 09:06:06 -0700479
Inseob Kim8fa54da2024-03-19 16:48:59 +0900480 ProductManufacturer string `json:",omitempty"`
481 ProductBrand string `json:",omitempty"`
Jihoon Kangc55e6882024-10-09 20:44:08 +0000482 ProductDevice string `json:",omitempty"`
483 ProductModel string `json:",omitempty"`
Joe Onoratofee845a2023-05-09 08:14:14 -0700484
Yu Liueebb2592023-10-12 20:31:27 -0700485 ReleaseVersion string `json:",omitempty"`
486 ReleaseAconfigValueSets []string `json:",omitempty"`
Kiyoung Kime623c582023-07-06 16:43:44 +0900487
Zhi Dou3f65a412023-08-10 21:47:40 +0000488 ReleaseAconfigFlagDefaultPermission string `json:",omitempty"`
489
Alyssa Ketpreechasawat34ab8792023-10-06 07:01:22 +0000490 ReleaseDefaultModuleBuildFromSource *bool `json:",omitempty"`
491
Inseob Kim5bac3b62023-08-25 21:29:46 +0900492 CheckVendorSeappViolations *bool `json:",omitempty"`
Cole Faustb4cb0c82023-09-14 15:16:58 -0700493
Inseob Kime4e85d52023-10-25 23:53:58 +0900494 BuildFlags map[string]string `json:",omitempty"`
Jihoon Kangc1b04d62023-11-16 19:07:04 +0000495
Cole Faust751a4a52024-05-21 16:51:59 -0700496 BuildFlagTypes map[string]string `json:",omitempty"`
497
Jihoon Kangc1b04d62023-11-16 19:07:04 +0000498 BuildFromSourceStub *bool `json:",omitempty"`
Spandan Das8ab28dd2024-02-17 03:31:45 +0000499
Spandan Das0d24ade2024-03-08 04:20:15 +0000500 BuildIgnoreApexContributionContents *bool `json:",omitempty"`
Jihoon Kangb36fc542024-02-22 19:35:26 +0000501
502 HiddenapiExportableStubs *bool `json:",omitempty"`
Jihoon Kang35349462024-02-22 19:52:46 +0000503
504 ExportRuntimeApis *bool `json:",omitempty"`
Yu Liu67a28422024-03-05 00:36:31 +0000505
506 AconfigContainerValidation string `json:",omitempty"`
Inseob Kim8fa54da2024-03-19 16:48:59 +0900507
508 ProductLocales []string `json:",omitempty"`
509
510 ProductDefaultWifiChannels []string `json:",omitempty"`
511
512 BoardUseVbmetaDigestInFingerprint *bool `json:",omitempty"`
513
514 OemProperties []string `json:",omitempty"`
Kiyoung Kim881e4652024-07-08 11:02:23 +0900515
516 ArtTargetIncludeDebugBuild *bool `json:",omitempty"`
Inseob Kimd8538e52024-07-31 02:00:41 +0000517
Inseob Kimacf91742024-08-05 12:51:05 +0900518 SystemPropFiles []string `json:",omitempty"`
519 SystemExtPropFiles []string `json:",omitempty"`
Inseob Kim01d4f8b2024-08-08 17:47:14 +0900520 ProductPropFiles []string `json:",omitempty"`
Inseob Kim9a22c7e2024-08-26 15:58:09 +0900521 OdmPropFiles []string `json:",omitempty"`
Inseob Kim6bd92d52024-07-31 02:01:03 +0000522
523 EnableUffdGc *string `json:",omitempty"`
Bill Yang3b3aac02024-09-05 09:22:09 +0000524
525 BoardAvbEnable *bool `json:",omitempty"`
526 BoardAvbSystemAddHashtreeFooterArgs []string `json:",omitempty"`
527 DeviceFrameworkCompatibilityMatrixFile []string `json:",omitempty"`
528 DeviceProductCompatibilityMatrixFile []string `json:",omitempty"`
mrziwanga4c03552024-09-26 10:39:20 -0700529
530 PartitionVarsForSoongMigrationOnlyDoNotUse PartitionVariables
Wei Li5c6d83b2024-10-03 05:35:03 +0000531
Nouby Mohamed8609a552024-09-04 22:19:51 +0000532 ExtraAllowedDepsTxt *string `json:",omitempty"`
533
Wei Li5c6d83b2024-10-03 05:35:03 +0000534 AdbKeys *string `json:",omitempty"`
Cole Faustcb193ec2023-09-20 16:01:18 -0700535}
536
Cole Faust11edf552023-10-13 11:32:14 -0700537type PartitionQualifiedVariablesType struct {
538 BuildingImage bool `json:",omitempty"`
539 BoardErofsCompressor string `json:",omitempty"`
540 BoardErofsCompressHints string `json:",omitempty"`
541 BoardErofsPclusterSize string `json:",omitempty"`
542 BoardExtfsInodeCount string `json:",omitempty"`
543 BoardExtfsRsvPct string `json:",omitempty"`
544 BoardF2fsSloadCompressFlags string `json:",omitempty"`
545 BoardFileSystemCompress string `json:",omitempty"`
546 BoardFileSystemType string `json:",omitempty"`
547 BoardJournalSize string `json:",omitempty"`
548 BoardPartitionReservedSize string `json:",omitempty"`
549 BoardPartitionSize string `json:",omitempty"`
550 BoardSquashfsBlockSize string `json:",omitempty"`
551 BoardSquashfsCompressor string `json:",omitempty"`
552 BoardSquashfsCompressorOpt string `json:",omitempty"`
553 BoardSquashfsDisable4kAlign string `json:",omitempty"`
554 ProductBaseFsPath string `json:",omitempty"`
555 ProductHeadroom string `json:",omitempty"`
556 ProductVerityPartition string `json:",omitempty"`
557
558 BoardAvbAddHashtreeFooterArgs string `json:",omitempty"`
559 BoardAvbKeyPath string `json:",omitempty"`
560 BoardAvbAlgorithm string `json:",omitempty"`
561 BoardAvbRollbackIndex string `json:",omitempty"`
562 BoardAvbRollbackIndexLocation string `json:",omitempty"`
563}
564
Cole Faustcb193ec2023-09-20 16:01:18 -0700565type PartitionVariables struct {
566 ProductDirectory string `json:",omitempty"`
Cole Faust11edf552023-10-13 11:32:14 -0700567 PartitionQualifiedVariables map[string]PartitionQualifiedVariablesType
568 TargetUserimagesUseExt2 bool `json:",omitempty"`
569 TargetUserimagesUseExt3 bool `json:",omitempty"`
570 TargetUserimagesUseExt4 bool `json:",omitempty"`
Cole Faustcb193ec2023-09-20 16:01:18 -0700571
572 TargetUserimagesSparseExtDisabled bool `json:",omitempty"`
573 TargetUserimagesSparseErofsDisabled bool `json:",omitempty"`
574 TargetUserimagesSparseSquashfsDisabled bool `json:",omitempty"`
575 TargetUserimagesSparseF2fsDisabled bool `json:",omitempty"`
576
Yi-Yo Chiang939fe1a2023-11-24 14:58:50 +0800577 BoardErofsCompressor string `json:",omitempty"`
578 BoardErofsCompressorHints string `json:",omitempty"`
579 BoardErofsPclusterSize string `json:",omitempty"`
580 BoardErofsShareDupBlocks string `json:",omitempty"`
581 BoardErofsUseLegacyCompression string `json:",omitempty"`
582 BoardExt4ShareDupBlocks string `json:",omitempty"`
583 BoardFlashLogicalBlockSize string `json:",omitempty"`
584 BoardFlashEraseBlockSize string `json:",omitempty"`
585 BoardUsesRecoveryAsBoot bool `json:",omitempty"`
586 ProductUseDynamicPartitionSize bool `json:",omitempty"`
587 CopyImagesForTargetFilesZip bool `json:",omitempty"`
Cole Faustb5055392023-09-27 13:44:40 -0700588
589 BoardAvbEnable bool `json:",omitempty"`
Cole Faust11edf552023-10-13 11:32:14 -0700590
mrziwanga4c03552024-09-26 10:39:20 -0700591 ProductPackages []string `json:",omitempty"`
592 ProductPackagesDebug []string `json:",omitempty"`
Colin Crossa6bc19e2015-09-16 13:53:42 -0700593}
594
595func boolPtr(v bool) *bool {
596 return &v
Colin Cross485e5722015-08-27 13:28:01 -0700597}
598
Dan Willemsen47cf66b2015-09-16 16:48:54 -0700599func intPtr(v int) *int {
600 return &v
601}
602
Colin Cross4225f652015-09-17 14:33:42 -0700603func stringPtr(v string) *string {
604 return &v
605}
606
Cole Faustf8231dd2023-04-21 17:37:11 -0700607func (v *ProductVariables) SetDefaultConfig() {
608 *v = ProductVariables{
Colin Cross2a2e0db2020-02-21 16:55:46 -0800609 BuildNumberFile: stringPtr("build_number.txt"),
Dan Willemsenb6d171b2019-04-07 09:41:44 -0700610
Dan Albert8c7a9942023-03-27 20:34:01 +0000611 Platform_version_name: stringPtr("S"),
612 Platform_base_sdk_extension_version: intPtr(30),
613 Platform_sdk_version: intPtr(30),
614 Platform_sdk_codename: stringPtr("S"),
615 Platform_sdk_final: boolPtr(false),
616 Platform_version_active_codenames: []string{"S"},
617 Platform_version_all_preview_codenames: []string{"S"},
Dan Willemsencbf9e822017-11-13 14:34:56 -0800618
Vilas Bhatb3d2d222023-12-04 22:51:20 +0000619 HostArch: stringPtr("x86_64"),
620 HostSecondaryArch: stringPtr("x86"),
621 DeviceName: stringPtr("generic_arm64"),
622 DeviceProduct: stringPtr("aosp_arm-eng"),
623 DeviceArch: stringPtr("arm64"),
624 DeviceArchVariant: stringPtr("armv8-a"),
625 DeviceCpuVariant: stringPtr("generic"),
626 DeviceAbi: []string{"arm64-v8a"},
627 DeviceSecondaryArch: stringPtr("arm"),
628 DeviceSecondaryArchVariant: stringPtr("armv8-a"),
629 DeviceSecondaryCpuVariant: stringPtr("generic"),
630 DeviceSecondaryAbi: []string{"armeabi-v7a", "armeabi"},
631 DeviceMaxPageSizeSupported: stringPtr("4096"),
632 DeviceNoBionicPageSizeMacro: boolPtr(false),
Colin Crossface4e42017-10-30 17:32:15 -0700633
Colin Crossa74ca042019-01-31 14:31:51 -0800634 AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
Colin Crossface4e42017-10-30 17:32:15 -0700635 AAPTPreferredConfig: stringPtr("xhdpi"),
636 AAPTCharacteristics: stringPtr("nosdcard"),
Colin Crossa74ca042019-01-31 14:31:51 -0800637 AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
Colin Crossface4e42017-10-30 17:32:15 -0700638
Christopher Ferrisa5a6b9c2024-04-23 17:17:49 -0700639 Malloc_low_memory: boolPtr(false),
Steven Morelandd1342012020-07-30 20:38:49 +0000640 Malloc_zero_contents: boolPtr(true),
Evgenii Stepanov19ff3c92020-04-29 14:57:30 -0700641 Malloc_pattern_fill_contents: boolPtr(false),
642 Safestack: boolPtr(false),
Dennis Shene2ed70c2023-01-11 14:15:43 +0000643 TrimmedApex: boolPtr(false),
Jihoon Kangcbcad7c2023-06-01 22:31:52 +0000644 Build_from_text_stub: boolPtr(false),
Lukacs T. Berki720b3962021-03-17 13:34:30 +0100645
satayevd604b212021-07-21 14:23:52 +0100646 BootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
647 ApexBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
Colin Cross485e5722015-08-27 13:28:01 -0700648 }
Dan Willemsen490fd492015-11-24 17:53:15 -0800649
650 if runtime.GOOS == "linux" {
651 v.CrossHost = stringPtr("windows")
652 v.CrossHostArch = stringPtr("x86")
Dan Willemsen07cd0512016-02-03 23:16:33 -0800653 v.CrossHostSecondaryArch = stringPtr("x86_64")
Dan Willemsen490fd492015-11-24 17:53:15 -0800654 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700655}
656
Joe Onorato3fefc232023-12-04 17:35:15 +0000657func (this *ProductVariables) GetBuildFlagBool(flag string) bool {
658 val, ok := this.BuildFlags[flag]
659 if !ok {
660 return false
661 }
662 return val == "true"
663}
664
Colin Crosseabaedd2020-02-06 17:01:55 -0800665func VariableMutator(mctx BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700666 var module Module
Colin Cross7f64b6d2015-07-09 13:57:48 -0700667 var ok bool
Colin Cross635c3b02016-05-18 15:37:25 -0700668 if module, ok = mctx.Module().(Module); !ok {
Colin Cross7f64b6d2015-07-09 13:57:48 -0700669 return
670 }
671
672 // TODO: depend on config variable, create variants, propagate variants up tree
673 a := module.base()
Colin Cross18c46802019-09-24 22:19:02 -0700674
675 if a.variableProperties == nil {
676 return
677 }
678
679 variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
Colin Cross7f64b6d2015-07-09 13:57:48 -0700680
Colin Cross0cec3122021-01-20 11:27:32 -0800681 productVariables := reflect.ValueOf(mctx.Config().productVariables)
682
Colin Cross7f64b6d2015-07-09 13:57:48 -0700683 for i := 0; i < variableValues.NumField(); i++ {
684 variableValue := variableValues.Field(i)
Colin Cross485e5722015-08-27 13:28:01 -0700685 name := variableValues.Type().Field(i).Name
686 property := "product_variables." + proptools.PropertyNameForField(name)
Colin Cross7f64b6d2015-07-09 13:57:48 -0700687
Colin Crossa6bc19e2015-09-16 13:53:42 -0700688 // Check that the variable was set for the product
Colin Cross0cec3122021-01-20 11:27:32 -0800689 val := productVariables.FieldByName(name)
Colin Crossa6bc19e2015-09-16 13:53:42 -0700690 if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() {
691 continue
Colin Cross7f64b6d2015-07-09 13:57:48 -0700692 }
Colin Crossa6bc19e2015-09-16 13:53:42 -0700693
694 val = val.Elem()
695
696 // For bools, check that the value is true
697 if val.Kind() == reflect.Bool && val.Bool() == false {
698 continue
699 }
700
701 // Check if any properties were set for the module
Colin Cross6961a492020-02-06 16:57:45 -0800702 if variableValue.IsZero() {
Colin Crossa6bc19e2015-09-16 13:53:42 -0700703 continue
704 }
Colin Crossa6bc19e2015-09-16 13:53:42 -0700705 a.setVariableProperties(mctx, property, variableValue, val.Interface())
Colin Cross7f64b6d2015-07-09 13:57:48 -0700706 }
707}
708
Colin Cross4157e882019-06-06 16:57:04 -0700709func (m *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext,
Colin Cross7f64b6d2015-07-09 13:57:48 -0700710 prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) {
711
Colin Cross7e0eaf12017-05-05 16:16:24 -0700712 printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue)
Colin Cross7f64b6d2015-07-09 13:57:48 -0700713
Usta851a3272022-01-05 23:42:33 -0500714 err := proptools.AppendMatchingProperties(m.GetProperties(),
Colin Cross06a931b2015-10-28 17:23:31 -0700715 productVariablePropertyValue.Addr().Interface(), nil)
716 if err != nil {
717 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
718 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
719 } else {
720 panic(err)
721 }
722 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700723}
724
Colin Cross7e0eaf12017-05-05 16:16:24 -0700725func printfIntoPropertiesError(ctx BottomUpMutatorContext, prefix string,
726 productVariablePropertyValue reflect.Value, i int, err error) {
727
728 field := productVariablePropertyValue.Type().Field(i).Name
729 property := prefix + "." + proptools.PropertyNameForField(field)
730 ctx.PropertyErrorf(property, "%s", err)
731}
732
733func printfIntoProperties(ctx BottomUpMutatorContext, prefix string,
734 productVariablePropertyValue reflect.Value, variableValue interface{}) {
735
Colin Cross7f64b6d2015-07-09 13:57:48 -0700736 for i := 0; i < productVariablePropertyValue.NumField(); i++ {
737 propertyValue := productVariablePropertyValue.Field(i)
Colin Crossdd0dbe62015-12-02 15:24:38 -0800738 kind := propertyValue.Kind()
739 if kind == reflect.Ptr {
740 if propertyValue.IsNil() {
741 continue
742 }
743 propertyValue = propertyValue.Elem()
744 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700745 switch propertyValue.Kind() {
746 case reflect.String:
Colin Cross7e0eaf12017-05-05 16:16:24 -0700747 err := printfIntoProperty(propertyValue, variableValue)
748 if err != nil {
749 printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
750 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700751 case reflect.Slice:
752 for j := 0; j < propertyValue.Len(); j++ {
Colin Cross7e0eaf12017-05-05 16:16:24 -0700753 err := printfIntoProperty(propertyValue.Index(j), variableValue)
754 if err != nil {
755 printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
756 }
Colin Cross7f64b6d2015-07-09 13:57:48 -0700757 }
Colin Crossdd0dbe62015-12-02 15:24:38 -0800758 case reflect.Bool:
759 // Nothing
Colin Cross7f64b6d2015-07-09 13:57:48 -0700760 case reflect.Struct:
Colin Cross7e0eaf12017-05-05 16:16:24 -0700761 printfIntoProperties(ctx, prefix, propertyValue, variableValue)
Colin Cross7f64b6d2015-07-09 13:57:48 -0700762 default:
763 panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind()))
764 }
765 }
766}
767
Colin Cross7e0eaf12017-05-05 16:16:24 -0700768func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) error {
Colin Cross7f64b6d2015-07-09 13:57:48 -0700769 s := propertyValue.String()
Colin Cross7e0eaf12017-05-05 16:16:24 -0700770
771 count := strings.Count(s, "%")
772 if count == 0 {
773 return nil
774 }
775
776 if count > 1 {
777 return fmt.Errorf("product variable properties only support a single '%%'")
778 }
779
Colin Cross7f64b6d2015-07-09 13:57:48 -0700780 if strings.Contains(s, "%d") {
781 switch v := variableValue.(type) {
782 case int:
Colin Cross7e0eaf12017-05-05 16:16:24 -0700783 // Nothing
Colin Cross7f64b6d2015-07-09 13:57:48 -0700784 case bool:
785 if v {
Colin Cross7e0eaf12017-05-05 16:16:24 -0700786 variableValue = 1
787 } else {
788 variableValue = 0
Colin Cross7f64b6d2015-07-09 13:57:48 -0700789 }
790 default:
Colin Cross7e0eaf12017-05-05 16:16:24 -0700791 return fmt.Errorf("unsupported type %T for %%d", variableValue)
Colin Cross7f64b6d2015-07-09 13:57:48 -0700792 }
Colin Cross7e0eaf12017-05-05 16:16:24 -0700793 } else if strings.Contains(s, "%s") {
794 switch variableValue.(type) {
795 case string:
796 // Nothing
797 default:
798 return fmt.Errorf("unsupported type %T for %%s", variableValue)
799 }
800 } else {
801 return fmt.Errorf("unsupported %% in product variable property")
Colin Cross7f64b6d2015-07-09 13:57:48 -0700802 }
Colin Cross7e0eaf12017-05-05 16:16:24 -0700803
804 propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, variableValue)))
805
806 return nil
Colin Cross7f64b6d2015-07-09 13:57:48 -0700807}
Colin Cross18c46802019-09-24 22:19:02 -0700808
809var variablePropTypeMap OncePer
810
811// sliceToTypeArray takes a slice of property structs and returns a reflection created array containing the
812// reflect.Types of each property struct. The result can be used as a key in a map.
813func sliceToTypeArray(s []interface{}) interface{} {
814 // Create an array using reflection whose length is the length of the input slice
815 ret := reflect.New(reflect.ArrayOf(len(s), reflect.TypeOf(reflect.TypeOf(0)))).Elem()
816 for i, e := range s {
817 ret.Index(i).Set(reflect.ValueOf(reflect.TypeOf(e)))
818 }
819 return ret.Interface()
820}
821
Colin Crosseabaedd2020-02-06 17:01:55 -0800822func initProductVariableModule(m Module) {
823 base := m.base()
824
825 // Allow tests to override the default product variables
826 if base.variableProperties == nil {
827 base.variableProperties = defaultProductVariables
828 }
829 // Filter the product variables properties to the ones that exist on this module
830 base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
831 if base.variableProperties != nil {
832 m.AddProperties(base.variableProperties)
833 }
834}
835
Colin Cross18c46802019-09-24 22:19:02 -0700836// createVariableProperties takes the list of property structs for a module and returns a property struct that
837// contains the product variable properties that exist in the property structs, or nil if there are none. It
838// caches the result.
839func createVariableProperties(moduleTypeProps []interface{}, productVariables interface{}) interface{} {
840 // Convert the moduleTypeProps to an array of reflect.Types that can be used as a key in the OncePer.
841 key := sliceToTypeArray(moduleTypeProps)
842
843 // Use the variablePropTypeMap OncePer to cache the result for each set of property struct types.
844 typ, _ := variablePropTypeMap.Once(NewCustomOnceKey(key), func() interface{} {
845 // Compute the filtered property struct type.
846 return createVariablePropertiesType(moduleTypeProps, productVariables)
847 }).(reflect.Type)
848
849 if typ == nil {
850 return nil
851 }
852
853 // Create a new pointer to a filtered property struct.
854 return reflect.New(typ).Interface()
855}
856
857// createVariablePropertiesType creates a new type that contains only the product variable properties that exist in
858// a list of property structs.
859func createVariablePropertiesType(moduleTypeProps []interface{}, productVariables interface{}) reflect.Type {
860 typ, _ := proptools.FilterPropertyStruct(reflect.TypeOf(productVariables),
861 func(field reflect.StructField, prefix string) (bool, reflect.StructField) {
862 // Filter function, returns true if the field should be in the resulting struct
863 if prefix == "" {
864 // Keep the top level Product_variables field
865 return true, field
866 }
867 _, rest := splitPrefix(prefix)
868 if rest == "" {
869 // Keep the 2nd level field (i.e. Product_variables.Eng)
870 return true, field
871 }
872
873 // Strip off the first 2 levels of the prefix
874 _, prefix = splitPrefix(rest)
875
876 for _, p := range moduleTypeProps {
877 if fieldExistsByNameRecursive(reflect.TypeOf(p).Elem(), prefix, field.Name) {
878 // Keep any fields that exist in one of the property structs
879 return true, field
880 }
881 }
882
883 return false, field
884 })
885 return typ
886}
887
888func splitPrefix(prefix string) (first, rest string) {
889 index := strings.IndexByte(prefix, '.')
890 if index == -1 {
891 return prefix, ""
892 }
893 return prefix[:index], prefix[index+1:]
894}
895
896func fieldExistsByNameRecursive(t reflect.Type, prefix, name string) bool {
897 if t.Kind() != reflect.Struct {
898 panic(fmt.Errorf("fieldExistsByNameRecursive can only be called on a reflect.Struct"))
899 }
900
901 if prefix != "" {
902 split := strings.SplitN(prefix, ".", 2)
903 firstPrefix := split[0]
904 rest := ""
905 if len(split) > 1 {
906 rest = split[1]
907 }
908 f, exists := t.FieldByName(firstPrefix)
909 if !exists {
910 return false
911 }
912 ft := f.Type
913 if ft.Kind() == reflect.Ptr {
914 ft = ft.Elem()
915 }
916 if ft.Kind() != reflect.Struct {
917 panic(fmt.Errorf("field %q in %q is not a struct", firstPrefix, t))
918 }
919 return fieldExistsByNameRecursive(ft, rest, name)
920 } else {
921 _, exists := t.FieldByName(name)
922 return exists
923 }
924}