variable.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. // Copyright 2015 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package android
  15. import (
  16. "fmt"
  17. "reflect"
  18. "runtime"
  19. "strings"
  20. "android/soong/android/soongconfig"
  21. "android/soong/bazel"
  22. "github.com/google/blueprint/proptools"
  23. )
  24. func init() {
  25. registerVariableBuildComponents(InitRegistrationContext)
  26. }
  27. func registerVariableBuildComponents(ctx RegistrationContext) {
  28. ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
  29. ctx.BottomUp("variable", VariableMutator).Parallel()
  30. })
  31. }
  32. var PrepareForTestWithVariables = FixtureRegisterWithContext(registerVariableBuildComponents)
  33. type variableProperties struct {
  34. Product_variables struct {
  35. Platform_sdk_version struct {
  36. Asflags []string
  37. Cflags []string
  38. Cmd *string
  39. }
  40. Platform_sdk_version_or_codename struct {
  41. Java_resource_dirs []string
  42. }
  43. Platform_sdk_extension_version struct {
  44. Cmd *string
  45. }
  46. Platform_version_name struct {
  47. Base_dir *string
  48. }
  49. // unbundled_build is a catch-all property to annotate modules that don't build in one or
  50. // more unbundled branches, usually due to dependencies missing from the manifest.
  51. Unbundled_build struct {
  52. Enabled *bool `android:"arch_variant"`
  53. } `android:"arch_variant"`
  54. Malloc_not_svelte struct {
  55. Cflags []string `android:"arch_variant"`
  56. Shared_libs []string `android:"arch_variant"`
  57. Whole_static_libs []string `android:"arch_variant"`
  58. Exclude_static_libs []string `android:"arch_variant"`
  59. Srcs []string `android:"arch_variant"`
  60. Header_libs []string `android:"arch_variant"`
  61. } `android:"arch_variant"`
  62. Malloc_zero_contents struct {
  63. Cflags []string `android:"arch_variant"`
  64. } `android:"arch_variant"`
  65. Malloc_pattern_fill_contents struct {
  66. Cflags []string `android:"arch_variant"`
  67. } `android:"arch_variant"`
  68. Safestack struct {
  69. Cflags []string `android:"arch_variant"`
  70. } `android:"arch_variant"`
  71. Binder32bit struct {
  72. Cflags []string
  73. }
  74. Override_rs_driver struct {
  75. Cflags []string
  76. }
  77. // treble_linker_namespaces is true when the system/vendor linker namespace separation is
  78. // enabled.
  79. Treble_linker_namespaces struct {
  80. Cflags []string
  81. }
  82. // enforce_vintf_manifest is true when a device is required to have a vintf manifest.
  83. Enforce_vintf_manifest struct {
  84. Cflags []string
  85. }
  86. // debuggable is true for eng and userdebug builds, and can be used to turn on additional
  87. // debugging features that don't significantly impact runtime behavior. userdebug builds
  88. // are used for dogfooding and performance testing, and should be as similar to user builds
  89. // as possible.
  90. Debuggable struct {
  91. Cflags []string
  92. Cppflags []string
  93. Init_rc []string
  94. Required []string
  95. Host_required []string
  96. Target_required []string
  97. Strip struct {
  98. All *bool
  99. Keep_symbols *bool
  100. Keep_symbols_and_debug_frame *bool
  101. }
  102. Static_libs []string
  103. Whole_static_libs []string
  104. Shared_libs []string
  105. Cmdline []string
  106. Srcs []string
  107. Exclude_srcs []string
  108. }
  109. // eng is true for -eng builds, and can be used to turn on additionaly heavyweight debugging
  110. // features.
  111. Eng struct {
  112. Cflags []string
  113. Cppflags []string
  114. Lto struct {
  115. Never *bool
  116. }
  117. Sanitize struct {
  118. Address *bool
  119. }
  120. Optimize struct {
  121. Enabled *bool
  122. }
  123. }
  124. Pdk struct {
  125. Enabled *bool `android:"arch_variant"`
  126. } `android:"arch_variant"`
  127. Uml struct {
  128. Cppflags []string
  129. }
  130. Arc struct {
  131. Cflags []string `android:"arch_variant"`
  132. Exclude_srcs []string `android:"arch_variant"`
  133. Header_libs []string `android:"arch_variant"`
  134. Include_dirs []string `android:"arch_variant"`
  135. Shared_libs []string `android:"arch_variant"`
  136. Static_libs []string `android:"arch_variant"`
  137. Srcs []string `android:"arch_variant"`
  138. Whole_static_libs []string `android:"arch_variant"`
  139. } `android:"arch_variant"`
  140. Flatten_apex struct {
  141. Enabled *bool
  142. }
  143. Native_coverage struct {
  144. Src *string `android:"arch_variant"`
  145. Srcs []string `android:"arch_variant"`
  146. Exclude_srcs []string `android:"arch_variant"`
  147. } `android:"arch_variant"`
  148. } `android:"arch_variant"`
  149. }
  150. var defaultProductVariables interface{} = variableProperties{}
  151. type productVariables struct {
  152. // Suffix to add to generated Makefiles
  153. Make_suffix *string `json:",omitempty"`
  154. BuildId *string `json:",omitempty"`
  155. BuildNumberFile *string `json:",omitempty"`
  156. Platform_version_name *string `json:",omitempty"`
  157. Platform_sdk_version *int `json:",omitempty"`
  158. Platform_sdk_codename *string `json:",omitempty"`
  159. Platform_sdk_version_or_codename *string `json:",omitempty"`
  160. Platform_sdk_final *bool `json:",omitempty"`
  161. Platform_sdk_extension_version *int `json:",omitempty"`
  162. Platform_version_active_codenames []string `json:",omitempty"`
  163. Platform_vndk_version *string `json:",omitempty"`
  164. Platform_systemsdk_versions []string `json:",omitempty"`
  165. Platform_security_patch *string `json:",omitempty"`
  166. Platform_preview_sdk_version *string `json:",omitempty"`
  167. Platform_min_supported_target_sdk_version *string `json:",omitempty"`
  168. Platform_base_os *string `json:",omitempty"`
  169. DeviceName *string `json:",omitempty"`
  170. DeviceArch *string `json:",omitempty"`
  171. DeviceArchVariant *string `json:",omitempty"`
  172. DeviceCpuVariant *string `json:",omitempty"`
  173. DeviceAbi []string `json:",omitempty"`
  174. DeviceVndkVersion *string `json:",omitempty"`
  175. DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"`
  176. DeviceSystemSdkVersions []string `json:",omitempty"`
  177. RecoverySnapshotVersion *string `json:",omitempty"`
  178. DeviceSecondaryArch *string `json:",omitempty"`
  179. DeviceSecondaryArchVariant *string `json:",omitempty"`
  180. DeviceSecondaryCpuVariant *string `json:",omitempty"`
  181. DeviceSecondaryAbi []string `json:",omitempty"`
  182. NativeBridgeArch *string `json:",omitempty"`
  183. NativeBridgeArchVariant *string `json:",omitempty"`
  184. NativeBridgeCpuVariant *string `json:",omitempty"`
  185. NativeBridgeAbi []string `json:",omitempty"`
  186. NativeBridgeRelativePath *string `json:",omitempty"`
  187. NativeBridgeSecondaryArch *string `json:",omitempty"`
  188. NativeBridgeSecondaryArchVariant *string `json:",omitempty"`
  189. NativeBridgeSecondaryCpuVariant *string `json:",omitempty"`
  190. NativeBridgeSecondaryAbi []string `json:",omitempty"`
  191. NativeBridgeSecondaryRelativePath *string `json:",omitempty"`
  192. HostArch *string `json:",omitempty"`
  193. HostSecondaryArch *string `json:",omitempty"`
  194. HostMusl *bool `json:",omitempty"`
  195. CrossHost *string `json:",omitempty"`
  196. CrossHostArch *string `json:",omitempty"`
  197. CrossHostSecondaryArch *string `json:",omitempty"`
  198. DeviceResourceOverlays []string `json:",omitempty"`
  199. ProductResourceOverlays []string `json:",omitempty"`
  200. EnforceRROTargets []string `json:",omitempty"`
  201. EnforceRROExcludedOverlays []string `json:",omitempty"`
  202. AAPTCharacteristics *string `json:",omitempty"`
  203. AAPTConfig []string `json:",omitempty"`
  204. AAPTPreferredConfig *string `json:",omitempty"`
  205. AAPTPrebuiltDPI []string `json:",omitempty"`
  206. DefaultAppCertificate *string `json:",omitempty"`
  207. AppsDefaultVersionName *string `json:",omitempty"`
  208. Allow_missing_dependencies *bool `json:",omitempty"`
  209. Unbundled_build *bool `json:",omitempty"`
  210. Unbundled_build_apps []string `json:",omitempty"`
  211. Unbundled_build_image *bool `json:",omitempty"`
  212. Always_use_prebuilt_sdks *bool `json:",omitempty"`
  213. Skip_boot_jars_check *bool `json:",omitempty"`
  214. Malloc_not_svelte *bool `json:",omitempty"`
  215. Malloc_zero_contents *bool `json:",omitempty"`
  216. Malloc_pattern_fill_contents *bool `json:",omitempty"`
  217. Safestack *bool `json:",omitempty"`
  218. HostStaticBinaries *bool `json:",omitempty"`
  219. Binder32bit *bool `json:",omitempty"`
  220. UseGoma *bool `json:",omitempty"`
  221. UseRBE *bool `json:",omitempty"`
  222. UseRBEJAVAC *bool `json:",omitempty"`
  223. UseRBER8 *bool `json:",omitempty"`
  224. UseRBED8 *bool `json:",omitempty"`
  225. Debuggable *bool `json:",omitempty"`
  226. Eng *bool `json:",omitempty"`
  227. Treble_linker_namespaces *bool `json:",omitempty"`
  228. Enforce_vintf_manifest *bool `json:",omitempty"`
  229. Uml *bool `json:",omitempty"`
  230. Arc *bool `json:",omitempty"`
  231. MinimizeJavaDebugInfo *bool `json:",omitempty"`
  232. Check_elf_files *bool `json:",omitempty"`
  233. UncompressPrivAppDex *bool `json:",omitempty"`
  234. ModulesLoadedByPrivilegedModules []string `json:",omitempty"`
  235. BootJars ConfiguredJarList `json:",omitempty"`
  236. ApexBootJars ConfiguredJarList `json:",omitempty"`
  237. IntegerOverflowExcludePaths []string `json:",omitempty"`
  238. EnableCFI *bool `json:",omitempty"`
  239. CFIExcludePaths []string `json:",omitempty"`
  240. CFIIncludePaths []string `json:",omitempty"`
  241. DisableScudo *bool `json:",omitempty"`
  242. MemtagHeapExcludePaths []string `json:",omitempty"`
  243. MemtagHeapAsyncIncludePaths []string `json:",omitempty"`
  244. MemtagHeapSyncIncludePaths []string `json:",omitempty"`
  245. VendorPath *string `json:",omitempty"`
  246. OdmPath *string `json:",omitempty"`
  247. ProductPath *string `json:",omitempty"`
  248. SystemExtPath *string `json:",omitempty"`
  249. ClangTidy *bool `json:",omitempty"`
  250. TidyChecks *string `json:",omitempty"`
  251. JavaCoveragePaths []string `json:",omitempty"`
  252. JavaCoverageExcludePaths []string `json:",omitempty"`
  253. GcovCoverage *bool `json:",omitempty"`
  254. ClangCoverage *bool `json:",omitempty"`
  255. NativeCoveragePaths []string `json:",omitempty"`
  256. NativeCoverageExcludePaths []string `json:",omitempty"`
  257. // Set by NewConfig
  258. Native_coverage *bool `json:",omitempty"`
  259. SanitizeHost []string `json:",omitempty"`
  260. SanitizeDevice []string `json:",omitempty"`
  261. SanitizeDeviceDiag []string `json:",omitempty"`
  262. SanitizeDeviceArch []string `json:",omitempty"`
  263. ArtUseReadBarrier *bool `json:",omitempty"`
  264. BtConfigIncludeDir *string `json:",omitempty"`
  265. Override_rs_driver *string `json:",omitempty"`
  266. DeviceKernelHeaders []string `json:",omitempty"`
  267. ExtraVndkVersions []string `json:",omitempty"`
  268. NamespacesToExport []string `json:",omitempty"`
  269. AfdoAdditionalProfileDirs []string `json:",omitempty"`
  270. PgoAdditionalProfileDirs []string `json:",omitempty"`
  271. VndkUseCoreVariant *bool `json:",omitempty"`
  272. VndkSnapshotBuildArtifacts *bool `json:",omitempty"`
  273. DirectedVendorSnapshot bool `json:",omitempty"`
  274. VendorSnapshotModules map[string]bool `json:",omitempty"`
  275. DirectedRecoverySnapshot bool `json:",omitempty"`
  276. RecoverySnapshotModules map[string]bool `json:",omitempty"`
  277. VendorSnapshotDirsIncluded []string `json:",omitempty"`
  278. VendorSnapshotDirsExcluded []string `json:",omitempty"`
  279. RecoverySnapshotDirsExcluded []string `json:",omitempty"`
  280. RecoverySnapshotDirsIncluded []string `json:",omitempty"`
  281. HostFakeSnapshotEnabled bool `json:",omitempty"`
  282. BoardVendorSepolicyDirs []string `json:",omitempty"`
  283. BoardOdmSepolicyDirs []string `json:",omitempty"`
  284. BoardReqdMaskPolicy []string `json:",omitempty"`
  285. BoardPlatVendorPolicy []string `json:",omitempty"`
  286. BoardSystemExtPublicPrebuiltDirs []string `json:",omitempty"`
  287. BoardSystemExtPrivatePrebuiltDirs []string `json:",omitempty"`
  288. BoardProductPublicPrebuiltDirs []string `json:",omitempty"`
  289. BoardProductPrivatePrebuiltDirs []string `json:",omitempty"`
  290. SystemExtPublicSepolicyDirs []string `json:",omitempty"`
  291. SystemExtPrivateSepolicyDirs []string `json:",omitempty"`
  292. BoardSepolicyM4Defs []string `json:",omitempty"`
  293. BoardSepolicyVers *string `json:",omitempty"`
  294. PlatformSepolicyVersion *string `json:",omitempty"`
  295. TotSepolicyVersion *string `json:",omitempty"`
  296. VendorVars map[string]map[string]string `json:",omitempty"`
  297. Ndk_abis *bool `json:",omitempty"`
  298. Flatten_apex *bool `json:",omitempty"`
  299. ForceApexSymlinkOptimization *bool `json:",omitempty"`
  300. CompressedApex *bool `json:",omitempty"`
  301. Aml_abis *bool `json:",omitempty"`
  302. DexpreoptGlobalConfig *string `json:",omitempty"`
  303. WithDexpreopt bool `json:",omitempty"`
  304. ManifestPackageNameOverrides []string `json:",omitempty"`
  305. CertificateOverrides []string `json:",omitempty"`
  306. PackageNameOverrides []string `json:",omitempty"`
  307. EnforceSystemCertificate *bool `json:",omitempty"`
  308. EnforceSystemCertificateAllowList []string `json:",omitempty"`
  309. ProductHiddenAPIStubs []string `json:",omitempty"`
  310. ProductHiddenAPIStubsSystem []string `json:",omitempty"`
  311. ProductHiddenAPIStubsTest []string `json:",omitempty"`
  312. ProductPublicSepolicyDirs []string `json:",omitempty"`
  313. ProductPrivateSepolicyDirs []string `json:",omitempty"`
  314. ProductVndkVersion *string `json:",omitempty"`
  315. TargetFSConfigGen []string `json:",omitempty"`
  316. MissingUsesLibraries []string `json:",omitempty"`
  317. EnforceProductPartitionInterface *bool `json:",omitempty"`
  318. EnforceInterPartitionJavaSdkLibrary *bool `json:",omitempty"`
  319. InterPartitionJavaLibraryAllowList []string `json:",omitempty"`
  320. InstallExtraFlattenedApexes *bool `json:",omitempty"`
  321. BoardUsesRecoveryAsBoot *bool `json:",omitempty"`
  322. BoardKernelBinaries []string `json:",omitempty"`
  323. BoardKernelModuleInterfaceVersions []string `json:",omitempty"`
  324. BoardMoveRecoveryResourcesToVendorBoot *bool `json:",omitempty"`
  325. PrebuiltHiddenApiDir *string `json:",omitempty"`
  326. ShippingApiLevel *string `json:",omitempty"`
  327. BuildBrokenEnforceSyspropOwner bool `json:",omitempty"`
  328. BuildBrokenTrebleSyspropNeverallow bool `json:",omitempty"`
  329. BuildBrokenVendorPropertyNamespace bool `json:",omitempty"`
  330. BuildDebugfsRestrictionsEnabled bool `json:",omitempty"`
  331. RequiresInsecureExecmemForSwiftshader bool `json:",omitempty"`
  332. SelinuxIgnoreNeverallows bool `json:",omitempty"`
  333. SepolicySplit bool `json:",omitempty"`
  334. SepolicyFreezeTestExtraDirs []string `json:",omitempty"`
  335. SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"`
  336. GenerateAidlNdkPlatformBackend bool `json:",omitempty"`
  337. }
  338. func boolPtr(v bool) *bool {
  339. return &v
  340. }
  341. func intPtr(v int) *int {
  342. return &v
  343. }
  344. func stringPtr(v string) *string {
  345. return &v
  346. }
  347. func (v *productVariables) SetDefaultConfig() {
  348. *v = productVariables{
  349. BuildNumberFile: stringPtr("build_number.txt"),
  350. Platform_version_name: stringPtr("S"),
  351. Platform_sdk_version: intPtr(30),
  352. Platform_sdk_codename: stringPtr("S"),
  353. Platform_sdk_final: boolPtr(false),
  354. Platform_version_active_codenames: []string{"S"},
  355. Platform_vndk_version: stringPtr("S"),
  356. HostArch: stringPtr("x86_64"),
  357. HostSecondaryArch: stringPtr("x86"),
  358. DeviceName: stringPtr("generic_arm64"),
  359. DeviceArch: stringPtr("arm64"),
  360. DeviceArchVariant: stringPtr("armv8-a"),
  361. DeviceCpuVariant: stringPtr("generic"),
  362. DeviceAbi: []string{"arm64-v8a"},
  363. DeviceSecondaryArch: stringPtr("arm"),
  364. DeviceSecondaryArchVariant: stringPtr("armv8-a"),
  365. DeviceSecondaryCpuVariant: stringPtr("generic"),
  366. DeviceSecondaryAbi: []string{"armeabi-v7a", "armeabi"},
  367. AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"},
  368. AAPTPreferredConfig: stringPtr("xhdpi"),
  369. AAPTCharacteristics: stringPtr("nosdcard"),
  370. AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
  371. Malloc_not_svelte: boolPtr(true),
  372. Malloc_zero_contents: boolPtr(true),
  373. Malloc_pattern_fill_contents: boolPtr(false),
  374. Safestack: boolPtr(false),
  375. BootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
  376. ApexBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
  377. }
  378. if runtime.GOOS == "linux" {
  379. v.CrossHost = stringPtr("windows")
  380. v.CrossHostArch = stringPtr("x86")
  381. v.CrossHostSecondaryArch = stringPtr("x86_64")
  382. }
  383. }
  384. // ProductConfigContext requires the access to the Module to get product config properties.
  385. type ProductConfigContext interface {
  386. Module() Module
  387. }
  388. // ProductConfigProperty contains the information for a single property (may be a struct) paired
  389. // with the appropriate ProductConfigVariable.
  390. type ProductConfigProperty struct {
  391. // The name of the product variable, e.g. "safestack", "malloc_not_svelte",
  392. // "board"
  393. Name string
  394. // Namespace of the variable, if this is a soong_config_module_type variable
  395. // e.g. "acme", "ANDROID", "vendor_name"
  396. Namespace string
  397. // Unique configuration to identify this product config property (i.e. a
  398. // primary key), as just using the product variable name is not sufficient.
  399. //
  400. // For product variables, this is the product variable name + optional
  401. // archvariant information. e.g.
  402. //
  403. // product_variables: {
  404. // foo: {
  405. // cflags: ["-Dfoo"],
  406. // },
  407. // },
  408. //
  409. // FullConfig would be "foo".
  410. //
  411. // target: {
  412. // android: {
  413. // product_variables: {
  414. // foo: {
  415. // cflags: ["-Dfoo-android"],
  416. // },
  417. // },
  418. // },
  419. // },
  420. //
  421. // FullConfig would be "foo-android".
  422. //
  423. // For soong config variables, this is the namespace + product variable name
  424. // + value of the variable, if applicable. The value can also be
  425. // conditions_default.
  426. //
  427. // e.g.
  428. //
  429. // soong_config_variables: {
  430. // feature1: {
  431. // conditions_default: {
  432. // cflags: ["-DDEFAULT1"],
  433. // },
  434. // cflags: ["-DFEATURE1"],
  435. // },
  436. // }
  437. //
  438. // where feature1 is created in the "acme" namespace, so FullConfig would be
  439. // "acme__feature1" and "acme__feature1__conditions_default".
  440. //
  441. // e.g.
  442. //
  443. // soong_config_variables: {
  444. // board: {
  445. // soc_a: {
  446. // cflags: ["-DSOC_A"],
  447. // },
  448. // soc_b: {
  449. // cflags: ["-DSOC_B"],
  450. // },
  451. // soc_c: {},
  452. // conditions_default: {
  453. // cflags: ["-DSOC_DEFAULT"]
  454. // },
  455. // },
  456. // }
  457. //
  458. // where board is created in the "acme" namespace, so FullConfig would be
  459. // "acme__board__soc_a", "acme__board__soc_b", and
  460. // "acme__board__conditions_default"
  461. FullConfig string
  462. }
  463. func (p *ProductConfigProperty) AlwaysEmit() bool {
  464. return p.Namespace != ""
  465. }
  466. func (p *ProductConfigProperty) ConfigurationAxis() bazel.ConfigurationAxis {
  467. if p.Namespace == "" {
  468. return bazel.ProductVariableConfigurationAxis(p.FullConfig)
  469. } else {
  470. // Soong config variables can be uniquely identified by the namespace
  471. // (e.g. acme, android) and the product variable name (e.g. board, size)
  472. return bazel.ProductVariableConfigurationAxis(p.Namespace + "__" + p.Name)
  473. }
  474. }
  475. // SelectKey returns the literal string that represents this variable in a BUILD
  476. // select statement.
  477. func (p *ProductConfigProperty) SelectKey() string {
  478. if p.Namespace == "" {
  479. return strings.ToLower(p.FullConfig)
  480. }
  481. if p.FullConfig == bazel.ConditionsDefaultConfigKey {
  482. return bazel.ConditionsDefaultConfigKey
  483. }
  484. value := p.FullConfig
  485. if value == p.Name {
  486. value = "enabled"
  487. }
  488. // e.g. acme__feature1__enabled, android__board__soc_a
  489. return strings.ToLower(strings.Join([]string{p.Namespace, p.Name, value}, "__"))
  490. }
  491. // ProductConfigProperties is a map of maps to group property values according
  492. // their property name and the product config variable they're set under.
  493. //
  494. // The outer map key is the name of the property, like "cflags".
  495. //
  496. // The inner map key is a ProductConfigProperty, which is a struct of product
  497. // variable name, namespace, and the "full configuration" of the product
  498. // variable.
  499. //
  500. // e.g. product variable name: board, namespace: acme, full config: vendor_chip_foo
  501. //
  502. // The value of the map is the interface{} representing the value of the
  503. // property, like ["-DDEFINES"] for cflags.
  504. type ProductConfigProperties map[string]map[ProductConfigProperty]interface{}
  505. // ProductVariableProperties returns a ProductConfigProperties containing only the properties which
  506. // have been set for the module in the given context.
  507. func ProductVariableProperties(ctx BazelConversionPathContext) ProductConfigProperties {
  508. module := ctx.Module()
  509. moduleBase := module.base()
  510. productConfigProperties := ProductConfigProperties{}
  511. if moduleBase.variableProperties != nil {
  512. productVariablesProperty := proptools.FieldNameForProperty("product_variables")
  513. productVariableValues(
  514. productVariablesProperty,
  515. moduleBase.variableProperties,
  516. "",
  517. "",
  518. &productConfigProperties)
  519. for _, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) {
  520. for config, props := range configToProps {
  521. // GetArchVariantProperties is creating an instance of the requested type
  522. // and productVariablesValues expects an interface, so no need to cast
  523. productVariableValues(
  524. productVariablesProperty,
  525. props,
  526. "",
  527. config,
  528. &productConfigProperties)
  529. }
  530. }
  531. }
  532. if m, ok := module.(Bazelable); ok && m.namespacedVariableProps() != nil {
  533. for namespace, namespacedVariableProps := range m.namespacedVariableProps() {
  534. for _, namespacedVariableProp := range namespacedVariableProps {
  535. productVariableValues(
  536. soongconfig.SoongConfigProperty,
  537. namespacedVariableProp,
  538. namespace,
  539. "",
  540. &productConfigProperties)
  541. }
  542. }
  543. }
  544. productConfigProperties.zeroValuesForNamespacedVariables()
  545. return productConfigProperties
  546. }
  547. // zeroValuesForNamespacedVariables ensures that selects that contain __only__
  548. // conditions default values have zero values set for the other non-default
  549. // values for that select statement.
  550. //
  551. // If the ProductConfigProperties map contains these items, as parsed from the .bp file:
  552. //
  553. // library_linking_strategy: {
  554. // prefer_static: {
  555. // static_libs: [
  556. // "lib_a",
  557. // "lib_b",
  558. // ],
  559. // },
  560. // conditions_default: {
  561. // shared_libs: [
  562. // "lib_a",
  563. // "lib_b",
  564. // ],
  565. // },
  566. // },
  567. //
  568. // Static_libs {Library_linking_strategy ANDROID prefer_static} [lib_a lib_b]
  569. // Shared_libs {Library_linking_strategy ANDROID conditions_default} [lib_a lib_b]
  570. //
  571. // We need to add this:
  572. //
  573. // Shared_libs {Library_linking_strategy ANDROID prefer_static} []
  574. //
  575. // so that the following gets generated for the "dynamic_deps" attribute,
  576. // instead of putting lib_a and lib_b directly into dynamic_deps without a
  577. // select:
  578. //
  579. // dynamic_deps = select({
  580. // "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": [],
  581. // "//conditions:default": [
  582. // "//foo/bar:lib_a",
  583. // "//foo/bar:lib_b",
  584. // ],
  585. // }),
  586. func (props *ProductConfigProperties) zeroValuesForNamespacedVariables() {
  587. // A map of product config properties to the zero values of their respective
  588. // property value.
  589. zeroValues := make(map[ProductConfigProperty]interface{})
  590. // A map of prop names (e.g. cflags) to product config properties where the
  591. // (prop name, ProductConfigProperty) tuple contains a non-conditions_default key.
  592. //
  593. // e.g.
  594. //
  595. // prefer_static: {
  596. // static_libs: [
  597. // "lib_a",
  598. // "lib_b",
  599. // ],
  600. // },
  601. // conditions_default: {
  602. // shared_libs: [
  603. // "lib_a",
  604. // "lib_b",
  605. // ],
  606. // },
  607. //
  608. // The tuple of ("static_libs", prefer_static) would be in this map.
  609. hasNonDefaultValue := make(map[string]map[ProductConfigProperty]bool)
  610. // Iterate over all added soong config variables.
  611. for propName, v := range *props {
  612. for p, intf := range v {
  613. if p.Namespace == "" {
  614. // If there's no namespace, this isn't a soong config variable,
  615. // i.e. this is a product variable. product variables have no
  616. // conditions_defaults, so skip them.
  617. continue
  618. }
  619. if p.FullConfig == bazel.ConditionsDefaultConfigKey {
  620. // Skip conditions_defaults.
  621. continue
  622. }
  623. if hasNonDefaultValue[propName] == nil {
  624. hasNonDefaultValue[propName] = make(map[ProductConfigProperty]bool)
  625. hasNonDefaultValue[propName][p] = false
  626. }
  627. // Create the zero value of the variable.
  628. if _, exists := zeroValues[p]; !exists {
  629. zeroValue := reflect.Zero(reflect.ValueOf(intf).Type()).Interface()
  630. if zeroValue == nil {
  631. panic(fmt.Errorf("Expected non-nil zero value for product/config variable %+v\n", intf))
  632. }
  633. zeroValues[p] = zeroValue
  634. }
  635. hasNonDefaultValue[propName][p] = true
  636. }
  637. }
  638. for propName := range *props {
  639. for p, zeroValue := range zeroValues {
  640. // Ignore variables that already have a non-default value for that axis
  641. if exists, _ := hasNonDefaultValue[propName][p]; !exists {
  642. // fmt.Println(propName, p.Namespace, p.Name, p.FullConfig, zeroValue)
  643. // Insert the zero value for this propname + product config value.
  644. props.AddProductConfigProperty(
  645. propName,
  646. p.Namespace,
  647. p.Name,
  648. p.FullConfig,
  649. zeroValue,
  650. )
  651. }
  652. }
  653. }
  654. }
  655. func (p *ProductConfigProperties) AddProductConfigProperty(
  656. propertyName, namespace, productVariableName, config string, property interface{}) {
  657. if (*p)[propertyName] == nil {
  658. (*p)[propertyName] = make(map[ProductConfigProperty]interface{})
  659. }
  660. productConfigProp := ProductConfigProperty{
  661. Namespace: namespace, // e.g. acme, android
  662. Name: productVariableName, // e.g. size, feature1, feature2, FEATURE3, board
  663. FullConfig: config, // e.g. size, feature1-x86, size__conditions_default
  664. }
  665. if existing, ok := (*p)[propertyName][productConfigProp]; ok && namespace != "" {
  666. switch dst := existing.(type) {
  667. case []string:
  668. if src, ok := property.([]string); ok {
  669. dst = append(dst, src...)
  670. (*p)[propertyName][productConfigProp] = dst
  671. }
  672. default:
  673. panic(fmt.Errorf("TODO: handle merging value %s", existing))
  674. }
  675. } else {
  676. (*p)[propertyName][productConfigProp] = property
  677. }
  678. }
  679. var (
  680. conditionsDefaultField string = proptools.FieldNameForProperty(bazel.ConditionsDefaultConfigKey)
  681. )
  682. // maybeExtractConfigVarProp attempts to read this value as a config var struct
  683. // wrapped by interfaces and ptrs. If it's not the right type, the second return
  684. // value is false.
  685. func maybeExtractConfigVarProp(v reflect.Value) (reflect.Value, bool) {
  686. if v.Kind() == reflect.Interface {
  687. // The conditions_default value can be either
  688. // 1) an ptr to an interface of a struct (bool config variables and product variables)
  689. // 2) an interface of 1) (config variables with nested structs, like string vars)
  690. v = v.Elem()
  691. }
  692. if v.Kind() != reflect.Ptr {
  693. return v, false
  694. }
  695. v = reflect.Indirect(v)
  696. if v.Kind() == reflect.Interface {
  697. // Extract the struct from the interface
  698. v = v.Elem()
  699. }
  700. if !v.IsValid() {
  701. return v, false
  702. }
  703. if v.Kind() != reflect.Struct {
  704. return v, false
  705. }
  706. return v, true
  707. }
  708. func (productConfigProperties *ProductConfigProperties) AddProductConfigProperties(namespace, suffix string, variableValues reflect.Value) {
  709. // variableValues can either be a product_variables or
  710. // soong_config_variables struct.
  711. //
  712. // Example of product_variables:
  713. //
  714. // product_variables: {
  715. // malloc_not_svelte: {
  716. // shared_libs: ["malloc_not_svelte_shared_lib"],
  717. // whole_static_libs: ["malloc_not_svelte_whole_static_lib"],
  718. // exclude_static_libs: [
  719. // "malloc_not_svelte_static_lib_excludes",
  720. // "malloc_not_svelte_whole_static_lib_excludes",
  721. // ],
  722. // },
  723. // },
  724. //
  725. // Example of soong_config_variables:
  726. //
  727. // soong_config_variables: {
  728. // feature1: {
  729. // conditions_default: {
  730. // ...
  731. // },
  732. // cflags: ...
  733. // },
  734. // feature2: {
  735. // cflags: ...
  736. // conditions_default: {
  737. // ...
  738. // },
  739. // },
  740. // board: {
  741. // soc_a: {
  742. // ...
  743. // },
  744. // soc_a: {
  745. // ...
  746. // },
  747. // soc_c: {},
  748. // conditions_default: {
  749. // ...
  750. // },
  751. // },
  752. // }
  753. for i := 0; i < variableValues.NumField(); i++ {
  754. // e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc.
  755. productVariableName := variableValues.Type().Field(i).Name
  756. variableValue := variableValues.Field(i)
  757. // Check if any properties were set for the module
  758. if variableValue.IsZero() {
  759. // e.g. feature1: {}, malloc_not_svelte: {}
  760. continue
  761. }
  762. // Unlike product variables, config variables require a few more
  763. // indirections to extract the struct from the reflect.Value.
  764. if v, ok := maybeExtractConfigVarProp(variableValue); ok {
  765. variableValue = v
  766. }
  767. for j := 0; j < variableValue.NumField(); j++ {
  768. property := variableValue.Field(j)
  769. // If the property wasn't set, no need to pass it along
  770. if property.IsZero() {
  771. continue
  772. }
  773. // e.g. Asflags, Cflags, Enabled, etc.
  774. propertyName := variableValue.Type().Field(j).Name
  775. if v, ok := maybeExtractConfigVarProp(property); ok {
  776. // The field is a struct, which is used by:
  777. // 1) soong_config_string_variables
  778. //
  779. // soc_a: {
  780. // cflags: ...,
  781. // }
  782. //
  783. // soc_b: {
  784. // cflags: ...,
  785. // }
  786. //
  787. // 2) conditions_default structs for all soong config variable types.
  788. //
  789. // conditions_default: {
  790. // cflags: ...,
  791. // static_libs: ...
  792. // }
  793. field := v
  794. for k := 0; k < field.NumField(); k++ {
  795. // Iterate over fields of this struct prop.
  796. if field.Field(k).IsZero() {
  797. continue
  798. }
  799. // config can also be "conditions_default".
  800. config := proptools.PropertyNameForField(propertyName)
  801. actualPropertyName := field.Type().Field(k).Name
  802. productConfigProperties.AddProductConfigProperty(
  803. actualPropertyName, // e.g. cflags, static_libs
  804. namespace, // e.g. acme, android
  805. productVariableName, // e.g. size, feature1, FEATURE2, board
  806. config,
  807. field.Field(k).Interface(), // e.g. ["-DDEFAULT"], ["foo", "bar"]
  808. )
  809. }
  810. } else if property.Kind() != reflect.Interface {
  811. // If not an interface, then this is not a conditions_default or
  812. // a struct prop. That is, this is a regular product variable,
  813. // or a bool/value config variable.
  814. config := productVariableName + suffix
  815. productConfigProperties.AddProductConfigProperty(
  816. propertyName,
  817. namespace,
  818. productVariableName,
  819. config,
  820. property.Interface(),
  821. )
  822. }
  823. }
  824. }
  825. }
  826. // productVariableValues uses reflection to convert a property struct for
  827. // product_variables and soong_config_variables to structs that can be generated
  828. // as select statements.
  829. func productVariableValues(
  830. fieldName string, variableProps interface{}, namespace, suffix string, productConfigProperties *ProductConfigProperties) {
  831. if suffix != "" {
  832. suffix = "-" + suffix
  833. }
  834. // variableValues represent the product_variables or soong_config_variables struct.
  835. variableValues := reflect.ValueOf(variableProps).Elem().FieldByName(fieldName)
  836. productConfigProperties.AddProductConfigProperties(namespace, suffix, variableValues)
  837. }
  838. func VariableMutator(mctx BottomUpMutatorContext) {
  839. var module Module
  840. var ok bool
  841. if module, ok = mctx.Module().(Module); !ok {
  842. return
  843. }
  844. // TODO: depend on config variable, create variants, propagate variants up tree
  845. a := module.base()
  846. if a.variableProperties == nil {
  847. return
  848. }
  849. variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
  850. productVariables := reflect.ValueOf(mctx.Config().productVariables)
  851. for i := 0; i < variableValues.NumField(); i++ {
  852. variableValue := variableValues.Field(i)
  853. name := variableValues.Type().Field(i).Name
  854. property := "product_variables." + proptools.PropertyNameForField(name)
  855. // Check that the variable was set for the product
  856. val := productVariables.FieldByName(name)
  857. if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() {
  858. continue
  859. }
  860. val = val.Elem()
  861. // For bools, check that the value is true
  862. if val.Kind() == reflect.Bool && val.Bool() == false {
  863. continue
  864. }
  865. // Check if any properties were set for the module
  866. if variableValue.IsZero() {
  867. continue
  868. }
  869. a.setVariableProperties(mctx, property, variableValue, val.Interface())
  870. }
  871. }
  872. func (m *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext,
  873. prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) {
  874. printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue)
  875. err := proptools.AppendMatchingProperties(m.GetProperties(),
  876. productVariablePropertyValue.Addr().Interface(), nil)
  877. if err != nil {
  878. if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
  879. ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
  880. } else {
  881. panic(err)
  882. }
  883. }
  884. }
  885. func printfIntoPropertiesError(ctx BottomUpMutatorContext, prefix string,
  886. productVariablePropertyValue reflect.Value, i int, err error) {
  887. field := productVariablePropertyValue.Type().Field(i).Name
  888. property := prefix + "." + proptools.PropertyNameForField(field)
  889. ctx.PropertyErrorf(property, "%s", err)
  890. }
  891. func printfIntoProperties(ctx BottomUpMutatorContext, prefix string,
  892. productVariablePropertyValue reflect.Value, variableValue interface{}) {
  893. for i := 0; i < productVariablePropertyValue.NumField(); i++ {
  894. propertyValue := productVariablePropertyValue.Field(i)
  895. kind := propertyValue.Kind()
  896. if kind == reflect.Ptr {
  897. if propertyValue.IsNil() {
  898. continue
  899. }
  900. propertyValue = propertyValue.Elem()
  901. }
  902. switch propertyValue.Kind() {
  903. case reflect.String:
  904. err := printfIntoProperty(propertyValue, variableValue)
  905. if err != nil {
  906. printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
  907. }
  908. case reflect.Slice:
  909. for j := 0; j < propertyValue.Len(); j++ {
  910. err := printfIntoProperty(propertyValue.Index(j), variableValue)
  911. if err != nil {
  912. printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
  913. }
  914. }
  915. case reflect.Bool:
  916. // Nothing
  917. case reflect.Struct:
  918. printfIntoProperties(ctx, prefix, propertyValue, variableValue)
  919. default:
  920. panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind()))
  921. }
  922. }
  923. }
  924. func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) error {
  925. s := propertyValue.String()
  926. count := strings.Count(s, "%")
  927. if count == 0 {
  928. return nil
  929. }
  930. if count > 1 {
  931. return fmt.Errorf("product variable properties only support a single '%%'")
  932. }
  933. if strings.Contains(s, "%d") {
  934. switch v := variableValue.(type) {
  935. case int:
  936. // Nothing
  937. case bool:
  938. if v {
  939. variableValue = 1
  940. } else {
  941. variableValue = 0
  942. }
  943. default:
  944. return fmt.Errorf("unsupported type %T for %%d", variableValue)
  945. }
  946. } else if strings.Contains(s, "%s") {
  947. switch variableValue.(type) {
  948. case string:
  949. // Nothing
  950. default:
  951. return fmt.Errorf("unsupported type %T for %%s", variableValue)
  952. }
  953. } else {
  954. return fmt.Errorf("unsupported %% in product variable property")
  955. }
  956. propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, variableValue)))
  957. return nil
  958. }
  959. var variablePropTypeMap OncePer
  960. // sliceToTypeArray takes a slice of property structs and returns a reflection created array containing the
  961. // reflect.Types of each property struct. The result can be used as a key in a map.
  962. func sliceToTypeArray(s []interface{}) interface{} {
  963. // Create an array using reflection whose length is the length of the input slice
  964. ret := reflect.New(reflect.ArrayOf(len(s), reflect.TypeOf(reflect.TypeOf(0)))).Elem()
  965. for i, e := range s {
  966. ret.Index(i).Set(reflect.ValueOf(reflect.TypeOf(e)))
  967. }
  968. return ret.Interface()
  969. }
  970. func initProductVariableModule(m Module) {
  971. base := m.base()
  972. // Allow tests to override the default product variables
  973. if base.variableProperties == nil {
  974. base.variableProperties = defaultProductVariables
  975. }
  976. // Filter the product variables properties to the ones that exist on this module
  977. base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
  978. if base.variableProperties != nil {
  979. m.AddProperties(base.variableProperties)
  980. }
  981. }
  982. // createVariableProperties takes the list of property structs for a module and returns a property struct that
  983. // contains the product variable properties that exist in the property structs, or nil if there are none. It
  984. // caches the result.
  985. func createVariableProperties(moduleTypeProps []interface{}, productVariables interface{}) interface{} {
  986. // Convert the moduleTypeProps to an array of reflect.Types that can be used as a key in the OncePer.
  987. key := sliceToTypeArray(moduleTypeProps)
  988. // Use the variablePropTypeMap OncePer to cache the result for each set of property struct types.
  989. typ, _ := variablePropTypeMap.Once(NewCustomOnceKey(key), func() interface{} {
  990. // Compute the filtered property struct type.
  991. return createVariablePropertiesType(moduleTypeProps, productVariables)
  992. }).(reflect.Type)
  993. if typ == nil {
  994. return nil
  995. }
  996. // Create a new pointer to a filtered property struct.
  997. return reflect.New(typ).Interface()
  998. }
  999. // createVariablePropertiesType creates a new type that contains only the product variable properties that exist in
  1000. // a list of property structs.
  1001. func createVariablePropertiesType(moduleTypeProps []interface{}, productVariables interface{}) reflect.Type {
  1002. typ, _ := proptools.FilterPropertyStruct(reflect.TypeOf(productVariables),
  1003. func(field reflect.StructField, prefix string) (bool, reflect.StructField) {
  1004. // Filter function, returns true if the field should be in the resulting struct
  1005. if prefix == "" {
  1006. // Keep the top level Product_variables field
  1007. return true, field
  1008. }
  1009. _, rest := splitPrefix(prefix)
  1010. if rest == "" {
  1011. // Keep the 2nd level field (i.e. Product_variables.Eng)
  1012. return true, field
  1013. }
  1014. // Strip off the first 2 levels of the prefix
  1015. _, prefix = splitPrefix(rest)
  1016. for _, p := range moduleTypeProps {
  1017. if fieldExistsByNameRecursive(reflect.TypeOf(p).Elem(), prefix, field.Name) {
  1018. // Keep any fields that exist in one of the property structs
  1019. return true, field
  1020. }
  1021. }
  1022. return false, field
  1023. })
  1024. return typ
  1025. }
  1026. func splitPrefix(prefix string) (first, rest string) {
  1027. index := strings.IndexByte(prefix, '.')
  1028. if index == -1 {
  1029. return prefix, ""
  1030. }
  1031. return prefix[:index], prefix[index+1:]
  1032. }
  1033. func fieldExistsByNameRecursive(t reflect.Type, prefix, name string) bool {
  1034. if t.Kind() != reflect.Struct {
  1035. panic(fmt.Errorf("fieldExistsByNameRecursive can only be called on a reflect.Struct"))
  1036. }
  1037. if prefix != "" {
  1038. split := strings.SplitN(prefix, ".", 2)
  1039. firstPrefix := split[0]
  1040. rest := ""
  1041. if len(split) > 1 {
  1042. rest = split[1]
  1043. }
  1044. f, exists := t.FieldByName(firstPrefix)
  1045. if !exists {
  1046. return false
  1047. }
  1048. ft := f.Type
  1049. if ft.Kind() == reflect.Ptr {
  1050. ft = ft.Elem()
  1051. }
  1052. if ft.Kind() != reflect.Struct {
  1053. panic(fmt.Errorf("field %q in %q is not a struct", firstPrefix, t))
  1054. }
  1055. return fieldExistsByNameRecursive(ft, rest, name)
  1056. } else {
  1057. _, exists := t.FieldByName(name)
  1058. return exists
  1059. }
  1060. }