blob: 27a7003279a7d6f6907aa5433ac2b97cbd9c3fb5 [file] [log] [blame]
Jiyong Park9b409bc2019-10-11 14:59:13 +09001// Copyright (C) 2019 The Android Open Source Project
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
15package sdk
16
17import (
18 "fmt"
Paul Duffinb645ec82019-11-27 17:43:54 +000019 "reflect"
Paul Duffina04c1072020-03-02 10:16:35 +000020 "sort"
Jiyong Park9b409bc2019-10-11 14:59:13 +090021 "strings"
22
Paul Duffin375058f2019-11-29 20:17:53 +000023 "github.com/google/blueprint"
Jiyong Park9b409bc2019-10-11 14:59:13 +090024 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
Jiyong Park9b409bc2019-10-11 14:59:13 +090027)
28
29var pctx = android.NewPackageContext("android/soong/sdk")
30
Paul Duffin375058f2019-11-29 20:17:53 +000031var (
32 repackageZip = pctx.AndroidStaticRule("SnapshotRepackageZip",
33 blueprint.RuleParams{
Paul Duffince482dc2019-12-09 19:58:17 +000034 Command: `${config.Zip2ZipCmd} -i $in -o $out -x META-INF/**/* "**/*:$destdir"`,
Paul Duffin375058f2019-11-29 20:17:53 +000035 CommandDeps: []string{
36 "${config.Zip2ZipCmd}",
37 },
38 },
39 "destdir")
40
41 zipFiles = pctx.AndroidStaticRule("SnapshotZipFiles",
42 blueprint.RuleParams{
43 Command: `${config.SoongZipCmd} -C $basedir -l $out.rsp -o $out`,
44 CommandDeps: []string{
45 "${config.SoongZipCmd}",
46 },
47 Rspfile: "$out.rsp",
48 RspfileContent: "$in",
49 },
50 "basedir")
51
52 mergeZips = pctx.AndroidStaticRule("SnapshotMergeZips",
53 blueprint.RuleParams{
54 Command: `${config.MergeZipsCmd} $out $in`,
55 CommandDeps: []string{
56 "${config.MergeZipsCmd}",
57 },
58 })
59)
60
Paul Duffinb645ec82019-11-27 17:43:54 +000061type generatedContents struct {
Jiyong Park73c54ee2019-10-22 20:31:18 +090062 content strings.Builder
63 indentLevel int
Jiyong Park9b409bc2019-10-11 14:59:13 +090064}
65
Paul Duffinb645ec82019-11-27 17:43:54 +000066// generatedFile abstracts operations for writing contents into a file and emit a build rule
67// for the file.
68type generatedFile struct {
69 generatedContents
70 path android.OutputPath
71}
72
Jiyong Park232e7852019-11-04 12:23:40 +090073func newGeneratedFile(ctx android.ModuleContext, path ...string) *generatedFile {
Jiyong Park9b409bc2019-10-11 14:59:13 +090074 return &generatedFile{
Paul Duffinb645ec82019-11-27 17:43:54 +000075 path: android.PathForModuleOut(ctx, path...).OutputPath,
Jiyong Park9b409bc2019-10-11 14:59:13 +090076 }
77}
78
Paul Duffinb645ec82019-11-27 17:43:54 +000079func (gc *generatedContents) Indent() {
80 gc.indentLevel++
Jiyong Park73c54ee2019-10-22 20:31:18 +090081}
82
Paul Duffinb645ec82019-11-27 17:43:54 +000083func (gc *generatedContents) Dedent() {
84 gc.indentLevel--
Jiyong Park73c54ee2019-10-22 20:31:18 +090085}
86
Paul Duffinb645ec82019-11-27 17:43:54 +000087func (gc *generatedContents) Printfln(format string, args ...interface{}) {
Jiyong Park9b409bc2019-10-11 14:59:13 +090088 // ninja consumes newline characters in rspfile_content. Prevent it by
Paul Duffin0e0cf1d2019-11-12 19:39:25 +000089 // escaping the backslash in the newline character. The extra backslash
Jiyong Park9b409bc2019-10-11 14:59:13 +090090 // is removed when the rspfile is written to the actual script file
Paul Duffinb645ec82019-11-27 17:43:54 +000091 fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format+"\\n", args...)
Jiyong Park9b409bc2019-10-11 14:59:13 +090092}
93
94func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderContext, implicits android.Paths) {
95 rb := android.NewRuleBuilder()
96 // convert \\n to \n
97 rb.Command().
98 Implicits(implicits).
99 Text("echo").Text(proptools.ShellEscape(gf.content.String())).
100 Text("| sed 's/\\\\n/\\n/g' >").Output(gf.path)
101 rb.Command().
102 Text("chmod a+x").Output(gf.path)
103 rb.Build(pctx, ctx, gf.path.Base(), "Build "+gf.path.Base())
104}
105
Paul Duffin13879572019-11-28 14:31:38 +0000106// Collect all the members.
107//
Paul Duffin1356d8c2020-02-25 19:26:33 +0000108// Returns a list containing type (extracted from the dependency tag) and the variant.
109func (s *sdk) collectMembers(ctx android.ModuleContext) []sdkMemberRef {
110 var memberRefs []sdkMemberRef
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000111 ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
112 tag := ctx.OtherModuleDependencyTag(child)
Paul Duffinf8539922019-11-19 19:44:10 +0000113 if memberTag, ok := tag.(android.SdkMemberTypeDependencyTag); ok {
114 memberType := memberTag.SdkMemberType()
Jiyong Park9b409bc2019-10-11 14:59:13 +0900115
Paul Duffin13879572019-11-28 14:31:38 +0000116 // Make sure that the resolved module is allowed in the member list property.
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000117 if !memberType.IsInstance(child) {
118 ctx.ModuleErrorf("module %q is not valid in property %s", ctx.OtherModuleName(child), memberType.SdkPropertyName())
Jiyong Park73c54ee2019-10-22 20:31:18 +0900119 }
Paul Duffin13879572019-11-28 14:31:38 +0000120
Paul Duffin1356d8c2020-02-25 19:26:33 +0000121 memberRefs = append(memberRefs, sdkMemberRef{memberType, child.(android.SdkAware)})
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000122
123 // If the member type supports transitive sdk members then recurse down into
124 // its dependencies, otherwise exit traversal.
125 return memberType.HasTransitiveSdkMembers()
Jiyong Park73c54ee2019-10-22 20:31:18 +0900126 }
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000127
128 return false
Paul Duffin13879572019-11-28 14:31:38 +0000129 })
130
Paul Duffin1356d8c2020-02-25 19:26:33 +0000131 return memberRefs
132}
133
134// Organize the members.
135//
136// The members are first grouped by type and then grouped by name. The order of
137// the types is the order they are referenced in android.SdkMemberTypesRegistry.
138// The names are in the order in which the dependencies were added.
139//
140// Returns the members as well as the multilib setting to use.
141func (s *sdk) organizeMembers(ctx android.ModuleContext, memberRefs []sdkMemberRef) ([]*sdkMember, string) {
142 byType := make(map[android.SdkMemberType][]*sdkMember)
143 byName := make(map[string]*sdkMember)
144
145 lib32 := false // True if any of the members have 32 bit version.
146 lib64 := false // True if any of the members have 64 bit version.
147
148 for _, memberRef := range memberRefs {
149 memberType := memberRef.memberType
150 variant := memberRef.variant
151
152 name := ctx.OtherModuleName(variant)
153 member := byName[name]
154 if member == nil {
155 member = &sdkMember{memberType: memberType, name: name}
156 byName[name] = member
157 byType[memberType] = append(byType[memberType], member)
158 }
159
160 multilib := variant.Target().Arch.ArchType.Multilib
161 if multilib == "lib32" {
162 lib32 = true
163 } else if multilib == "lib64" {
164 lib64 = true
165 }
166
167 // Only append new variants to the list. This is needed because a member can be both
168 // exported by the sdk and also be a transitive sdk member.
169 member.variants = appendUniqueVariants(member.variants, variant)
170 }
171
Paul Duffin13879572019-11-28 14:31:38 +0000172 var members []*sdkMember
Paul Duffin72910952020-01-20 18:16:30 +0000173 for _, memberListProperty := range s.memberListProperties() {
Paul Duffin13879572019-11-28 14:31:38 +0000174 membersOfType := byType[memberListProperty.memberType]
175 members = append(members, membersOfType...)
Jiyong Park9b409bc2019-10-11 14:59:13 +0900176 }
177
Paul Duffin13ad94f2020-02-19 16:19:27 +0000178 // Compute the setting of multilib.
179 var multilib string
180 if lib32 && lib64 {
181 multilib = "both"
182 } else if lib32 {
183 multilib = "32"
184 } else if lib64 {
185 multilib = "64"
186 }
187
188 return members, multilib
Jiyong Park73c54ee2019-10-22 20:31:18 +0900189}
Jiyong Park9b409bc2019-10-11 14:59:13 +0900190
Paul Duffin72910952020-01-20 18:16:30 +0000191func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware {
192 for _, v := range variants {
193 if v == newVariant {
194 return variants
195 }
196 }
197 return append(variants, newVariant)
198}
199
Jiyong Park73c54ee2019-10-22 20:31:18 +0900200// SDK directory structure
201// <sdk_root>/
202// Android.bp : definition of a 'sdk' module is here. This is a hand-made one.
203// <api_ver>/ : below this directory are all auto-generated
204// Android.bp : definition of 'sdk_snapshot' module is here
205// aidl/
206// frameworks/base/core/..../IFoo.aidl : an exported AIDL file
207// java/
Jiyong Park232e7852019-11-04 12:23:40 +0900208// <module_name>.jar : the stub jar for a java library 'module_name'
Jiyong Park73c54ee2019-10-22 20:31:18 +0900209// include/
210// bionic/libc/include/stdlib.h : an exported header file
211// include_gen/
Jiyong Park232e7852019-11-04 12:23:40 +0900212// <module_name>/com/android/.../IFoo.h : a generated header file
Jiyong Park73c54ee2019-10-22 20:31:18 +0900213// <arch>/include/ : arch-specific exported headers
214// <arch>/include_gen/ : arch-specific generated headers
215// <arch>/lib/
216// libFoo.so : a stub library
217
Jiyong Park232e7852019-11-04 12:23:40 +0900218// A name that uniquely identifies a prebuilt SDK member for a version of SDK snapshot
Jiyong Park73c54ee2019-10-22 20:31:18 +0900219// This isn't visible to users, so could be changed in future.
220func versionedSdkMemberName(ctx android.ModuleContext, memberName string, version string) string {
221 return ctx.ModuleName() + "_" + memberName + string(android.SdkVersionSeparator) + version
222}
223
Jiyong Park232e7852019-11-04 12:23:40 +0900224// buildSnapshot is the main function in this source file. It creates rules to copy
225// the contents (header files, stub libraries, etc) into the zip file.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000226func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) android.OutputPath {
227
Paul Duffin865171e2020-03-02 18:38:15 +0000228 exportedMembers := make(map[string]struct{})
Paul Duffin1356d8c2020-02-25 19:26:33 +0000229 var memberRefs []sdkMemberRef
230 for _, sdkVariant := range sdkVariants {
231 memberRefs = append(memberRefs, sdkVariant.memberRefs...)
Paul Duffin865171e2020-03-02 18:38:15 +0000232
233 // Merge the exported member sets from all sdk variants.
234 for key, _ := range sdkVariant.getExportedMembers() {
235 exportedMembers[key] = struct{}{}
236 }
Paul Duffin1356d8c2020-02-25 19:26:33 +0000237 }
Paul Duffin865171e2020-03-02 18:38:15 +0000238 s.exportedMembers = exportedMembers
Paul Duffin1356d8c2020-02-25 19:26:33 +0000239
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000240 snapshotDir := android.PathForModuleOut(ctx, "snapshot")
Jiyong Park9b409bc2019-10-11 14:59:13 +0900241
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000242 bp := newGeneratedFile(ctx, "snapshot", "Android.bp")
Paul Duffinb645ec82019-11-27 17:43:54 +0000243
244 bpFile := &bpFile{
245 modules: make(map[string]*bpModule),
246 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000247
248 builder := &snapshotBuilder{
Paul Duffinb645ec82019-11-27 17:43:54 +0000249 ctx: ctx,
Paul Duffine44358f2019-11-26 18:04:12 +0000250 sdk: s,
Paul Duffinb645ec82019-11-27 17:43:54 +0000251 version: "current",
252 snapshotDir: snapshotDir.OutputPath,
Paul Duffinc62a5102019-12-11 18:34:15 +0000253 copies: make(map[string]string),
Paul Duffinb645ec82019-11-27 17:43:54 +0000254 filesToZip: []android.Path{bp.path},
255 bpFile: bpFile,
256 prebuiltModules: make(map[string]*bpModule),
Jiyong Park73c54ee2019-10-22 20:31:18 +0900257 }
Paul Duffinac37c502019-11-26 18:02:20 +0000258 s.builderForTests = builder
Jiyong Park9b409bc2019-10-11 14:59:13 +0900259
Paul Duffin1356d8c2020-02-25 19:26:33 +0000260 members, multilib := s.organizeMembers(ctx, memberRefs)
Paul Duffin13ad94f2020-02-19 16:19:27 +0000261 for _, member := range members {
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000262 memberType := member.memberType
263 prebuiltModule := memberType.AddPrebuiltModule(ctx, builder, member)
264 if prebuiltModule == nil {
265 // Fall back to legacy method of building a snapshot
266 memberType.BuildSnapshot(ctx, builder, member)
267 } else {
268 s.createMemberSnapshot(ctx, builder, member, prebuiltModule)
269 }
Jiyong Park73c54ee2019-10-22 20:31:18 +0900270 }
Jiyong Park9b409bc2019-10-11 14:59:13 +0900271
Paul Duffine6c0d842020-01-15 14:08:51 +0000272 // Create a transformer that will transform an unversioned module into a versioned module.
273 unversionedToVersionedTransformer := unversionedToVersionedTransformation{builder: builder}
274
Paul Duffin72910952020-01-20 18:16:30 +0000275 // Create a transformer that will transform an unversioned module by replacing any references
276 // to internal members with a unique module name and setting prefer: false.
277 unversionedTransformer := unversionedTransformation{builder: builder}
278
Paul Duffinb645ec82019-11-27 17:43:54 +0000279 for _, unversioned := range builder.prebuiltOrder {
Paul Duffina78f3a72020-02-21 16:29:35 +0000280 // Prune any empty property sets.
281 unversioned = unversioned.transform(pruneEmptySetTransformer{})
282
Paul Duffinb645ec82019-11-27 17:43:54 +0000283 // Copy the unversioned module so it can be modified to make it versioned.
Paul Duffincc72e982020-01-14 15:53:11 +0000284 versioned := unversioned.deepCopy()
Paul Duffine6c0d842020-01-15 14:08:51 +0000285
286 // Transform the unversioned module into a versioned one.
287 versioned.transform(unversionedToVersionedTransformer)
Paul Duffinb645ec82019-11-27 17:43:54 +0000288 bpFile.AddModule(versioned)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000289
Paul Duffin72910952020-01-20 18:16:30 +0000290 // Transform the unversioned module to make it suitable for use in the snapshot.
291 unversioned.transform(unversionedTransformer)
Paul Duffinb645ec82019-11-27 17:43:54 +0000292 bpFile.AddModule(unversioned)
293 }
294
295 // Create the snapshot module.
296 snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version
Paul Duffin8150da62019-12-16 17:21:27 +0000297 var snapshotModuleType string
298 if s.properties.Module_exports {
299 snapshotModuleType = "module_exports_snapshot"
300 } else {
301 snapshotModuleType = "sdk_snapshot"
302 }
303 snapshotModule := bpFile.newModule(snapshotModuleType)
Paul Duffinb645ec82019-11-27 17:43:54 +0000304 snapshotModule.AddProperty("name", snapshotName)
Paul Duffin593b3c92019-12-05 14:31:48 +0000305
306 // Make sure that the snapshot has the same visibility as the sdk.
307 visibility := android.EffectiveVisibilityRules(ctx, s)
308 if len(visibility) != 0 {
309 snapshotModule.AddProperty("visibility", visibility)
310 }
311
Paul Duffin865171e2020-03-02 18:38:15 +0000312 addHostDeviceSupportedProperties(s.ModuleBase.DeviceSupported(), s.ModuleBase.HostSupported(), snapshotModule)
Paul Duffin13ad94f2020-02-19 16:19:27 +0000313
314 // Compile_multilib defaults to both and must always be set to both on the
315 // device and so only needs to be set when targeted at the host and is neither
316 // unspecified or both.
Paul Duffin865171e2020-03-02 18:38:15 +0000317 targetPropertySet := snapshotModule.AddPropertySet("target")
Paul Duffin13ad94f2020-02-19 16:19:27 +0000318 if s.HostSupported() && multilib != "" && multilib != "both" {
Paul Duffin865171e2020-03-02 18:38:15 +0000319 hostSet := targetPropertySet.AddPropertySet("host")
Paul Duffin13ad94f2020-02-19 16:19:27 +0000320 hostSet.AddProperty("compile_multilib", multilib)
321 }
322
Paul Duffin865171e2020-03-02 18:38:15 +0000323 var dynamicMemberPropertiesList []interface{}
324 osTypeToMemberProperties := make(map[android.OsType]*sdk)
325 for _, sdkVariant := range sdkVariants {
326 properties := sdkVariant.dynamicMemberTypeListProperties
327 osTypeToMemberProperties[sdkVariant.Target().Os] = sdkVariant
328 dynamicMemberPropertiesList = append(dynamicMemberPropertiesList, properties)
329 }
330
331 // Extract the common lists of members into a separate struct.
332 commonDynamicMemberProperties := s.dynamicSdkMemberTypes.createMemberListProperties()
333 extractCommonProperties(commonDynamicMemberProperties, dynamicMemberPropertiesList)
334
335 // Add properties common to all os types.
336 s.addMemberPropertiesToPropertySet(builder, snapshotModule, commonDynamicMemberProperties)
337
338 // Iterate over the os types in a fixed order.
339 for _, osType := range s.getPossibleOsTypes() {
340 if sdkVariant, ok := osTypeToMemberProperties[osType]; ok {
341 osPropertySet := targetPropertySet.AddPropertySet(sdkVariant.Target().Os.Name)
342 s.addMemberPropertiesToPropertySet(builder, osPropertySet, sdkVariant.dynamicMemberTypeListProperties)
Paul Duffin13879572019-11-28 14:31:38 +0000343 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000344 }
Paul Duffin865171e2020-03-02 18:38:15 +0000345
346 // Prune any empty property sets.
347 snapshotModule.transform(pruneEmptySetTransformer{})
348
Paul Duffinb645ec82019-11-27 17:43:54 +0000349 bpFile.AddModule(snapshotModule)
350
351 // generate Android.bp
352 bp = newGeneratedFile(ctx, "snapshot", "Android.bp")
353 generateBpContents(&bp.generatedContents, bpFile)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000354
355 bp.build(pctx, ctx, nil)
356
357 filesToZip := builder.filesToZip
Jiyong Park9b409bc2019-10-11 14:59:13 +0900358
Jiyong Park232e7852019-11-04 12:23:40 +0900359 // zip them all
Paul Duffin91547182019-11-12 19:39:36 +0000360 outputZipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000361 outputDesc := "Building snapshot for " + ctx.ModuleName()
362
363 // If there are no zips to merge then generate the output zip directly.
364 // Otherwise, generate an intermediate zip file into which other zips can be
365 // merged.
366 var zipFile android.OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000367 var desc string
368 if len(builder.zipsToMerge) == 0 {
369 zipFile = outputZipFile
Paul Duffin91547182019-11-12 19:39:36 +0000370 desc = outputDesc
371 } else {
372 zipFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.unmerged.zip").OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000373 desc = "Building intermediate snapshot for " + ctx.ModuleName()
374 }
375
Paul Duffin375058f2019-11-29 20:17:53 +0000376 ctx.Build(pctx, android.BuildParams{
377 Description: desc,
378 Rule: zipFiles,
379 Inputs: filesToZip,
380 Output: zipFile,
381 Args: map[string]string{
382 "basedir": builder.snapshotDir.String(),
383 },
384 })
Jiyong Park9b409bc2019-10-11 14:59:13 +0900385
Paul Duffin91547182019-11-12 19:39:36 +0000386 if len(builder.zipsToMerge) != 0 {
Paul Duffin375058f2019-11-29 20:17:53 +0000387 ctx.Build(pctx, android.BuildParams{
388 Description: outputDesc,
389 Rule: mergeZips,
390 Input: zipFile,
391 Inputs: builder.zipsToMerge,
392 Output: outputZipFile,
393 })
Paul Duffin91547182019-11-12 19:39:36 +0000394 }
395
396 return outputZipFile
Jiyong Park9b409bc2019-10-11 14:59:13 +0900397}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000398
Paul Duffin865171e2020-03-02 18:38:15 +0000399func (s *sdk) addMemberPropertiesToPropertySet(builder *snapshotBuilder, propertySet android.BpPropertySet, dynamicMemberTypeListProperties interface{}) {
400 for _, memberListProperty := range s.memberListProperties() {
401 names := memberListProperty.getter(dynamicMemberTypeListProperties)
402 if len(names) > 0 {
403 propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names))
404 }
405 }
406}
407
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000408type propertyTag struct {
409 name string
410}
411
Paul Duffin0cb37b92020-03-04 14:52:46 +0000412// A BpPropertyTag to add to a property that contains references to other sdk members.
413//
414// This will cause the references to be rewritten to a versioned reference in the version
415// specific instance of a snapshot module.
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000416var sdkMemberReferencePropertyTag = propertyTag{"sdkMemberReferencePropertyTag"}
417
Paul Duffin0cb37b92020-03-04 14:52:46 +0000418// A BpPropertyTag that indicates the property should only be present in the versioned
419// module.
420//
421// This will cause the property to be removed from the unversioned instance of a
422// snapshot module.
423var sdkVersionedOnlyPropertyTag = propertyTag{"sdkVersionedOnlyPropertyTag"}
424
Paul Duffine6c0d842020-01-15 14:08:51 +0000425type unversionedToVersionedTransformation struct {
426 identityTransformation
427 builder *snapshotBuilder
428}
429
Paul Duffine6c0d842020-01-15 14:08:51 +0000430func (t unversionedToVersionedTransformation) transformModule(module *bpModule) *bpModule {
431 // Use a versioned name for the module but remember the original name for the
432 // snapshot.
433 name := module.getValue("name").(string)
434 module.setProperty("name", t.builder.versionedSdkMemberName(name))
435 module.insertAfter("name", "sdk_member_name", name)
436 return module
437}
438
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000439func (t unversionedToVersionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) {
440 if tag == sdkMemberReferencePropertyTag {
441 return t.builder.versionedSdkMemberNames(value.([]string)), tag
442 } else {
443 return value, tag
444 }
445}
446
Paul Duffin72910952020-01-20 18:16:30 +0000447type unversionedTransformation struct {
448 identityTransformation
449 builder *snapshotBuilder
450}
451
452func (t unversionedTransformation) transformModule(module *bpModule) *bpModule {
453 // If the module is an internal member then use a unique name for it.
454 name := module.getValue("name").(string)
455 module.setProperty("name", t.builder.unversionedSdkMemberName(name))
456
457 // Set prefer: false - this is not strictly required as that is the default.
458 module.insertAfter("name", "prefer", false)
459
460 return module
461}
462
463func (t unversionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) {
464 if tag == sdkMemberReferencePropertyTag {
465 return t.builder.unversionedSdkMemberNames(value.([]string)), tag
Paul Duffin0cb37b92020-03-04 14:52:46 +0000466 } else if tag == sdkVersionedOnlyPropertyTag {
467 // The property is not allowed in the unversioned module so remove it.
468 return nil, nil
Paul Duffin72910952020-01-20 18:16:30 +0000469 } else {
470 return value, tag
471 }
472}
473
Paul Duffina78f3a72020-02-21 16:29:35 +0000474type pruneEmptySetTransformer struct {
475 identityTransformation
476}
477
478var _ bpTransformer = (*pruneEmptySetTransformer)(nil)
479
480func (t pruneEmptySetTransformer) transformPropertySetAfterContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) {
481 if len(propertySet.properties) == 0 {
482 return nil, nil
483 } else {
484 return propertySet, tag
485 }
486}
487
Paul Duffinb645ec82019-11-27 17:43:54 +0000488func generateBpContents(contents *generatedContents, bpFile *bpFile) {
489 contents.Printfln("// This is auto-generated. DO NOT EDIT.")
490 for _, bpModule := range bpFile.order {
491 contents.Printfln("")
492 contents.Printfln("%s {", bpModule.moduleType)
Paul Duffincc72e982020-01-14 15:53:11 +0000493 outputPropertySet(contents, bpModule.bpPropertySet)
Paul Duffinb645ec82019-11-27 17:43:54 +0000494 contents.Printfln("}")
495 }
Paul Duffinb645ec82019-11-27 17:43:54 +0000496}
497
498func outputPropertySet(contents *generatedContents, set *bpPropertySet) {
499 contents.Indent()
500 for _, name := range set.order {
Paul Duffin5b511a22020-01-15 14:23:52 +0000501 value := set.getValue(name)
Paul Duffinb645ec82019-11-27 17:43:54 +0000502
503 reflectedValue := reflect.ValueOf(value)
504 t := reflectedValue.Type()
505
506 kind := t.Kind()
507 switch kind {
508 case reflect.Slice:
509 length := reflectedValue.Len()
510 if length > 1 {
511 contents.Printfln("%s: [", name)
512 contents.Indent()
513 for i := 0; i < length; i = i + 1 {
514 contents.Printfln("%q,", reflectedValue.Index(i).Interface())
515 }
516 contents.Dedent()
517 contents.Printfln("],")
518 } else if length == 0 {
519 contents.Printfln("%s: [],", name)
520 } else {
521 contents.Printfln("%s: [%q],", name, reflectedValue.Index(0).Interface())
522 }
523 case reflect.Bool:
524 contents.Printfln("%s: %t,", name, reflectedValue.Bool())
525
526 case reflect.Ptr:
527 contents.Printfln("%s: {", name)
528 outputPropertySet(contents, reflectedValue.Interface().(*bpPropertySet))
529 contents.Printfln("},")
530
531 default:
532 contents.Printfln("%s: %q,", name, value)
533 }
534 }
535 contents.Dedent()
536}
537
Paul Duffinac37c502019-11-26 18:02:20 +0000538func (s *sdk) GetAndroidBpContentsForTests() string {
Paul Duffinb645ec82019-11-27 17:43:54 +0000539 contents := &generatedContents{}
540 generateBpContents(contents, s.builderForTests.bpFile)
541 return contents.content.String()
Paul Duffinac37c502019-11-26 18:02:20 +0000542}
543
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000544type snapshotBuilder struct {
Paul Duffinb645ec82019-11-27 17:43:54 +0000545 ctx android.ModuleContext
Paul Duffine44358f2019-11-26 18:04:12 +0000546 sdk *sdk
Paul Duffinb645ec82019-11-27 17:43:54 +0000547 version string
548 snapshotDir android.OutputPath
549 bpFile *bpFile
Paul Duffinc62a5102019-12-11 18:34:15 +0000550
551 // Map from destination to source of each copy - used to eliminate duplicates and
552 // detect conflicts.
553 copies map[string]string
554
Paul Duffinb645ec82019-11-27 17:43:54 +0000555 filesToZip android.Paths
556 zipsToMerge android.Paths
557
558 prebuiltModules map[string]*bpModule
559 prebuiltOrder []*bpModule
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000560}
561
562func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) {
Paul Duffinc62a5102019-12-11 18:34:15 +0000563 if existing, ok := s.copies[dest]; ok {
564 if existing != src.String() {
565 s.ctx.ModuleErrorf("conflicting copy, %s copied from both %s and %s", dest, existing, src)
566 return
567 }
568 } else {
569 path := s.snapshotDir.Join(s.ctx, dest)
570 s.ctx.Build(pctx, android.BuildParams{
571 Rule: android.Cp,
572 Input: src,
573 Output: path,
574 })
575 s.filesToZip = append(s.filesToZip, path)
576
577 s.copies[dest] = src.String()
578 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000579}
580
Paul Duffin91547182019-11-12 19:39:36 +0000581func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string) {
582 ctx := s.ctx
583
584 // Repackage the zip file so that the entries are in the destDir directory.
585 // This will allow the zip file to be merged into the snapshot.
586 tmpZipPath := android.PathForModuleOut(ctx, "tmp", destDir+".zip").OutputPath
Paul Duffin375058f2019-11-29 20:17:53 +0000587
588 ctx.Build(pctx, android.BuildParams{
589 Description: "Repackaging zip file " + destDir + " for snapshot " + ctx.ModuleName(),
590 Rule: repackageZip,
591 Input: zipPath,
592 Output: tmpZipPath,
593 Args: map[string]string{
594 "destdir": destDir,
595 },
596 })
Paul Duffin91547182019-11-12 19:39:36 +0000597
598 // Add the repackaged zip file to the files to merge.
599 s.zipsToMerge = append(s.zipsToMerge, tmpZipPath)
600}
601
Paul Duffin9d8d6092019-12-05 18:19:29 +0000602func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType string) android.BpModule {
603 name := member.Name()
Paul Duffinb645ec82019-11-27 17:43:54 +0000604 if s.prebuiltModules[name] != nil {
605 panic(fmt.Sprintf("Duplicate module detected, module %s has already been added", name))
606 }
607
608 m := s.bpFile.newModule(moduleType)
609 m.AddProperty("name", name)
Paul Duffin593b3c92019-12-05 14:31:48 +0000610
Paul Duffinbefa4b92020-03-04 14:22:45 +0000611 variant := member.Variants()[0]
612
Paul Duffin72910952020-01-20 18:16:30 +0000613 if s.sdk.isInternalMember(name) {
614 // An internal member is only referenced from the sdk snapshot which is in the
615 // same package so can be marked as private.
616 m.AddProperty("visibility", []string{"//visibility:private"})
617 } else {
618 // Extract visibility information from a member variant. All variants have the same
619 // visibility so it doesn't matter which one is used.
Paul Duffinbefa4b92020-03-04 14:22:45 +0000620 visibility := android.EffectiveVisibilityRules(s.ctx, variant)
Paul Duffin72910952020-01-20 18:16:30 +0000621 if len(visibility) != 0 {
622 m.AddProperty("visibility", visibility)
623 }
Paul Duffin593b3c92019-12-05 14:31:48 +0000624 }
625
Paul Duffin865171e2020-03-02 18:38:15 +0000626 deviceSupported := false
627 hostSupported := false
628
629 for _, variant := range member.Variants() {
630 osClass := variant.Target().Os.Class
631 if osClass == android.Host || osClass == android.HostCross {
632 hostSupported = true
633 } else if osClass == android.Device {
634 deviceSupported = true
635 }
636 }
637
638 addHostDeviceSupportedProperties(deviceSupported, hostSupported, m)
Paul Duffinb645ec82019-11-27 17:43:54 +0000639
Paul Duffinbefa4b92020-03-04 14:22:45 +0000640 // Where available copy apex_available properties from the member.
641 if apexAware, ok := variant.(interface{ ApexAvailable() []string }); ok {
642 apexAvailable := apexAware.ApexAvailable()
643 if len(apexAvailable) > 0 {
644 m.AddProperty("apex_available", apexAvailable)
645 }
646 }
647
Paul Duffin0cb37b92020-03-04 14:52:46 +0000648 // Disable installation in the versioned module of those modules that are ever installable.
649 if installable, ok := variant.(interface{ EverInstallable() bool }); ok {
650 if installable.EverInstallable() {
651 m.AddPropertyWithTag("installable", false, sdkVersionedOnlyPropertyTag)
652 }
653 }
654
Paul Duffinb645ec82019-11-27 17:43:54 +0000655 s.prebuiltModules[name] = m
656 s.prebuiltOrder = append(s.prebuiltOrder, m)
657 return m
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000658}
659
Paul Duffin865171e2020-03-02 18:38:15 +0000660func addHostDeviceSupportedProperties(deviceSupported bool, hostSupported bool, bpModule *bpModule) {
661 if !deviceSupported {
Paul Duffine44358f2019-11-26 18:04:12 +0000662 bpModule.AddProperty("device_supported", false)
663 }
Paul Duffin865171e2020-03-02 18:38:15 +0000664 if hostSupported {
Paul Duffine44358f2019-11-26 18:04:12 +0000665 bpModule.AddProperty("host_supported", true)
666 }
667}
668
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000669func (s *snapshotBuilder) SdkMemberReferencePropertyTag() android.BpPropertyTag {
670 return sdkMemberReferencePropertyTag
671}
672
Paul Duffinb645ec82019-11-27 17:43:54 +0000673// Get a versioned name appropriate for the SDK snapshot version being taken.
674func (s *snapshotBuilder) versionedSdkMemberName(unversionedName string) string {
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000675 return versionedSdkMemberName(s.ctx, unversionedName, s.version)
676}
Paul Duffinb645ec82019-11-27 17:43:54 +0000677
678func (s *snapshotBuilder) versionedSdkMemberNames(members []string) []string {
679 var references []string = nil
680 for _, m := range members {
681 references = append(references, s.versionedSdkMemberName(m))
682 }
683 return references
684}
Paul Duffin13879572019-11-28 14:31:38 +0000685
Paul Duffin72910952020-01-20 18:16:30 +0000686// Get an internal name unique to the sdk.
687func (s *snapshotBuilder) unversionedSdkMemberName(unversionedName string) string {
688 if s.sdk.isInternalMember(unversionedName) {
689 return s.ctx.ModuleName() + "_" + unversionedName
690 } else {
691 return unversionedName
692 }
693}
694
695func (s *snapshotBuilder) unversionedSdkMemberNames(members []string) []string {
696 var references []string = nil
697 for _, m := range members {
698 references = append(references, s.unversionedSdkMemberName(m))
699 }
700 return references
701}
702
Paul Duffin1356d8c2020-02-25 19:26:33 +0000703type sdkMemberRef struct {
704 memberType android.SdkMemberType
705 variant android.SdkAware
706}
707
Paul Duffin13879572019-11-28 14:31:38 +0000708var _ android.SdkMember = (*sdkMember)(nil)
709
710type sdkMember struct {
711 memberType android.SdkMemberType
712 name string
713 variants []android.SdkAware
714}
715
716func (m *sdkMember) Name() string {
717 return m.name
718}
719
720func (m *sdkMember) Variants() []android.SdkAware {
721 return m.variants
722}
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000723
724type baseInfo struct {
725 Properties android.SdkMemberProperties
726}
727
728type osTypeSpecificInfo struct {
729 baseInfo
730
731 // The list of arch type specific info for this os type.
732 archTypes []*archTypeSpecificInfo
Paul Duffina04c1072020-03-02 10:16:35 +0000733
734 // True if the member has common arch variants for this os type.
735 commonArch bool
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000736}
737
738type archTypeSpecificInfo struct {
739 baseInfo
740
741 archType android.ArchType
742}
743
744func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, builder *snapshotBuilder, member *sdkMember, bpModule android.BpModule) {
745
746 memberType := member.memberType
747
Paul Duffina04c1072020-03-02 10:16:35 +0000748 // Group the variants by os type.
749 variantsByOsType := make(map[android.OsType][]android.SdkAware)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000750 variants := member.Variants()
751 for _, variant := range variants {
Paul Duffina04c1072020-03-02 10:16:35 +0000752 osType := variant.Target().Os
753 variantsByOsType[osType] = append(variantsByOsType[osType], variant)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000754 }
755
Paul Duffina04c1072020-03-02 10:16:35 +0000756 osCount := len(variantsByOsType)
757 createVariantPropertiesStruct := func(os android.OsType) android.SdkMemberProperties {
758 properties := memberType.CreateVariantPropertiesStruct()
759 base := properties.Base()
760 base.Os_count = osCount
761 base.Os = os
762 return properties
763 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000764
Paul Duffina04c1072020-03-02 10:16:35 +0000765 osTypeToInfo := make(map[android.OsType]*osTypeSpecificInfo)
Paul Duffin14eb4672020-03-02 11:33:02 +0000766
Paul Duffina04c1072020-03-02 10:16:35 +0000767 // The set of properties that are common across all architectures and os types.
768 commonProperties := createVariantPropertiesStruct(android.CommonOS)
769
770 // The list of property structures which are os type specific but common across
771 // architectures within that os type.
772 var osSpecificPropertiesList []android.SdkMemberProperties
773
774 for osType, osTypeVariants := range variantsByOsType {
775 // Group the properties for each variant by arch type within the os.
776 osInfo := &osTypeSpecificInfo{}
777 osTypeToInfo[osType] = osInfo
778
779 // Create a structure into which properties common across the architectures in
780 // this os type will be stored. Add it to the list of os type specific yet
781 // architecture independent properties structs.
782 osInfo.Properties = createVariantPropertiesStruct(osType)
783 osSpecificPropertiesList = append(osSpecificPropertiesList, osInfo.Properties)
784
785 commonArch := false
786 for _, variant := range osTypeVariants {
787 var properties android.SdkMemberProperties
788
789 // Get the info associated with the arch type inside the os info.
790 archType := variant.Target().Arch.ArchType
791
792 if archType.Name == "common" {
793 // The arch type is common so populate the common properties directly.
794 properties = osInfo.Properties
795
796 commonArch = true
Paul Duffin14eb4672020-03-02 11:33:02 +0000797 } else {
Paul Duffina04c1072020-03-02 10:16:35 +0000798 archInfo := &archTypeSpecificInfo{archType: archType}
799 properties = createVariantPropertiesStruct(osType)
800 archInfo.Properties = properties
801
802 osInfo.archTypes = append(osInfo.archTypes, archInfo)
Paul Duffin14eb4672020-03-02 11:33:02 +0000803 }
Paul Duffina04c1072020-03-02 10:16:35 +0000804
805 properties.PopulateFromVariant(variant)
Paul Duffin14eb4672020-03-02 11:33:02 +0000806 }
807
Paul Duffina04c1072020-03-02 10:16:35 +0000808 if commonArch {
809 if len(osTypeVariants) != 1 {
810 panic("Expected to only have 1 variant when arch type is common but found " + string(len(variants)))
811 }
812 } else {
813 var archPropertiesList []android.SdkMemberProperties
814 for _, archInfo := range osInfo.archTypes {
815 archPropertiesList = append(archPropertiesList, archInfo.Properties)
816 }
817
818 extractCommonProperties(osInfo.Properties, archPropertiesList)
819
820 // Choose setting for compile_multilib that is appropriate for the arch variants supplied.
821 var multilib string
822 archVariantCount := len(osInfo.archTypes)
823 if archVariantCount == 2 {
824 multilib = "both"
825 } else if archVariantCount == 1 {
826 if strings.HasSuffix(osInfo.archTypes[0].archType.Name, "64") {
827 multilib = "64"
828 } else {
829 multilib = "32"
830 }
831 }
832
833 osInfo.commonArch = commonArch
834 osInfo.Properties.Base().Compile_multilib = multilib
835 }
Paul Duffin14eb4672020-03-02 11:33:02 +0000836 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000837
Paul Duffina04c1072020-03-02 10:16:35 +0000838 // Extract properties which are common across all architectures and os types.
839 extractCommonProperties(commonProperties, osSpecificPropertiesList)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000840
Paul Duffina04c1072020-03-02 10:16:35 +0000841 // Add the common properties to the module.
842 commonProperties.AddToPropertySet(sdkModuleContext, builder, bpModule)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000843
Paul Duffina04c1072020-03-02 10:16:35 +0000844 // Create a target property set into which target specific properties can be
845 // added.
846 targetPropertySet := bpModule.AddPropertySet("target")
847
848 // Iterate over the os types in a fixed order.
849 for _, osType := range s.getPossibleOsTypes() {
850 osInfo := osTypeToInfo[osType]
851 if osInfo == nil {
852 continue
853 }
854
855 var osPropertySet android.BpPropertySet
856 var archOsPrefix string
857 if len(osTypeToInfo) == 1 {
858 // There is only one os type present in the variants sp don't bother
859 // with adding target specific properties.
860
861 // Create a structure that looks like:
862 // module_type {
863 // name: "...",
864 // ...
865 // <common properties>
866 // ...
867 // <single os type specific properties>
868 //
869 // arch: {
870 // <arch specific sections>
871 // }
872 //
873 osPropertySet = bpModule
874
875 // Arch specific properties need to be added to an arch specific section
876 // within arch.
877 archOsPrefix = ""
878 } else {
879 // Create a structure that looks like:
880 // module_type {
881 // name: "...",
882 // ...
883 // <common properties>
884 // ...
885 // target: {
886 // <arch independent os specific sections, e.g. android>
887 // ...
888 // <arch and os specific sections, e.g. android_x86>
889 // }
890 //
891 osPropertySet = targetPropertySet.AddPropertySet(osType.Name)
892
893 // Arch specific properties need to be added to an os and arch specific
894 // section prefixed with <os>_.
895 archOsPrefix = osType.Name + "_"
896 }
897
898 osInfo.Properties.AddToPropertySet(sdkModuleContext, builder, osPropertySet)
899 if !osInfo.commonArch {
900 // Either add the arch specific sections into the target or arch sections
901 // depending on whether they will also be os specific.
902 var archPropertySet android.BpPropertySet
903 if archOsPrefix == "" {
904 archPropertySet = osPropertySet.AddPropertySet("arch")
905 } else {
906 archPropertySet = targetPropertySet
907 }
908
909 // Add arch (and possibly os) specific sections for each set of
910 // arch (and possibly os) specific properties.
911 for _, av := range osInfo.archTypes {
912 archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + av.archType.Name)
913
914 av.Properties.AddToPropertySet(sdkModuleContext, builder, archTypePropertySet)
915 }
Paul Duffin14eb4672020-03-02 11:33:02 +0000916 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000917 }
918
919 memberType.FinalizeModule(sdkModuleContext, builder, member, bpModule)
920}
921
Paul Duffina04c1072020-03-02 10:16:35 +0000922// Compute the list of possible os types that this sdk could support.
923func (s *sdk) getPossibleOsTypes() []android.OsType {
924 var osTypes []android.OsType
925 for _, osType := range android.OsTypeList {
926 if s.DeviceSupported() {
927 if osType.Class == android.Device && osType != android.Fuchsia {
928 osTypes = append(osTypes, osType)
929 }
930 }
931 if s.HostSupported() {
932 if osType.Class == android.Host || osType.Class == android.HostCross {
933 osTypes = append(osTypes, osType)
934 }
935 }
936 }
937 sort.SliceStable(osTypes, func(i, j int) bool { return osTypes[i].Name < osTypes[j].Name })
938 return osTypes
939}
940
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000941// Extract common properties from a slice of property structures of the same type.
942//
943// All the property structures must be of the same type.
944// commonProperties - must be a pointer to the structure into which common properties will be added.
945// inputPropertiesSlice - must be a slice of input properties structures.
946//
947// Iterates over each exported field (capitalized name) and checks to see whether they
948// have the same value (using DeepEquals) across all the input properties. If it does not then no
949// change is made. Otherwise, the common value is stored in the field in the commonProperties
950// and the field in each of the input properties structure is set to its default value.
951func extractCommonProperties(commonProperties interface{}, inputPropertiesSlice interface{}) {
952 commonPropertiesValue := reflect.ValueOf(commonProperties)
953 commonStructValue := commonPropertiesValue.Elem()
954 propertiesStructType := commonStructValue.Type()
955
956 // Create an empty structure from which default values for the field can be copied.
957 emptyStructValue := reflect.New(propertiesStructType).Elem()
958
959 for f := 0; f < propertiesStructType.NumField(); f++ {
960 // Check to see if all the structures have the same value for the field. The commonValue
961 // is nil on entry to the loop and if it is nil on exit then there is no common value,
962 // otherwise it points to the common value.
963 var commonValue *reflect.Value
964 sliceValue := reflect.ValueOf(inputPropertiesSlice)
965
Paul Duffina04c1072020-03-02 10:16:35 +0000966 field := propertiesStructType.Field(f)
967 if field.Name == "SdkMemberPropertiesBase" {
968 continue
969 }
970
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000971 for i := 0; i < sliceValue.Len(); i++ {
972 structValue := sliceValue.Index(i).Elem().Elem()
973 fieldValue := structValue.Field(f)
974 if !fieldValue.CanInterface() {
975 // The field is not exported so ignore it.
976 continue
977 }
978
979 if commonValue == nil {
980 // Use the first value as the commonProperties value.
981 commonValue = &fieldValue
982 } else {
983 // If the value does not match the current common value then there is
984 // no value in common so break out.
985 if !reflect.DeepEqual(fieldValue.Interface(), commonValue.Interface()) {
986 commonValue = nil
987 break
988 }
989 }
990 }
991
992 // If the fields all have a common value then store it in the common struct field
993 // and set the input struct's field to the empty value.
994 if commonValue != nil {
995 emptyValue := emptyStructValue.Field(f)
996 commonStructValue.Field(f).Set(*commonValue)
997 for i := 0; i < sliceValue.Len(); i++ {
998 structValue := sliceValue.Index(i).Elem().Elem()
999 fieldValue := structValue.Field(f)
1000 fieldValue.Set(emptyValue)
1001 }
1002 }
1003 }
1004}