blob: 063091e86ae2213954009dbbcf2e3a66fd1c2b03 [file] [log] [blame]
Jiyong Parkd1063c12019-07-17 20:08:41 +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 android
16
17import (
Paul Duffind19f8942021-07-14 12:08:37 +010018 "fmt"
Paul Duffin255f18e2019-12-13 11:22:16 +000019 "sort"
Jiyong Parkd1063c12019-07-17 20:08:41 +090020 "strings"
21
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jiyong Parkd1063c12019-07-17 20:08:41 +090023 "github.com/google/blueprint/proptools"
24)
25
Paul Duffin94289702021-09-09 15:38:32 +010026// sdkAwareWithoutModule is provided simply to improve code navigation with the IDE.
Paul Duffin50f0da42020-07-22 13:52:01 +010027type sdkAwareWithoutModule interface {
Jiyong Parkd1063c12019-07-17 20:08:41 +090028 sdkBase() *SdkBase
29 MakeMemberOf(sdk SdkRef)
30 IsInAnySdk() bool
Paul Duffinb9e7a3c2021-05-06 15:53:19 +010031
32 // IsVersioned determines whether the module is versioned, i.e. has a name of the form
33 // <name>@<version>
34 IsVersioned() bool
35
Jiyong Parkd1063c12019-07-17 20:08:41 +090036 ContainingSdk() SdkRef
37 MemberName() string
Jiyong Parkd1063c12019-07-17 20:08:41 +090038}
39
Paul Duffin50f0da42020-07-22 13:52:01 +010040// SdkAware is the interface that must be supported by any module to become a member of SDK or to be
41// built with SDK
42type SdkAware interface {
43 Module
44 sdkAwareWithoutModule
45}
46
Paul Duffin1938dba2022-07-26 23:53:00 +000047// minApiLevelForSdkSnapshot provides access to the min_sdk_version for MinApiLevelForSdkSnapshot
48type minApiLevelForSdkSnapshot interface {
49 MinSdkVersion(ctx EarlyModuleContext) SdkSpec
50}
51
52// MinApiLevelForSdkSnapshot returns the ApiLevel of the min_sdk_version of the supplied module.
53//
54// If the module does not provide a min_sdk_version then it defaults to 1.
55func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel {
56 minApiLevel := NoneApiLevel
57 if m, ok := module.(minApiLevelForSdkSnapshot); ok {
58 minApiLevel = m.MinSdkVersion(ctx).ApiLevel
59 }
60 if minApiLevel == NoneApiLevel {
61 // The default min API level is 1.
62 minApiLevel = uncheckedFinalApiLevel(1)
63 }
64 return minApiLevel
65}
66
Jiyong Parkd1063c12019-07-17 20:08:41 +090067// SdkRef refers to a version of an SDK
68type SdkRef struct {
69 Name string
70 Version string
71}
72
Jiyong Park9b409bc2019-10-11 14:59:13 +090073// Unversioned determines if the SdkRef is referencing to the unversioned SDK module
74func (s SdkRef) Unversioned() bool {
75 return s.Version == ""
Jiyong Parkd1063c12019-07-17 20:08:41 +090076}
77
Jiyong Parka7bc8ad2019-10-15 15:20:07 +090078// String returns string representation of this SdkRef for debugging purpose
79func (s SdkRef) String() string {
80 if s.Name == "" {
81 return "(No Sdk)"
82 }
83 if s.Unversioned() {
84 return s.Name
85 }
86 return s.Name + string(SdkVersionSeparator) + s.Version
87}
88
Jiyong Park9b409bc2019-10-11 14:59:13 +090089// SdkVersionSeparator is a character used to separate an sdk name and its version
90const SdkVersionSeparator = '@'
Jiyong Parkd1063c12019-07-17 20:08:41 +090091
Jiyong Park9b409bc2019-10-11 14:59:13 +090092// ParseSdkRef parses a `name@version` style string into a corresponding SdkRef struct
Jiyong Parkd1063c12019-07-17 20:08:41 +090093func ParseSdkRef(ctx BaseModuleContext, str string, property string) SdkRef {
Jiyong Park9b409bc2019-10-11 14:59:13 +090094 tokens := strings.Split(str, string(SdkVersionSeparator))
Jiyong Parkd1063c12019-07-17 20:08:41 +090095 if len(tokens) < 1 || len(tokens) > 2 {
Paul Duffin525a5902021-05-06 16:33:52 +010096 ctx.PropertyErrorf(property, "%q does not follow name@version syntax", str)
Jiyong Parkd1063c12019-07-17 20:08:41 +090097 return SdkRef{Name: "invalid sdk name", Version: "invalid sdk version"}
98 }
99
100 name := tokens[0]
101
Jiyong Park9b409bc2019-10-11 14:59:13 +0900102 var version string
Jiyong Parkd1063c12019-07-17 20:08:41 +0900103 if len(tokens) == 2 {
104 version = tokens[1]
105 }
106
107 return SdkRef{Name: name, Version: version}
108}
109
110type SdkRefs []SdkRef
111
Jiyong Park9b409bc2019-10-11 14:59:13 +0900112// Contains tells if the given SdkRef is in this list of SdkRef's
Jiyong Parkd1063c12019-07-17 20:08:41 +0900113func (refs SdkRefs) Contains(s SdkRef) bool {
114 for _, r := range refs {
115 if r == s {
116 return true
117 }
118 }
119 return false
120}
121
122type sdkProperties struct {
123 // The SDK that this module is a member of. nil if it is not a member of any SDK
124 ContainingSdk *SdkRef `blueprint:"mutated"`
125
Jiyong Parkd1063c12019-07-17 20:08:41 +0900126 // Name of the module that this sdk member is representing
127 Sdk_member_name *string
128}
129
130// SdkBase is a struct that is expected to be included in module types to implement the SdkAware
131// interface. InitSdkAwareModule should be called to initialize this struct.
132type SdkBase struct {
133 properties sdkProperties
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000134 module SdkAware
Jiyong Parkd1063c12019-07-17 20:08:41 +0900135}
136
137func (s *SdkBase) sdkBase() *SdkBase {
138 return s
139}
140
Jiyong Park9b409bc2019-10-11 14:59:13 +0900141// MakeMemberOf sets this module to be a member of a specific SDK
Jiyong Parkd1063c12019-07-17 20:08:41 +0900142func (s *SdkBase) MakeMemberOf(sdk SdkRef) {
143 s.properties.ContainingSdk = &sdk
144}
145
146// IsInAnySdk returns true if this module is a member of any SDK
147func (s *SdkBase) IsInAnySdk() bool {
148 return s.properties.ContainingSdk != nil
149}
150
Paul Duffinb9e7a3c2021-05-06 15:53:19 +0100151// IsVersioned returns true if this module is versioned.
152func (s *SdkBase) IsVersioned() bool {
153 return strings.Contains(s.module.Name(), "@")
154}
155
Jiyong Parkd1063c12019-07-17 20:08:41 +0900156// ContainingSdk returns the SDK that this module is a member of
157func (s *SdkBase) ContainingSdk() SdkRef {
158 if s.properties.ContainingSdk != nil {
159 return *s.properties.ContainingSdk
160 }
Jiyong Park9b409bc2019-10-11 14:59:13 +0900161 return SdkRef{Name: "", Version: ""}
Jiyong Parkd1063c12019-07-17 20:08:41 +0900162}
163
Jiyong Park9b409bc2019-10-11 14:59:13 +0900164// MemberName returns the name of the module that this SDK member is overriding
Jiyong Parkd1063c12019-07-17 20:08:41 +0900165func (s *SdkBase) MemberName() string {
166 return proptools.String(s.properties.Sdk_member_name)
167}
168
Jiyong Parkd1063c12019-07-17 20:08:41 +0900169// InitSdkAwareModule initializes the SdkBase struct. This must be called by all modules including
170// SdkBase.
171func InitSdkAwareModule(m SdkAware) {
172 base := m.sdkBase()
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000173 base.module = m
Jiyong Parkd1063c12019-07-17 20:08:41 +0900174 m.AddProperties(&base.properties)
175}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000176
Paul Duffin94289702021-09-09 15:38:32 +0100177// SnapshotBuilder provides support for generating the build rules which will build the snapshot.
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000178type SnapshotBuilder interface {
Paul Duffin94289702021-09-09 15:38:32 +0100179 // CopyToSnapshot generates a rule that will copy the src to the dest (which is a snapshot
180 // relative path) and add the dest to the zip.
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000181 CopyToSnapshot(src Path, dest string)
182
Paul Duffin7ed6ff82022-11-21 10:57:30 +0000183 // EmptyFile returns the path to an empty file.
184 //
185 // This can be used by sdk member types that need to create an empty file in the snapshot, simply
186 // pass the value returned from this to the CopyToSnapshot() method.
187 EmptyFile() Path
188
Paul Duffin94289702021-09-09 15:38:32 +0100189 // UnzipToSnapshot generates a rule that will unzip the supplied zip into the snapshot relative
190 // directory destDir.
Paul Duffin91547182019-11-12 19:39:36 +0000191 UnzipToSnapshot(zipPath Path, destDir string)
192
Paul Duffin94289702021-09-09 15:38:32 +0100193 // AddPrebuiltModule adds a new prebuilt module to the snapshot.
194 //
195 // It is intended to be called from SdkMemberType.AddPrebuiltModule which can add module type
196 // specific properties that are not variant specific. The following properties will be
197 // automatically populated before returning.
Paul Duffinb645ec82019-11-27 17:43:54 +0000198 //
199 // * name
200 // * sdk_member_name
201 // * prefer
202 //
Paul Duffin94289702021-09-09 15:38:32 +0100203 // Properties that are variant specific will be handled by SdkMemberProperties structure.
204 //
205 // Each module created by this method can be output to the generated Android.bp file in two
206 // different forms, depending on the setting of the SOONG_SDK_SNAPSHOT_VERSION build property.
207 // The two forms are:
208 // 1. A versioned Soong module that is referenced from a corresponding similarly versioned
209 // snapshot module.
210 // 2. An unversioned Soong module that.
211 //
212 // See sdk/update.go for more information.
Paul Duffin9d8d6092019-12-05 18:19:29 +0000213 AddPrebuiltModule(member SdkMember, moduleType string) BpModule
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000214
Paul Duffin94289702021-09-09 15:38:32 +0100215 // SdkMemberReferencePropertyTag returns a property tag to use when adding a property to a
216 // BpModule that contains references to other sdk members.
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000217 //
Paul Duffin94289702021-09-09 15:38:32 +0100218 // Using this will ensure that the reference is correctly output for both versioned and
219 // unversioned prebuilts in the snapshot.
Paul Duffin13f02712020-03-06 12:30:43 +0000220 //
Paul Duffin94289702021-09-09 15:38:32 +0100221 // "required: true" means that the property must only contain references to other members of the
222 // sdk. Passing a reference to a module that is not a member of the sdk will result in a build
223 // error.
Paul Duffin13f02712020-03-06 12:30:43 +0000224 //
Paul Duffin94289702021-09-09 15:38:32 +0100225 // "required: false" means that the property can contain references to modules that are either
226 // members or not members of the sdk. If a reference is to a module that is a non member then the
227 // reference is left unchanged, i.e. it is not transformed as references to members are.
228 //
229 // The handling of the member names is dependent on whether it is an internal or exported member.
230 // An exported member is one whose name is specified in one of the member type specific
231 // properties. An internal member is one that is added due to being a part of an exported (or
232 // other internal) member and is not itself an exported member.
Paul Duffin13f02712020-03-06 12:30:43 +0000233 //
234 // Member names are handled as follows:
Paul Duffin94289702021-09-09 15:38:32 +0100235 // * When creating the unversioned form of the module the name is left unchecked unless the member
236 // is internal in which case it is transformed into an sdk specific name, i.e. by prefixing with
237 // the sdk name.
Paul Duffin13f02712020-03-06 12:30:43 +0000238 //
Paul Duffin94289702021-09-09 15:38:32 +0100239 // * When creating the versioned form of the module the name is transformed into a versioned sdk
240 // specific name, i.e. by prefixing with the sdk name and suffixing with the version.
Paul Duffin13f02712020-03-06 12:30:43 +0000241 //
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000242 // e.g.
Paul Duffin13f02712020-03-06 12:30:43 +0000243 // bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag(true))
244 SdkMemberReferencePropertyTag(required bool) BpPropertyTag
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000245}
246
Paul Duffin94289702021-09-09 15:38:32 +0100247// BpPropertyTag is a marker interface that can be associated with properties in a BpPropertySet to
248// provide additional information which can be used to customize their behavior.
Paul Duffin5b511a22020-01-15 14:23:52 +0000249type BpPropertyTag interface{}
250
Paul Duffin94289702021-09-09 15:38:32 +0100251// BpPropertySet is a set of properties for use in a .bp file.
Paul Duffinb645ec82019-11-27 17:43:54 +0000252type BpPropertySet interface {
Paul Duffin94289702021-09-09 15:38:32 +0100253 // AddProperty adds a property.
254 //
255 // The value can be one of the following types:
Paul Duffinb645ec82019-11-27 17:43:54 +0000256 // * string
257 // * array of the above
258 // * bool
Martin Stjernholm191c25f2020-09-10 00:40:37 +0100259 // For these types it is an error if multiple properties with the same name
260 // are added.
261 //
262 // * pointer to a struct
Paul Duffinb645ec82019-11-27 17:43:54 +0000263 // * BpPropertySet
264 //
Martin Stjernholm191c25f2020-09-10 00:40:37 +0100265 // A pointer to a Blueprint-style property struct is first converted into a
266 // BpPropertySet by traversing the fields and adding their values as
267 // properties in a BpPropertySet. A field with a struct value is itself
268 // converted into a BpPropertySet before adding.
269 //
270 // Adding a BpPropertySet is done as follows:
271 // * If no property with the name exists then the BpPropertySet is added
272 // directly to this property. Care must be taken to ensure that it does not
273 // introduce a cycle.
274 // * If a property exists with the name and the current value is a
275 // BpPropertySet then every property of the new BpPropertySet is added to
276 // the existing BpPropertySet.
277 // * Otherwise, if a property exists with the name then it is an error.
Paul Duffinb645ec82019-11-27 17:43:54 +0000278 AddProperty(name string, value interface{})
279
Paul Duffin94289702021-09-09 15:38:32 +0100280 // AddPropertyWithTag adds a property with an associated property tag.
Paul Duffin5b511a22020-01-15 14:23:52 +0000281 AddPropertyWithTag(name string, value interface{}, tag BpPropertyTag)
282
Paul Duffin94289702021-09-09 15:38:32 +0100283 // AddPropertySet adds a property set with the specified name and returns it so that additional
284 // properties can be added to it.
Paul Duffinb645ec82019-11-27 17:43:54 +0000285 AddPropertySet(name string) BpPropertySet
Paul Duffin0df49682021-05-07 01:10:01 +0100286
Paul Duffin94289702021-09-09 15:38:32 +0100287 // AddCommentForProperty adds a comment for the named property (or property set).
Paul Duffin0df49682021-05-07 01:10:01 +0100288 AddCommentForProperty(name, text string)
Paul Duffinb645ec82019-11-27 17:43:54 +0000289}
290
Paul Duffin94289702021-09-09 15:38:32 +0100291// BpModule represents a module definition in a .bp file.
Paul Duffinb645ec82019-11-27 17:43:54 +0000292type BpModule interface {
293 BpPropertySet
Paul Duffin0df49682021-05-07 01:10:01 +0100294
295 // ModuleType returns the module type of the module
296 ModuleType() string
297
298 // Name returns the name of the module or "" if no name has been specified.
299 Name() string
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000300}
Paul Duffin13879572019-11-28 14:31:38 +0000301
Paul Duffin51227d82021-05-18 12:54:27 +0100302// BpPrintable is a marker interface that must be implemented by any struct that is added as a
303// property value.
304type BpPrintable interface {
305 bpPrintable()
306}
307
308// BpPrintableBase must be embedded within any struct that is added as a
309// property value.
310type BpPrintableBase struct {
311}
312
313func (b BpPrintableBase) bpPrintable() {
314}
315
316var _ BpPrintable = BpPrintableBase{}
317
Paul Duffinf04033b2021-09-22 11:51:09 +0100318// sdkRegisterable defines the interface that must be implemented by objects that can be registered
319// in an sdkRegistry.
320type sdkRegisterable interface {
321 // SdkPropertyName returns the name of the corresponding property on an sdk module.
322 SdkPropertyName() string
323}
324
325// sdkRegistry provides support for registering and retrieving objects that define properties for
326// use by sdk and module_exports module types.
327type sdkRegistry struct {
328 // The list of registered objects sorted by property name.
329 list []sdkRegisterable
330}
331
332// copyAndAppend creates a new sdkRegistry that includes all the traits registered in
333// this registry plus the supplied trait.
334func (r *sdkRegistry) copyAndAppend(registerable sdkRegisterable) *sdkRegistry {
335 oldList := r.list
336
Paul Duffin581f2e52021-09-22 13:25:23 +0100337 // Make sure that list does not already contain the property. Uses a simple linear search instead
338 // of a binary search even though the list is sorted. That is because the number of items in the
339 // list is small and so not worth the overhead of a binary search.
340 found := false
341 newPropertyName := registerable.SdkPropertyName()
342 for _, r := range oldList {
343 if r.SdkPropertyName() == newPropertyName {
344 found = true
345 break
346 }
347 }
348 if found {
349 names := []string{}
350 for _, r := range oldList {
351 names = append(names, r.SdkPropertyName())
352 }
353 panic(fmt.Errorf("duplicate properties found, %q already exists in %q", newPropertyName, names))
354 }
355
Paul Duffinf04033b2021-09-22 11:51:09 +0100356 // Copy the slice just in case this is being read while being modified, e.g. when testing.
357 list := make([]sdkRegisterable, 0, len(oldList)+1)
358 list = append(list, oldList...)
359 list = append(list, registerable)
360
361 // Sort the registered objects by their property name to ensure that registry order has no effect
362 // on behavior.
363 sort.Slice(list, func(i1, i2 int) bool {
364 t1 := list[i1]
365 t2 := list[i2]
366
367 return t1.SdkPropertyName() < t2.SdkPropertyName()
368 })
369
370 // Create a new registry so the pointer uniquely identifies the set of registered types.
371 return &sdkRegistry{
372 list: list,
373 }
374}
375
376// registeredObjects returns the list of registered instances.
377func (r *sdkRegistry) registeredObjects() []sdkRegisterable {
378 return r.list
379}
380
381// uniqueOnceKey returns a key that uniquely identifies this instance and can be used with
382// OncePer.Once
383func (r *sdkRegistry) uniqueOnceKey() OnceKey {
384 // Use the pointer to the registry as the unique key. The pointer is used because it is guaranteed
385 // to uniquely identify the contained list. The list itself cannot be used as slices are not
386 // comparable. Using the pointer does mean that two separate registries with identical lists would
387 // have different keys and so cause whatever information is cached to be created multiple times.
388 // However, that is not an issue in practice as it should not occur outside tests. Constructing a
389 // string representation of the list to use instead would avoid that but is an unnecessary
390 // complication that provides no significant benefit.
391 return NewCustomOnceKey(r)
392}
393
Paul Duffind19f8942021-07-14 12:08:37 +0100394// SdkMemberTrait represents a trait that members of an sdk module can contribute to the sdk
395// snapshot.
396//
397// A trait is simply a characteristic of sdk member that is not required by default which may be
398// required for some members but not others. Traits can cause additional information to be output
399// to the sdk snapshot or replace the default information exported for a member with something else.
400// e.g.
Colin Crossd079e0b2022-08-16 10:27:33 -0700401// - By default cc libraries only export the default image variants to the SDK. However, for some
402// members it may be necessary to export specific image variants, e.g. vendor, or recovery.
403// - By default cc libraries export all the configured architecture variants except for the native
404// bridge architecture variants. However, for some members it may be necessary to export the
405// native bridge architecture variants as well.
406// - By default cc libraries export the platform variant (i.e. sdk:). However, for some members it
407// may be necessary to export the sdk variant (i.e. sdk:sdk).
Paul Duffind19f8942021-07-14 12:08:37 +0100408//
409// A sdk can request a module to provide no traits, one trait or a collection of traits. The exact
410// behavior of a trait is determined by how SdkMemberType implementations handle the traits. A trait
411// could be specific to one SdkMemberType or many. Some trait combinations could be incompatible.
412//
413// The sdk module type will create a special traits structure that contains a property for each
414// trait registered with RegisterSdkMemberTrait(). The property names are those returned from
415// SdkPropertyName(). Each property contains a list of modules that are required to have that trait.
416// e.g. something like this:
417//
Colin Crossd079e0b2022-08-16 10:27:33 -0700418// sdk {
419// name: "sdk",
420// ...
421// traits: {
422// recovery_image: ["module1", "module4", "module5"],
423// native_bridge: ["module1", "module2"],
424// native_sdk: ["module1", "module3"],
425// ...
426// },
427// ...
428// }
Paul Duffind19f8942021-07-14 12:08:37 +0100429type SdkMemberTrait interface {
430 // SdkPropertyName returns the name of the traits property on an sdk module.
431 SdkPropertyName() string
432}
433
Paul Duffinf04033b2021-09-22 11:51:09 +0100434var _ sdkRegisterable = (SdkMemberTrait)(nil)
435
Paul Duffind19f8942021-07-14 12:08:37 +0100436// SdkMemberTraitBase is the base struct that must be embedded within any type that implements
437// SdkMemberTrait.
438type SdkMemberTraitBase struct {
439 // PropertyName is the name of the property
440 PropertyName string
441}
442
443func (b *SdkMemberTraitBase) SdkPropertyName() string {
444 return b.PropertyName
445}
446
447// SdkMemberTraitSet is a set of SdkMemberTrait instances.
448type SdkMemberTraitSet interface {
449 // Empty returns true if this set is empty.
450 Empty() bool
451
452 // Contains returns true if this set contains the specified trait.
453 Contains(trait SdkMemberTrait) bool
454
455 // Subtract returns a new set containing all elements of this set except for those in the
456 // other set.
457 Subtract(other SdkMemberTraitSet) SdkMemberTraitSet
458
459 // String returns a string representation of the set and its contents.
460 String() string
461}
462
463func NewSdkMemberTraitSet(traits []SdkMemberTrait) SdkMemberTraitSet {
464 if len(traits) == 0 {
465 return EmptySdkMemberTraitSet()
466 }
467
468 m := sdkMemberTraitSet{}
469 for _, trait := range traits {
470 m[trait] = true
471 }
472 return m
473}
474
475func EmptySdkMemberTraitSet() SdkMemberTraitSet {
476 return (sdkMemberTraitSet)(nil)
477}
478
479type sdkMemberTraitSet map[SdkMemberTrait]bool
480
481var _ SdkMemberTraitSet = (sdkMemberTraitSet{})
482
483func (s sdkMemberTraitSet) Empty() bool {
484 return len(s) == 0
485}
486
487func (s sdkMemberTraitSet) Contains(trait SdkMemberTrait) bool {
488 return s[trait]
489}
490
491func (s sdkMemberTraitSet) Subtract(other SdkMemberTraitSet) SdkMemberTraitSet {
492 if other.Empty() {
493 return s
494 }
495
496 var remainder []SdkMemberTrait
497 for trait, _ := range s {
498 if !other.Contains(trait) {
499 remainder = append(remainder, trait)
500 }
501 }
502
503 return NewSdkMemberTraitSet(remainder)
504}
505
506func (s sdkMemberTraitSet) String() string {
507 list := []string{}
508 for trait, _ := range s {
509 list = append(list, trait.SdkPropertyName())
510 }
511 sort.Strings(list)
512 return fmt.Sprintf("[%s]", strings.Join(list, ","))
513}
514
Paul Duffinf04033b2021-09-22 11:51:09 +0100515var registeredSdkMemberTraits = &sdkRegistry{}
Paul Duffin30c830b2021-09-22 11:49:47 +0100516
517// RegisteredSdkMemberTraits returns a OnceKey and a sorted list of registered traits.
518//
519// The key uniquely identifies the array of traits and can be used with OncePer.Once() to cache
520// information derived from the array of traits.
521func RegisteredSdkMemberTraits() (OnceKey, []SdkMemberTrait) {
Paul Duffinf04033b2021-09-22 11:51:09 +0100522 registerables := registeredSdkMemberTraits.registeredObjects()
523 traits := make([]SdkMemberTrait, len(registerables))
524 for i, registerable := range registerables {
525 traits[i] = registerable.(SdkMemberTrait)
526 }
527 return registeredSdkMemberTraits.uniqueOnceKey(), traits
Paul Duffin30c830b2021-09-22 11:49:47 +0100528}
Paul Duffind19f8942021-07-14 12:08:37 +0100529
530// RegisterSdkMemberTrait registers an SdkMemberTrait object to allow them to be used in the
531// module_exports, module_exports_snapshot, sdk and sdk_snapshot module types.
532func RegisterSdkMemberTrait(trait SdkMemberTrait) {
Paul Duffin30c830b2021-09-22 11:49:47 +0100533 registeredSdkMemberTraits = registeredSdkMemberTraits.copyAndAppend(trait)
Paul Duffind19f8942021-07-14 12:08:37 +0100534}
535
Paul Duffin94289702021-09-09 15:38:32 +0100536// SdkMember is an individual member of the SDK.
537//
538// It includes all of the variants that the SDK depends upon.
Paul Duffin13879572019-11-28 14:31:38 +0000539type SdkMember interface {
Paul Duffin94289702021-09-09 15:38:32 +0100540 // Name returns the name of the member.
Paul Duffin13879572019-11-28 14:31:38 +0000541 Name() string
542
Paul Duffin94289702021-09-09 15:38:32 +0100543 // Variants returns all the variants of this module depended upon by the SDK.
Paul Duffin5e71e682022-11-23 18:09:54 +0000544 Variants() []Module
Paul Duffin13879572019-11-28 14:31:38 +0000545}
546
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100547// SdkMemberDependencyTag is the interface that a tag must implement in order to allow the
Paul Duffin2d3da312021-05-06 12:02:27 +0100548// dependent module to be automatically added to the sdk.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100549type SdkMemberDependencyTag interface {
Paul Duffinf8539922019-11-19 19:44:10 +0000550 blueprint.DependencyTag
551
Paul Duffina7208112021-04-23 21:20:20 +0100552 // SdkMemberType returns the SdkMemberType that will be used to automatically add the child module
553 // to the sdk.
Paul Duffin5cca7c42021-05-26 10:16:01 +0100554 //
555 // Returning nil will prevent the module being added to the sdk.
Paul Duffineee466e2021-04-27 23:17:56 +0100556 SdkMemberType(child Module) SdkMemberType
Paul Duffina7208112021-04-23 21:20:20 +0100557
558 // ExportMember determines whether a module added to the sdk through this tag will be exported
559 // from the sdk or not.
560 //
561 // An exported member is added to the sdk using its own name, e.g. if "foo" was exported from sdk
562 // "bar" then its prebuilt would be simply called "foo". A member can be added to the sdk via
563 // multiple tags and if any of those tags returns true from this method then the membe will be
564 // exported. Every module added directly to the sdk via one of the member type specific
565 // properties, e.g. java_libs, will automatically be exported.
566 //
567 // If a member is not exported then it is treated as an internal implementation detail of the
568 // sdk and so will be added with an sdk specific name. e.g. if "foo" was an internal member of sdk
569 // "bar" then its prebuilt would be called "bar_foo". Additionally its visibility will be set to
570 // "//visibility:private" so it will not be accessible from outside its Android.bp file.
571 ExportMember() bool
Paul Duffinf8539922019-11-19 19:44:10 +0000572}
573
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100574var _ SdkMemberDependencyTag = (*sdkMemberDependencyTag)(nil)
575var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil)
Paul Duffincee7e662020-07-09 17:32:57 +0100576
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100577type sdkMemberDependencyTag struct {
Paul Duffinf8539922019-11-19 19:44:10 +0000578 blueprint.BaseDependencyTag
579 memberType SdkMemberType
Paul Duffina7208112021-04-23 21:20:20 +0100580 export bool
Paul Duffinf8539922019-11-19 19:44:10 +0000581}
582
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100583func (t *sdkMemberDependencyTag) SdkMemberType(_ Module) SdkMemberType {
Paul Duffinf8539922019-11-19 19:44:10 +0000584 return t.memberType
585}
586
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100587func (t *sdkMemberDependencyTag) ExportMember() bool {
Paul Duffina7208112021-04-23 21:20:20 +0100588 return t.export
589}
590
Paul Duffin94289702021-09-09 15:38:32 +0100591// ReplaceSourceWithPrebuilt prevents dependencies from the sdk/module_exports onto their members
592// from being replaced with a preferred prebuilt.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100593func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool {
Paul Duffincee7e662020-07-09 17:32:57 +0100594 return false
595}
596
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100597// DependencyTagForSdkMemberType creates an SdkMemberDependencyTag that will cause any
Paul Duffina7208112021-04-23 21:20:20 +0100598// dependencies added by the tag to be added to the sdk as the specified SdkMemberType and exported
599// (or not) as specified by the export parameter.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100600func DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMemberDependencyTag {
601 return &sdkMemberDependencyTag{memberType: memberType, export: export}
Paul Duffinf8539922019-11-19 19:44:10 +0000602}
603
Paul Duffin94289702021-09-09 15:38:32 +0100604// SdkMemberType is the interface that must be implemented for every type that can be a member of an
Paul Duffin13879572019-11-28 14:31:38 +0000605// sdk.
606//
607// The basic implementation should look something like this, where ModuleType is
608// the name of the module type being supported.
609//
Colin Crossd079e0b2022-08-16 10:27:33 -0700610// type moduleTypeSdkMemberType struct {
611// android.SdkMemberTypeBase
612// }
Paul Duffin13879572019-11-28 14:31:38 +0000613//
Colin Crossd079e0b2022-08-16 10:27:33 -0700614// func init() {
615// android.RegisterSdkMemberType(&moduleTypeSdkMemberType{
616// SdkMemberTypeBase: android.SdkMemberTypeBase{
617// PropertyName: "module_types",
618// },
619// }
620// }
Paul Duffin13879572019-11-28 14:31:38 +0000621//
Colin Crossd079e0b2022-08-16 10:27:33 -0700622// ...methods...
Paul Duffin13879572019-11-28 14:31:38 +0000623type SdkMemberType interface {
Paul Duffin94289702021-09-09 15:38:32 +0100624 // SdkPropertyName returns the name of the member type property on an sdk module.
Paul Duffin255f18e2019-12-13 11:22:16 +0000625 SdkPropertyName() string
626
Paul Duffin13082052021-05-11 00:31:38 +0100627 // RequiresBpProperty returns true if this member type requires its property to be usable within
628 // an Android.bp file.
629 RequiresBpProperty() bool
630
Paul Duffinf861df72022-07-01 15:56:06 +0000631 // SupportedBuildReleases returns the string representation of a set of target build releases that
632 // support this member type.
633 SupportedBuildReleases() string
634
Paul Duffin94289702021-09-09 15:38:32 +0100635 // UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot,
636 // false otherwise.
Paul Duffine6029182019-12-16 17:43:48 +0000637 UsableWithSdkAndSdkSnapshot() bool
638
Paul Duffin94289702021-09-09 15:38:32 +0100639 // IsHostOsDependent returns true if prebuilt host artifacts may be specific to the host OS. Only
640 // applicable to modules where HostSupported() is true. If this is true, snapshots will list each
641 // host OS variant explicitly and disable all other host OS'es.
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100642 IsHostOsDependent() bool
643
Liz Kammer96320df2022-05-12 20:40:00 -0400644 // SupportedLinkages returns the names of the linkage variants supported by this module.
645 SupportedLinkages() []string
646
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000647 // ArePrebuiltsRequired returns true if prebuilts are required in the sdk snapshot, false
648 // otherwise.
649 ArePrebuiltsRequired() bool
650
Paul Duffin94289702021-09-09 15:38:32 +0100651 // AddDependencies adds dependencies from the SDK module to all the module variants the member
652 // type contributes to the SDK. `names` is the list of module names given in the member type
653 // property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants
654 // required is determined by the SDK and its properties. The dependencies must be added with the
655 // supplied tag.
Paul Duffin13879572019-11-28 14:31:38 +0000656 //
657 // The BottomUpMutatorContext provided is for the SDK module.
Paul Duffin296701e2021-07-14 10:29:36 +0100658 AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string)
Paul Duffin13879572019-11-28 14:31:38 +0000659
Paul Duffin94289702021-09-09 15:38:32 +0100660 // IsInstance returns true if the supplied module is an instance of this member type.
Paul Duffin13879572019-11-28 14:31:38 +0000661 //
Paul Duffin94289702021-09-09 15:38:32 +0100662 // This is used to check the type of each variant before added to the SdkMember. Returning false
663 // will cause an error to be logged explaining that the module is not allowed in whichever sdk
664 // property it was added.
Paul Duffin13879572019-11-28 14:31:38 +0000665 IsInstance(module Module) bool
666
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100667 // UsesSourceModuleTypeInSnapshot returns true when the AddPrebuiltModule() method returns a
668 // source module type.
669 UsesSourceModuleTypeInSnapshot() bool
670
Paul Duffin94289702021-09-09 15:38:32 +0100671 // AddPrebuiltModule is called to add a prebuilt module that the sdk will populate.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000672 //
Paul Duffin425b0ea2020-05-06 12:41:39 +0100673 // The sdk module code generates the snapshot as follows:
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000674 //
675 // * A properties struct of type SdkMemberProperties is created for each variant and
Paul Duffin5e71e682022-11-23 18:09:54 +0000676 // populated with information from the variant by calling PopulateFromVariant(Module)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000677 // on the struct.
678 //
679 // * An additional properties struct is created into which the common properties will be
680 // added.
681 //
682 // * The variant property structs are analysed to find exported (capitalized) fields which
683 // have common values. Those fields are cleared and the common value added to the common
Paul Duffin864e1b42020-05-06 10:23:19 +0100684 // properties.
685 //
Paul Duffin02e25c82022-09-22 15:30:58 +0100686 // A field annotated with a tag of `sdk:"ignore"` will be treated as if it
687 // was not capitalized, i.e. ignored and not optimized for common values.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000688 //
Paul Duffinbfdca962022-09-22 16:21:54 +0100689 // A field annotated with a tag of `sdk:"keep"` will not be cleared even if the value is common
690 // across multiple structs. Common values will still be copied into the common property struct.
691 // So, if the same value is placed in all structs populated from variants that value would be
692 // copied into all common property structs and so be available in every instance.
693 //
Paul Duffin864e1b42020-05-06 10:23:19 +0100694 // A field annotated with a tag of `android:"arch_variant"` will be allowed to have
695 // values that differ by arch, fields not tagged as such must have common values across
696 // all variants.
697 //
Paul Duffinc459f892020-04-30 18:08:29 +0100698 // * Additional field tags can be specified on a field that will ignore certain values
699 // for the purpose of common value optimization. A value that is ignored must have the
700 // default value for the property type. This is to ensure that significant value are not
701 // ignored by accident. The purpose of this is to allow the snapshot generation to reflect
702 // the behavior of the runtime. e.g. if a property is ignored on the host then a property
703 // that is common for android can be treated as if it was common for android and host as
704 // the setting for host is ignored anyway.
705 // * `sdk:"ignored-on-host" - this indicates the property is ignored on the host variant.
706 //
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000707 // * The sdk module type populates the BpModule structure, creating the arch specific
708 // structure and calls AddToPropertySet(...) on the properties struct to add the member
709 // specific properties in the correct place in the structure.
710 //
Paul Duffin3a4eb502020-03-19 16:11:18 +0000711 AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000712
Paul Duffin94289702021-09-09 15:38:32 +0100713 // CreateVariantPropertiesStruct creates a structure into which variant specific properties can be
714 // added.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000715 CreateVariantPropertiesStruct() SdkMemberProperties
Paul Duffind19f8942021-07-14 12:08:37 +0100716
717 // SupportedTraits returns the set of traits supported by this member type.
718 SupportedTraits() SdkMemberTraitSet
Liz Kammer96320df2022-05-12 20:40:00 -0400719
720 // Overrides returns whether type overrides other SdkMemberType
721 Overrides(SdkMemberType) bool
Paul Duffin13879572019-11-28 14:31:38 +0000722}
Paul Duffin255f18e2019-12-13 11:22:16 +0000723
Paul Duffinf04033b2021-09-22 11:51:09 +0100724var _ sdkRegisterable = (SdkMemberType)(nil)
725
Paul Duffin296701e2021-07-14 10:29:36 +0100726// SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies()
727// implementations.
728type SdkDependencyContext interface {
729 BottomUpMutatorContext
Paul Duffind19f8942021-07-14 12:08:37 +0100730
731 // RequiredTraits returns the set of SdkMemberTrait instances that the sdk requires the named
732 // member to provide.
733 RequiredTraits(name string) SdkMemberTraitSet
734
735 // RequiresTrait returns true if the sdk requires the member with the supplied name to provide the
736 // supplied trait.
737 RequiresTrait(name string, trait SdkMemberTrait) bool
Paul Duffin296701e2021-07-14 10:29:36 +0100738}
739
Paul Duffin94289702021-09-09 15:38:32 +0100740// SdkMemberTypeBase is the base type for SdkMemberType implementations and must be embedded in any
741// struct that implements SdkMemberType.
Paul Duffin255f18e2019-12-13 11:22:16 +0000742type SdkMemberTypeBase struct {
Paul Duffin13082052021-05-11 00:31:38 +0100743 PropertyName string
744
Liz Kammer96320df2022-05-12 20:40:00 -0400745 // Property names that this SdkMemberTypeBase can override, this is useful when a module type is a
746 // superset of another module type.
747 OverridesPropertyNames map[string]bool
748
749 // The names of linkage variants supported by this module.
750 SupportedLinkageNames []string
751
Paul Duffin13082052021-05-11 00:31:38 +0100752 // When set to true BpPropertyNotRequired indicates that the member type does not require the
753 // property to be specifiable in an Android.bp file.
754 BpPropertyNotRequired bool
755
Paul Duffinf861df72022-07-01 15:56:06 +0000756 // The name of the first targeted build release.
757 //
758 // If not specified then it is assumed to be available on all targeted build releases.
759 SupportedBuildReleaseSpecification string
760
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000761 // Set to true if this must be usable with the sdk/sdk_snapshot module types. Otherwise, it will
762 // only be usable with module_exports/module_exports_snapshots module types.
763 SupportsSdk bool
764
765 // Set to true if prebuilt host artifacts of this member may be specific to the host OS. Only
766 // applicable to modules where HostSupported() is true.
Paul Duffin2d3da312021-05-06 12:02:27 +0100767 HostOsDependent bool
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100768
769 // When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source
770 // module type in its SdkMemberType.AddPrebuiltModule() method. That prevents the sdk snapshot
771 // code from automatically adding a prefer: true flag.
772 UseSourceModuleTypeInSnapshot bool
Paul Duffind19f8942021-07-14 12:08:37 +0100773
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000774 // Set to proptools.BoolPtr(false) if this member does not generate prebuilts but is only provided
775 // to allow the sdk to gather members from this member's dependencies. If not specified then
776 // defaults to true.
777 PrebuiltsRequired *bool
778
Paul Duffind19f8942021-07-14 12:08:37 +0100779 // The list of supported traits.
780 Traits []SdkMemberTrait
Paul Duffin255f18e2019-12-13 11:22:16 +0000781}
782
783func (b *SdkMemberTypeBase) SdkPropertyName() string {
784 return b.PropertyName
785}
786
Paul Duffin13082052021-05-11 00:31:38 +0100787func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
788 return !b.BpPropertyNotRequired
789}
790
Paul Duffinf861df72022-07-01 15:56:06 +0000791func (b *SdkMemberTypeBase) SupportedBuildReleases() string {
792 return b.SupportedBuildReleaseSpecification
793}
794
Paul Duffine6029182019-12-16 17:43:48 +0000795func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
796 return b.SupportsSdk
797}
798
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100799func (b *SdkMemberTypeBase) IsHostOsDependent() bool {
800 return b.HostOsDependent
801}
802
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000803func (b *SdkMemberTypeBase) ArePrebuiltsRequired() bool {
804 return proptools.BoolDefault(b.PrebuiltsRequired, true)
805}
806
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100807func (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool {
808 return b.UseSourceModuleTypeInSnapshot
809}
810
Paul Duffind19f8942021-07-14 12:08:37 +0100811func (b *SdkMemberTypeBase) SupportedTraits() SdkMemberTraitSet {
812 return NewSdkMemberTraitSet(b.Traits)
813}
814
Liz Kammer96320df2022-05-12 20:40:00 -0400815func (b *SdkMemberTypeBase) Overrides(other SdkMemberType) bool {
816 return b.OverridesPropertyNames[other.SdkPropertyName()]
817}
818
819func (b *SdkMemberTypeBase) SupportedLinkages() []string {
820 return b.SupportedLinkageNames
821}
822
Paul Duffin30c830b2021-09-22 11:49:47 +0100823// registeredModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports
824// modules.
Paul Duffinf04033b2021-09-22 11:51:09 +0100825var registeredModuleExportsMemberTypes = &sdkRegistry{}
Paul Duffin62782de2021-07-14 12:05:16 +0100826
Paul Duffinf04033b2021-09-22 11:51:09 +0100827// registeredSdkMemberTypes is the set of registered registeredSdkMemberTypes for sdk modules.
828var registeredSdkMemberTypes = &sdkRegistry{}
Paul Duffin30c830b2021-09-22 11:49:47 +0100829
830// RegisteredSdkMemberTypes returns a OnceKey and a sorted list of registered types.
831//
832// If moduleExports is true then the slice of types includes all registered types that can be used
833// with the module_exports and module_exports_snapshot module types. Otherwise, the slice of types
834// only includes those registered types that can be used with the sdk and sdk_snapshot module
835// types.
836//
837// The key uniquely identifies the array of types and can be used with OncePer.Once() to cache
838// information derived from the array of types.
839func RegisteredSdkMemberTypes(moduleExports bool) (OnceKey, []SdkMemberType) {
Paul Duffinf04033b2021-09-22 11:51:09 +0100840 var registry *sdkRegistry
Paul Duffin30c830b2021-09-22 11:49:47 +0100841 if moduleExports {
842 registry = registeredModuleExportsMemberTypes
843 } else {
844 registry = registeredSdkMemberTypes
845 }
846
Paul Duffinf04033b2021-09-22 11:51:09 +0100847 registerables := registry.registeredObjects()
848 types := make([]SdkMemberType, len(registerables))
849 for i, registerable := range registerables {
850 types[i] = registerable.(SdkMemberType)
851 }
852 return registry.uniqueOnceKey(), types
Paul Duffin30c830b2021-09-22 11:49:47 +0100853}
Paul Duffine6029182019-12-16 17:43:48 +0000854
Paul Duffin94289702021-09-09 15:38:32 +0100855// RegisterSdkMemberType registers an SdkMemberType object to allow them to be used in the
856// module_exports, module_exports_snapshot and (depending on the value returned from
857// SdkMemberType.UsableWithSdkAndSdkSnapshot) the sdk and sdk_snapshot module types.
Paul Duffine6029182019-12-16 17:43:48 +0000858func RegisterSdkMemberType(memberType SdkMemberType) {
859 // All member types are usable with module_exports.
Paul Duffin30c830b2021-09-22 11:49:47 +0100860 registeredModuleExportsMemberTypes = registeredModuleExportsMemberTypes.copyAndAppend(memberType)
Paul Duffine6029182019-12-16 17:43:48 +0000861
862 // Only those that explicitly indicate it are usable with sdk.
863 if memberType.UsableWithSdkAndSdkSnapshot() {
Paul Duffin30c830b2021-09-22 11:49:47 +0100864 registeredSdkMemberTypes = registeredSdkMemberTypes.copyAndAppend(memberType)
Paul Duffine6029182019-12-16 17:43:48 +0000865 }
866}
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000867
Paul Duffin94289702021-09-09 15:38:32 +0100868// SdkMemberPropertiesBase is the base structure for all implementations of SdkMemberProperties and
869// must be embedded in any struct that implements SdkMemberProperties.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000870//
Martin Stjernholm89238f42020-07-10 00:14:03 +0100871// Contains common properties that apply across many different member types.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000872type SdkMemberPropertiesBase struct {
Paul Duffina04c1072020-03-02 10:16:35 +0000873 // The number of unique os types supported by the member variants.
Paul Duffina551a1c2020-03-17 21:04:24 +0000874 //
875 // If a member has a variant with more than one os type then it will need to differentiate
876 // the locations of any of their prebuilt files in the snapshot by os type to prevent them
877 // from colliding. See OsPrefix().
878 //
Paul Duffin02e25c82022-09-22 15:30:58 +0100879 // Ignore this property during optimization. This is needed because this property is the same for
880 // all variants of a member and so would be optimized away if it was not ignored.
881 Os_count int `sdk:"ignore"`
Paul Duffina04c1072020-03-02 10:16:35 +0000882
883 // The os type for which these properties refer.
Paul Duffina551a1c2020-03-17 21:04:24 +0000884 //
885 // Provided to allow a member to differentiate between os types in the locations of their
886 // prebuilt files when it supports more than one os type.
887 //
Paul Duffin02e25c82022-09-22 15:30:58 +0100888 // Ignore this property during optimization. This is needed because this property is the same for
889 // all variants of a member and so would be optimized away if it was not ignored.
890 Os OsType `sdk:"ignore"`
Paul Duffina551a1c2020-03-17 21:04:24 +0000891
892 // The setting to use for the compile_multilib property.
Martin Stjernholm89238f42020-07-10 00:14:03 +0100893 Compile_multilib string `android:"arch_variant"`
Paul Duffina04c1072020-03-02 10:16:35 +0000894}
895
Paul Duffin94289702021-09-09 15:38:32 +0100896// OsPrefix returns the os prefix to use for any file paths in the sdk.
Paul Duffina04c1072020-03-02 10:16:35 +0000897//
898// Is an empty string if the member only provides variants for a single os type, otherwise
899// is the OsType.Name.
900func (b *SdkMemberPropertiesBase) OsPrefix() string {
901 if b.Os_count == 1 {
902 return ""
903 } else {
904 return b.Os.Name
905 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000906}
907
908func (b *SdkMemberPropertiesBase) Base() *SdkMemberPropertiesBase {
909 return b
910}
911
Paul Duffin94289702021-09-09 15:38:32 +0100912// SdkMemberProperties is the interface to be implemented on top of a structure that contains
913// variant specific information.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000914//
Paul Duffin94289702021-09-09 15:38:32 +0100915// Struct fields that are capitalized are examined for common values to extract. Fields that are not
916// capitalized are assumed to be arch specific.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000917type SdkMemberProperties interface {
Paul Duffin94289702021-09-09 15:38:32 +0100918 // Base returns the base structure.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000919 Base() *SdkMemberPropertiesBase
920
Paul Duffin94289702021-09-09 15:38:32 +0100921 // PopulateFromVariant populates this structure with information from a module variant.
922 //
923 // It will typically be called once for each variant of a member module that the SDK depends upon.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000924 PopulateFromVariant(ctx SdkMemberContext, variant Module)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000925
Paul Duffin94289702021-09-09 15:38:32 +0100926 // AddToPropertySet adds the information from this structure to the property set.
927 //
928 // This will be called for each instance of this structure on which the PopulateFromVariant method
929 // was called and also on a number of different instances of this structure into which properties
930 // common to one or more variants have been copied. Therefore, implementations of this must handle
931 // the case when this structure is only partially populated.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000932 AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet)
933}
934
Paul Duffin94289702021-09-09 15:38:32 +0100935// SdkMemberContext provides access to information common to a specific member.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000936type SdkMemberContext interface {
937
Paul Duffin94289702021-09-09 15:38:32 +0100938 // SdkModuleContext returns the module context of the sdk common os variant which is creating the
939 // snapshot.
940 //
941 // This is common to all members of the sdk and is not specific to the member being processed.
942 // If information about the member being processed needs to be obtained from this ModuleContext it
943 // must be obtained using one of the OtherModule... methods not the Module... methods.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000944 SdkModuleContext() ModuleContext
945
Paul Duffin94289702021-09-09 15:38:32 +0100946 // SnapshotBuilder the builder of the snapshot.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000947 SnapshotBuilder() SnapshotBuilder
Paul Duffina551a1c2020-03-17 21:04:24 +0000948
Paul Duffin94289702021-09-09 15:38:32 +0100949 // MemberType returns the type of the member currently being processed.
Paul Duffina551a1c2020-03-17 21:04:24 +0000950 MemberType() SdkMemberType
951
Paul Duffin94289702021-09-09 15:38:32 +0100952 // Name returns the name of the member currently being processed.
Paul Duffina551a1c2020-03-17 21:04:24 +0000953 //
954 // Provided for use by sdk members to create a member specific location within the snapshot
955 // into which to copy the prebuilt files.
956 Name() string
Paul Duffind19f8942021-07-14 12:08:37 +0100957
958 // RequiresTrait returns true if this member is expected to provide the specified trait.
959 RequiresTrait(trait SdkMemberTrait) bool
Paul Duffin13648912022-07-15 13:12:35 +0000960
961 // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is
962 // being generated is before Tiramisu, i.e. S.
963 IsTargetBuildBeforeTiramisu() bool
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000964}
Paul Duffinb97b1572021-04-29 21:50:40 +0100965
966// ExportedComponentsInfo contains information about the components that this module exports to an
967// sdk snapshot.
968//
969// A component of a module is a child module that the module creates and which forms an integral
970// part of the functionality that the creating module provides. A component module is essentially
971// owned by its creator and is tightly coupled to the creator and other components.
972//
973// e.g. the child modules created by prebuilt_apis are not components because they are not tightly
974// coupled to the prebuilt_apis module. Once they are created the prebuilt_apis ignores them. The
975// child impl and stub library created by java_sdk_library (and corresponding import) are components
976// because the creating module depends upon them in order to provide some of its own functionality.
977//
978// A component is exported if it is part of an sdk snapshot. e.g. The xml and impl child modules are
979// components but they are not exported as they are not part of an sdk snapshot.
980//
981// This information is used by the sdk snapshot generation code to ensure that it does not create
982// an sdk snapshot that contains a declaration of the component module and the module that creates
983// it as that would result in duplicate modules when attempting to use the snapshot. e.g. a snapshot
984// that included the java_sdk_library_import "foo" and also a java_import "foo.stubs" would fail
985// as there would be two modules called "foo.stubs".
986type ExportedComponentsInfo struct {
987 // The names of the exported components.
988 Components []string
989}
990
991var ExportedComponentsInfoProvider = blueprint.NewProvider(ExportedComponentsInfo{})
Paul Duffin958806b2022-05-16 13:10:47 +0000992
993// AdditionalSdkInfo contains additional properties to add to the generated SDK info file.
994type AdditionalSdkInfo struct {
995 Properties map[string]interface{}
996}
997
998var AdditionalSdkInfoProvider = blueprint.NewProvider(AdditionalSdkInfo{})