blob: 97bafa1ba333124bdbda5cf1f8bcdd4829299a73 [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 Duffin255f18e2019-12-13 11:22:16 +0000108// the types is the order they are referenced in android.SdkMemberTypes. The
Paul Duffin13879572019-11-28 14:31:38 +0000109// names are in 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
Jiyong Park9b409bc2019-10-11 14:59:13 +0900114 ctx.VisitDirectDeps(func(m android.Module) {
Paul Duffin13879572019-11-28 14:31:38 +0000115 tag := ctx.OtherModuleDependencyTag(m)
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.
120 if !memberType.IsInstance(m) {
Paul Duffin255f18e2019-12-13 11:22:16 +0000121 ctx.ModuleErrorf("module %q is not valid in property %s", ctx.OtherModuleName(m), memberType.SdkPropertyName())
Jiyong Park73c54ee2019-10-22 20:31:18 +0900122 }
Paul Duffin13879572019-11-28 14:31:38 +0000123
124 name := ctx.OtherModuleName(m)
125
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
133 member.variants = append(member.variants, m.(android.SdkAware))
Jiyong Park73c54ee2019-10-22 20:31:18 +0900134 }
Paul Duffin13879572019-11-28 14:31:38 +0000135 })
136
137 var members []*sdkMember
Paul Duffin255f18e2019-12-13 11:22:16 +0000138 for _, memberListProperty := range s.dynamicSdkMemberTypes.memberListProperties {
Paul Duffin13879572019-11-28 14:31:38 +0000139 membersOfType := byType[memberListProperty.memberType]
140 members = append(members, membersOfType...)
Jiyong Park9b409bc2019-10-11 14:59:13 +0900141 }
142
Paul Duffin13879572019-11-28 14:31:38 +0000143 return members
Jiyong Park73c54ee2019-10-22 20:31:18 +0900144}
Jiyong Park9b409bc2019-10-11 14:59:13 +0900145
Jiyong Park73c54ee2019-10-22 20:31:18 +0900146// SDK directory structure
147// <sdk_root>/
148// Android.bp : definition of a 'sdk' module is here. This is a hand-made one.
149// <api_ver>/ : below this directory are all auto-generated
150// Android.bp : definition of 'sdk_snapshot' module is here
151// aidl/
152// frameworks/base/core/..../IFoo.aidl : an exported AIDL file
153// java/
Jiyong Park232e7852019-11-04 12:23:40 +0900154// <module_name>.jar : the stub jar for a java library 'module_name'
Jiyong Park73c54ee2019-10-22 20:31:18 +0900155// include/
156// bionic/libc/include/stdlib.h : an exported header file
157// include_gen/
Jiyong Park232e7852019-11-04 12:23:40 +0900158// <module_name>/com/android/.../IFoo.h : a generated header file
Jiyong Park73c54ee2019-10-22 20:31:18 +0900159// <arch>/include/ : arch-specific exported headers
160// <arch>/include_gen/ : arch-specific generated headers
161// <arch>/lib/
162// libFoo.so : a stub library
163
Jiyong Park232e7852019-11-04 12:23:40 +0900164// A name that uniquely identifies a prebuilt SDK member for a version of SDK snapshot
Jiyong Park73c54ee2019-10-22 20:31:18 +0900165// This isn't visible to users, so could be changed in future.
166func versionedSdkMemberName(ctx android.ModuleContext, memberName string, version string) string {
167 return ctx.ModuleName() + "_" + memberName + string(android.SdkVersionSeparator) + version
168}
169
Jiyong Park232e7852019-11-04 12:23:40 +0900170// buildSnapshot is the main function in this source file. It creates rules to copy
171// the contents (header files, stub libraries, etc) into the zip file.
172func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000173 snapshotDir := android.PathForModuleOut(ctx, "snapshot")
Jiyong Park9b409bc2019-10-11 14:59:13 +0900174
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000175 bp := newGeneratedFile(ctx, "snapshot", "Android.bp")
Paul Duffinb645ec82019-11-27 17:43:54 +0000176
177 bpFile := &bpFile{
178 modules: make(map[string]*bpModule),
179 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000180
181 builder := &snapshotBuilder{
Paul Duffinb645ec82019-11-27 17:43:54 +0000182 ctx: ctx,
Paul Duffine44358f2019-11-26 18:04:12 +0000183 sdk: s,
Paul Duffinb645ec82019-11-27 17:43:54 +0000184 version: "current",
185 snapshotDir: snapshotDir.OutputPath,
Paul Duffinc62a5102019-12-11 18:34:15 +0000186 copies: make(map[string]string),
Paul Duffinb645ec82019-11-27 17:43:54 +0000187 filesToZip: []android.Path{bp.path},
188 bpFile: bpFile,
189 prebuiltModules: make(map[string]*bpModule),
Jiyong Park73c54ee2019-10-22 20:31:18 +0900190 }
Paul Duffinac37c502019-11-26 18:02:20 +0000191 s.builderForTests = builder
Jiyong Park9b409bc2019-10-11 14:59:13 +0900192
Paul Duffin255f18e2019-12-13 11:22:16 +0000193 for _, member := range s.collectMembers(ctx) {
Paul Duffin13879572019-11-28 14:31:38 +0000194 member.memberType.BuildSnapshot(ctx, builder, member)
Jiyong Park73c54ee2019-10-22 20:31:18 +0900195 }
Jiyong Park9b409bc2019-10-11 14:59:13 +0900196
Paul Duffine6c0d842020-01-15 14:08:51 +0000197 // Create a transformer that will transform an unversioned module into a versioned module.
198 unversionedToVersionedTransformer := unversionedToVersionedTransformation{builder: builder}
199
Paul Duffinb645ec82019-11-27 17:43:54 +0000200 for _, unversioned := range builder.prebuiltOrder {
201 // Copy the unversioned module so it can be modified to make it versioned.
Paul Duffincc72e982020-01-14 15:53:11 +0000202 versioned := unversioned.deepCopy()
Paul Duffine6c0d842020-01-15 14:08:51 +0000203
204 // Transform the unversioned module into a versioned one.
205 versioned.transform(unversionedToVersionedTransformer)
206
Paul Duffinb645ec82019-11-27 17:43:54 +0000207 bpFile.AddModule(versioned)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000208
Paul Duffinb645ec82019-11-27 17:43:54 +0000209 // Set prefer: false - this is not strictly required as that is the default.
210 unversioned.insertAfter("name", "prefer", false)
211 bpFile.AddModule(unversioned)
212 }
213
214 // Create the snapshot module.
215 snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version
Paul Duffin8150da62019-12-16 17:21:27 +0000216 var snapshotModuleType string
217 if s.properties.Module_exports {
218 snapshotModuleType = "module_exports_snapshot"
219 } else {
220 snapshotModuleType = "sdk_snapshot"
221 }
222 snapshotModule := bpFile.newModule(snapshotModuleType)
Paul Duffinb645ec82019-11-27 17:43:54 +0000223 snapshotModule.AddProperty("name", snapshotName)
Paul Duffin593b3c92019-12-05 14:31:48 +0000224
225 // Make sure that the snapshot has the same visibility as the sdk.
226 visibility := android.EffectiveVisibilityRules(ctx, s)
227 if len(visibility) != 0 {
228 snapshotModule.AddProperty("visibility", visibility)
229 }
230
Paul Duffine44358f2019-11-26 18:04:12 +0000231 addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule)
Paul Duffin255f18e2019-12-13 11:22:16 +0000232 for _, memberListProperty := range s.dynamicSdkMemberTypes.memberListProperties {
233 names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
Paul Duffin13879572019-11-28 14:31:38 +0000234 if len(names) > 0 {
Paul Duffin255f18e2019-12-13 11:22:16 +0000235 snapshotModule.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names))
Paul Duffin13879572019-11-28 14:31:38 +0000236 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000237 }
Paul Duffinb645ec82019-11-27 17:43:54 +0000238 bpFile.AddModule(snapshotModule)
239
240 // generate Android.bp
241 bp = newGeneratedFile(ctx, "snapshot", "Android.bp")
242 generateBpContents(&bp.generatedContents, bpFile)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000243
244 bp.build(pctx, ctx, nil)
245
246 filesToZip := builder.filesToZip
Jiyong Park9b409bc2019-10-11 14:59:13 +0900247
Jiyong Park232e7852019-11-04 12:23:40 +0900248 // zip them all
Paul Duffin91547182019-11-12 19:39:36 +0000249 outputZipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000250 outputDesc := "Building snapshot for " + ctx.ModuleName()
251
252 // If there are no zips to merge then generate the output zip directly.
253 // Otherwise, generate an intermediate zip file into which other zips can be
254 // merged.
255 var zipFile android.OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000256 var desc string
257 if len(builder.zipsToMerge) == 0 {
258 zipFile = outputZipFile
Paul Duffin91547182019-11-12 19:39:36 +0000259 desc = outputDesc
260 } else {
261 zipFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.unmerged.zip").OutputPath
Paul Duffin91547182019-11-12 19:39:36 +0000262 desc = "Building intermediate snapshot for " + ctx.ModuleName()
263 }
264
Paul Duffin375058f2019-11-29 20:17:53 +0000265 ctx.Build(pctx, android.BuildParams{
266 Description: desc,
267 Rule: zipFiles,
268 Inputs: filesToZip,
269 Output: zipFile,
270 Args: map[string]string{
271 "basedir": builder.snapshotDir.String(),
272 },
273 })
Jiyong Park9b409bc2019-10-11 14:59:13 +0900274
Paul Duffin91547182019-11-12 19:39:36 +0000275 if len(builder.zipsToMerge) != 0 {
Paul Duffin375058f2019-11-29 20:17:53 +0000276 ctx.Build(pctx, android.BuildParams{
277 Description: outputDesc,
278 Rule: mergeZips,
279 Input: zipFile,
280 Inputs: builder.zipsToMerge,
281 Output: outputZipFile,
282 })
Paul Duffin91547182019-11-12 19:39:36 +0000283 }
284
285 return outputZipFile
Jiyong Park9b409bc2019-10-11 14:59:13 +0900286}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000287
Paul Duffine6c0d842020-01-15 14:08:51 +0000288type unversionedToVersionedTransformation struct {
289 identityTransformation
290 builder *snapshotBuilder
291}
292
293var _ bpTransformer = (*unversionedToVersionedTransformation)(nil)
294
295func (t unversionedToVersionedTransformation) transformModule(module *bpModule) *bpModule {
296 // Use a versioned name for the module but remember the original name for the
297 // snapshot.
298 name := module.getValue("name").(string)
299 module.setProperty("name", t.builder.versionedSdkMemberName(name))
300 module.insertAfter("name", "sdk_member_name", name)
301 return module
302}
303
Paul Duffinb645ec82019-11-27 17:43:54 +0000304func generateBpContents(contents *generatedContents, bpFile *bpFile) {
305 contents.Printfln("// This is auto-generated. DO NOT EDIT.")
306 for _, bpModule := range bpFile.order {
307 contents.Printfln("")
308 contents.Printfln("%s {", bpModule.moduleType)
Paul Duffincc72e982020-01-14 15:53:11 +0000309 outputPropertySet(contents, bpModule.bpPropertySet)
Paul Duffinb645ec82019-11-27 17:43:54 +0000310 contents.Printfln("}")
311 }
Paul Duffinb645ec82019-11-27 17:43:54 +0000312}
313
314func outputPropertySet(contents *generatedContents, set *bpPropertySet) {
315 contents.Indent()
316 for _, name := range set.order {
Paul Duffin5b511a22020-01-15 14:23:52 +0000317 value := set.getValue(name)
Paul Duffinb645ec82019-11-27 17:43:54 +0000318
319 reflectedValue := reflect.ValueOf(value)
320 t := reflectedValue.Type()
321
322 kind := t.Kind()
323 switch kind {
324 case reflect.Slice:
325 length := reflectedValue.Len()
326 if length > 1 {
327 contents.Printfln("%s: [", name)
328 contents.Indent()
329 for i := 0; i < length; i = i + 1 {
330 contents.Printfln("%q,", reflectedValue.Index(i).Interface())
331 }
332 contents.Dedent()
333 contents.Printfln("],")
334 } else if length == 0 {
335 contents.Printfln("%s: [],", name)
336 } else {
337 contents.Printfln("%s: [%q],", name, reflectedValue.Index(0).Interface())
338 }
339 case reflect.Bool:
340 contents.Printfln("%s: %t,", name, reflectedValue.Bool())
341
342 case reflect.Ptr:
343 contents.Printfln("%s: {", name)
344 outputPropertySet(contents, reflectedValue.Interface().(*bpPropertySet))
345 contents.Printfln("},")
346
347 default:
348 contents.Printfln("%s: %q,", name, value)
349 }
350 }
351 contents.Dedent()
352}
353
Paul Duffinac37c502019-11-26 18:02:20 +0000354func (s *sdk) GetAndroidBpContentsForTests() string {
Paul Duffinb645ec82019-11-27 17:43:54 +0000355 contents := &generatedContents{}
356 generateBpContents(contents, s.builderForTests.bpFile)
357 return contents.content.String()
Paul Duffinac37c502019-11-26 18:02:20 +0000358}
359
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000360type snapshotBuilder struct {
Paul Duffinb645ec82019-11-27 17:43:54 +0000361 ctx android.ModuleContext
Paul Duffine44358f2019-11-26 18:04:12 +0000362 sdk *sdk
Paul Duffinb645ec82019-11-27 17:43:54 +0000363 version string
364 snapshotDir android.OutputPath
365 bpFile *bpFile
Paul Duffinc62a5102019-12-11 18:34:15 +0000366
367 // Map from destination to source of each copy - used to eliminate duplicates and
368 // detect conflicts.
369 copies map[string]string
370
Paul Duffinb645ec82019-11-27 17:43:54 +0000371 filesToZip android.Paths
372 zipsToMerge android.Paths
373
374 prebuiltModules map[string]*bpModule
375 prebuiltOrder []*bpModule
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000376}
377
378func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) {
Paul Duffinc62a5102019-12-11 18:34:15 +0000379 if existing, ok := s.copies[dest]; ok {
380 if existing != src.String() {
381 s.ctx.ModuleErrorf("conflicting copy, %s copied from both %s and %s", dest, existing, src)
382 return
383 }
384 } else {
385 path := s.snapshotDir.Join(s.ctx, dest)
386 s.ctx.Build(pctx, android.BuildParams{
387 Rule: android.Cp,
388 Input: src,
389 Output: path,
390 })
391 s.filesToZip = append(s.filesToZip, path)
392
393 s.copies[dest] = src.String()
394 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000395}
396
Paul Duffin91547182019-11-12 19:39:36 +0000397func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string) {
398 ctx := s.ctx
399
400 // Repackage the zip file so that the entries are in the destDir directory.
401 // This will allow the zip file to be merged into the snapshot.
402 tmpZipPath := android.PathForModuleOut(ctx, "tmp", destDir+".zip").OutputPath
Paul Duffin375058f2019-11-29 20:17:53 +0000403
404 ctx.Build(pctx, android.BuildParams{
405 Description: "Repackaging zip file " + destDir + " for snapshot " + ctx.ModuleName(),
406 Rule: repackageZip,
407 Input: zipPath,
408 Output: tmpZipPath,
409 Args: map[string]string{
410 "destdir": destDir,
411 },
412 })
Paul Duffin91547182019-11-12 19:39:36 +0000413
414 // Add the repackaged zip file to the files to merge.
415 s.zipsToMerge = append(s.zipsToMerge, tmpZipPath)
416}
417
Paul Duffin9d8d6092019-12-05 18:19:29 +0000418func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType string) android.BpModule {
419 name := member.Name()
Paul Duffinb645ec82019-11-27 17:43:54 +0000420 if s.prebuiltModules[name] != nil {
421 panic(fmt.Sprintf("Duplicate module detected, module %s has already been added", name))
422 }
423
424 m := s.bpFile.newModule(moduleType)
425 m.AddProperty("name", name)
Paul Duffin593b3c92019-12-05 14:31:48 +0000426
427 // Extract visibility information from a member variant. All variants have the same
428 // visibility so it doesn't matter which one is used.
429 visibility := android.EffectiveVisibilityRules(s.ctx, member.Variants()[0])
430 if len(visibility) != 0 {
431 m.AddProperty("visibility", visibility)
432 }
433
Paul Duffine44358f2019-11-26 18:04:12 +0000434 addHostDeviceSupportedProperties(&s.sdk.ModuleBase, m)
Paul Duffinb645ec82019-11-27 17:43:54 +0000435
436 s.prebuiltModules[name] = m
437 s.prebuiltOrder = append(s.prebuiltOrder, m)
438 return m
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000439}
440
Paul Duffine44358f2019-11-26 18:04:12 +0000441func addHostDeviceSupportedProperties(module *android.ModuleBase, bpModule *bpModule) {
442 if !module.DeviceSupported() {
443 bpModule.AddProperty("device_supported", false)
444 }
445 if module.HostSupported() {
446 bpModule.AddProperty("host_supported", true)
447 }
448}
449
Paul Duffinb645ec82019-11-27 17:43:54 +0000450// Get a versioned name appropriate for the SDK snapshot version being taken.
451func (s *snapshotBuilder) versionedSdkMemberName(unversionedName string) string {
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000452 return versionedSdkMemberName(s.ctx, unversionedName, s.version)
453}
Paul Duffinb645ec82019-11-27 17:43:54 +0000454
455func (s *snapshotBuilder) versionedSdkMemberNames(members []string) []string {
456 var references []string = nil
457 for _, m := range members {
458 references = append(references, s.versionedSdkMemberName(m))
459 }
460 return references
461}
Paul Duffin13879572019-11-28 14:31:38 +0000462
463var _ android.SdkMember = (*sdkMember)(nil)
464
465type sdkMember struct {
466 memberType android.SdkMemberType
467 name string
468 variants []android.SdkAware
469}
470
471func (m *sdkMember) Name() string {
472 return m.name
473}
474
475func (m *sdkMember) Variants() []android.SdkAware {
476 return m.variants
477}