blob: 1518a873188d1114549f13e2ab811583ba45595f [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// RequiredSdks provides access to the set of SDKs required by an APEX and its contents.
27//
Paul Duffin923e8a52020-03-30 15:33:32 +010028// Extracted from SdkAware to make it easier to define custom subsets of the
29// SdkAware interface and improve code navigation within the IDE.
30//
31// In addition to its use in SdkAware this interface must also be implemented by
32// APEX to specify the SDKs required by that module and its contents. e.g. APEX
33// is expected to implement RequiredSdks() by reading its own properties like
34// `uses_sdks`.
35type RequiredSdks interface {
Paul Duffin94289702021-09-09 15:38:32 +010036 // RequiredSdks returns the set of SDKs required by an APEX and its contents.
Paul Duffin923e8a52020-03-30 15:33:32 +010037 RequiredSdks() SdkRefs
38}
39
Paul Duffin94289702021-09-09 15:38:32 +010040// sdkAwareWithoutModule is provided simply to improve code navigation with the IDE.
Paul Duffin50f0da42020-07-22 13:52:01 +010041type sdkAwareWithoutModule interface {
Paul Duffin923e8a52020-03-30 15:33:32 +010042 RequiredSdks
43
Paul Duffinb97b1572021-04-29 21:50:40 +010044 // SdkMemberComponentName will return the name to use for a component of this module based on the
45 // base name of this module.
46 //
47 // The baseName is the name returned by ModuleBase.BaseModuleName(), i.e. the name specified in
48 // the name property in the .bp file so will not include the prebuilt_ prefix.
49 //
50 // The componentNameCreator is a func for creating the name of a component from the base name of
51 // the module, e.g. it could just append ".component" to the name passed in.
52 //
53 // This is intended to be called by prebuilt modules that create component models. It is because
54 // prebuilt module base names come in a variety of different forms:
55 // * unversioned - this is the same as the source module.
56 // * internal to an sdk - this is the unversioned name prefixed by the base name of the sdk
57 // module.
58 // * versioned - this is the same as the internal with the addition of an "@<version>" suffix.
59 //
60 // While this can be called from a source module in that case it will behave the same way as the
61 // unversioned name and return the result of calling the componentNameCreator func on the supplied
62 // base name.
63 //
64 // e.g. Assuming the componentNameCreator func simply appends ".component" to the name passed in
65 // then this will work as follows:
66 // * An unversioned name of "foo" will return "foo.component".
67 // * An internal to the sdk name of "sdk_foo" will return "sdk_foo.component".
68 // * A versioned name of "sdk_foo@current" will return "sdk_foo.component@current".
69 //
70 // Note that in the latter case the ".component" suffix is added before the version. Adding it
71 // after would change the version.
72 SdkMemberComponentName(baseName string, componentNameCreator func(string) string) string
73
Jiyong Parkd1063c12019-07-17 20:08:41 +090074 sdkBase() *SdkBase
75 MakeMemberOf(sdk SdkRef)
76 IsInAnySdk() bool
Paul Duffinb9e7a3c2021-05-06 15:53:19 +010077
78 // IsVersioned determines whether the module is versioned, i.e. has a name of the form
79 // <name>@<version>
80 IsVersioned() bool
81
Jiyong Parkd1063c12019-07-17 20:08:41 +090082 ContainingSdk() SdkRef
83 MemberName() string
84 BuildWithSdks(sdks SdkRefs)
Jiyong Parkd1063c12019-07-17 20:08:41 +090085}
86
Paul Duffin50f0da42020-07-22 13:52:01 +010087// SdkAware is the interface that must be supported by any module to become a member of SDK or to be
88// built with SDK
89type SdkAware interface {
90 Module
91 sdkAwareWithoutModule
92}
93
Jiyong Parkd1063c12019-07-17 20:08:41 +090094// SdkRef refers to a version of an SDK
95type SdkRef struct {
96 Name string
97 Version string
98}
99
Jiyong Park9b409bc2019-10-11 14:59:13 +0900100// Unversioned determines if the SdkRef is referencing to the unversioned SDK module
101func (s SdkRef) Unversioned() bool {
102 return s.Version == ""
Jiyong Parkd1063c12019-07-17 20:08:41 +0900103}
104
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900105// String returns string representation of this SdkRef for debugging purpose
106func (s SdkRef) String() string {
107 if s.Name == "" {
108 return "(No Sdk)"
109 }
110 if s.Unversioned() {
111 return s.Name
112 }
113 return s.Name + string(SdkVersionSeparator) + s.Version
114}
115
Jiyong Park9b409bc2019-10-11 14:59:13 +0900116// SdkVersionSeparator is a character used to separate an sdk name and its version
117const SdkVersionSeparator = '@'
Jiyong Parkd1063c12019-07-17 20:08:41 +0900118
Jiyong Park9b409bc2019-10-11 14:59:13 +0900119// ParseSdkRef parses a `name@version` style string into a corresponding SdkRef struct
Jiyong Parkd1063c12019-07-17 20:08:41 +0900120func ParseSdkRef(ctx BaseModuleContext, str string, property string) SdkRef {
Jiyong Park9b409bc2019-10-11 14:59:13 +0900121 tokens := strings.Split(str, string(SdkVersionSeparator))
Jiyong Parkd1063c12019-07-17 20:08:41 +0900122 if len(tokens) < 1 || len(tokens) > 2 {
Paul Duffin525a5902021-05-06 16:33:52 +0100123 ctx.PropertyErrorf(property, "%q does not follow name@version syntax", str)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900124 return SdkRef{Name: "invalid sdk name", Version: "invalid sdk version"}
125 }
126
127 name := tokens[0]
128
Jiyong Park9b409bc2019-10-11 14:59:13 +0900129 var version string
Jiyong Parkd1063c12019-07-17 20:08:41 +0900130 if len(tokens) == 2 {
131 version = tokens[1]
132 }
133
134 return SdkRef{Name: name, Version: version}
135}
136
137type SdkRefs []SdkRef
138
Jiyong Park9b409bc2019-10-11 14:59:13 +0900139// Contains tells if the given SdkRef is in this list of SdkRef's
Jiyong Parkd1063c12019-07-17 20:08:41 +0900140func (refs SdkRefs) Contains(s SdkRef) bool {
141 for _, r := range refs {
142 if r == s {
143 return true
144 }
145 }
146 return false
147}
148
149type sdkProperties struct {
150 // The SDK that this module is a member of. nil if it is not a member of any SDK
151 ContainingSdk *SdkRef `blueprint:"mutated"`
152
153 // The list of SDK names and versions that are used to build this module
154 RequiredSdks SdkRefs `blueprint:"mutated"`
155
156 // Name of the module that this sdk member is representing
157 Sdk_member_name *string
158}
159
160// SdkBase is a struct that is expected to be included in module types to implement the SdkAware
161// interface. InitSdkAwareModule should be called to initialize this struct.
162type SdkBase struct {
163 properties sdkProperties
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000164 module SdkAware
Jiyong Parkd1063c12019-07-17 20:08:41 +0900165}
166
167func (s *SdkBase) sdkBase() *SdkBase {
168 return s
169}
170
Paul Duffinb97b1572021-04-29 21:50:40 +0100171func (s *SdkBase) SdkMemberComponentName(baseName string, componentNameCreator func(string) string) string {
172 if s.MemberName() == "" {
173 return componentNameCreator(baseName)
174 } else {
175 index := strings.LastIndex(baseName, "@")
176 unversionedName := baseName[:index]
177 unversionedComponentName := componentNameCreator(unversionedName)
178 versionSuffix := baseName[index:]
179 return unversionedComponentName + versionSuffix
180 }
181}
182
Jiyong Park9b409bc2019-10-11 14:59:13 +0900183// MakeMemberOf sets this module to be a member of a specific SDK
Jiyong Parkd1063c12019-07-17 20:08:41 +0900184func (s *SdkBase) MakeMemberOf(sdk SdkRef) {
185 s.properties.ContainingSdk = &sdk
186}
187
188// IsInAnySdk returns true if this module is a member of any SDK
189func (s *SdkBase) IsInAnySdk() bool {
190 return s.properties.ContainingSdk != nil
191}
192
Paul Duffinb9e7a3c2021-05-06 15:53:19 +0100193// IsVersioned returns true if this module is versioned.
194func (s *SdkBase) IsVersioned() bool {
195 return strings.Contains(s.module.Name(), "@")
196}
197
Jiyong Parkd1063c12019-07-17 20:08:41 +0900198// ContainingSdk returns the SDK that this module is a member of
199func (s *SdkBase) ContainingSdk() SdkRef {
200 if s.properties.ContainingSdk != nil {
201 return *s.properties.ContainingSdk
202 }
Jiyong Park9b409bc2019-10-11 14:59:13 +0900203 return SdkRef{Name: "", Version: ""}
Jiyong Parkd1063c12019-07-17 20:08:41 +0900204}
205
Jiyong Park9b409bc2019-10-11 14:59:13 +0900206// MemberName returns the name of the module that this SDK member is overriding
Jiyong Parkd1063c12019-07-17 20:08:41 +0900207func (s *SdkBase) MemberName() string {
208 return proptools.String(s.properties.Sdk_member_name)
209}
210
211// BuildWithSdks is used to mark that this module has to be built with the given SDK(s).
212func (s *SdkBase) BuildWithSdks(sdks SdkRefs) {
213 s.properties.RequiredSdks = sdks
214}
215
216// RequiredSdks returns the SDK(s) that this module has to be built with
217func (s *SdkBase) RequiredSdks() SdkRefs {
218 return s.properties.RequiredSdks
219}
220
221// InitSdkAwareModule initializes the SdkBase struct. This must be called by all modules including
222// SdkBase.
223func InitSdkAwareModule(m SdkAware) {
224 base := m.sdkBase()
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000225 base.module = m
Jiyong Parkd1063c12019-07-17 20:08:41 +0900226 m.AddProperties(&base.properties)
227}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000228
Paul Duffin0c2e0832021-04-28 00:39:52 +0100229// IsModuleInVersionedSdk returns true if the module is an versioned sdk.
230func IsModuleInVersionedSdk(module Module) bool {
231 if s, ok := module.(SdkAware); ok {
232 if !s.ContainingSdk().Unversioned() {
233 return true
234 }
235 }
236 return false
237}
238
Paul Duffin94289702021-09-09 15:38:32 +0100239// SnapshotBuilder provides support for generating the build rules which will build the snapshot.
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000240type SnapshotBuilder interface {
Paul Duffin94289702021-09-09 15:38:32 +0100241 // CopyToSnapshot generates a rule that will copy the src to the dest (which is a snapshot
242 // relative path) and add the dest to the zip.
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000243 CopyToSnapshot(src Path, dest string)
244
Paul Duffin94289702021-09-09 15:38:32 +0100245 // EmptyFile returns the path to an empty file.
Paul Duffin5c211452021-07-15 12:42:44 +0100246 //
247 // This can be used by sdk member types that need to create an empty file in the snapshot, simply
248 // pass the value returned from this to the CopyToSnapshot() method.
249 EmptyFile() Path
250
Paul Duffin94289702021-09-09 15:38:32 +0100251 // UnzipToSnapshot generates a rule that will unzip the supplied zip into the snapshot relative
252 // directory destDir.
Paul Duffin91547182019-11-12 19:39:36 +0000253 UnzipToSnapshot(zipPath Path, destDir string)
254
Paul Duffin94289702021-09-09 15:38:32 +0100255 // AddPrebuiltModule adds a new prebuilt module to the snapshot.
256 //
257 // It is intended to be called from SdkMemberType.AddPrebuiltModule which can add module type
258 // specific properties that are not variant specific. The following properties will be
259 // automatically populated before returning.
Paul Duffinb645ec82019-11-27 17:43:54 +0000260 //
261 // * name
262 // * sdk_member_name
263 // * prefer
264 //
Paul Duffin94289702021-09-09 15:38:32 +0100265 // Properties that are variant specific will be handled by SdkMemberProperties structure.
266 //
267 // Each module created by this method can be output to the generated Android.bp file in two
268 // different forms, depending on the setting of the SOONG_SDK_SNAPSHOT_VERSION build property.
269 // The two forms are:
270 // 1. A versioned Soong module that is referenced from a corresponding similarly versioned
271 // snapshot module.
272 // 2. An unversioned Soong module that.
273 //
274 // See sdk/update.go for more information.
Paul Duffin9d8d6092019-12-05 18:19:29 +0000275 AddPrebuiltModule(member SdkMember, moduleType string) BpModule
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000276
Paul Duffin94289702021-09-09 15:38:32 +0100277 // SdkMemberReferencePropertyTag returns a property tag to use when adding a property to a
278 // BpModule that contains references to other sdk members.
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000279 //
Paul Duffin94289702021-09-09 15:38:32 +0100280 // Using this will ensure that the reference is correctly output for both versioned and
281 // unversioned prebuilts in the snapshot.
Paul Duffin13f02712020-03-06 12:30:43 +0000282 //
Paul Duffin94289702021-09-09 15:38:32 +0100283 // "required: true" means that the property must only contain references to other members of the
284 // sdk. Passing a reference to a module that is not a member of the sdk will result in a build
285 // error.
Paul Duffin13f02712020-03-06 12:30:43 +0000286 //
Paul Duffin94289702021-09-09 15:38:32 +0100287 // "required: false" means that the property can contain references to modules that are either
288 // members or not members of the sdk. If a reference is to a module that is a non member then the
289 // reference is left unchanged, i.e. it is not transformed as references to members are.
290 //
291 // The handling of the member names is dependent on whether it is an internal or exported member.
292 // An exported member is one whose name is specified in one of the member type specific
293 // properties. An internal member is one that is added due to being a part of an exported (or
294 // other internal) member and is not itself an exported member.
Paul Duffin13f02712020-03-06 12:30:43 +0000295 //
296 // Member names are handled as follows:
Paul Duffin94289702021-09-09 15:38:32 +0100297 // * When creating the unversioned form of the module the name is left unchecked unless the member
298 // is internal in which case it is transformed into an sdk specific name, i.e. by prefixing with
299 // the sdk name.
Paul Duffin13f02712020-03-06 12:30:43 +0000300 //
Paul Duffin94289702021-09-09 15:38:32 +0100301 // * When creating the versioned form of the module the name is transformed into a versioned sdk
302 // specific name, i.e. by prefixing with the sdk name and suffixing with the version.
Paul Duffin13f02712020-03-06 12:30:43 +0000303 //
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000304 // e.g.
Paul Duffin13f02712020-03-06 12:30:43 +0000305 // bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag(true))
306 SdkMemberReferencePropertyTag(required bool) BpPropertyTag
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000307}
308
Paul Duffin94289702021-09-09 15:38:32 +0100309// BpPropertyTag is a marker interface that can be associated with properties in a BpPropertySet to
310// provide additional information which can be used to customize their behavior.
Paul Duffin5b511a22020-01-15 14:23:52 +0000311type BpPropertyTag interface{}
312
Paul Duffin94289702021-09-09 15:38:32 +0100313// BpPropertySet is a set of properties for use in a .bp file.
Paul Duffinb645ec82019-11-27 17:43:54 +0000314type BpPropertySet interface {
Paul Duffin94289702021-09-09 15:38:32 +0100315 // AddProperty adds a property.
316 //
317 // The value can be one of the following types:
Paul Duffinb645ec82019-11-27 17:43:54 +0000318 // * string
319 // * array of the above
320 // * bool
Martin Stjernholm191c25f2020-09-10 00:40:37 +0100321 // For these types it is an error if multiple properties with the same name
322 // are added.
323 //
324 // * pointer to a struct
Paul Duffinb645ec82019-11-27 17:43:54 +0000325 // * BpPropertySet
326 //
Martin Stjernholm191c25f2020-09-10 00:40:37 +0100327 // A pointer to a Blueprint-style property struct is first converted into a
328 // BpPropertySet by traversing the fields and adding their values as
329 // properties in a BpPropertySet. A field with a struct value is itself
330 // converted into a BpPropertySet before adding.
331 //
332 // Adding a BpPropertySet is done as follows:
333 // * If no property with the name exists then the BpPropertySet is added
334 // directly to this property. Care must be taken to ensure that it does not
335 // introduce a cycle.
336 // * If a property exists with the name and the current value is a
337 // BpPropertySet then every property of the new BpPropertySet is added to
338 // the existing BpPropertySet.
339 // * Otherwise, if a property exists with the name then it is an error.
Paul Duffinb645ec82019-11-27 17:43:54 +0000340 AddProperty(name string, value interface{})
341
Paul Duffin94289702021-09-09 15:38:32 +0100342 // AddPropertyWithTag adds a property with an associated property tag.
Paul Duffin5b511a22020-01-15 14:23:52 +0000343 AddPropertyWithTag(name string, value interface{}, tag BpPropertyTag)
344
Paul Duffin94289702021-09-09 15:38:32 +0100345 // AddPropertySet adds a property set with the specified name and returns it so that additional
346 // properties can be added to it.
Paul Duffinb645ec82019-11-27 17:43:54 +0000347 AddPropertySet(name string) BpPropertySet
Paul Duffin0df49682021-05-07 01:10:01 +0100348
Paul Duffin94289702021-09-09 15:38:32 +0100349 // AddCommentForProperty adds a comment for the named property (or property set).
Paul Duffin0df49682021-05-07 01:10:01 +0100350 AddCommentForProperty(name, text string)
Paul Duffinb645ec82019-11-27 17:43:54 +0000351}
352
Paul Duffin94289702021-09-09 15:38:32 +0100353// BpModule represents a module definition in a .bp file.
Paul Duffinb645ec82019-11-27 17:43:54 +0000354type BpModule interface {
355 BpPropertySet
Paul Duffin0df49682021-05-07 01:10:01 +0100356
357 // ModuleType returns the module type of the module
358 ModuleType() string
359
360 // Name returns the name of the module or "" if no name has been specified.
361 Name() string
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000362}
Paul Duffin13879572019-11-28 14:31:38 +0000363
Paul Duffin51227d82021-05-18 12:54:27 +0100364// BpPrintable is a marker interface that must be implemented by any struct that is added as a
365// property value.
366type BpPrintable interface {
367 bpPrintable()
368}
369
370// BpPrintableBase must be embedded within any struct that is added as a
371// property value.
372type BpPrintableBase struct {
373}
374
375func (b BpPrintableBase) bpPrintable() {
376}
377
378var _ BpPrintable = BpPrintableBase{}
379
Paul Duffinf04033b2021-09-22 11:51:09 +0100380// sdkRegisterable defines the interface that must be implemented by objects that can be registered
381// in an sdkRegistry.
382type sdkRegisterable interface {
383 // SdkPropertyName returns the name of the corresponding property on an sdk module.
384 SdkPropertyName() string
385}
386
387// sdkRegistry provides support for registering and retrieving objects that define properties for
388// use by sdk and module_exports module types.
389type sdkRegistry struct {
390 // The list of registered objects sorted by property name.
391 list []sdkRegisterable
392}
393
394// copyAndAppend creates a new sdkRegistry that includes all the traits registered in
395// this registry plus the supplied trait.
396func (r *sdkRegistry) copyAndAppend(registerable sdkRegisterable) *sdkRegistry {
397 oldList := r.list
398
399 // Copy the slice just in case this is being read while being modified, e.g. when testing.
400 list := make([]sdkRegisterable, 0, len(oldList)+1)
401 list = append(list, oldList...)
402 list = append(list, registerable)
403
404 // Sort the registered objects by their property name to ensure that registry order has no effect
405 // on behavior.
406 sort.Slice(list, func(i1, i2 int) bool {
407 t1 := list[i1]
408 t2 := list[i2]
409
410 return t1.SdkPropertyName() < t2.SdkPropertyName()
411 })
412
413 // Create a new registry so the pointer uniquely identifies the set of registered types.
414 return &sdkRegistry{
415 list: list,
416 }
417}
418
419// registeredObjects returns the list of registered instances.
420func (r *sdkRegistry) registeredObjects() []sdkRegisterable {
421 return r.list
422}
423
424// uniqueOnceKey returns a key that uniquely identifies this instance and can be used with
425// OncePer.Once
426func (r *sdkRegistry) uniqueOnceKey() OnceKey {
427 // Use the pointer to the registry as the unique key. The pointer is used because it is guaranteed
428 // to uniquely identify the contained list. The list itself cannot be used as slices are not
429 // comparable. Using the pointer does mean that two separate registries with identical lists would
430 // have different keys and so cause whatever information is cached to be created multiple times.
431 // However, that is not an issue in practice as it should not occur outside tests. Constructing a
432 // string representation of the list to use instead would avoid that but is an unnecessary
433 // complication that provides no significant benefit.
434 return NewCustomOnceKey(r)
435}
436
Paul Duffind19f8942021-07-14 12:08:37 +0100437// SdkMemberTrait represents a trait that members of an sdk module can contribute to the sdk
438// snapshot.
439//
440// A trait is simply a characteristic of sdk member that is not required by default which may be
441// required for some members but not others. Traits can cause additional information to be output
442// to the sdk snapshot or replace the default information exported for a member with something else.
443// e.g.
444// * By default cc libraries only export the default image variants to the SDK. However, for some
445// members it may be necessary to export specific image variants, e.g. vendor, or recovery.
446// * By default cc libraries export all the configured architecture variants except for the native
447// bridge architecture variants. However, for some members it may be necessary to export the
448// native bridge architecture variants as well.
449// * By default cc libraries export the platform variant (i.e. sdk:). However, for some members it
450// may be necessary to export the sdk variant (i.e. sdk:sdk).
451//
452// A sdk can request a module to provide no traits, one trait or a collection of traits. The exact
453// behavior of a trait is determined by how SdkMemberType implementations handle the traits. A trait
454// could be specific to one SdkMemberType or many. Some trait combinations could be incompatible.
455//
456// The sdk module type will create a special traits structure that contains a property for each
457// trait registered with RegisterSdkMemberTrait(). The property names are those returned from
458// SdkPropertyName(). Each property contains a list of modules that are required to have that trait.
459// e.g. something like this:
460//
461// sdk {
462// name: "sdk",
463// ...
464// traits: {
465// recovery_image: ["module1", "module4", "module5"],
466// native_bridge: ["module1", "module2"],
467// native_sdk: ["module1", "module3"],
468// ...
469// },
470// ...
471// }
472type SdkMemberTrait interface {
473 // SdkPropertyName returns the name of the traits property on an sdk module.
474 SdkPropertyName() string
475}
476
Paul Duffinf04033b2021-09-22 11:51:09 +0100477var _ sdkRegisterable = (SdkMemberTrait)(nil)
478
Paul Duffind19f8942021-07-14 12:08:37 +0100479// SdkMemberTraitBase is the base struct that must be embedded within any type that implements
480// SdkMemberTrait.
481type SdkMemberTraitBase struct {
482 // PropertyName is the name of the property
483 PropertyName string
484}
485
486func (b *SdkMemberTraitBase) SdkPropertyName() string {
487 return b.PropertyName
488}
489
490// SdkMemberTraitSet is a set of SdkMemberTrait instances.
491type SdkMemberTraitSet interface {
492 // Empty returns true if this set is empty.
493 Empty() bool
494
495 // Contains returns true if this set contains the specified trait.
496 Contains(trait SdkMemberTrait) bool
497
498 // Subtract returns a new set containing all elements of this set except for those in the
499 // other set.
500 Subtract(other SdkMemberTraitSet) SdkMemberTraitSet
501
502 // String returns a string representation of the set and its contents.
503 String() string
504}
505
506func NewSdkMemberTraitSet(traits []SdkMemberTrait) SdkMemberTraitSet {
507 if len(traits) == 0 {
508 return EmptySdkMemberTraitSet()
509 }
510
511 m := sdkMemberTraitSet{}
512 for _, trait := range traits {
513 m[trait] = true
514 }
515 return m
516}
517
518func EmptySdkMemberTraitSet() SdkMemberTraitSet {
519 return (sdkMemberTraitSet)(nil)
520}
521
522type sdkMemberTraitSet map[SdkMemberTrait]bool
523
524var _ SdkMemberTraitSet = (sdkMemberTraitSet{})
525
526func (s sdkMemberTraitSet) Empty() bool {
527 return len(s) == 0
528}
529
530func (s sdkMemberTraitSet) Contains(trait SdkMemberTrait) bool {
531 return s[trait]
532}
533
534func (s sdkMemberTraitSet) Subtract(other SdkMemberTraitSet) SdkMemberTraitSet {
535 if other.Empty() {
536 return s
537 }
538
539 var remainder []SdkMemberTrait
540 for trait, _ := range s {
541 if !other.Contains(trait) {
542 remainder = append(remainder, trait)
543 }
544 }
545
546 return NewSdkMemberTraitSet(remainder)
547}
548
549func (s sdkMemberTraitSet) String() string {
550 list := []string{}
551 for trait, _ := range s {
552 list = append(list, trait.SdkPropertyName())
553 }
554 sort.Strings(list)
555 return fmt.Sprintf("[%s]", strings.Join(list, ","))
556}
557
Paul Duffinf04033b2021-09-22 11:51:09 +0100558var registeredSdkMemberTraits = &sdkRegistry{}
Paul Duffin30c830b2021-09-22 11:49:47 +0100559
560// RegisteredSdkMemberTraits returns a OnceKey and a sorted list of registered traits.
561//
562// The key uniquely identifies the array of traits and can be used with OncePer.Once() to cache
563// information derived from the array of traits.
564func RegisteredSdkMemberTraits() (OnceKey, []SdkMemberTrait) {
Paul Duffinf04033b2021-09-22 11:51:09 +0100565 registerables := registeredSdkMemberTraits.registeredObjects()
566 traits := make([]SdkMemberTrait, len(registerables))
567 for i, registerable := range registerables {
568 traits[i] = registerable.(SdkMemberTrait)
569 }
570 return registeredSdkMemberTraits.uniqueOnceKey(), traits
Paul Duffin30c830b2021-09-22 11:49:47 +0100571}
Paul Duffind19f8942021-07-14 12:08:37 +0100572
573// RegisterSdkMemberTrait registers an SdkMemberTrait object to allow them to be used in the
574// module_exports, module_exports_snapshot, sdk and sdk_snapshot module types.
575func RegisterSdkMemberTrait(trait SdkMemberTrait) {
Paul Duffin30c830b2021-09-22 11:49:47 +0100576 registeredSdkMemberTraits = registeredSdkMemberTraits.copyAndAppend(trait)
Paul Duffind19f8942021-07-14 12:08:37 +0100577}
578
Paul Duffin94289702021-09-09 15:38:32 +0100579// SdkMember is an individual member of the SDK.
580//
581// It includes all of the variants that the SDK depends upon.
Paul Duffin13879572019-11-28 14:31:38 +0000582type SdkMember interface {
Paul Duffin94289702021-09-09 15:38:32 +0100583 // Name returns the name of the member.
Paul Duffin13879572019-11-28 14:31:38 +0000584 Name() string
585
Paul Duffin94289702021-09-09 15:38:32 +0100586 // Variants returns all the variants of this module depended upon by the SDK.
Paul Duffin13879572019-11-28 14:31:38 +0000587 Variants() []SdkAware
588}
589
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100590// SdkMemberDependencyTag is the interface that a tag must implement in order to allow the
Paul Duffin2d3da312021-05-06 12:02:27 +0100591// dependent module to be automatically added to the sdk.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100592type SdkMemberDependencyTag interface {
Paul Duffinf8539922019-11-19 19:44:10 +0000593 blueprint.DependencyTag
594
Paul Duffina7208112021-04-23 21:20:20 +0100595 // SdkMemberType returns the SdkMemberType that will be used to automatically add the child module
596 // to the sdk.
Paul Duffin5cca7c42021-05-26 10:16:01 +0100597 //
598 // Returning nil will prevent the module being added to the sdk.
Paul Duffineee466e2021-04-27 23:17:56 +0100599 SdkMemberType(child Module) SdkMemberType
Paul Duffina7208112021-04-23 21:20:20 +0100600
601 // ExportMember determines whether a module added to the sdk through this tag will be exported
602 // from the sdk or not.
603 //
604 // An exported member is added to the sdk using its own name, e.g. if "foo" was exported from sdk
605 // "bar" then its prebuilt would be simply called "foo". A member can be added to the sdk via
606 // multiple tags and if any of those tags returns true from this method then the membe will be
607 // exported. Every module added directly to the sdk via one of the member type specific
608 // properties, e.g. java_libs, will automatically be exported.
609 //
610 // If a member is not exported then it is treated as an internal implementation detail of the
611 // sdk and so will be added with an sdk specific name. e.g. if "foo" was an internal member of sdk
612 // "bar" then its prebuilt would be called "bar_foo". Additionally its visibility will be set to
613 // "//visibility:private" so it will not be accessible from outside its Android.bp file.
614 ExportMember() bool
Paul Duffinf8539922019-11-19 19:44:10 +0000615}
616
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100617var _ SdkMemberDependencyTag = (*sdkMemberDependencyTag)(nil)
618var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil)
Paul Duffincee7e662020-07-09 17:32:57 +0100619
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100620type sdkMemberDependencyTag struct {
Paul Duffinf8539922019-11-19 19:44:10 +0000621 blueprint.BaseDependencyTag
622 memberType SdkMemberType
Paul Duffina7208112021-04-23 21:20:20 +0100623 export bool
Paul Duffinf8539922019-11-19 19:44:10 +0000624}
625
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100626func (t *sdkMemberDependencyTag) SdkMemberType(_ Module) SdkMemberType {
Paul Duffinf8539922019-11-19 19:44:10 +0000627 return t.memberType
628}
629
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100630func (t *sdkMemberDependencyTag) ExportMember() bool {
Paul Duffina7208112021-04-23 21:20:20 +0100631 return t.export
632}
633
Paul Duffin94289702021-09-09 15:38:32 +0100634// ReplaceSourceWithPrebuilt prevents dependencies from the sdk/module_exports onto their members
635// from being replaced with a preferred prebuilt.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100636func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool {
Paul Duffincee7e662020-07-09 17:32:57 +0100637 return false
638}
639
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100640// DependencyTagForSdkMemberType creates an SdkMemberDependencyTag that will cause any
Paul Duffina7208112021-04-23 21:20:20 +0100641// dependencies added by the tag to be added to the sdk as the specified SdkMemberType and exported
642// (or not) as specified by the export parameter.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100643func DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMemberDependencyTag {
644 return &sdkMemberDependencyTag{memberType: memberType, export: export}
Paul Duffinf8539922019-11-19 19:44:10 +0000645}
646
Paul Duffin94289702021-09-09 15:38:32 +0100647// 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 +0000648// sdk.
649//
650// The basic implementation should look something like this, where ModuleType is
651// the name of the module type being supported.
652//
Paul Duffin255f18e2019-12-13 11:22:16 +0000653// type moduleTypeSdkMemberType struct {
654// android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +0000655// }
656//
Paul Duffin255f18e2019-12-13 11:22:16 +0000657// func init() {
658// android.RegisterSdkMemberType(&moduleTypeSdkMemberType{
659// SdkMemberTypeBase: android.SdkMemberTypeBase{
660// PropertyName: "module_types",
661// },
662// }
Paul Duffin13879572019-11-28 14:31:38 +0000663// }
664//
665// ...methods...
666//
667type SdkMemberType interface {
Paul Duffin94289702021-09-09 15:38:32 +0100668 // SdkPropertyName returns the name of the member type property on an sdk module.
Paul Duffin255f18e2019-12-13 11:22:16 +0000669 SdkPropertyName() string
670
Paul Duffin13082052021-05-11 00:31:38 +0100671 // RequiresBpProperty returns true if this member type requires its property to be usable within
672 // an Android.bp file.
673 RequiresBpProperty() bool
674
Paul Duffin94289702021-09-09 15:38:32 +0100675 // UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot,
676 // false otherwise.
Paul Duffine6029182019-12-16 17:43:48 +0000677 UsableWithSdkAndSdkSnapshot() bool
678
Paul Duffin94289702021-09-09 15:38:32 +0100679 // IsHostOsDependent returns true if prebuilt host artifacts may be specific to the host OS. Only
680 // applicable to modules where HostSupported() is true. If this is true, snapshots will list each
681 // host OS variant explicitly and disable all other host OS'es.
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100682 IsHostOsDependent() bool
683
Paul Duffin94289702021-09-09 15:38:32 +0100684 // AddDependencies adds dependencies from the SDK module to all the module variants the member
685 // type contributes to the SDK. `names` is the list of module names given in the member type
686 // property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants
687 // required is determined by the SDK and its properties. The dependencies must be added with the
688 // supplied tag.
Paul Duffin13879572019-11-28 14:31:38 +0000689 //
690 // The BottomUpMutatorContext provided is for the SDK module.
Paul Duffin296701e2021-07-14 10:29:36 +0100691 AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string)
Paul Duffin13879572019-11-28 14:31:38 +0000692
Paul Duffin94289702021-09-09 15:38:32 +0100693 // IsInstance returns true if the supplied module is an instance of this member type.
Paul Duffin13879572019-11-28 14:31:38 +0000694 //
Paul Duffin94289702021-09-09 15:38:32 +0100695 // This is used to check the type of each variant before added to the SdkMember. Returning false
696 // will cause an error to be logged explaining that the module is not allowed in whichever sdk
697 // property it was added.
Paul Duffin13879572019-11-28 14:31:38 +0000698 IsInstance(module Module) bool
699
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100700 // UsesSourceModuleTypeInSnapshot returns true when the AddPrebuiltModule() method returns a
701 // source module type.
702 UsesSourceModuleTypeInSnapshot() bool
703
Paul Duffin94289702021-09-09 15:38:32 +0100704 // AddPrebuiltModule is called to add a prebuilt module that the sdk will populate.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000705 //
Paul Duffin425b0ea2020-05-06 12:41:39 +0100706 // The sdk module code generates the snapshot as follows:
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000707 //
708 // * A properties struct of type SdkMemberProperties is created for each variant and
709 // populated with information from the variant by calling PopulateFromVariant(SdkAware)
710 // on the struct.
711 //
712 // * An additional properties struct is created into which the common properties will be
713 // added.
714 //
715 // * The variant property structs are analysed to find exported (capitalized) fields which
716 // have common values. Those fields are cleared and the common value added to the common
Paul Duffin864e1b42020-05-06 10:23:19 +0100717 // properties.
718 //
719 // A field annotated with a tag of `sdk:"keep"` will be treated as if it
Paul Duffinb07fa512020-03-10 22:17:04 +0000720 // was not capitalized, i.e. not optimized for common values.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000721 //
Paul Duffin864e1b42020-05-06 10:23:19 +0100722 // A field annotated with a tag of `android:"arch_variant"` will be allowed to have
723 // values that differ by arch, fields not tagged as such must have common values across
724 // all variants.
725 //
Paul Duffinc459f892020-04-30 18:08:29 +0100726 // * Additional field tags can be specified on a field that will ignore certain values
727 // for the purpose of common value optimization. A value that is ignored must have the
728 // default value for the property type. This is to ensure that significant value are not
729 // ignored by accident. The purpose of this is to allow the snapshot generation to reflect
730 // the behavior of the runtime. e.g. if a property is ignored on the host then a property
731 // that is common for android can be treated as if it was common for android and host as
732 // the setting for host is ignored anyway.
733 // * `sdk:"ignored-on-host" - this indicates the property is ignored on the host variant.
734 //
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000735 // * The sdk module type populates the BpModule structure, creating the arch specific
736 // structure and calls AddToPropertySet(...) on the properties struct to add the member
737 // specific properties in the correct place in the structure.
738 //
Paul Duffin3a4eb502020-03-19 16:11:18 +0000739 AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000740
Paul Duffin94289702021-09-09 15:38:32 +0100741 // CreateVariantPropertiesStruct creates a structure into which variant specific properties can be
742 // added.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000743 CreateVariantPropertiesStruct() SdkMemberProperties
Paul Duffind19f8942021-07-14 12:08:37 +0100744
745 // SupportedTraits returns the set of traits supported by this member type.
746 SupportedTraits() SdkMemberTraitSet
Paul Duffin13879572019-11-28 14:31:38 +0000747}
Paul Duffin255f18e2019-12-13 11:22:16 +0000748
Paul Duffinf04033b2021-09-22 11:51:09 +0100749var _ sdkRegisterable = (SdkMemberType)(nil)
750
Paul Duffin296701e2021-07-14 10:29:36 +0100751// SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies()
752// implementations.
753type SdkDependencyContext interface {
754 BottomUpMutatorContext
Paul Duffind19f8942021-07-14 12:08:37 +0100755
756 // RequiredTraits returns the set of SdkMemberTrait instances that the sdk requires the named
757 // member to provide.
758 RequiredTraits(name string) SdkMemberTraitSet
759
760 // RequiresTrait returns true if the sdk requires the member with the supplied name to provide the
761 // supplied trait.
762 RequiresTrait(name string, trait SdkMemberTrait) bool
Paul Duffin296701e2021-07-14 10:29:36 +0100763}
764
Paul Duffin94289702021-09-09 15:38:32 +0100765// SdkMemberTypeBase is the base type for SdkMemberType implementations and must be embedded in any
766// struct that implements SdkMemberType.
Paul Duffin255f18e2019-12-13 11:22:16 +0000767type SdkMemberTypeBase struct {
Paul Duffin13082052021-05-11 00:31:38 +0100768 PropertyName string
769
770 // When set to true BpPropertyNotRequired indicates that the member type does not require the
771 // property to be specifiable in an Android.bp file.
772 BpPropertyNotRequired bool
773
Paul Duffin2d3da312021-05-06 12:02:27 +0100774 SupportsSdk bool
775 HostOsDependent bool
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100776
777 // When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source
778 // module type in its SdkMemberType.AddPrebuiltModule() method. That prevents the sdk snapshot
779 // code from automatically adding a prefer: true flag.
780 UseSourceModuleTypeInSnapshot bool
Paul Duffind19f8942021-07-14 12:08:37 +0100781
782 // The list of supported traits.
783 Traits []SdkMemberTrait
Paul Duffin255f18e2019-12-13 11:22:16 +0000784}
785
786func (b *SdkMemberTypeBase) SdkPropertyName() string {
787 return b.PropertyName
788}
789
Paul Duffin13082052021-05-11 00:31:38 +0100790func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
791 return !b.BpPropertyNotRequired
792}
793
Paul Duffine6029182019-12-16 17:43:48 +0000794func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
795 return b.SupportsSdk
796}
797
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100798func (b *SdkMemberTypeBase) IsHostOsDependent() bool {
799 return b.HostOsDependent
800}
801
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100802func (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool {
803 return b.UseSourceModuleTypeInSnapshot
804}
805
Paul Duffind19f8942021-07-14 12:08:37 +0100806func (b *SdkMemberTypeBase) SupportedTraits() SdkMemberTraitSet {
807 return NewSdkMemberTraitSet(b.Traits)
808}
809
Paul Duffin30c830b2021-09-22 11:49:47 +0100810// registeredModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports
811// modules.
Paul Duffinf04033b2021-09-22 11:51:09 +0100812var registeredModuleExportsMemberTypes = &sdkRegistry{}
Paul Duffin62782de2021-07-14 12:05:16 +0100813
Paul Duffinf04033b2021-09-22 11:51:09 +0100814// registeredSdkMemberTypes is the set of registered registeredSdkMemberTypes for sdk modules.
815var registeredSdkMemberTypes = &sdkRegistry{}
Paul Duffin30c830b2021-09-22 11:49:47 +0100816
817// RegisteredSdkMemberTypes returns a OnceKey and a sorted list of registered types.
818//
819// If moduleExports is true then the slice of types includes all registered types that can be used
820// with the module_exports and module_exports_snapshot module types. Otherwise, the slice of types
821// only includes those registered types that can be used with the sdk and sdk_snapshot module
822// types.
823//
824// The key uniquely identifies the array of types and can be used with OncePer.Once() to cache
825// information derived from the array of types.
826func RegisteredSdkMemberTypes(moduleExports bool) (OnceKey, []SdkMemberType) {
Paul Duffinf04033b2021-09-22 11:51:09 +0100827 var registry *sdkRegistry
Paul Duffin30c830b2021-09-22 11:49:47 +0100828 if moduleExports {
829 registry = registeredModuleExportsMemberTypes
830 } else {
831 registry = registeredSdkMemberTypes
832 }
833
Paul Duffinf04033b2021-09-22 11:51:09 +0100834 registerables := registry.registeredObjects()
835 types := make([]SdkMemberType, len(registerables))
836 for i, registerable := range registerables {
837 types[i] = registerable.(SdkMemberType)
838 }
839 return registry.uniqueOnceKey(), types
Paul Duffin30c830b2021-09-22 11:49:47 +0100840}
Paul Duffine6029182019-12-16 17:43:48 +0000841
Paul Duffin94289702021-09-09 15:38:32 +0100842// RegisterSdkMemberType registers an SdkMemberType object to allow them to be used in the
843// module_exports, module_exports_snapshot and (depending on the value returned from
844// SdkMemberType.UsableWithSdkAndSdkSnapshot) the sdk and sdk_snapshot module types.
Paul Duffine6029182019-12-16 17:43:48 +0000845func RegisterSdkMemberType(memberType SdkMemberType) {
846 // All member types are usable with module_exports.
Paul Duffin30c830b2021-09-22 11:49:47 +0100847 registeredModuleExportsMemberTypes = registeredModuleExportsMemberTypes.copyAndAppend(memberType)
Paul Duffine6029182019-12-16 17:43:48 +0000848
849 // Only those that explicitly indicate it are usable with sdk.
850 if memberType.UsableWithSdkAndSdkSnapshot() {
Paul Duffin30c830b2021-09-22 11:49:47 +0100851 registeredSdkMemberTypes = registeredSdkMemberTypes.copyAndAppend(memberType)
Paul Duffine6029182019-12-16 17:43:48 +0000852 }
853}
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000854
Paul Duffin94289702021-09-09 15:38:32 +0100855// SdkMemberPropertiesBase is the base structure for all implementations of SdkMemberProperties and
856// must be embedded in any struct that implements SdkMemberProperties.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000857//
Martin Stjernholm89238f42020-07-10 00:14:03 +0100858// Contains common properties that apply across many different member types.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000859type SdkMemberPropertiesBase struct {
Paul Duffina04c1072020-03-02 10:16:35 +0000860 // The number of unique os types supported by the member variants.
Paul Duffina551a1c2020-03-17 21:04:24 +0000861 //
862 // If a member has a variant with more than one os type then it will need to differentiate
863 // the locations of any of their prebuilt files in the snapshot by os type to prevent them
864 // from colliding. See OsPrefix().
865 //
866 // This property is the same for all variants of a member and so would be optimized away
867 // if it was not explicitly kept.
Paul Duffinb07fa512020-03-10 22:17:04 +0000868 Os_count int `sdk:"keep"`
Paul Duffina04c1072020-03-02 10:16:35 +0000869
870 // The os type for which these properties refer.
Paul Duffina551a1c2020-03-17 21:04:24 +0000871 //
872 // Provided to allow a member to differentiate between os types in the locations of their
873 // prebuilt files when it supports more than one os type.
874 //
875 // This property is the same for all os type specific variants of a member and so would be
876 // optimized away if it was not explicitly kept.
Paul Duffinb07fa512020-03-10 22:17:04 +0000877 Os OsType `sdk:"keep"`
Paul Duffina551a1c2020-03-17 21:04:24 +0000878
879 // The setting to use for the compile_multilib property.
Martin Stjernholm89238f42020-07-10 00:14:03 +0100880 Compile_multilib string `android:"arch_variant"`
Paul Duffina04c1072020-03-02 10:16:35 +0000881}
882
Paul Duffin94289702021-09-09 15:38:32 +0100883// OsPrefix returns the os prefix to use for any file paths in the sdk.
Paul Duffina04c1072020-03-02 10:16:35 +0000884//
885// Is an empty string if the member only provides variants for a single os type, otherwise
886// is the OsType.Name.
887func (b *SdkMemberPropertiesBase) OsPrefix() string {
888 if b.Os_count == 1 {
889 return ""
890 } else {
891 return b.Os.Name
892 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000893}
894
895func (b *SdkMemberPropertiesBase) Base() *SdkMemberPropertiesBase {
896 return b
897}
898
Paul Duffin94289702021-09-09 15:38:32 +0100899// SdkMemberProperties is the interface to be implemented on top of a structure that contains
900// variant specific information.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000901//
Paul Duffin94289702021-09-09 15:38:32 +0100902// Struct fields that are capitalized are examined for common values to extract. Fields that are not
903// capitalized are assumed to be arch specific.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000904type SdkMemberProperties interface {
Paul Duffin94289702021-09-09 15:38:32 +0100905 // Base returns the base structure.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000906 Base() *SdkMemberPropertiesBase
907
Paul Duffin94289702021-09-09 15:38:32 +0100908 // PopulateFromVariant populates this structure with information from a module variant.
909 //
910 // 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 +0000911 PopulateFromVariant(ctx SdkMemberContext, variant Module)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000912
Paul Duffin94289702021-09-09 15:38:32 +0100913 // AddToPropertySet adds the information from this structure to the property set.
914 //
915 // This will be called for each instance of this structure on which the PopulateFromVariant method
916 // was called and also on a number of different instances of this structure into which properties
917 // common to one or more variants have been copied. Therefore, implementations of this must handle
918 // the case when this structure is only partially populated.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000919 AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet)
920}
921
Paul Duffin94289702021-09-09 15:38:32 +0100922// SdkMemberContext provides access to information common to a specific member.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000923type SdkMemberContext interface {
924
Paul Duffin94289702021-09-09 15:38:32 +0100925 // SdkModuleContext returns the module context of the sdk common os variant which is creating the
926 // snapshot.
927 //
928 // This is common to all members of the sdk and is not specific to the member being processed.
929 // If information about the member being processed needs to be obtained from this ModuleContext it
930 // must be obtained using one of the OtherModule... methods not the Module... methods.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000931 SdkModuleContext() ModuleContext
932
Paul Duffin94289702021-09-09 15:38:32 +0100933 // SnapshotBuilder the builder of the snapshot.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000934 SnapshotBuilder() SnapshotBuilder
Paul Duffina551a1c2020-03-17 21:04:24 +0000935
Paul Duffin94289702021-09-09 15:38:32 +0100936 // MemberType returns the type of the member currently being processed.
Paul Duffina551a1c2020-03-17 21:04:24 +0000937 MemberType() SdkMemberType
938
Paul Duffin94289702021-09-09 15:38:32 +0100939 // Name returns the name of the member currently being processed.
Paul Duffina551a1c2020-03-17 21:04:24 +0000940 //
941 // Provided for use by sdk members to create a member specific location within the snapshot
942 // into which to copy the prebuilt files.
943 Name() string
Paul Duffind19f8942021-07-14 12:08:37 +0100944
945 // RequiresTrait returns true if this member is expected to provide the specified trait.
946 RequiresTrait(trait SdkMemberTrait) bool
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000947}
Paul Duffinb97b1572021-04-29 21:50:40 +0100948
949// ExportedComponentsInfo contains information about the components that this module exports to an
950// sdk snapshot.
951//
952// A component of a module is a child module that the module creates and which forms an integral
953// part of the functionality that the creating module provides. A component module is essentially
954// owned by its creator and is tightly coupled to the creator and other components.
955//
956// e.g. the child modules created by prebuilt_apis are not components because they are not tightly
957// coupled to the prebuilt_apis module. Once they are created the prebuilt_apis ignores them. The
958// child impl and stub library created by java_sdk_library (and corresponding import) are components
959// because the creating module depends upon them in order to provide some of its own functionality.
960//
961// A component is exported if it is part of an sdk snapshot. e.g. The xml and impl child modules are
962// components but they are not exported as they are not part of an sdk snapshot.
963//
964// This information is used by the sdk snapshot generation code to ensure that it does not create
965// an sdk snapshot that contains a declaration of the component module and the module that creates
966// it as that would result in duplicate modules when attempting to use the snapshot. e.g. a snapshot
967// that included the java_sdk_library_import "foo" and also a java_import "foo.stubs" would fail
968// as there would be two modules called "foo.stubs".
969type ExportedComponentsInfo struct {
970 // The names of the exported components.
971 Components []string
972}
973
974var ExportedComponentsInfoProvider = blueprint.NewProvider(ExportedComponentsInfo{})