blob: 9032d1fb814a9f85a87f2e4f29dab0752bede89a [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"
Jiyong Park9b409bc2019-10-11 14:59:13 +090020 "strings"
21
Paul Duffin375058f2019-11-29 20:17:53 +000022 "github.com/google/blueprint"
Jiyong Park9b409bc2019-10-11 14:59:13 +090023 "github.com/google/blueprint/proptools"
24
25 "android/soong/android"
Jiyong Park9b409bc2019-10-11 14:59:13 +090026)
27
28var pctx = android.NewPackageContext("android/soong/sdk")
29
Paul Duffin375058f2019-11-29 20:17:53 +000030var (
31 repackageZip = pctx.AndroidStaticRule("SnapshotRepackageZip",
32 blueprint.RuleParams{
Paul Duffince482dc2019-12-09 19:58:17 +000033 Command: `${config.Zip2ZipCmd} -i $in -o $out -x META-INF/**/* "**/*:$destdir"`,
Paul Duffin375058f2019-11-29 20:17:53 +000034 CommandDeps: []string{
35 "${config.Zip2ZipCmd}",
36 },
37 },
38 "destdir")
39
40 zipFiles = pctx.AndroidStaticRule("SnapshotZipFiles",
41 blueprint.RuleParams{
42 Command: `${config.SoongZipCmd} -C $basedir -l $out.rsp -o $out`,
43 CommandDeps: []string{
44 "${config.SoongZipCmd}",
45 },
46 Rspfile: "$out.rsp",
47 RspfileContent: "$in",
48 },
49 "basedir")
50
51 mergeZips = pctx.AndroidStaticRule("SnapshotMergeZips",
52 blueprint.RuleParams{
53 Command: `${config.MergeZipsCmd} $out $in`,
54 CommandDeps: []string{
55 "${config.MergeZipsCmd}",
56 },
57 })
58)
59
Paul Duffinb645ec82019-11-27 17:43:54 +000060type generatedContents struct {
Jiyong Park73c54ee2019-10-22 20:31:18 +090061 content strings.Builder
62 indentLevel int
Jiyong Park9b409bc2019-10-11 14:59:13 +090063}
64
Paul Duffinb645ec82019-11-27 17:43:54 +000065// generatedFile abstracts operations for writing contents into a file and emit a build rule
66// for the file.
67type generatedFile struct {
68 generatedContents
69 path android.OutputPath
70}
71
Jiyong Park232e7852019-11-04 12:23:40 +090072func newGeneratedFile(ctx android.ModuleContext, path ...string) *generatedFile {
Jiyong Park9b409bc2019-10-11 14:59:13 +090073 return &generatedFile{
Paul Duffinb645ec82019-11-27 17:43:54 +000074 path: android.PathForModuleOut(ctx, path...).OutputPath,
Jiyong Park9b409bc2019-10-11 14:59:13 +090075 }
76}
77
Paul Duffinb645ec82019-11-27 17:43:54 +000078func (gc *generatedContents) Indent() {
79 gc.indentLevel++
Jiyong Park73c54ee2019-10-22 20:31:18 +090080}
81
Paul Duffinb645ec82019-11-27 17:43:54 +000082func (gc *generatedContents) Dedent() {
83 gc.indentLevel--
Jiyong Park73c54ee2019-10-22 20:31:18 +090084}
85
Paul Duffinb645ec82019-11-27 17:43:54 +000086func (gc *generatedContents) Printfln(format string, args ...interface{}) {
Jiyong Park9b409bc2019-10-11 14:59:13 +090087 // ninja consumes newline characters in rspfile_content. Prevent it by
Paul Duffin0e0cf1d2019-11-12 19:39:25 +000088 // escaping the backslash in the newline character. The extra backslash
Jiyong Park9b409bc2019-10-11 14:59:13 +090089 // is removed when the rspfile is written to the actual script file
Paul Duffinb645ec82019-11-27 17:43:54 +000090 fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format+"\\n", args...)
Jiyong Park9b409bc2019-10-11 14:59:13 +090091}
92
93func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderContext, implicits android.Paths) {
94 rb := android.NewRuleBuilder()
95 // convert \\n to \n
96 rb.Command().
97 Implicits(implicits).
98 Text("echo").Text(proptools.ShellEscape(gf.content.String())).
99 Text("| sed 's/\\\\n/\\n/g' >").Output(gf.path)
100 rb.Command().
101 Text("chmod a+x").Output(gf.path)
102 rb.Build(pctx, ctx, gf.path.Base(), "Build "+gf.path.Base())
103}
104
Paul Duffin13879572019-11-28 14:31:38 +0000105// Collect all the members.
106//
107// The members are first grouped by type and then grouped by name. The order of
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000108// the types is the order they are referenced in android.SdkMemberTypesRegistry.
109// The names are in the order in which the dependencies were added.
Paul Duffin255f18e2019-12-13 11:22:16 +0000110func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember {
Paul Duffin13879572019-11-28 14:31:38 +0000111 byType := make(map[android.SdkMemberType][]*sdkMember)
112 byName := make(map[string]*sdkMember)
113
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000114 ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
115 tag := ctx.OtherModuleDependencyTag(child)
Paul Duffinf8539922019-11-19 19:44:10 +0000116 if memberTag, ok := tag.(android.SdkMemberTypeDependencyTag); ok {
117 memberType := memberTag.SdkMemberType()
Jiyong Park9b409bc2019-10-11 14:59:13 +0900118
Paul Duffin13879572019-11-28 14:31:38 +0000119 // Make sure that the resolved module is allowed in the member list property.
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000120 if !memberType.IsInstance(child) {
121 ctx.ModuleErrorf("module %q is not valid in property %s", ctx.OtherModuleName(child), memberType.SdkPropertyName())
Jiyong Park73c54ee2019-10-22 20:31:18 +0900122 }
Paul Duffin13879572019-11-28 14:31:38 +0000123
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000124 name := ctx.OtherModuleName(child)
Paul Duffin13879572019-11-28 14:31:38 +0000125
126 member := byName[name]
127 if member == nil {
128 member = &sdkMember{memberType: memberType, name: name}
129 byName[name] = member
130 byType[memberType] = append(byType[memberType], member)
Jiyong Park73c54ee2019-10-22 20:31:18 +0900131 }
Paul Duffin13879572019-11-28 14:31:38 +0000132
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000133 member.variants = append(member.variants, child.(android.SdkAware))
134
135 // If the member type supports transitive sdk members then recurse down into
136 // its dependencies, otherwise exit traversal.
137 return memberType.HasTransitiveSdkMembers()
Jiyong Park73c54ee2019-10-22 20:31:18 +0900138 }
Paul Duffinf4ae4f12020-01-13 20:58:25 +0000139
140 return false
Paul Duffin13879572019-11-28 14:31:38 +0000141 })
142
143 var members []*sdkMember
Paul Duffin255f18e2019-12-13 11:22:16 +0000144 for _, memberListProperty := range s.dynamicSdkMemberTypes.memberListProperties {
Paul Duffin13879572019-11-28 14:31:38 +0000145 membersOfType := byType[memberListProperty.memberType]
146 members = append(members, membersOfType...)
Jiyong Park9b409bc2019-10-11 14:59:13 +0900147 }
148
Paul Duffin13879572019-11-28 14:31:38 +0000149 return members
Jiyong Park73c54ee2019-10-22 20:31:18 +0900150}
Jiyong Park9b409bc2019-10-11 14:59:13 +0900151
Jiyong Park73c54ee2019-10-22 20:31:18 +0900152// SDK directory structure
153// <sdk_root>/
154// Android.bp : definition of a 'sdk' module is here. This is a hand-made one.
155// <api_ver>/ : below this directory are all auto-generated
156// Android.bp : definition of 'sdk_snapshot' module is here
157// aidl/
158// frameworks/base/core/..../IFoo.aidl : an exported AIDL file
159// java/
Jiyong Park232e7852019-11-04 12:23:40 +0900160// <module_name>.jar : the stub jar for a java library 'module_name'
Jiyong Park73c54ee2019-10-22 20:31:18 +0900161// include/
162// bionic/libc/include/stdlib.h : an exported header file
163// include_gen/
Jiyong Park232e7852019-11-04 12:23:40 +0900164// <module_name>/com/android/.../IFoo.h : a generated header file
Jiyong Park73c54ee2019-10-22 20:31:18 +0900165// <arch>/include/ : arch-specific exported headers
166// <arch>/include_gen/ : arch-specific generated headers
167// <arch>/lib/
168// libFoo.so : a stub library
169
Jiyong Park232e7852019-11-04 12:23:40 +0900170// A name that uniquely identifies a prebuilt SDK member for a version of SDK snapshot
Jiyong Park73c54ee2019-10-22 20:31:18 +0900171// This isn't visible to users, so could be changed in future.
172func versionedSdkMemberName(ctx android.ModuleContext, memberName string, version string) string {
173 return ctx.ModuleName() + "_" + memberName + string(android.SdkVersionSeparator) + version
174}
175
Jiyong Park232e7852019-11-04 12:23:40 +0900176// buildSnapshot is the main function in this source file. It creates rules to copy
177// the contents (header files, stub libraries, etc) into the zip file.
178func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000179 snapshotDir := android.PathForModuleOut(ctx, "snapshot")
Jiyong Park9b409bc2019-10-11 14:59:13 +0900180
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000181 bp := newGeneratedFile(ctx, "snapshot", "Android.bp")
Paul Duffinb645ec82019-11-27 17:43:54 +0000182
183 bpFile := &bpFile{
184 modules: make(map[string]*bpModule),
185 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000186
187 builder := &snapshotBuilder{
Paul Duffinb645ec82019-11-27 17:43:54 +0000188 ctx: ctx,
Paul Duffine44358f2019-11-26 18:04:12 +0000189 sdk: s,
Paul Duffinb645ec82019-11-27 17:43:54 +0000190 version: "current",
191 snapshotDir: snapshotDir.OutputPath,
Paul Duffinc62a5102019-12-11 18:34:15 +0000192 copies: make(map[string]string),
Paul Duffinb645ec82019-11-27 17:43:54 +0000193 filesToZip: []android.Path{bp.path},
194 bpFile: bpFile,
195 prebuiltModules: make(map[string]*bpModule),
Jiyong Park73c54ee2019-10-22 20:31:18 +0900196 }
Paul Duffinac37c502019-11-26 18:02:20 +0000197 s.builderForTests = builder
Jiyong Park9b409bc2019-10-11 14:59:13 +0900198
Paul Duffin255f18e2019-12-13 11:22:16 +0000199 for _, member := range s.collectMembers(ctx) {
Paul Duffin13879572019-11-28 14:31:38 +0000200 member.memberType.BuildSnapshot(ctx, builder, member)
Jiyong Park73c54ee2019-10-22 20:31:18 +0900201 }
Jiyong Park9b409bc2019-10-11 14:59:13 +0900202
Paul Duffine6c0d842020-01-15 14:08:51 +0000203 // Create a transformer that will transform an unversioned module into a versioned module.
204 unversionedToVersionedTransformer := unversionedToVersionedTransformation{builder: builder}
205
Paul Duffinb645ec82019-11-27 17:43:54 +0000206 for _, unversioned := range builder.prebuiltOrder {
207 // Copy the unversioned module so it can be modified to make it versioned.
Paul Duffincc72e982020-01-14 15:53:11 +0000208 versioned := unversioned.deepCopy()
Paul Duffine6c0d842020-01-15 14:08:51 +0000209
210 // Transform the unversioned module into a versioned one.
211 versioned.transform(unversionedToVersionedTransformer)
212
Paul Duffinb645ec82019-11-27 17:43:54 +0000213 bpFile.AddModule(versioned)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000214
Paul Duffinb645ec82019-11-27 17:43:54 +0000215 // Set prefer: false - this is not strictly required as that is the default.
216 unversioned.insertAfter("name", "prefer", false)
217 bpFile.AddModule(unversioned)
218 }
219
220 // Create the snapshot module.
221 snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version
Paul Duffin8150da62019-12-16 17:21:27 +0000222 var snapshotModuleType string
223 if s.properties.Module_exports {
224 snapshotModuleType = "module_exports_snapshot"
225 } else {
226 snapshotModuleType = "sdk_snapshot"
227 }
228 snapshotModule := bpFile.newModule(snapshotModuleType)
Paul Duffinb645ec82019-11-27 17:43:54 +0000229 snapshotModule.AddProperty("name", snapshotName)
Paul Duffin593b3c92019-12-05 14:31:48 +0000230
231 // Make sure that the snapshot has the same visibility as the sdk.
232 visibility := android.EffectiveVisibilityRules(ctx, s)
233 if len(visibility) != 0 {
234 snapshotModule.AddProperty("visibility", visibility)
235 }
236
Paul Duffine44358f2019-11-26 18:04:12 +0000237 addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule)
Paul Duffin255f18e2019-12-13 11:22:16 +0000238 for _, memberListProperty := range s.dynamicSdkMemberTypes.memberListProperties {
239 names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
Paul Duffin13879572019-11-28 14:31:38 +0000240 if len(names) > 0 {
Paul Duffin255f18e2019-12-13 11:22:16 +0000241 snapshotModule.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names))
Paul Duffin13879572019-11-28 14:31:38 +0000242 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000243 }
Paul Duffinb645ec82019-11-27 17:43:54 +0000244 bpFile.AddModule(snapshotModule)
245
246 // generate Android.bp
247 bp = newGeneratedFile(ctx, "snapshot", "Android.bp")
248 generateBpContents(&bp.generatedContents, bpFile)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000249
250 bp.build(pctx, ctx, nil)
251
252 filesToZip := builder.filesToZip
Jiyong Park9b409bc2019-10-11 14:59:13 +0900253
Jiyong Park232e7852019-11-04 12:23:40 +0900254 // zip them all
Paul Duffin91547182019-11-12 19:39:36 +0000255 outputZipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000256 outputDesc := "Building snapshot for " + ctx.ModuleName()
257
258 // If there are no zips to merge then generate the output zip directly.
259 // Otherwise, generate an intermediate zip file into which other zips can be
260 // merged.
261 var zipFile android.OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000262 var desc string
263 if len(builder.zipsToMerge) == 0 {
264 zipFile = outputZipFile
Paul Duffin91547182019-11-12 19:39:36 +0000265 desc = outputDesc
266 } else {
267 zipFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.unmerged.zip").OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000268 desc = "Building intermediate snapshot for " + ctx.ModuleName()
269 }
270
Paul Duffin375058f2019-11-29 20:17:53 +0000271 ctx.Build(pctx, android.BuildParams{
272 Description: desc,
273 Rule: zipFiles,
274 Inputs: filesToZip,
275 Output: zipFile,
276 Args: map[string]string{
277 "basedir": builder.snapshotDir.String(),
278 },
279 })
Jiyong Park9b409bc2019-10-11 14:59:13 +0900280
Paul Duffin91547182019-11-12 19:39:36 +0000281 if len(builder.zipsToMerge) != 0 {
Paul Duffin375058f2019-11-29 20:17:53 +0000282 ctx.Build(pctx, android.BuildParams{
283 Description: outputDesc,
284 Rule: mergeZips,
285 Input: zipFile,
286 Inputs: builder.zipsToMerge,
287 Output: outputZipFile,
288 })
Paul Duffin91547182019-11-12 19:39:36 +0000289 }
290
291 return outputZipFile
Jiyong Park9b409bc2019-10-11 14:59:13 +0900292}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000293
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000294type propertyTag struct {
295 name string
296}
297
298var sdkMemberReferencePropertyTag = propertyTag{"sdkMemberReferencePropertyTag"}
299
Paul Duffine6c0d842020-01-15 14:08:51 +0000300type unversionedToVersionedTransformation struct {
301 identityTransformation
302 builder *snapshotBuilder
303}
304
Paul Duffine6c0d842020-01-15 14:08:51 +0000305func (t unversionedToVersionedTransformation) transformModule(module *bpModule) *bpModule {
306 // Use a versioned name for the module but remember the original name for the
307 // snapshot.
308 name := module.getValue("name").(string)
309 module.setProperty("name", t.builder.versionedSdkMemberName(name))
310 module.insertAfter("name", "sdk_member_name", name)
311 return module
312}
313
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000314func (t unversionedToVersionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) {
315 if tag == sdkMemberReferencePropertyTag {
316 return t.builder.versionedSdkMemberNames(value.([]string)), tag
317 } else {
318 return value, tag
319 }
320}
321
Paul Duffinb645ec82019-11-27 17:43:54 +0000322func generateBpContents(contents *generatedContents, bpFile *bpFile) {
323 contents.Printfln("// This is auto-generated. DO NOT EDIT.")
324 for _, bpModule := range bpFile.order {
325 contents.Printfln("")
326 contents.Printfln("%s {", bpModule.moduleType)
Paul Duffincc72e982020-01-14 15:53:11 +0000327 outputPropertySet(contents, bpModule.bpPropertySet)
Paul Duffinb645ec82019-11-27 17:43:54 +0000328 contents.Printfln("}")
329 }
Paul Duffinb645ec82019-11-27 17:43:54 +0000330}
331
332func outputPropertySet(contents *generatedContents, set *bpPropertySet) {
333 contents.Indent()
334 for _, name := range set.order {
Paul Duffin5b511a22020-01-15 14:23:52 +0000335 value := set.getValue(name)
Paul Duffinb645ec82019-11-27 17:43:54 +0000336
337 reflectedValue := reflect.ValueOf(value)
338 t := reflectedValue.Type()
339
340 kind := t.Kind()
341 switch kind {
342 case reflect.Slice:
343 length := reflectedValue.Len()
344 if length > 1 {
345 contents.Printfln("%s: [", name)
346 contents.Indent()
347 for i := 0; i < length; i = i + 1 {
348 contents.Printfln("%q,", reflectedValue.Index(i).Interface())
349 }
350 contents.Dedent()
351 contents.Printfln("],")
352 } else if length == 0 {
353 contents.Printfln("%s: [],", name)
354 } else {
355 contents.Printfln("%s: [%q],", name, reflectedValue.Index(0).Interface())
356 }
357 case reflect.Bool:
358 contents.Printfln("%s: %t,", name, reflectedValue.Bool())
359
360 case reflect.Ptr:
361 contents.Printfln("%s: {", name)
362 outputPropertySet(contents, reflectedValue.Interface().(*bpPropertySet))
363 contents.Printfln("},")
364
365 default:
366 contents.Printfln("%s: %q,", name, value)
367 }
368 }
369 contents.Dedent()
370}
371
Paul Duffinac37c502019-11-26 18:02:20 +0000372func (s *sdk) GetAndroidBpContentsForTests() string {
Paul Duffinb645ec82019-11-27 17:43:54 +0000373 contents := &generatedContents{}
374 generateBpContents(contents, s.builderForTests.bpFile)
375 return contents.content.String()
Paul Duffinac37c502019-11-26 18:02:20 +0000376}
377
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000378type snapshotBuilder struct {
Paul Duffinb645ec82019-11-27 17:43:54 +0000379 ctx android.ModuleContext
Paul Duffine44358f2019-11-26 18:04:12 +0000380 sdk *sdk
Paul Duffinb645ec82019-11-27 17:43:54 +0000381 version string
382 snapshotDir android.OutputPath
383 bpFile *bpFile
Paul Duffinc62a5102019-12-11 18:34:15 +0000384
385 // Map from destination to source of each copy - used to eliminate duplicates and
386 // detect conflicts.
387 copies map[string]string
388
Paul Duffinb645ec82019-11-27 17:43:54 +0000389 filesToZip android.Paths
390 zipsToMerge android.Paths
391
392 prebuiltModules map[string]*bpModule
393 prebuiltOrder []*bpModule
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000394}
395
396func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) {
Paul Duffinc62a5102019-12-11 18:34:15 +0000397 if existing, ok := s.copies[dest]; ok {
398 if existing != src.String() {
399 s.ctx.ModuleErrorf("conflicting copy, %s copied from both %s and %s", dest, existing, src)
400 return
401 }
402 } else {
403 path := s.snapshotDir.Join(s.ctx, dest)
404 s.ctx.Build(pctx, android.BuildParams{
405 Rule: android.Cp,
406 Input: src,
407 Output: path,
408 })
409 s.filesToZip = append(s.filesToZip, path)
410
411 s.copies[dest] = src.String()
412 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000413}
414
Paul Duffin91547182019-11-12 19:39:36 +0000415func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string) {
416 ctx := s.ctx
417
418 // Repackage the zip file so that the entries are in the destDir directory.
419 // This will allow the zip file to be merged into the snapshot.
420 tmpZipPath := android.PathForModuleOut(ctx, "tmp", destDir+".zip").OutputPath
Paul Duffin375058f2019-11-29 20:17:53 +0000421
422 ctx.Build(pctx, android.BuildParams{
423 Description: "Repackaging zip file " + destDir + " for snapshot " + ctx.ModuleName(),
424 Rule: repackageZip,
425 Input: zipPath,
426 Output: tmpZipPath,
427 Args: map[string]string{
428 "destdir": destDir,
429 },
430 })
Paul Duffin91547182019-11-12 19:39:36 +0000431
432 // Add the repackaged zip file to the files to merge.
433 s.zipsToMerge = append(s.zipsToMerge, tmpZipPath)
434}
435
Paul Duffin9d8d6092019-12-05 18:19:29 +0000436func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType string) android.BpModule {
437 name := member.Name()
Paul Duffinb645ec82019-11-27 17:43:54 +0000438 if s.prebuiltModules[name] != nil {
439 panic(fmt.Sprintf("Duplicate module detected, module %s has already been added", name))
440 }
441
442 m := s.bpFile.newModule(moduleType)
443 m.AddProperty("name", name)
Paul Duffin593b3c92019-12-05 14:31:48 +0000444
445 // Extract visibility information from a member variant. All variants have the same
446 // visibility so it doesn't matter which one is used.
447 visibility := android.EffectiveVisibilityRules(s.ctx, member.Variants()[0])
448 if len(visibility) != 0 {
449 m.AddProperty("visibility", visibility)
450 }
451
Paul Duffine44358f2019-11-26 18:04:12 +0000452 addHostDeviceSupportedProperties(&s.sdk.ModuleBase, m)
Paul Duffinb645ec82019-11-27 17:43:54 +0000453
454 s.prebuiltModules[name] = m
455 s.prebuiltOrder = append(s.prebuiltOrder, m)
456 return m
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000457}
458
Paul Duffine44358f2019-11-26 18:04:12 +0000459func addHostDeviceSupportedProperties(module *android.ModuleBase, bpModule *bpModule) {
460 if !module.DeviceSupported() {
461 bpModule.AddProperty("device_supported", false)
462 }
463 if module.HostSupported() {
464 bpModule.AddProperty("host_supported", true)
465 }
466}
467
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000468func (s *snapshotBuilder) SdkMemberReferencePropertyTag() android.BpPropertyTag {
469 return sdkMemberReferencePropertyTag
470}
471
Paul Duffinb645ec82019-11-27 17:43:54 +0000472// Get a versioned name appropriate for the SDK snapshot version being taken.
473func (s *snapshotBuilder) versionedSdkMemberName(unversionedName string) string {
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000474 return versionedSdkMemberName(s.ctx, unversionedName, s.version)
475}
Paul Duffinb645ec82019-11-27 17:43:54 +0000476
477func (s *snapshotBuilder) versionedSdkMemberNames(members []string) []string {
478 var references []string = nil
479 for _, m := range members {
480 references = append(references, s.versionedSdkMemberName(m))
481 }
482 return references
483}
Paul Duffin13879572019-11-28 14:31:38 +0000484
485var _ android.SdkMember = (*sdkMember)(nil)
486
487type sdkMember struct {
488 memberType android.SdkMemberType
489 name string
490 variants []android.SdkAware
491}
492
493func (m *sdkMember) Name() string {
494 return m.name
495}
496
497func (m *sdkMember) Variants() []android.SdkAware {
498 return m.variants
499}