blob: 853f6b0a08de128396d69577503475fd604c4f18 [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 Duffin7d74e7b2020-03-06 12:30:13 +000023 "android/soong/apex"
Paul Duffin9b76c0b2020-03-12 10:24:35 +000024 "android/soong/cc"
Colin Cross440e0d02020-06-11 11:32:11 -070025
Paul Duffin375058f2019-11-29 20:17:53 +000026 "github.com/google/blueprint"
Jiyong Park9b409bc2019-10-11 14:59:13 +090027 "github.com/google/blueprint/proptools"
28
29 "android/soong/android"
Jiyong Park9b409bc2019-10-11 14:59:13 +090030)
31
Paul Duffin64fb5262021-05-05 21:36:04 +010032// Environment variables that affect the generated snapshot
33// ========================================================
34//
35// SOONG_SDK_SNAPSHOT_PREFER
36// By default every unversioned module in the generated snapshot has prefer: false. Building it
37// with SOONG_SDK_SNAPSHOT_PREFER=true will force them to use prefer: true.
38//
39
Jiyong Park9b409bc2019-10-11 14:59:13 +090040var pctx = android.NewPackageContext("android/soong/sdk")
41
Paul Duffin375058f2019-11-29 20:17:53 +000042var (
43 repackageZip = pctx.AndroidStaticRule("SnapshotRepackageZip",
44 blueprint.RuleParams{
Paul Duffince482dc2019-12-09 19:58:17 +000045 Command: `${config.Zip2ZipCmd} -i $in -o $out -x META-INF/**/* "**/*:$destdir"`,
Paul Duffin375058f2019-11-29 20:17:53 +000046 CommandDeps: []string{
47 "${config.Zip2ZipCmd}",
48 },
49 },
50 "destdir")
51
52 zipFiles = pctx.AndroidStaticRule("SnapshotZipFiles",
53 blueprint.RuleParams{
Colin Cross053fca12020-08-19 13:51:47 -070054 Command: `${config.SoongZipCmd} -C $basedir -r $out.rsp -o $out`,
Paul Duffin375058f2019-11-29 20:17:53 +000055 CommandDeps: []string{
56 "${config.SoongZipCmd}",
57 },
58 Rspfile: "$out.rsp",
59 RspfileContent: "$in",
60 },
61 "basedir")
62
63 mergeZips = pctx.AndroidStaticRule("SnapshotMergeZips",
64 blueprint.RuleParams{
65 Command: `${config.MergeZipsCmd} $out $in`,
66 CommandDeps: []string{
67 "${config.MergeZipsCmd}",
68 },
69 })
70)
71
Paul Duffinb645ec82019-11-27 17:43:54 +000072type generatedContents struct {
Jiyong Park73c54ee2019-10-22 20:31:18 +090073 content strings.Builder
74 indentLevel int
Jiyong Park9b409bc2019-10-11 14:59:13 +090075}
76
Paul Duffinb645ec82019-11-27 17:43:54 +000077// generatedFile abstracts operations for writing contents into a file and emit a build rule
78// for the file.
79type generatedFile struct {
80 generatedContents
81 path android.OutputPath
82}
83
Jiyong Park232e7852019-11-04 12:23:40 +090084func newGeneratedFile(ctx android.ModuleContext, path ...string) *generatedFile {
Jiyong Park9b409bc2019-10-11 14:59:13 +090085 return &generatedFile{
Paul Duffinb645ec82019-11-27 17:43:54 +000086 path: android.PathForModuleOut(ctx, path...).OutputPath,
Jiyong Park9b409bc2019-10-11 14:59:13 +090087 }
88}
89
Paul Duffinb645ec82019-11-27 17:43:54 +000090func (gc *generatedContents) Indent() {
91 gc.indentLevel++
Jiyong Park73c54ee2019-10-22 20:31:18 +090092}
93
Paul Duffinb645ec82019-11-27 17:43:54 +000094func (gc *generatedContents) Dedent() {
95 gc.indentLevel--
Jiyong Park73c54ee2019-10-22 20:31:18 +090096}
97
Paul Duffinb645ec82019-11-27 17:43:54 +000098func (gc *generatedContents) Printfln(format string, args ...interface{}) {
Paul Duffin11108272020-05-11 22:59:25 +010099 fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format+"\n", args...)
Jiyong Park9b409bc2019-10-11 14:59:13 +0900100}
101
102func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderContext, implicits android.Paths) {
Colin Crossf1a035e2020-11-16 17:32:30 -0800103 rb := android.NewRuleBuilder(pctx, ctx)
Paul Duffin11108272020-05-11 22:59:25 +0100104
105 content := gf.content.String()
106
107 // ninja consumes newline characters in rspfile_content. Prevent it by
108 // escaping the backslash in the newline character. The extra backslash
109 // is removed when the rspfile is written to the actual script file
110 content = strings.ReplaceAll(content, "\n", "\\n")
111
Jiyong Park9b409bc2019-10-11 14:59:13 +0900112 rb.Command().
113 Implicits(implicits).
Martin Stjernholmee9b24e2021-04-20 15:54:21 +0100114 Text("echo -n").Text(proptools.ShellEscape(content)).
Paul Duffin11108272020-05-11 22:59:25 +0100115 // convert \\n to \n
Jiyong Park9b409bc2019-10-11 14:59:13 +0900116 Text("| sed 's/\\\\n/\\n/g' >").Output(gf.path)
117 rb.Command().
118 Text("chmod a+x").Output(gf.path)
Colin Crossf1a035e2020-11-16 17:32:30 -0800119 rb.Build(gf.path.Base(), "Build "+gf.path.Base())
Jiyong Park9b409bc2019-10-11 14:59:13 +0900120}
121
Paul Duffin13879572019-11-28 14:31:38 +0000122// Collect all the members.
123//
Paul Duffincc3132e2021-04-24 01:10:30 +0100124// Updates the sdk module with a list of sdkMemberVariantDeps and details as to which multilibs
125// (32/64/both) are used by this sdk variant.
Paul Duffin6a7e9532020-03-20 17:50:07 +0000126func (s *sdk) collectMembers(ctx android.ModuleContext) {
127 s.multilibUsages = multilibNone
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000128 ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
129 tag := ctx.OtherModuleDependencyTag(child)
Paul Duffinf8539922019-11-19 19:44:10 +0000130 if memberTag, ok := tag.(android.SdkMemberTypeDependencyTag); ok {
Paul Duffineee466e2021-04-27 23:17:56 +0100131 memberType := memberTag.SdkMemberType(child)
Jiyong Park9b409bc2019-10-11 14:59:13 +0900132
Paul Duffin13879572019-11-28 14:31:38 +0000133 // Make sure that the resolved module is allowed in the member list property.
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000134 if !memberType.IsInstance(child) {
135 ctx.ModuleErrorf("module %q is not valid in property %s", ctx.OtherModuleName(child), memberType.SdkPropertyName())
Jiyong Park73c54ee2019-10-22 20:31:18 +0900136 }
Paul Duffin13879572019-11-28 14:31:38 +0000137
Paul Duffin6a7e9532020-03-20 17:50:07 +0000138 // Keep track of which multilib variants are used by the sdk.
139 s.multilibUsages = s.multilibUsages.addArchType(child.Target().Arch.ArchType)
140
Paul Duffina7208112021-04-23 21:20:20 +0100141 export := memberTag.ExportMember()
Paul Duffincd064672021-04-24 00:47:29 +0100142 s.memberVariantDeps = append(s.memberVariantDeps, sdkMemberVariantDep{s, memberType, child.(android.SdkAware), export})
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000143
Paul Duffin2d3da312021-05-06 12:02:27 +0100144 // Recurse down into the member's dependencies as it may have dependencies that need to be
145 // automatically added to the sdk.
146 return true
Jiyong Park73c54ee2019-10-22 20:31:18 +0900147 }
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000148
149 return false
Paul Duffin13879572019-11-28 14:31:38 +0000150 })
Paul Duffin1356d8c2020-02-25 19:26:33 +0000151}
152
Paul Duffincc3132e2021-04-24 01:10:30 +0100153// groupMemberVariantsByMemberThenType groups the member variant dependencies so that all the
154// variants of each member are grouped together within an sdkMember instance.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000155//
Paul Duffincc3132e2021-04-24 01:10:30 +0100156// The sdkMember instances are then grouped into slices by member type. Within each such slice the
157// sdkMember instances appear in the order they were added as dependencies.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000158//
Paul Duffincc3132e2021-04-24 01:10:30 +0100159// Finally, the member type slices are concatenated together to form a single slice. The order in
160// which they are concatenated is the order in which the member types were registered in the
161// android.SdkMemberTypesRegistry.
162func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, memberVariantDeps []sdkMemberVariantDep) []*sdkMember {
Paul Duffin1356d8c2020-02-25 19:26:33 +0000163 byType := make(map[android.SdkMemberType][]*sdkMember)
164 byName := make(map[string]*sdkMember)
165
Paul Duffin21827262021-04-24 12:16:36 +0100166 for _, memberVariantDep := range memberVariantDeps {
167 memberType := memberVariantDep.memberType
168 variant := memberVariantDep.variant
Paul Duffin1356d8c2020-02-25 19:26:33 +0000169
170 name := ctx.OtherModuleName(variant)
171 member := byName[name]
172 if member == nil {
173 member = &sdkMember{memberType: memberType, name: name}
174 byName[name] = member
175 byType[memberType] = append(byType[memberType], member)
176 }
177
Paul Duffin1356d8c2020-02-25 19:26:33 +0000178 // Only append new variants to the list. This is needed because a member can be both
179 // exported by the sdk and also be a transitive sdk member.
180 member.variants = appendUniqueVariants(member.variants, variant)
181 }
182
Paul Duffin13879572019-11-28 14:31:38 +0000183 var members []*sdkMember
Paul Duffin72910952020-01-20 18:16:30 +0000184 for _, memberListProperty := range s.memberListProperties() {
Paul Duffin13879572019-11-28 14:31:38 +0000185 membersOfType := byType[memberListProperty.memberType]
186 members = append(members, membersOfType...)
Jiyong Park9b409bc2019-10-11 14:59:13 +0900187 }
188
Paul Duffin6a7e9532020-03-20 17:50:07 +0000189 return members
Jiyong Park73c54ee2019-10-22 20:31:18 +0900190}
Jiyong Park9b409bc2019-10-11 14:59:13 +0900191
Paul Duffin72910952020-01-20 18:16:30 +0000192func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware {
193 for _, v := range variants {
194 if v == newVariant {
195 return variants
196 }
197 }
198 return append(variants, newVariant)
199}
200
Jiyong Park73c54ee2019-10-22 20:31:18 +0900201// SDK directory structure
202// <sdk_root>/
203// Android.bp : definition of a 'sdk' module is here. This is a hand-made one.
204// <api_ver>/ : below this directory are all auto-generated
205// Android.bp : definition of 'sdk_snapshot' module is here
206// aidl/
207// frameworks/base/core/..../IFoo.aidl : an exported AIDL file
208// java/
Jiyong Park232e7852019-11-04 12:23:40 +0900209// <module_name>.jar : the stub jar for a java library 'module_name'
Jiyong Park73c54ee2019-10-22 20:31:18 +0900210// include/
211// bionic/libc/include/stdlib.h : an exported header file
212// include_gen/
Jiyong Park232e7852019-11-04 12:23:40 +0900213// <module_name>/com/android/.../IFoo.h : a generated header file
Jiyong Park73c54ee2019-10-22 20:31:18 +0900214// <arch>/include/ : arch-specific exported headers
215// <arch>/include_gen/ : arch-specific generated headers
216// <arch>/lib/
217// libFoo.so : a stub library
218
Jiyong Park232e7852019-11-04 12:23:40 +0900219// A name that uniquely identifies a prebuilt SDK member for a version of SDK snapshot
Jiyong Park73c54ee2019-10-22 20:31:18 +0900220// This isn't visible to users, so could be changed in future.
221func versionedSdkMemberName(ctx android.ModuleContext, memberName string, version string) string {
222 return ctx.ModuleName() + "_" + memberName + string(android.SdkVersionSeparator) + version
223}
224
Jiyong Park232e7852019-11-04 12:23:40 +0900225// buildSnapshot is the main function in this source file. It creates rules to copy
226// the contents (header files, stub libraries, etc) into the zip file.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000227func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) android.OutputPath {
228
Paul Duffin13f02712020-03-06 12:30:43 +0000229 allMembersByName := make(map[string]struct{})
230 exportedMembersByName := make(map[string]struct{})
Paul Duffin21827262021-04-24 12:16:36 +0100231 var memberVariantDeps []sdkMemberVariantDep
Paul Duffin1356d8c2020-02-25 19:26:33 +0000232 for _, sdkVariant := range sdkVariants {
Paul Duffin21827262021-04-24 12:16:36 +0100233 memberVariantDeps = append(memberVariantDeps, sdkVariant.memberVariantDeps...)
Paul Duffin865171e2020-03-02 18:38:15 +0000234
Paul Duffin13f02712020-03-06 12:30:43 +0000235 // Record the names of all the members, both explicitly specified and implicitly
236 // included.
Paul Duffin21827262021-04-24 12:16:36 +0100237 for _, memberVariantDep := range sdkVariant.memberVariantDeps {
Paul Duffina7208112021-04-23 21:20:20 +0100238 name := memberVariantDep.variant.Name()
239 allMembersByName[name] = struct{}{}
Paul Duffin13f02712020-03-06 12:30:43 +0000240
Paul Duffina7208112021-04-23 21:20:20 +0100241 if memberVariantDep.export {
242 exportedMembersByName[name] = struct{}{}
243 }
Paul Duffin865171e2020-03-02 18:38:15 +0000244 }
Paul Duffin1356d8c2020-02-25 19:26:33 +0000245 }
246
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000247 snapshotDir := android.PathForModuleOut(ctx, "snapshot")
Jiyong Park9b409bc2019-10-11 14:59:13 +0900248
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000249 bp := newGeneratedFile(ctx, "snapshot", "Android.bp")
Paul Duffinb645ec82019-11-27 17:43:54 +0000250
251 bpFile := &bpFile{
252 modules: make(map[string]*bpModule),
253 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000254
255 builder := &snapshotBuilder{
Paul Duffin13f02712020-03-06 12:30:43 +0000256 ctx: ctx,
257 sdk: s,
258 version: "current",
259 snapshotDir: snapshotDir.OutputPath,
260 copies: make(map[string]string),
261 filesToZip: []android.Path{bp.path},
262 bpFile: bpFile,
263 prebuiltModules: make(map[string]*bpModule),
264 allMembersByName: allMembersByName,
265 exportedMembersByName: exportedMembersByName,
Jiyong Park73c54ee2019-10-22 20:31:18 +0900266 }
Paul Duffinac37c502019-11-26 18:02:20 +0000267 s.builderForTests = builder
Jiyong Park9b409bc2019-10-11 14:59:13 +0900268
Paul Duffincc3132e2021-04-24 01:10:30 +0100269 // Create the prebuilt modules for each of the member modules.
270 members := s.groupMemberVariantsByMemberThenType(ctx, memberVariantDeps)
Paul Duffin13ad94f2020-02-19 16:19:27 +0000271 for _, member := range members {
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000272 memberType := member.memberType
Paul Duffin3a4eb502020-03-19 16:11:18 +0000273
Paul Duffina551a1c2020-03-17 21:04:24 +0000274 memberCtx := &memberContext{ctx, builder, memberType, member.name}
Paul Duffin3a4eb502020-03-19 16:11:18 +0000275
276 prebuiltModule := memberType.AddPrebuiltModule(memberCtx, member)
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100277 s.createMemberSnapshot(memberCtx, member, prebuiltModule.(*bpModule))
Jiyong Park73c54ee2019-10-22 20:31:18 +0900278 }
Jiyong Park9b409bc2019-10-11 14:59:13 +0900279
Paul Duffine6c0d842020-01-15 14:08:51 +0000280 // Create a transformer that will transform an unversioned module into a versioned module.
281 unversionedToVersionedTransformer := unversionedToVersionedTransformation{builder: builder}
282
Paul Duffin72910952020-01-20 18:16:30 +0000283 // Create a transformer that will transform an unversioned module by replacing any references
284 // to internal members with a unique module name and setting prefer: false.
Paul Duffin64fb5262021-05-05 21:36:04 +0100285 unversionedTransformer := unversionedTransformation{
286 builder: builder,
287 // Set the prefer based on the environment variable. This is a temporary work around to allow a
288 // snapshot to be created that sets prefer: true.
289 // TODO(b/174997203): Remove once the ability to select the modules to prefer can be done
290 // dynamically at build time not at snapshot generation time.
291 prefer: ctx.Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER"),
292 }
Paul Duffin72910952020-01-20 18:16:30 +0000293
Paul Duffinb645ec82019-11-27 17:43:54 +0000294 for _, unversioned := range builder.prebuiltOrder {
Paul Duffina78f3a72020-02-21 16:29:35 +0000295 // Prune any empty property sets.
296 unversioned = unversioned.transform(pruneEmptySetTransformer{})
297
Paul Duffinb645ec82019-11-27 17:43:54 +0000298 // Copy the unversioned module so it can be modified to make it versioned.
Paul Duffincc72e982020-01-14 15:53:11 +0000299 versioned := unversioned.deepCopy()
Paul Duffine6c0d842020-01-15 14:08:51 +0000300
301 // Transform the unversioned module into a versioned one.
302 versioned.transform(unversionedToVersionedTransformer)
Paul Duffinb645ec82019-11-27 17:43:54 +0000303 bpFile.AddModule(versioned)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000304
Paul Duffin72910952020-01-20 18:16:30 +0000305 // Transform the unversioned module to make it suitable for use in the snapshot.
306 unversioned.transform(unversionedTransformer)
Paul Duffinb645ec82019-11-27 17:43:54 +0000307 bpFile.AddModule(unversioned)
308 }
309
Paul Duffin26197a62021-04-24 00:34:10 +0100310 // Add the sdk/module_exports_snapshot module to the bp file.
Paul Duffin21827262021-04-24 12:16:36 +0100311 s.addSnapshotModule(ctx, builder, sdkVariants, memberVariantDeps)
Paul Duffin26197a62021-04-24 00:34:10 +0100312
313 // generate Android.bp
314 bp = newGeneratedFile(ctx, "snapshot", "Android.bp")
315 generateBpContents(&bp.generatedContents, bpFile)
316
317 contents := bp.content.String()
318 syntaxCheckSnapshotBpFile(ctx, contents)
319
320 bp.build(pctx, ctx, nil)
321
322 filesToZip := builder.filesToZip
323
324 // zip them all
325 outputZipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath
326 outputDesc := "Building snapshot for " + ctx.ModuleName()
327
328 // If there are no zips to merge then generate the output zip directly.
329 // Otherwise, generate an intermediate zip file into which other zips can be
330 // merged.
331 var zipFile android.OutputPath
332 var desc string
333 if len(builder.zipsToMerge) == 0 {
334 zipFile = outputZipFile
335 desc = outputDesc
336 } else {
337 zipFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.unmerged.zip").OutputPath
338 desc = "Building intermediate snapshot for " + ctx.ModuleName()
339 }
340
341 ctx.Build(pctx, android.BuildParams{
342 Description: desc,
343 Rule: zipFiles,
344 Inputs: filesToZip,
345 Output: zipFile,
346 Args: map[string]string{
347 "basedir": builder.snapshotDir.String(),
348 },
349 })
350
351 if len(builder.zipsToMerge) != 0 {
352 ctx.Build(pctx, android.BuildParams{
353 Description: outputDesc,
354 Rule: mergeZips,
355 Input: zipFile,
356 Inputs: builder.zipsToMerge,
357 Output: outputZipFile,
358 })
359 }
360
361 return outputZipFile
362}
363
364// addSnapshotModule adds the sdk_snapshot/module_exports_snapshot module to the builder.
Paul Duffin21827262021-04-24 12:16:36 +0100365func (s *sdk) addSnapshotModule(ctx android.ModuleContext, builder *snapshotBuilder, sdkVariants []*sdk, memberVariantDeps []sdkMemberVariantDep) {
Paul Duffin26197a62021-04-24 00:34:10 +0100366 bpFile := builder.bpFile
367
Paul Duffinb645ec82019-11-27 17:43:54 +0000368 snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version
Paul Duffin8150da62019-12-16 17:21:27 +0000369 var snapshotModuleType string
370 if s.properties.Module_exports {
371 snapshotModuleType = "module_exports_snapshot"
372 } else {
373 snapshotModuleType = "sdk_snapshot"
374 }
375 snapshotModule := bpFile.newModule(snapshotModuleType)
Paul Duffinb645ec82019-11-27 17:43:54 +0000376 snapshotModule.AddProperty("name", snapshotName)
Paul Duffin593b3c92019-12-05 14:31:48 +0000377
378 // Make sure that the snapshot has the same visibility as the sdk.
Paul Duffin157f40f2020-09-29 16:01:08 +0100379 visibility := android.EffectiveVisibilityRules(ctx, s).Strings()
Paul Duffin593b3c92019-12-05 14:31:48 +0000380 if len(visibility) != 0 {
381 snapshotModule.AddProperty("visibility", visibility)
382 }
383
Paul Duffin865171e2020-03-02 18:38:15 +0000384 addHostDeviceSupportedProperties(s.ModuleBase.DeviceSupported(), s.ModuleBase.HostSupported(), snapshotModule)
Paul Duffin13ad94f2020-02-19 16:19:27 +0000385
Paul Duffincd064672021-04-24 00:47:29 +0100386 combinedPropertiesList := s.collateSnapshotModuleInfo(ctx, sdkVariants, memberVariantDeps)
Paul Duffin2d1bb892021-04-24 11:32:59 +0100387 commonCombinedProperties := s.optimizeSnapshotModuleProperties(ctx, combinedPropertiesList)
Paul Duffin865171e2020-03-02 18:38:15 +0000388
Paul Duffin2d1bb892021-04-24 11:32:59 +0100389 s.addSnapshotPropertiesToPropertySet(builder, snapshotModule, commonCombinedProperties)
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100390
Paul Duffin6a7e9532020-03-20 17:50:07 +0000391 targetPropertySet := snapshotModule.AddPropertySet("target")
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100392
Paul Duffin2d1bb892021-04-24 11:32:59 +0100393 // Create a mapping from osType to combined properties.
394 osTypeToCombinedProperties := map[android.OsType]*combinedSnapshotModuleProperties{}
395 for _, combined := range combinedPropertiesList {
396 osTypeToCombinedProperties[combined.sdkVariant.Os()] = combined
397 }
398
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100399 // Iterate over the os types in a fixed order.
Paul Duffin865171e2020-03-02 18:38:15 +0000400 for _, osType := range s.getPossibleOsTypes() {
Paul Duffin2d1bb892021-04-24 11:32:59 +0100401 if combined, ok := osTypeToCombinedProperties[osType]; ok {
Paul Duffincc3132e2021-04-24 01:10:30 +0100402 osPropertySet := targetPropertySet.AddPropertySet(osType.Name)
Paul Duffin6a7e9532020-03-20 17:50:07 +0000403
Paul Duffin2d1bb892021-04-24 11:32:59 +0100404 s.addSnapshotPropertiesToPropertySet(builder, osPropertySet, combined)
Paul Duffin13879572019-11-28 14:31:38 +0000405 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000406 }
Paul Duffin865171e2020-03-02 18:38:15 +0000407
Jiyong Park8fe14e62020-10-19 22:47:34 +0900408 // If host is supported and any member is host OS dependent then disable host
409 // by default, so that we can enable each host OS variant explicitly. This
410 // avoids problems with implicitly enabled OS variants when the snapshot is
411 // used, which might be different from this run (e.g. different build OS).
412 if s.HostSupported() {
413 var supportedHostTargets []string
Paul Duffin21827262021-04-24 12:16:36 +0100414 for _, memberVariantDep := range memberVariantDeps {
415 if memberVariantDep.memberType.IsHostOsDependent() && memberVariantDep.variant.Target().Os.Class == android.Host {
416 targetString := memberVariantDep.variant.Target().Os.String() + "_" + memberVariantDep.variant.Target().Arch.ArchType.String()
Jiyong Park8fe14e62020-10-19 22:47:34 +0900417 if !android.InList(targetString, supportedHostTargets) {
418 supportedHostTargets = append(supportedHostTargets, targetString)
419 }
420 }
421 }
422 if len(supportedHostTargets) > 0 {
423 hostPropertySet := targetPropertySet.AddPropertySet("host")
424 hostPropertySet.AddProperty("enabled", false)
425 }
426 // Enable the <os>_<arch> variant explicitly when we've disabled it by default on host.
427 for _, hostTarget := range supportedHostTargets {
428 propertySet := targetPropertySet.AddPropertySet(hostTarget)
429 propertySet.AddProperty("enabled", true)
430 }
431 }
432
Paul Duffin865171e2020-03-02 18:38:15 +0000433 // Prune any empty property sets.
434 snapshotModule.transform(pruneEmptySetTransformer{})
435
Paul Duffinb645ec82019-11-27 17:43:54 +0000436 bpFile.AddModule(snapshotModule)
Jiyong Park9b409bc2019-10-11 14:59:13 +0900437}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000438
Paul Duffinf88d8e02020-05-07 20:21:34 +0100439// Check the syntax of the generated Android.bp file contents and if they are
440// invalid then log an error with the contents (tagged with line numbers) and the
441// errors that were found so that it is easy to see where the problem lies.
442func syntaxCheckSnapshotBpFile(ctx android.ModuleContext, contents string) {
443 errs := android.CheckBlueprintSyntax(ctx, "Android.bp", contents)
444 if len(errs) != 0 {
445 message := &strings.Builder{}
446 _, _ = fmt.Fprint(message, `errors in generated Android.bp snapshot:
447
448Generated Android.bp contents
449========================================================================
450`)
451 for i, line := range strings.Split(contents, "\n") {
452 _, _ = fmt.Fprintf(message, "%6d: %s\n", i+1, line)
453 }
454
455 _, _ = fmt.Fprint(message, `
456========================================================================
457
458Errors found:
459`)
460
461 for _, err := range errs {
462 _, _ = fmt.Fprintf(message, "%s\n", err.Error())
463 }
464
465 ctx.ModuleErrorf("%s", message.String())
466 }
467}
468
Paul Duffin4b8b7932020-05-06 12:35:38 +0100469func extractCommonProperties(ctx android.ModuleContext, extractor *commonValueExtractor, commonProperties interface{}, inputPropertiesSlice interface{}) {
470 err := extractor.extractCommonProperties(commonProperties, inputPropertiesSlice)
471 if err != nil {
472 ctx.ModuleErrorf("error extracting common properties: %s", err)
473 }
474}
475
Paul Duffinfbe470e2021-04-24 12:37:13 +0100476// snapshotModuleStaticProperties contains snapshot static (i.e. not dynamically generated) properties.
477type snapshotModuleStaticProperties struct {
478 Compile_multilib string `android:"arch_variant"`
479}
480
Paul Duffin2d1bb892021-04-24 11:32:59 +0100481// combinedSnapshotModuleProperties are the properties that are associated with the snapshot module.
482type combinedSnapshotModuleProperties struct {
483 // The sdk variant from which this information was collected.
484 sdkVariant *sdk
485
486 // Static snapshot module properties.
487 staticProperties *snapshotModuleStaticProperties
488
489 // The dynamically generated member list properties.
490 dynamicProperties interface{}
491}
492
493// collateSnapshotModuleInfo collates all the snapshot module info from supplied sdk variants.
Paul Duffincd064672021-04-24 00:47:29 +0100494func (s *sdk) collateSnapshotModuleInfo(ctx android.BaseModuleContext, sdkVariants []*sdk, memberVariantDeps []sdkMemberVariantDep) []*combinedSnapshotModuleProperties {
495 sdkVariantToCombinedProperties := map[*sdk]*combinedSnapshotModuleProperties{}
Paul Duffin2d1bb892021-04-24 11:32:59 +0100496 var list []*combinedSnapshotModuleProperties
497 for _, sdkVariant := range sdkVariants {
498 staticProperties := &snapshotModuleStaticProperties{
499 Compile_multilib: sdkVariant.multilibUsages.String(),
500 }
Paul Duffincd064672021-04-24 00:47:29 +0100501 dynamicProperties := s.dynamicSdkMemberTypes.createMemberListProperties()
Paul Duffin2d1bb892021-04-24 11:32:59 +0100502
Paul Duffincd064672021-04-24 00:47:29 +0100503 combinedProperties := &combinedSnapshotModuleProperties{
Paul Duffin2d1bb892021-04-24 11:32:59 +0100504 sdkVariant: sdkVariant,
505 staticProperties: staticProperties,
506 dynamicProperties: dynamicProperties,
Paul Duffincd064672021-04-24 00:47:29 +0100507 }
508 sdkVariantToCombinedProperties[sdkVariant] = combinedProperties
509
510 list = append(list, combinedProperties)
Paul Duffin2d1bb892021-04-24 11:32:59 +0100511 }
Paul Duffincd064672021-04-24 00:47:29 +0100512
513 for _, memberVariantDep := range memberVariantDeps {
514 // If the member dependency is internal then do not add the dependency to the snapshot member
515 // list properties.
516 if !memberVariantDep.export {
517 continue
518 }
519
520 combined := sdkVariantToCombinedProperties[memberVariantDep.sdkVariant]
521 memberTypeProperty := s.memberListProperty(memberVariantDep.memberType)
522 memberName := ctx.OtherModuleName(memberVariantDep.variant)
523
524 // Append the member to the appropriate list, if it is not already present in the list.
525 memberList := memberTypeProperty.getter(combined.dynamicProperties)
526 if !android.InList(memberName, memberList) {
527 memberList = append(memberList, memberName)
528 }
529 memberTypeProperty.setter(combined.dynamicProperties, memberList)
530 }
531
Paul Duffin2d1bb892021-04-24 11:32:59 +0100532 return list
533}
534
535func (s *sdk) optimizeSnapshotModuleProperties(ctx android.ModuleContext, list []*combinedSnapshotModuleProperties) *combinedSnapshotModuleProperties {
536
537 // Extract the dynamic properties and add them to a list of propertiesContainer.
538 propertyContainers := []propertiesContainer{}
539 for _, i := range list {
540 propertyContainers = append(propertyContainers, sdkVariantPropertiesContainer{
541 sdkVariant: i.sdkVariant,
542 properties: i.dynamicProperties,
543 })
544 }
545
546 // Extract the common members, removing them from the original properties.
547 commonDynamicProperties := s.dynamicSdkMemberTypes.createMemberListProperties()
548 extractor := newCommonValueExtractor(commonDynamicProperties)
549 extractCommonProperties(ctx, extractor, commonDynamicProperties, propertyContainers)
550
551 // Extract the static properties and add them to a list of propertiesContainer.
552 propertyContainers = []propertiesContainer{}
553 for _, i := range list {
554 propertyContainers = append(propertyContainers, sdkVariantPropertiesContainer{
555 sdkVariant: i.sdkVariant,
556 properties: i.staticProperties,
557 })
558 }
559
560 commonStaticProperties := &snapshotModuleStaticProperties{}
561 extractor = newCommonValueExtractor(commonStaticProperties)
562 extractCommonProperties(ctx, extractor, &commonStaticProperties, propertyContainers)
563
564 return &combinedSnapshotModuleProperties{
565 sdkVariant: nil,
566 staticProperties: commonStaticProperties,
567 dynamicProperties: commonDynamicProperties,
568 }
569}
570
571func (s *sdk) addSnapshotPropertiesToPropertySet(builder *snapshotBuilder, propertySet android.BpPropertySet, combined *combinedSnapshotModuleProperties) {
572 staticProperties := combined.staticProperties
Paul Duffinfbe470e2021-04-24 12:37:13 +0100573 multilib := staticProperties.Compile_multilib
574 if multilib != "" && multilib != "both" {
575 // Compile_multilib defaults to both so only needs to be set when it's specified and not both.
576 propertySet.AddProperty("compile_multilib", multilib)
577 }
578
Paul Duffin2d1bb892021-04-24 11:32:59 +0100579 dynamicMemberTypeListProperties := combined.dynamicProperties
Paul Duffin865171e2020-03-02 18:38:15 +0000580 for _, memberListProperty := range s.memberListProperties() {
581 names := memberListProperty.getter(dynamicMemberTypeListProperties)
582 if len(names) > 0 {
Paul Duffin13f02712020-03-06 12:30:43 +0000583 propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false))
Paul Duffin865171e2020-03-02 18:38:15 +0000584 }
585 }
586}
587
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000588type propertyTag struct {
589 name string
590}
591
Paul Duffin0cb37b92020-03-04 14:52:46 +0000592// A BpPropertyTag to add to a property that contains references to other sdk members.
593//
594// This will cause the references to be rewritten to a versioned reference in the version
595// specific instance of a snapshot module.
Paul Duffin13f02712020-03-06 12:30:43 +0000596var requiredSdkMemberReferencePropertyTag = propertyTag{"requiredSdkMemberReferencePropertyTag"}
Paul Duffin13f02712020-03-06 12:30:43 +0000597var optionalSdkMemberReferencePropertyTag = propertyTag{"optionalSdkMemberReferencePropertyTag"}
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000598
Paul Duffin0cb37b92020-03-04 14:52:46 +0000599// A BpPropertyTag that indicates the property should only be present in the versioned
600// module.
601//
602// This will cause the property to be removed from the unversioned instance of a
603// snapshot module.
604var sdkVersionedOnlyPropertyTag = propertyTag{"sdkVersionedOnlyPropertyTag"}
605
Paul Duffine6c0d842020-01-15 14:08:51 +0000606type unversionedToVersionedTransformation struct {
607 identityTransformation
608 builder *snapshotBuilder
609}
610
Paul Duffine6c0d842020-01-15 14:08:51 +0000611func (t unversionedToVersionedTransformation) transformModule(module *bpModule) *bpModule {
612 // Use a versioned name for the module but remember the original name for the
613 // snapshot.
614 name := module.getValue("name").(string)
Paul Duffin13f02712020-03-06 12:30:43 +0000615 module.setProperty("name", t.builder.versionedSdkMemberName(name, true))
Paul Duffine6c0d842020-01-15 14:08:51 +0000616 module.insertAfter("name", "sdk_member_name", name)
617 return module
618}
619
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000620func (t unversionedToVersionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) {
Paul Duffin13f02712020-03-06 12:30:43 +0000621 if tag == requiredSdkMemberReferencePropertyTag || tag == optionalSdkMemberReferencePropertyTag {
622 required := tag == requiredSdkMemberReferencePropertyTag
623 return t.builder.versionedSdkMemberNames(value.([]string), required), tag
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000624 } else {
625 return value, tag
626 }
627}
628
Paul Duffin72910952020-01-20 18:16:30 +0000629type unversionedTransformation struct {
630 identityTransformation
631 builder *snapshotBuilder
Paul Duffin64fb5262021-05-05 21:36:04 +0100632 prefer bool
Paul Duffin72910952020-01-20 18:16:30 +0000633}
634
635func (t unversionedTransformation) transformModule(module *bpModule) *bpModule {
636 // If the module is an internal member then use a unique name for it.
637 name := module.getValue("name").(string)
Paul Duffin13f02712020-03-06 12:30:43 +0000638 module.setProperty("name", t.builder.unversionedSdkMemberName(name, true))
Paul Duffin72910952020-01-20 18:16:30 +0000639
Paul Duffin64fb5262021-05-05 21:36:04 +0100640 // Set prefer. Setting this to false is not strictly required as that is the default but it does
641 // provide a convenient hook to post-process the generated Android.bp file, e.g. in tests to check
642 // the behavior when a prebuilt is preferred. It also makes it explicit what the default behavior
643 // is for the module.
644 module.insertAfter("name", "prefer", t.prefer)
Paul Duffin72910952020-01-20 18:16:30 +0000645
646 return module
647}
648
649func (t unversionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) {
Paul Duffin13f02712020-03-06 12:30:43 +0000650 if tag == requiredSdkMemberReferencePropertyTag || tag == optionalSdkMemberReferencePropertyTag {
651 required := tag == requiredSdkMemberReferencePropertyTag
652 return t.builder.unversionedSdkMemberNames(value.([]string), required), tag
Paul Duffin0cb37b92020-03-04 14:52:46 +0000653 } else if tag == sdkVersionedOnlyPropertyTag {
654 // The property is not allowed in the unversioned module so remove it.
655 return nil, nil
Paul Duffin72910952020-01-20 18:16:30 +0000656 } else {
657 return value, tag
658 }
659}
660
Paul Duffina78f3a72020-02-21 16:29:35 +0000661type pruneEmptySetTransformer struct {
662 identityTransformation
663}
664
665var _ bpTransformer = (*pruneEmptySetTransformer)(nil)
666
667func (t pruneEmptySetTransformer) transformPropertySetAfterContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) {
668 if len(propertySet.properties) == 0 {
669 return nil, nil
670 } else {
671 return propertySet, tag
672 }
673}
674
Paul Duffinb645ec82019-11-27 17:43:54 +0000675func generateBpContents(contents *generatedContents, bpFile *bpFile) {
Paul Duffind0759072021-02-17 11:23:00 +0000676 generateFilteredBpContents(contents, bpFile, func(*bpModule) bool {
677 return true
678 })
679}
680
681func generateFilteredBpContents(contents *generatedContents, bpFile *bpFile, moduleFilter func(module *bpModule) bool) {
Paul Duffinb645ec82019-11-27 17:43:54 +0000682 contents.Printfln("// This is auto-generated. DO NOT EDIT.")
683 for _, bpModule := range bpFile.order {
Paul Duffind0759072021-02-17 11:23:00 +0000684 if moduleFilter(bpModule) {
685 contents.Printfln("")
686 contents.Printfln("%s {", bpModule.moduleType)
687 outputPropertySet(contents, bpModule.bpPropertySet)
688 contents.Printfln("}")
689 }
Paul Duffinb645ec82019-11-27 17:43:54 +0000690 }
Paul Duffinb645ec82019-11-27 17:43:54 +0000691}
692
693func outputPropertySet(contents *generatedContents, set *bpPropertySet) {
694 contents.Indent()
Paul Duffin07ef3cb2020-03-11 18:17:42 +0000695
696 // Output the properties first, followed by the nested sets. This ensures a
697 // consistent output irrespective of whether property sets are created before
698 // or after the properties. This simplifies the creation of the module.
Paul Duffinb645ec82019-11-27 17:43:54 +0000699 for _, name := range set.order {
Paul Duffin5b511a22020-01-15 14:23:52 +0000700 value := set.getValue(name)
Paul Duffinb645ec82019-11-27 17:43:54 +0000701
Paul Duffin07ef3cb2020-03-11 18:17:42 +0000702 switch v := value.(type) {
703 case []string:
704 length := len(v)
Paul Duffinb645ec82019-11-27 17:43:54 +0000705 if length > 1 {
706 contents.Printfln("%s: [", name)
707 contents.Indent()
708 for i := 0; i < length; i = i + 1 {
Paul Duffin07ef3cb2020-03-11 18:17:42 +0000709 contents.Printfln("%q,", v[i])
Paul Duffinb645ec82019-11-27 17:43:54 +0000710 }
711 contents.Dedent()
712 contents.Printfln("],")
713 } else if length == 0 {
714 contents.Printfln("%s: [],", name)
715 } else {
Paul Duffin07ef3cb2020-03-11 18:17:42 +0000716 contents.Printfln("%s: [%q],", name, v[0])
Paul Duffinb645ec82019-11-27 17:43:54 +0000717 }
Paul Duffinb645ec82019-11-27 17:43:54 +0000718
Paul Duffin07ef3cb2020-03-11 18:17:42 +0000719 case bool:
720 contents.Printfln("%s: %t,", name, v)
721
722 case *bpPropertySet:
723 // Do not write property sets in the properties phase.
Paul Duffinb645ec82019-11-27 17:43:54 +0000724
725 default:
726 contents.Printfln("%s: %q,", name, value)
727 }
728 }
Paul Duffin07ef3cb2020-03-11 18:17:42 +0000729
730 for _, name := range set.order {
731 value := set.getValue(name)
732
733 // Only write property sets in the sets phase.
734 switch v := value.(type) {
735 case *bpPropertySet:
736 contents.Printfln("%s: {", name)
737 outputPropertySet(contents, v)
738 contents.Printfln("},")
739 }
740 }
741
Paul Duffinb645ec82019-11-27 17:43:54 +0000742 contents.Dedent()
743}
744
Paul Duffinac37c502019-11-26 18:02:20 +0000745func (s *sdk) GetAndroidBpContentsForTests() string {
Paul Duffinb645ec82019-11-27 17:43:54 +0000746 contents := &generatedContents{}
747 generateBpContents(contents, s.builderForTests.bpFile)
748 return contents.content.String()
Paul Duffinac37c502019-11-26 18:02:20 +0000749}
750
Paul Duffind0759072021-02-17 11:23:00 +0000751func (s *sdk) GetUnversionedAndroidBpContentsForTests() string {
752 contents := &generatedContents{}
753 generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool {
754 return !strings.Contains(module.properties["name"].(string), "@")
755 })
756 return contents.content.String()
757}
758
759func (s *sdk) GetVersionedAndroidBpContentsForTests() string {
760 contents := &generatedContents{}
761 generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool {
762 return strings.Contains(module.properties["name"].(string), "@")
763 })
764 return contents.content.String()
765}
766
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000767type snapshotBuilder struct {
Paul Duffinb645ec82019-11-27 17:43:54 +0000768 ctx android.ModuleContext
Paul Duffine44358f2019-11-26 18:04:12 +0000769 sdk *sdk
Paul Duffinb645ec82019-11-27 17:43:54 +0000770 version string
771 snapshotDir android.OutputPath
772 bpFile *bpFile
Paul Duffinc62a5102019-12-11 18:34:15 +0000773
774 // Map from destination to source of each copy - used to eliminate duplicates and
775 // detect conflicts.
776 copies map[string]string
777
Paul Duffinb645ec82019-11-27 17:43:54 +0000778 filesToZip android.Paths
779 zipsToMerge android.Paths
780
781 prebuiltModules map[string]*bpModule
782 prebuiltOrder []*bpModule
Paul Duffin13f02712020-03-06 12:30:43 +0000783
784 // The set of all members by name.
785 allMembersByName map[string]struct{}
786
787 // The set of exported members by name.
788 exportedMembersByName map[string]struct{}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000789}
790
791func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) {
Paul Duffinc62a5102019-12-11 18:34:15 +0000792 if existing, ok := s.copies[dest]; ok {
793 if existing != src.String() {
794 s.ctx.ModuleErrorf("conflicting copy, %s copied from both %s and %s", dest, existing, src)
795 return
796 }
797 } else {
798 path := s.snapshotDir.Join(s.ctx, dest)
799 s.ctx.Build(pctx, android.BuildParams{
800 Rule: android.Cp,
801 Input: src,
802 Output: path,
803 })
804 s.filesToZip = append(s.filesToZip, path)
805
806 s.copies[dest] = src.String()
807 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000808}
809
Paul Duffin91547182019-11-12 19:39:36 +0000810func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string) {
811 ctx := s.ctx
812
813 // Repackage the zip file so that the entries are in the destDir directory.
814 // This will allow the zip file to be merged into the snapshot.
815 tmpZipPath := android.PathForModuleOut(ctx, "tmp", destDir+".zip").OutputPath
Paul Duffin375058f2019-11-29 20:17:53 +0000816
817 ctx.Build(pctx, android.BuildParams{
818 Description: "Repackaging zip file " + destDir + " for snapshot " + ctx.ModuleName(),
819 Rule: repackageZip,
820 Input: zipPath,
821 Output: tmpZipPath,
822 Args: map[string]string{
823 "destdir": destDir,
824 },
825 })
Paul Duffin91547182019-11-12 19:39:36 +0000826
827 // Add the repackaged zip file to the files to merge.
828 s.zipsToMerge = append(s.zipsToMerge, tmpZipPath)
829}
830
Paul Duffin9d8d6092019-12-05 18:19:29 +0000831func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType string) android.BpModule {
832 name := member.Name()
Paul Duffinb645ec82019-11-27 17:43:54 +0000833 if s.prebuiltModules[name] != nil {
834 panic(fmt.Sprintf("Duplicate module detected, module %s has already been added", name))
835 }
836
837 m := s.bpFile.newModule(moduleType)
838 m.AddProperty("name", name)
Paul Duffin593b3c92019-12-05 14:31:48 +0000839
Paul Duffinbefa4b92020-03-04 14:22:45 +0000840 variant := member.Variants()[0]
841
Paul Duffin13f02712020-03-06 12:30:43 +0000842 if s.isInternalMember(name) {
Paul Duffin72910952020-01-20 18:16:30 +0000843 // An internal member is only referenced from the sdk snapshot which is in the
844 // same package so can be marked as private.
845 m.AddProperty("visibility", []string{"//visibility:private"})
846 } else {
847 // Extract visibility information from a member variant. All variants have the same
848 // visibility so it doesn't matter which one is used.
Paul Duffin157f40f2020-09-29 16:01:08 +0100849 visibilityRules := android.EffectiveVisibilityRules(s.ctx, variant)
850
851 // Add any additional visibility rules needed for the prebuilts to reference each other.
852 err := visibilityRules.Widen(s.sdk.properties.Prebuilt_visibility)
853 if err != nil {
854 s.ctx.PropertyErrorf("prebuilt_visibility", "%s", err)
855 }
856
857 visibility := visibilityRules.Strings()
Paul Duffin72910952020-01-20 18:16:30 +0000858 if len(visibility) != 0 {
859 m.AddProperty("visibility", visibility)
860 }
Paul Duffin593b3c92019-12-05 14:31:48 +0000861 }
862
Martin Stjernholm1e041092020-11-03 00:11:09 +0000863 // Where available copy apex_available properties from the member.
864 if apexAware, ok := variant.(interface{ ApexAvailable() []string }); ok {
865 apexAvailable := apexAware.ApexAvailable()
866 if len(apexAvailable) == 0 {
867 // //apex_available:platform is the default.
868 apexAvailable = []string{android.AvailableToPlatform}
869 }
870
871 // Add in any baseline apex available settings.
872 apexAvailable = append(apexAvailable, apex.BaselineApexAvailable(member.Name())...)
873
874 // Remove duplicates and sort.
875 apexAvailable = android.FirstUniqueStrings(apexAvailable)
876 sort.Strings(apexAvailable)
877
878 m.AddProperty("apex_available", apexAvailable)
879 }
880
Paul Duffin865171e2020-03-02 18:38:15 +0000881 deviceSupported := false
882 hostSupported := false
883
884 for _, variant := range member.Variants() {
885 osClass := variant.Target().Os.Class
Jiyong Park1613e552020-09-14 19:43:17 +0900886 if osClass == android.Host {
Paul Duffin865171e2020-03-02 18:38:15 +0000887 hostSupported = true
888 } else if osClass == android.Device {
889 deviceSupported = true
890 }
891 }
892
893 addHostDeviceSupportedProperties(deviceSupported, hostSupported, m)
Paul Duffinb645ec82019-11-27 17:43:54 +0000894
Paul Duffin0cb37b92020-03-04 14:52:46 +0000895 // Disable installation in the versioned module of those modules that are ever installable.
896 if installable, ok := variant.(interface{ EverInstallable() bool }); ok {
897 if installable.EverInstallable() {
898 m.AddPropertyWithTag("installable", false, sdkVersionedOnlyPropertyTag)
899 }
900 }
901
Paul Duffinb645ec82019-11-27 17:43:54 +0000902 s.prebuiltModules[name] = m
903 s.prebuiltOrder = append(s.prebuiltOrder, m)
904 return m
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000905}
906
Paul Duffin865171e2020-03-02 18:38:15 +0000907func addHostDeviceSupportedProperties(deviceSupported bool, hostSupported bool, bpModule *bpModule) {
908 if !deviceSupported {
Paul Duffine44358f2019-11-26 18:04:12 +0000909 bpModule.AddProperty("device_supported", false)
910 }
Paul Duffin865171e2020-03-02 18:38:15 +0000911 if hostSupported {
Paul Duffine44358f2019-11-26 18:04:12 +0000912 bpModule.AddProperty("host_supported", true)
913 }
914}
915
Paul Duffin13f02712020-03-06 12:30:43 +0000916func (s *snapshotBuilder) SdkMemberReferencePropertyTag(required bool) android.BpPropertyTag {
917 if required {
918 return requiredSdkMemberReferencePropertyTag
919 } else {
920 return optionalSdkMemberReferencePropertyTag
921 }
922}
923
924func (s *snapshotBuilder) OptionalSdkMemberReferencePropertyTag() android.BpPropertyTag {
925 return optionalSdkMemberReferencePropertyTag
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000926}
927
Paul Duffinb645ec82019-11-27 17:43:54 +0000928// Get a versioned name appropriate for the SDK snapshot version being taken.
Paul Duffin13f02712020-03-06 12:30:43 +0000929func (s *snapshotBuilder) versionedSdkMemberName(unversionedName string, required bool) string {
930 if _, ok := s.allMembersByName[unversionedName]; !ok {
931 if required {
932 s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", unversionedName)
933 }
934 return unversionedName
935 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000936 return versionedSdkMemberName(s.ctx, unversionedName, s.version)
937}
Paul Duffinb645ec82019-11-27 17:43:54 +0000938
Paul Duffin13f02712020-03-06 12:30:43 +0000939func (s *snapshotBuilder) versionedSdkMemberNames(members []string, required bool) []string {
Paul Duffinb645ec82019-11-27 17:43:54 +0000940 var references []string = nil
941 for _, m := range members {
Paul Duffin13f02712020-03-06 12:30:43 +0000942 references = append(references, s.versionedSdkMemberName(m, required))
Paul Duffinb645ec82019-11-27 17:43:54 +0000943 }
944 return references
945}
Paul Duffin13879572019-11-28 14:31:38 +0000946
Paul Duffin72910952020-01-20 18:16:30 +0000947// Get an internal name unique to the sdk.
Paul Duffin13f02712020-03-06 12:30:43 +0000948func (s *snapshotBuilder) unversionedSdkMemberName(unversionedName string, required bool) string {
949 if _, ok := s.allMembersByName[unversionedName]; !ok {
950 if required {
951 s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", unversionedName)
952 }
953 return unversionedName
954 }
955
956 if s.isInternalMember(unversionedName) {
Paul Duffin72910952020-01-20 18:16:30 +0000957 return s.ctx.ModuleName() + "_" + unversionedName
958 } else {
959 return unversionedName
960 }
961}
962
Paul Duffin13f02712020-03-06 12:30:43 +0000963func (s *snapshotBuilder) unversionedSdkMemberNames(members []string, required bool) []string {
Paul Duffin72910952020-01-20 18:16:30 +0000964 var references []string = nil
965 for _, m := range members {
Paul Duffin13f02712020-03-06 12:30:43 +0000966 references = append(references, s.unversionedSdkMemberName(m, required))
Paul Duffin72910952020-01-20 18:16:30 +0000967 }
968 return references
969}
970
Paul Duffin13f02712020-03-06 12:30:43 +0000971func (s *snapshotBuilder) isInternalMember(memberName string) bool {
972 _, ok := s.exportedMembersByName[memberName]
973 return !ok
974}
975
Martin Stjernholm89238f42020-07-10 00:14:03 +0100976// Add the properties from the given SdkMemberProperties to the blueprint
977// property set. This handles common properties in SdkMemberPropertiesBase and
978// calls the member-specific AddToPropertySet for the rest.
979func addSdkMemberPropertiesToSet(ctx *memberContext, memberProperties android.SdkMemberProperties, targetPropertySet android.BpPropertySet) {
980 if memberProperties.Base().Compile_multilib != "" {
981 targetPropertySet.AddProperty("compile_multilib", memberProperties.Base().Compile_multilib)
982 }
983
984 memberProperties.AddToPropertySet(ctx, targetPropertySet)
985}
986
Paul Duffin21827262021-04-24 12:16:36 +0100987// sdkMemberVariantDep represents a dependency from an sdk variant onto a member variant.
988type sdkMemberVariantDep struct {
Paul Duffincd064672021-04-24 00:47:29 +0100989 // The sdk variant that depends (possibly indirectly) on the member variant.
990 sdkVariant *sdk
Paul Duffin1356d8c2020-02-25 19:26:33 +0000991 memberType android.SdkMemberType
992 variant android.SdkAware
Paul Duffina7208112021-04-23 21:20:20 +0100993 export bool
Paul Duffin1356d8c2020-02-25 19:26:33 +0000994}
995
Paul Duffin13879572019-11-28 14:31:38 +0000996var _ android.SdkMember = (*sdkMember)(nil)
997
Paul Duffin21827262021-04-24 12:16:36 +0100998// sdkMember groups all the variants of a specific member module together along with the name of the
999// module and the member type. This is used to generate the prebuilt modules for a specific member.
Paul Duffin13879572019-11-28 14:31:38 +00001000type sdkMember struct {
1001 memberType android.SdkMemberType
1002 name string
1003 variants []android.SdkAware
1004}
1005
1006func (m *sdkMember) Name() string {
1007 return m.name
1008}
1009
1010func (m *sdkMember) Variants() []android.SdkAware {
1011 return m.variants
1012}
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001013
Paul Duffin9c3760e2020-03-16 19:52:08 +00001014// Track usages of multilib variants.
1015type multilibUsage int
1016
1017const (
1018 multilibNone multilibUsage = 0
1019 multilib32 multilibUsage = 1
1020 multilib64 multilibUsage = 2
1021 multilibBoth = multilib32 | multilib64
1022)
1023
1024// Add the multilib that is used in the arch type.
1025func (m multilibUsage) addArchType(archType android.ArchType) multilibUsage {
1026 multilib := archType.Multilib
1027 switch multilib {
1028 case "":
1029 return m
1030 case "lib32":
1031 return m | multilib32
1032 case "lib64":
1033 return m | multilib64
1034 default:
1035 panic(fmt.Errorf("Unknown Multilib field in ArchType, expected 'lib32' or 'lib64', found %q", multilib))
1036 }
1037}
1038
1039func (m multilibUsage) String() string {
1040 switch m {
1041 case multilibNone:
1042 return ""
1043 case multilib32:
1044 return "32"
1045 case multilib64:
1046 return "64"
1047 case multilibBoth:
1048 return "both"
1049 default:
1050 panic(fmt.Errorf("Unknown multilib value, found %b, expected one of %b, %b, %b or %b",
1051 m, multilibNone, multilib32, multilib64, multilibBoth))
1052 }
1053}
1054
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001055type baseInfo struct {
1056 Properties android.SdkMemberProperties
1057}
1058
Paul Duffinf34f6d82020-04-30 15:48:31 +01001059func (b *baseInfo) optimizableProperties() interface{} {
1060 return b.Properties
1061}
1062
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001063type osTypeSpecificInfo struct {
1064 baseInfo
1065
Paul Duffin00e46802020-03-12 20:40:35 +00001066 osType android.OsType
1067
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001068 // The list of arch type specific info for this os type.
Paul Duffinb44b33a2020-03-17 10:58:23 +00001069 //
1070 // Nil if there is one variant whose arch type is common
1071 archInfos []*archTypeSpecificInfo
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001072}
1073
Paul Duffin4b8b7932020-05-06 12:35:38 +01001074var _ propertiesContainer = (*osTypeSpecificInfo)(nil)
1075
Paul Duffinfc8dd232020-03-17 12:51:37 +00001076type variantPropertiesFactoryFunc func() android.SdkMemberProperties
1077
Paul Duffin00e46802020-03-12 20:40:35 +00001078// Create a new osTypeSpecificInfo for the specified os type and its properties
1079// structures populated with information from the variants.
Paul Duffin3a4eb502020-03-19 16:11:18 +00001080func newOsTypeSpecificInfo(ctx android.SdkMemberContext, osType android.OsType, variantPropertiesFactory variantPropertiesFactoryFunc, osTypeVariants []android.Module) *osTypeSpecificInfo {
Paul Duffin00e46802020-03-12 20:40:35 +00001081 osInfo := &osTypeSpecificInfo{
1082 osType: osType,
1083 }
1084
1085 osSpecificVariantPropertiesFactory := func() android.SdkMemberProperties {
1086 properties := variantPropertiesFactory()
1087 properties.Base().Os = osType
1088 return properties
1089 }
1090
1091 // Create a structure into which properties common across the architectures in
1092 // this os type will be stored.
1093 osInfo.Properties = osSpecificVariantPropertiesFactory()
1094
1095 // Group the variants by arch type.
Paul Duffin3a4eb502020-03-19 16:11:18 +00001096 var variantsByArchName = make(map[string][]android.Module)
Paul Duffin00e46802020-03-12 20:40:35 +00001097 var archTypes []android.ArchType
1098 for _, variant := range osTypeVariants {
1099 archType := variant.Target().Arch.ArchType
1100 archTypeName := archType.Name
1101 if _, ok := variantsByArchName[archTypeName]; !ok {
1102 archTypes = append(archTypes, archType)
1103 }
1104
1105 variantsByArchName[archTypeName] = append(variantsByArchName[archTypeName], variant)
1106 }
1107
1108 if commonVariants, ok := variantsByArchName["common"]; ok {
1109 if len(osTypeVariants) != 1 {
Colin Crossafa6a772020-07-06 17:41:08 -07001110 panic(fmt.Errorf("Expected to only have 1 variant when arch type is common but found %d", len(osTypeVariants)))
Paul Duffin00e46802020-03-12 20:40:35 +00001111 }
1112
1113 // A common arch type only has one variant and its properties should be treated
1114 // as common to the os type.
Paul Duffin3a4eb502020-03-19 16:11:18 +00001115 osInfo.Properties.PopulateFromVariant(ctx, commonVariants[0])
Paul Duffin00e46802020-03-12 20:40:35 +00001116 } else {
1117 // Create an arch specific info for each supported architecture type.
1118 for _, archType := range archTypes {
1119 archTypeName := archType.Name
1120
1121 archVariants := variantsByArchName[archTypeName]
Jiyong Park8fe14e62020-10-19 22:47:34 +09001122 archInfo := newArchSpecificInfo(ctx, archType, osType, osSpecificVariantPropertiesFactory, archVariants)
Paul Duffin00e46802020-03-12 20:40:35 +00001123
1124 osInfo.archInfos = append(osInfo.archInfos, archInfo)
1125 }
1126 }
1127
1128 return osInfo
1129}
1130
1131// Optimize the properties by extracting common properties from arch type specific
1132// properties into os type specific properties.
Paul Duffin4b8b7932020-05-06 12:35:38 +01001133func (osInfo *osTypeSpecificInfo) optimizeProperties(ctx *memberContext, commonValueExtractor *commonValueExtractor) {
Paul Duffin00e46802020-03-12 20:40:35 +00001134 // Nothing to do if there is only a single common architecture.
1135 if len(osInfo.archInfos) == 0 {
1136 return
1137 }
1138
Paul Duffin9c3760e2020-03-16 19:52:08 +00001139 multilib := multilibNone
Paul Duffin00e46802020-03-12 20:40:35 +00001140 for _, archInfo := range osInfo.archInfos {
Paul Duffin9c3760e2020-03-16 19:52:08 +00001141 multilib = multilib.addArchType(archInfo.archType)
1142
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001143 // Optimize the arch properties first.
Paul Duffin4b8b7932020-05-06 12:35:38 +01001144 archInfo.optimizeProperties(ctx, commonValueExtractor)
Paul Duffin00e46802020-03-12 20:40:35 +00001145 }
1146
Paul Duffin4b8b7932020-05-06 12:35:38 +01001147 extractCommonProperties(ctx.sdkMemberContext, commonValueExtractor, osInfo.Properties, osInfo.archInfos)
Paul Duffin00e46802020-03-12 20:40:35 +00001148
1149 // Choose setting for compile_multilib that is appropriate for the arch variants supplied.
Paul Duffin9c3760e2020-03-16 19:52:08 +00001150 osInfo.Properties.Base().Compile_multilib = multilib.String()
Paul Duffin00e46802020-03-12 20:40:35 +00001151}
1152
1153// Add the properties for an os to a property set.
1154//
1155// Maps the properties related to the os variants through to an appropriate
1156// module structure that will produce equivalent set of variants when it is
1157// processed in a build.
Paul Duffin3a4eb502020-03-19 16:11:18 +00001158func (osInfo *osTypeSpecificInfo) addToPropertySet(ctx *memberContext, bpModule android.BpModule, targetPropertySet android.BpPropertySet) {
Paul Duffin00e46802020-03-12 20:40:35 +00001159
1160 var osPropertySet android.BpPropertySet
1161 var archPropertySet android.BpPropertySet
1162 var archOsPrefix string
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001163 if osInfo.Properties.Base().Os_count == 1 &&
1164 (osInfo.osType.Class == android.Device || !ctx.memberType.IsHostOsDependent()) {
1165 // There is only one OS type present in the variants and it shouldn't have a
1166 // variant-specific target. The latter is the case if it's either for device
1167 // where there is only one OS (android), or for host and the member type
1168 // isn't host OS dependent.
Paul Duffin00e46802020-03-12 20:40:35 +00001169
1170 // Create a structure that looks like:
1171 // module_type {
1172 // name: "...",
1173 // ...
1174 // <common properties>
1175 // ...
1176 // <single os type specific properties>
1177 //
1178 // arch: {
1179 // <arch specific sections>
1180 // }
1181 //
1182 osPropertySet = bpModule
1183 archPropertySet = osPropertySet.AddPropertySet("arch")
1184
1185 // Arch specific properties need to be added to an arch specific section
1186 // within arch.
1187 archOsPrefix = ""
1188 } else {
1189 // Create a structure that looks like:
1190 // module_type {
1191 // name: "...",
1192 // ...
1193 // <common properties>
1194 // ...
1195 // target: {
1196 // <arch independent os specific sections, e.g. android>
1197 // ...
1198 // <arch and os specific sections, e.g. android_x86>
1199 // }
1200 //
1201 osType := osInfo.osType
1202 osPropertySet = targetPropertySet.AddPropertySet(osType.Name)
1203 archPropertySet = targetPropertySet
1204
1205 // Arch specific properties need to be added to an os and arch specific
1206 // section prefixed with <os>_.
1207 archOsPrefix = osType.Name + "_"
1208 }
1209
1210 // Add the os specific but arch independent properties to the module.
Martin Stjernholm89238f42020-07-10 00:14:03 +01001211 addSdkMemberPropertiesToSet(ctx, osInfo.Properties, osPropertySet)
Paul Duffin00e46802020-03-12 20:40:35 +00001212
1213 // Add arch (and possibly os) specific sections for each set of arch (and possibly
1214 // os) specific properties.
1215 //
1216 // The archInfos list will be empty if the os contains variants for the common
1217 // architecture.
1218 for _, archInfo := range osInfo.archInfos {
Paul Duffin3a4eb502020-03-19 16:11:18 +00001219 archInfo.addToPropertySet(ctx, archPropertySet, archOsPrefix)
Paul Duffin00e46802020-03-12 20:40:35 +00001220 }
1221}
1222
Paul Duffin7a1f7f32020-05-04 15:32:08 +01001223func (osInfo *osTypeSpecificInfo) isHostVariant() bool {
1224 osClass := osInfo.osType.Class
Jiyong Park1613e552020-09-14 19:43:17 +09001225 return osClass == android.Host
Paul Duffin7a1f7f32020-05-04 15:32:08 +01001226}
1227
1228var _ isHostVariant = (*osTypeSpecificInfo)(nil)
1229
Paul Duffin4b8b7932020-05-06 12:35:38 +01001230func (osInfo *osTypeSpecificInfo) String() string {
1231 return fmt.Sprintf("OsType{%s}", osInfo.osType)
1232}
1233
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001234type archTypeSpecificInfo struct {
1235 baseInfo
1236
1237 archType android.ArchType
Jiyong Park8fe14e62020-10-19 22:47:34 +09001238 osType android.OsType
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001239
1240 linkInfos []*linkTypeSpecificInfo
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001241}
1242
Paul Duffin4b8b7932020-05-06 12:35:38 +01001243var _ propertiesContainer = (*archTypeSpecificInfo)(nil)
1244
Paul Duffinfc8dd232020-03-17 12:51:37 +00001245// Create a new archTypeSpecificInfo for the specified arch type and its properties
1246// structures populated with information from the variants.
Jiyong Park8fe14e62020-10-19 22:47:34 +09001247func newArchSpecificInfo(ctx android.SdkMemberContext, archType android.ArchType, osType android.OsType, variantPropertiesFactory variantPropertiesFactoryFunc, archVariants []android.Module) *archTypeSpecificInfo {
Paul Duffinfc8dd232020-03-17 12:51:37 +00001248
Paul Duffinfc8dd232020-03-17 12:51:37 +00001249 // Create an arch specific info into which the variant properties can be copied.
Jiyong Park8fe14e62020-10-19 22:47:34 +09001250 archInfo := &archTypeSpecificInfo{archType: archType, osType: osType}
Paul Duffinfc8dd232020-03-17 12:51:37 +00001251
1252 // Create the properties into which the arch type specific properties will be
1253 // added.
1254 archInfo.Properties = variantPropertiesFactory()
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001255
1256 if len(archVariants) == 1 {
Paul Duffin3a4eb502020-03-19 16:11:18 +00001257 archInfo.Properties.PopulateFromVariant(ctx, archVariants[0])
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001258 } else {
1259 // There is more than one variant for this arch type which must be differentiated
1260 // by link type.
1261 for _, linkVariant := range archVariants {
1262 linkType := getLinkType(linkVariant)
1263 if linkType == "" {
1264 panic(fmt.Errorf("expected one arch specific variant as it is not identified by link type but found %d", len(archVariants)))
1265 } else {
Paul Duffin3a4eb502020-03-19 16:11:18 +00001266 linkInfo := newLinkSpecificInfo(ctx, linkType, variantPropertiesFactory, linkVariant)
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001267
1268 archInfo.linkInfos = append(archInfo.linkInfos, linkInfo)
1269 }
1270 }
1271 }
Paul Duffinfc8dd232020-03-17 12:51:37 +00001272
1273 return archInfo
1274}
1275
Paul Duffinf34f6d82020-04-30 15:48:31 +01001276func (archInfo *archTypeSpecificInfo) optimizableProperties() interface{} {
1277 return archInfo.Properties
1278}
1279
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001280// Get the link type of the variant
1281//
1282// If the variant is not differentiated by link type then it returns "",
1283// otherwise it returns one of "static" or "shared".
1284func getLinkType(variant android.Module) string {
1285 linkType := ""
1286 if linkable, ok := variant.(cc.LinkableInterface); ok {
1287 if linkable.Shared() && linkable.Static() {
1288 panic(fmt.Errorf("expected variant %q to be either static or shared but was both", variant.String()))
1289 } else if linkable.Shared() {
1290 linkType = "shared"
1291 } else if linkable.Static() {
1292 linkType = "static"
1293 } else {
1294 panic(fmt.Errorf("expected variant %q to be either static or shared but was neither", variant.String()))
1295 }
1296 }
1297 return linkType
1298}
1299
1300// Optimize the properties by extracting common properties from link type specific
1301// properties into arch type specific properties.
Paul Duffin4b8b7932020-05-06 12:35:38 +01001302func (archInfo *archTypeSpecificInfo) optimizeProperties(ctx *memberContext, commonValueExtractor *commonValueExtractor) {
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001303 if len(archInfo.linkInfos) == 0 {
1304 return
1305 }
1306
Paul Duffin4b8b7932020-05-06 12:35:38 +01001307 extractCommonProperties(ctx.sdkMemberContext, commonValueExtractor, archInfo.Properties, archInfo.linkInfos)
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001308}
1309
Paul Duffinfc8dd232020-03-17 12:51:37 +00001310// Add the properties for an arch type to a property set.
Paul Duffin3a4eb502020-03-19 16:11:18 +00001311func (archInfo *archTypeSpecificInfo) addToPropertySet(ctx *memberContext, archPropertySet android.BpPropertySet, archOsPrefix string) {
Paul Duffinfc8dd232020-03-17 12:51:37 +00001312 archTypeName := archInfo.archType.Name
1313 archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archTypeName)
Jiyong Park8fe14e62020-10-19 22:47:34 +09001314 // Enable the <os>_<arch> variant explicitly when we've disabled it by default on host.
1315 if ctx.memberType.IsHostOsDependent() && archInfo.osType.Class == android.Host {
1316 archTypePropertySet.AddProperty("enabled", true)
1317 }
Martin Stjernholm89238f42020-07-10 00:14:03 +01001318 addSdkMemberPropertiesToSet(ctx, archInfo.Properties, archTypePropertySet)
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001319
1320 for _, linkInfo := range archInfo.linkInfos {
1321 linkPropertySet := archTypePropertySet.AddPropertySet(linkInfo.linkType)
Martin Stjernholm89238f42020-07-10 00:14:03 +01001322 addSdkMemberPropertiesToSet(ctx, linkInfo.Properties, linkPropertySet)
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001323 }
1324}
1325
Paul Duffin4b8b7932020-05-06 12:35:38 +01001326func (archInfo *archTypeSpecificInfo) String() string {
1327 return fmt.Sprintf("ArchType{%s}", archInfo.archType)
1328}
1329
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001330type linkTypeSpecificInfo struct {
1331 baseInfo
1332
1333 linkType string
1334}
1335
Paul Duffin4b8b7932020-05-06 12:35:38 +01001336var _ propertiesContainer = (*linkTypeSpecificInfo)(nil)
1337
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001338// Create a new linkTypeSpecificInfo for the specified link type and its properties
1339// structures populated with information from the variant.
Paul Duffin3a4eb502020-03-19 16:11:18 +00001340func newLinkSpecificInfo(ctx android.SdkMemberContext, linkType string, variantPropertiesFactory variantPropertiesFactoryFunc, linkVariant android.Module) *linkTypeSpecificInfo {
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001341 linkInfo := &linkTypeSpecificInfo{
1342 baseInfo: baseInfo{
1343 // Create the properties into which the link type specific properties will be
1344 // added.
1345 Properties: variantPropertiesFactory(),
1346 },
1347 linkType: linkType,
1348 }
Paul Duffin3a4eb502020-03-19 16:11:18 +00001349 linkInfo.Properties.PopulateFromVariant(ctx, linkVariant)
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001350 return linkInfo
Paul Duffinfc8dd232020-03-17 12:51:37 +00001351}
1352
Paul Duffin4b8b7932020-05-06 12:35:38 +01001353func (l *linkTypeSpecificInfo) String() string {
1354 return fmt.Sprintf("LinkType{%s}", l.linkType)
1355}
1356
Paul Duffin3a4eb502020-03-19 16:11:18 +00001357type memberContext struct {
1358 sdkMemberContext android.ModuleContext
1359 builder *snapshotBuilder
Paul Duffina551a1c2020-03-17 21:04:24 +00001360 memberType android.SdkMemberType
1361 name string
Paul Duffin3a4eb502020-03-19 16:11:18 +00001362}
1363
1364func (m *memberContext) SdkModuleContext() android.ModuleContext {
1365 return m.sdkMemberContext
1366}
1367
1368func (m *memberContext) SnapshotBuilder() android.SnapshotBuilder {
1369 return m.builder
1370}
1371
Paul Duffina551a1c2020-03-17 21:04:24 +00001372func (m *memberContext) MemberType() android.SdkMemberType {
1373 return m.memberType
1374}
1375
1376func (m *memberContext) Name() string {
1377 return m.name
1378}
1379
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001380func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) {
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001381
1382 memberType := member.memberType
1383
Paul Duffina04c1072020-03-02 10:16:35 +00001384 // Group the variants by os type.
Paul Duffin3a4eb502020-03-19 16:11:18 +00001385 variantsByOsType := make(map[android.OsType][]android.Module)
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001386 variants := member.Variants()
1387 for _, variant := range variants {
Paul Duffina04c1072020-03-02 10:16:35 +00001388 osType := variant.Target().Os
1389 variantsByOsType[osType] = append(variantsByOsType[osType], variant)
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001390 }
1391
Paul Duffina04c1072020-03-02 10:16:35 +00001392 osCount := len(variantsByOsType)
Paul Duffinb44b33a2020-03-17 10:58:23 +00001393 variantPropertiesFactory := func() android.SdkMemberProperties {
Paul Duffina04c1072020-03-02 10:16:35 +00001394 properties := memberType.CreateVariantPropertiesStruct()
1395 base := properties.Base()
1396 base.Os_count = osCount
Paul Duffina04c1072020-03-02 10:16:35 +00001397 return properties
1398 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001399
Paul Duffina04c1072020-03-02 10:16:35 +00001400 osTypeToInfo := make(map[android.OsType]*osTypeSpecificInfo)
Paul Duffin14eb4672020-03-02 11:33:02 +00001401
Paul Duffina04c1072020-03-02 10:16:35 +00001402 // The set of properties that are common across all architectures and os types.
Paul Duffinb44b33a2020-03-17 10:58:23 +00001403 commonProperties := variantPropertiesFactory()
1404 commonProperties.Base().Os = android.CommonOS
Paul Duffina04c1072020-03-02 10:16:35 +00001405
Paul Duffinc097e362020-03-10 22:50:03 +00001406 // Create common value extractor that can be used to optimize the properties.
1407 commonValueExtractor := newCommonValueExtractor(commonProperties)
1408
Paul Duffina04c1072020-03-02 10:16:35 +00001409 // The list of property structures which are os type specific but common across
1410 // architectures within that os type.
Paul Duffinf34f6d82020-04-30 15:48:31 +01001411 var osSpecificPropertiesContainers []*osTypeSpecificInfo
Paul Duffina04c1072020-03-02 10:16:35 +00001412
1413 for osType, osTypeVariants := range variantsByOsType {
Paul Duffin3a4eb502020-03-19 16:11:18 +00001414 osInfo := newOsTypeSpecificInfo(ctx, osType, variantPropertiesFactory, osTypeVariants)
Paul Duffina04c1072020-03-02 10:16:35 +00001415 osTypeToInfo[osType] = osInfo
Paul Duffinb44b33a2020-03-17 10:58:23 +00001416 // Add the os specific properties to a list of os type specific yet architecture
1417 // independent properties structs.
Paul Duffinf34f6d82020-04-30 15:48:31 +01001418 osSpecificPropertiesContainers = append(osSpecificPropertiesContainers, osInfo)
Paul Duffina04c1072020-03-02 10:16:35 +00001419
Paul Duffin00e46802020-03-12 20:40:35 +00001420 // Optimize the properties across all the variants for a specific os type.
Paul Duffin4b8b7932020-05-06 12:35:38 +01001421 osInfo.optimizeProperties(ctx, commonValueExtractor)
Paul Duffin14eb4672020-03-02 11:33:02 +00001422 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001423
Paul Duffina04c1072020-03-02 10:16:35 +00001424 // Extract properties which are common across all architectures and os types.
Paul Duffin4b8b7932020-05-06 12:35:38 +01001425 extractCommonProperties(ctx.sdkMemberContext, commonValueExtractor, commonProperties, osSpecificPropertiesContainers)
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001426
Paul Duffina04c1072020-03-02 10:16:35 +00001427 // Add the common properties to the module.
Martin Stjernholm89238f42020-07-10 00:14:03 +01001428 addSdkMemberPropertiesToSet(ctx, commonProperties, bpModule)
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001429
Paul Duffina04c1072020-03-02 10:16:35 +00001430 // Create a target property set into which target specific properties can be
1431 // added.
1432 targetPropertySet := bpModule.AddPropertySet("target")
1433
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001434 // If the member is host OS dependent and has host_supported then disable by
1435 // default and enable each host OS variant explicitly. This avoids problems
1436 // with implicitly enabled OS variants when the snapshot is used, which might
1437 // be different from this run (e.g. different build OS).
1438 if ctx.memberType.IsHostOsDependent() {
1439 hostSupported := bpModule.getValue("host_supported") == true // Missing means false.
1440 if hostSupported {
1441 hostPropertySet := targetPropertySet.AddPropertySet("host")
1442 hostPropertySet.AddProperty("enabled", false)
1443 }
1444 }
1445
Paul Duffina04c1072020-03-02 10:16:35 +00001446 // Iterate over the os types in a fixed order.
1447 for _, osType := range s.getPossibleOsTypes() {
1448 osInfo := osTypeToInfo[osType]
1449 if osInfo == nil {
1450 continue
1451 }
1452
Paul Duffin3a4eb502020-03-19 16:11:18 +00001453 osInfo.addToPropertySet(ctx, bpModule, targetPropertySet)
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001454 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001455}
1456
Paul Duffina04c1072020-03-02 10:16:35 +00001457// Compute the list of possible os types that this sdk could support.
1458func (s *sdk) getPossibleOsTypes() []android.OsType {
1459 var osTypes []android.OsType
Jingwen Chen2f6a21e2021-04-05 07:33:05 +00001460 for _, osType := range android.OsTypeList() {
Paul Duffina04c1072020-03-02 10:16:35 +00001461 if s.DeviceSupported() {
1462 if osType.Class == android.Device && osType != android.Fuchsia {
1463 osTypes = append(osTypes, osType)
1464 }
1465 }
1466 if s.HostSupported() {
Jiyong Park1613e552020-09-14 19:43:17 +09001467 if osType.Class == android.Host {
Paul Duffina04c1072020-03-02 10:16:35 +00001468 osTypes = append(osTypes, osType)
1469 }
1470 }
1471 }
1472 sort.SliceStable(osTypes, func(i, j int) bool { return osTypes[i].Name < osTypes[j].Name })
1473 return osTypes
1474}
1475
Paul Duffinb28369a2020-05-04 15:39:59 +01001476// Given a set of properties (struct value), return the value of the field within that
1477// struct (or one of its embedded structs).
Paul Duffinc097e362020-03-10 22:50:03 +00001478type fieldAccessorFunc func(structValue reflect.Value) reflect.Value
1479
Paul Duffinc459f892020-04-30 18:08:29 +01001480// Checks the metadata to determine whether the property should be ignored for the
1481// purposes of common value extraction or not.
1482type extractorMetadataPredicate func(metadata propertiesContainer) bool
1483
1484// Indicates whether optimizable properties are provided by a host variant or
1485// not.
1486type isHostVariant interface {
1487 isHostVariant() bool
1488}
1489
Paul Duffinb28369a2020-05-04 15:39:59 +01001490// A property that can be optimized by the commonValueExtractor.
1491type extractorProperty struct {
Martin Stjernholmb0249572020-09-15 02:32:35 +01001492 // The name of the field for this property. It is a "."-separated path for
1493 // fields in non-anonymous substructs.
Paul Duffin4b8b7932020-05-06 12:35:38 +01001494 name string
1495
Paul Duffinc459f892020-04-30 18:08:29 +01001496 // Filter that can use metadata associated with the properties being optimized
1497 // to determine whether the field should be ignored during common value
1498 // optimization.
1499 filter extractorMetadataPredicate
1500
Paul Duffinb28369a2020-05-04 15:39:59 +01001501 // Retrieves the value on which common value optimization will be performed.
1502 getter fieldAccessorFunc
1503
1504 // The empty value for the field.
1505 emptyValue reflect.Value
Paul Duffin864e1b42020-05-06 10:23:19 +01001506
1507 // True if the property can support arch variants false otherwise.
1508 archVariant bool
Paul Duffinb28369a2020-05-04 15:39:59 +01001509}
1510
Paul Duffin4b8b7932020-05-06 12:35:38 +01001511func (p extractorProperty) String() string {
1512 return p.name
1513}
1514
Paul Duffinc097e362020-03-10 22:50:03 +00001515// Supports extracting common values from a number of instances of a properties
1516// structure into a separate common set of properties.
1517type commonValueExtractor struct {
Paul Duffinb28369a2020-05-04 15:39:59 +01001518 // The properties that the extractor can optimize.
1519 properties []extractorProperty
Paul Duffinc097e362020-03-10 22:50:03 +00001520}
1521
1522// Create a new common value extractor for the structure type for the supplied
1523// properties struct.
1524//
1525// The returned extractor can be used on any properties structure of the same type
1526// as the supplied set of properties.
1527func newCommonValueExtractor(propertiesStruct interface{}) *commonValueExtractor {
1528 structType := getStructValue(reflect.ValueOf(propertiesStruct)).Type()
1529 extractor := &commonValueExtractor{}
Martin Stjernholmb0249572020-09-15 02:32:35 +01001530 extractor.gatherFields(structType, nil, "")
Paul Duffinc097e362020-03-10 22:50:03 +00001531 return extractor
1532}
1533
1534// Gather the fields from the supplied structure type from which common values will
1535// be extracted.
Paul Duffinb07fa512020-03-10 22:17:04 +00001536//
Martin Stjernholmb0249572020-09-15 02:32:35 +01001537// This is recursive function. If it encounters a struct then it will recurse
1538// into it, passing in the accessor for the field and the struct name as prefix
1539// for the nested fields. That will then be used in the accessors for the fields
1540// in the embedded struct.
1541func (e *commonValueExtractor) gatherFields(structType reflect.Type, containingStructAccessor fieldAccessorFunc, namePrefix string) {
Paul Duffinc097e362020-03-10 22:50:03 +00001542 for f := 0; f < structType.NumField(); f++ {
1543 field := structType.Field(f)
1544 if field.PkgPath != "" {
1545 // Ignore unexported fields.
1546 continue
1547 }
1548
Paul Duffinb07fa512020-03-10 22:17:04 +00001549 // Ignore fields whose value should be kept.
1550 if proptools.HasTag(field, "sdk", "keep") {
Paul Duffinc097e362020-03-10 22:50:03 +00001551 continue
1552 }
1553
Paul Duffinc459f892020-04-30 18:08:29 +01001554 var filter extractorMetadataPredicate
1555
1556 // Add a filter
1557 if proptools.HasTag(field, "sdk", "ignored-on-host") {
1558 filter = func(metadata propertiesContainer) bool {
1559 if m, ok := metadata.(isHostVariant); ok {
1560 if m.isHostVariant() {
1561 return false
1562 }
1563 }
1564 return true
1565 }
1566 }
1567
Paul Duffinc097e362020-03-10 22:50:03 +00001568 // Save a copy of the field index for use in the function.
1569 fieldIndex := f
Paul Duffin4b8b7932020-05-06 12:35:38 +01001570
Martin Stjernholmb0249572020-09-15 02:32:35 +01001571 name := namePrefix + field.Name
Paul Duffin4b8b7932020-05-06 12:35:38 +01001572
Paul Duffinc097e362020-03-10 22:50:03 +00001573 fieldGetter := func(value reflect.Value) reflect.Value {
Paul Duffinb07fa512020-03-10 22:17:04 +00001574 if containingStructAccessor != nil {
1575 // This is an embedded structure so first access the field for the embedded
1576 // structure.
1577 value = containingStructAccessor(value)
1578 }
1579
Paul Duffinc097e362020-03-10 22:50:03 +00001580 // Skip through interface and pointer values to find the structure.
1581 value = getStructValue(value)
1582
Paul Duffin4b8b7932020-05-06 12:35:38 +01001583 defer func() {
1584 if r := recover(); r != nil {
1585 panic(fmt.Errorf("%s for fieldIndex %d of field %s of value %#v", r, fieldIndex, name, value.Interface()))
1586 }
1587 }()
1588
Paul Duffinc097e362020-03-10 22:50:03 +00001589 // Return the field.
1590 return value.Field(fieldIndex)
1591 }
1592
Martin Stjernholmb0249572020-09-15 02:32:35 +01001593 if field.Type.Kind() == reflect.Struct {
1594 // Gather fields from the nested or embedded structure.
1595 var subNamePrefix string
1596 if field.Anonymous {
1597 subNamePrefix = namePrefix
1598 } else {
1599 subNamePrefix = name + "."
1600 }
1601 e.gatherFields(field.Type, fieldGetter, subNamePrefix)
Paul Duffinb07fa512020-03-10 22:17:04 +00001602 } else {
Paul Duffinb28369a2020-05-04 15:39:59 +01001603 property := extractorProperty{
Paul Duffin4b8b7932020-05-06 12:35:38 +01001604 name,
Paul Duffinc459f892020-04-30 18:08:29 +01001605 filter,
Paul Duffinb28369a2020-05-04 15:39:59 +01001606 fieldGetter,
1607 reflect.Zero(field.Type),
Paul Duffin864e1b42020-05-06 10:23:19 +01001608 proptools.HasTag(field, "android", "arch_variant"),
Paul Duffinb28369a2020-05-04 15:39:59 +01001609 }
1610 e.properties = append(e.properties, property)
Paul Duffinb07fa512020-03-10 22:17:04 +00001611 }
Paul Duffinc097e362020-03-10 22:50:03 +00001612 }
1613}
1614
1615func getStructValue(value reflect.Value) reflect.Value {
1616foundStruct:
1617 for {
1618 kind := value.Kind()
1619 switch kind {
1620 case reflect.Interface, reflect.Ptr:
1621 value = value.Elem()
1622 case reflect.Struct:
1623 break foundStruct
1624 default:
1625 panic(fmt.Errorf("expecting struct, interface or pointer, found %v of kind %s", value, kind))
1626 }
1627 }
1628 return value
1629}
1630
Paul Duffinf34f6d82020-04-30 15:48:31 +01001631// A container of properties to be optimized.
1632//
1633// Allows additional information to be associated with the properties, e.g. for
1634// filtering.
1635type propertiesContainer interface {
Paul Duffin4b8b7932020-05-06 12:35:38 +01001636 fmt.Stringer
1637
Paul Duffinf34f6d82020-04-30 15:48:31 +01001638 // Get the properties that need optimizing.
1639 optimizableProperties() interface{}
1640}
1641
Paul Duffin2d1bb892021-04-24 11:32:59 +01001642// A wrapper for sdk variant related properties to allow them to be optimized.
1643type sdkVariantPropertiesContainer struct {
1644 sdkVariant *sdk
1645 properties interface{}
Paul Duffinf34f6d82020-04-30 15:48:31 +01001646}
1647
Paul Duffin2d1bb892021-04-24 11:32:59 +01001648func (c sdkVariantPropertiesContainer) optimizableProperties() interface{} {
1649 return c.properties
Paul Duffinf34f6d82020-04-30 15:48:31 +01001650}
1651
Paul Duffin2d1bb892021-04-24 11:32:59 +01001652func (c sdkVariantPropertiesContainer) String() string {
Paul Duffin4b8b7932020-05-06 12:35:38 +01001653 return c.sdkVariant.String()
1654}
1655
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001656// Extract common properties from a slice of property structures of the same type.
1657//
1658// All the property structures must be of the same type.
1659// commonProperties - must be a pointer to the structure into which common properties will be added.
Paul Duffinf34f6d82020-04-30 15:48:31 +01001660// inputPropertiesSlice - must be a slice of propertiesContainer interfaces.
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001661//
1662// Iterates over each exported field (capitalized name) and checks to see whether they
1663// have the same value (using DeepEquals) across all the input properties. If it does not then no
1664// change is made. Otherwise, the common value is stored in the field in the commonProperties
Martin Stjernholmb0249572020-09-15 02:32:35 +01001665// and the field in each of the input properties structure is set to its default value. Nested
1666// structs are visited recursively and their non-struct fields are compared.
Paul Duffin4b8b7932020-05-06 12:35:38 +01001667func (e *commonValueExtractor) extractCommonProperties(commonProperties interface{}, inputPropertiesSlice interface{}) error {
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001668 commonPropertiesValue := reflect.ValueOf(commonProperties)
1669 commonStructValue := commonPropertiesValue.Elem()
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001670
Paul Duffinf34f6d82020-04-30 15:48:31 +01001671 sliceValue := reflect.ValueOf(inputPropertiesSlice)
1672
Paul Duffinb28369a2020-05-04 15:39:59 +01001673 for _, property := range e.properties {
1674 fieldGetter := property.getter
Paul Duffinc459f892020-04-30 18:08:29 +01001675 filter := property.filter
1676 if filter == nil {
1677 filter = func(metadata propertiesContainer) bool {
1678 return true
1679 }
1680 }
Paul Duffinb28369a2020-05-04 15:39:59 +01001681
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001682 // Check to see if all the structures have the same value for the field. The commonValue
Paul Duffin864e1b42020-05-06 10:23:19 +01001683 // is nil on entry to the loop and if it is nil on exit then there is no common value or
1684 // all the values have been filtered out, otherwise it points to the common value.
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001685 var commonValue *reflect.Value
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001686
Paul Duffin864e1b42020-05-06 10:23:19 +01001687 // Assume that all the values will be the same.
1688 //
1689 // While similar to this is not quite the same as commonValue == nil. If all the values
1690 // have been filtered out then this will be false but commonValue == nil will be true.
1691 valuesDiffer := false
1692
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001693 for i := 0; i < sliceValue.Len(); i++ {
Paul Duffinf34f6d82020-04-30 15:48:31 +01001694 container := sliceValue.Index(i).Interface().(propertiesContainer)
1695 itemValue := reflect.ValueOf(container.optimizableProperties())
Paul Duffinc097e362020-03-10 22:50:03 +00001696 fieldValue := fieldGetter(itemValue)
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001697
Paul Duffinc459f892020-04-30 18:08:29 +01001698 if !filter(container) {
1699 expectedValue := property.emptyValue.Interface()
1700 actualValue := fieldValue.Interface()
1701 if !reflect.DeepEqual(expectedValue, actualValue) {
1702 return fmt.Errorf("field %q is supposed to be ignored for %q but is set to %#v instead of %#v", property, container, actualValue, expectedValue)
1703 }
1704 continue
1705 }
1706
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001707 if commonValue == nil {
1708 // Use the first value as the commonProperties value.
1709 commonValue = &fieldValue
1710 } else {
1711 // If the value does not match the current common value then there is
1712 // no value in common so break out.
1713 if !reflect.DeepEqual(fieldValue.Interface(), commonValue.Interface()) {
1714 commonValue = nil
Paul Duffin864e1b42020-05-06 10:23:19 +01001715 valuesDiffer = true
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001716 break
1717 }
1718 }
1719 }
1720
Paul Duffin864e1b42020-05-06 10:23:19 +01001721 // If the fields all have common value then store it in the common struct field
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001722 // and set the input struct's field to the empty value.
1723 if commonValue != nil {
Paul Duffinb28369a2020-05-04 15:39:59 +01001724 emptyValue := property.emptyValue
Paul Duffinc097e362020-03-10 22:50:03 +00001725 fieldGetter(commonStructValue).Set(*commonValue)
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001726 for i := 0; i < sliceValue.Len(); i++ {
Paul Duffinf34f6d82020-04-30 15:48:31 +01001727 container := sliceValue.Index(i).Interface().(propertiesContainer)
1728 itemValue := reflect.ValueOf(container.optimizableProperties())
Paul Duffinc097e362020-03-10 22:50:03 +00001729 fieldValue := fieldGetter(itemValue)
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001730 fieldValue.Set(emptyValue)
1731 }
1732 }
Paul Duffin864e1b42020-05-06 10:23:19 +01001733
1734 if valuesDiffer && !property.archVariant {
1735 // The values differ but the property does not support arch variants so it
1736 // is an error.
1737 var details strings.Builder
1738 for i := 0; i < sliceValue.Len(); i++ {
1739 container := sliceValue.Index(i).Interface().(propertiesContainer)
1740 itemValue := reflect.ValueOf(container.optimizableProperties())
1741 fieldValue := fieldGetter(itemValue)
1742
1743 _, _ = fmt.Fprintf(&details, "\n %q has value %q", container.String(), fieldValue.Interface())
1744 }
1745
1746 return fmt.Errorf("field %q is not tagged as \"arch_variant\" but has arch specific properties:%s", property.String(), details.String())
1747 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001748 }
Paul Duffin4b8b7932020-05-06 12:35:38 +01001749
1750 return nil
Paul Duffin88f2fbe2020-02-27 16:00:53 +00001751}