blob: 4bcbe2e7a4fc109379c0b1a7d0369fe322ecccd8 [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 Duffin1938dba2022-07-26 23:53:00 +000026// minApiLevelForSdkSnapshot provides access to the min_sdk_version for MinApiLevelForSdkSnapshot
27type minApiLevelForSdkSnapshot interface {
Spandan Das8c9ae7e2023-03-03 21:20:36 +000028 MinSdkVersion(ctx EarlyModuleContext) ApiLevel
Paul Duffin1938dba2022-07-26 23:53:00 +000029}
30
31// MinApiLevelForSdkSnapshot returns the ApiLevel of the min_sdk_version of the supplied module.
32//
33// If the module does not provide a min_sdk_version then it defaults to 1.
34func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel {
35 minApiLevel := NoneApiLevel
36 if m, ok := module.(minApiLevelForSdkSnapshot); ok {
Spandan Das8c9ae7e2023-03-03 21:20:36 +000037 minApiLevel = m.MinSdkVersion(ctx)
Paul Duffin1938dba2022-07-26 23:53:00 +000038 }
39 if minApiLevel == NoneApiLevel {
40 // The default min API level is 1.
41 minApiLevel = uncheckedFinalApiLevel(1)
42 }
43 return minApiLevel
44}
45
Paul Duffin94289702021-09-09 15:38:32 +010046// SnapshotBuilder provides support for generating the build rules which will build the snapshot.
Paul Duffin0e0cf1d2019-11-12 19:39:25 +000047type SnapshotBuilder interface {
Paul Duffin94289702021-09-09 15:38:32 +010048 // CopyToSnapshot generates a rule that will copy the src to the dest (which is a snapshot
49 // relative path) and add the dest to the zip.
Paul Duffin0e0cf1d2019-11-12 19:39:25 +000050 CopyToSnapshot(src Path, dest string)
51
Paul Duffin7ed6ff82022-11-21 10:57:30 +000052 // EmptyFile returns the path to an empty file.
53 //
54 // This can be used by sdk member types that need to create an empty file in the snapshot, simply
55 // pass the value returned from this to the CopyToSnapshot() method.
56 EmptyFile() Path
57
Paul Duffin94289702021-09-09 15:38:32 +010058 // UnzipToSnapshot generates a rule that will unzip the supplied zip into the snapshot relative
59 // directory destDir.
Paul Duffin91547182019-11-12 19:39:36 +000060 UnzipToSnapshot(zipPath Path, destDir string)
61
Paul Duffin94289702021-09-09 15:38:32 +010062 // AddPrebuiltModule adds a new prebuilt module to the snapshot.
63 //
64 // It is intended to be called from SdkMemberType.AddPrebuiltModule which can add module type
65 // specific properties that are not variant specific. The following properties will be
66 // automatically populated before returning.
Paul Duffinb645ec82019-11-27 17:43:54 +000067 //
68 // * name
69 // * sdk_member_name
70 // * prefer
71 //
Paul Duffin94289702021-09-09 15:38:32 +010072 // Properties that are variant specific will be handled by SdkMemberProperties structure.
73 //
74 // Each module created by this method can be output to the generated Android.bp file in two
75 // different forms, depending on the setting of the SOONG_SDK_SNAPSHOT_VERSION build property.
76 // The two forms are:
77 // 1. A versioned Soong module that is referenced from a corresponding similarly versioned
78 // snapshot module.
79 // 2. An unversioned Soong module that.
80 //
81 // See sdk/update.go for more information.
Paul Duffin9d8d6092019-12-05 18:19:29 +000082 AddPrebuiltModule(member SdkMember, moduleType string) BpModule
Paul Duffin7b81f5e2020-01-13 21:03:22 +000083
Paul Duffin94289702021-09-09 15:38:32 +010084 // SdkMemberReferencePropertyTag returns a property tag to use when adding a property to a
85 // BpModule that contains references to other sdk members.
Paul Duffin7b81f5e2020-01-13 21:03:22 +000086 //
Paul Duffin94289702021-09-09 15:38:32 +010087 // Using this will ensure that the reference is correctly output for both versioned and
88 // unversioned prebuilts in the snapshot.
Paul Duffin13f02712020-03-06 12:30:43 +000089 //
Paul Duffin94289702021-09-09 15:38:32 +010090 // "required: true" means that the property must only contain references to other members of the
91 // sdk. Passing a reference to a module that is not a member of the sdk will result in a build
92 // error.
Paul Duffin13f02712020-03-06 12:30:43 +000093 //
Paul Duffin94289702021-09-09 15:38:32 +010094 // "required: false" means that the property can contain references to modules that are either
95 // members or not members of the sdk. If a reference is to a module that is a non member then the
96 // reference is left unchanged, i.e. it is not transformed as references to members are.
97 //
98 // The handling of the member names is dependent on whether it is an internal or exported member.
99 // An exported member is one whose name is specified in one of the member type specific
100 // properties. An internal member is one that is added due to being a part of an exported (or
101 // other internal) member and is not itself an exported member.
Paul Duffin13f02712020-03-06 12:30:43 +0000102 //
103 // Member names are handled as follows:
Paul Duffin94289702021-09-09 15:38:32 +0100104 // * When creating the unversioned form of the module the name is left unchecked unless the member
105 // is internal in which case it is transformed into an sdk specific name, i.e. by prefixing with
106 // the sdk name.
Paul Duffin13f02712020-03-06 12:30:43 +0000107 //
Paul Duffin94289702021-09-09 15:38:32 +0100108 // * When creating the versioned form of the module the name is transformed into a versioned sdk
109 // specific name, i.e. by prefixing with the sdk name and suffixing with the version.
Paul Duffin13f02712020-03-06 12:30:43 +0000110 //
Paul Duffin7b81f5e2020-01-13 21:03:22 +0000111 // e.g.
Paul Duffin13f02712020-03-06 12:30:43 +0000112 // bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag(true))
113 SdkMemberReferencePropertyTag(required bool) BpPropertyTag
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000114}
115
Paul Duffin94289702021-09-09 15:38:32 +0100116// BpPropertyTag is a marker interface that can be associated with properties in a BpPropertySet to
117// provide additional information which can be used to customize their behavior.
Paul Duffin5b511a22020-01-15 14:23:52 +0000118type BpPropertyTag interface{}
119
Paul Duffin94289702021-09-09 15:38:32 +0100120// BpPropertySet is a set of properties for use in a .bp file.
Paul Duffinb645ec82019-11-27 17:43:54 +0000121type BpPropertySet interface {
Paul Duffin94289702021-09-09 15:38:32 +0100122 // AddProperty adds a property.
123 //
124 // The value can be one of the following types:
Paul Duffinb645ec82019-11-27 17:43:54 +0000125 // * string
126 // * array of the above
127 // * bool
Martin Stjernholm191c25f2020-09-10 00:40:37 +0100128 // For these types it is an error if multiple properties with the same name
129 // are added.
130 //
131 // * pointer to a struct
Paul Duffinb645ec82019-11-27 17:43:54 +0000132 // * BpPropertySet
133 //
Martin Stjernholm191c25f2020-09-10 00:40:37 +0100134 // A pointer to a Blueprint-style property struct is first converted into a
135 // BpPropertySet by traversing the fields and adding their values as
136 // properties in a BpPropertySet. A field with a struct value is itself
137 // converted into a BpPropertySet before adding.
138 //
139 // Adding a BpPropertySet is done as follows:
140 // * If no property with the name exists then the BpPropertySet is added
141 // directly to this property. Care must be taken to ensure that it does not
142 // introduce a cycle.
143 // * If a property exists with the name and the current value is a
144 // BpPropertySet then every property of the new BpPropertySet is added to
145 // the existing BpPropertySet.
146 // * Otherwise, if a property exists with the name then it is an error.
Paul Duffinb645ec82019-11-27 17:43:54 +0000147 AddProperty(name string, value interface{})
148
Paul Duffin94289702021-09-09 15:38:32 +0100149 // AddPropertyWithTag adds a property with an associated property tag.
Paul Duffin5b511a22020-01-15 14:23:52 +0000150 AddPropertyWithTag(name string, value interface{}, tag BpPropertyTag)
151
Paul Duffin94289702021-09-09 15:38:32 +0100152 // AddPropertySet adds a property set with the specified name and returns it so that additional
153 // properties can be added to it.
Paul Duffinb645ec82019-11-27 17:43:54 +0000154 AddPropertySet(name string) BpPropertySet
Paul Duffin0df49682021-05-07 01:10:01 +0100155
Paul Duffin94289702021-09-09 15:38:32 +0100156 // AddCommentForProperty adds a comment for the named property (or property set).
Paul Duffin0df49682021-05-07 01:10:01 +0100157 AddCommentForProperty(name, text string)
Paul Duffinb645ec82019-11-27 17:43:54 +0000158}
159
Paul Duffin94289702021-09-09 15:38:32 +0100160// BpModule represents a module definition in a .bp file.
Paul Duffinb645ec82019-11-27 17:43:54 +0000161type BpModule interface {
162 BpPropertySet
Paul Duffin0df49682021-05-07 01:10:01 +0100163
164 // ModuleType returns the module type of the module
165 ModuleType() string
166
167 // Name returns the name of the module or "" if no name has been specified.
168 Name() string
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000169}
Paul Duffin13879572019-11-28 14:31:38 +0000170
Paul Duffin51227d82021-05-18 12:54:27 +0100171// BpPrintable is a marker interface that must be implemented by any struct that is added as a
172// property value.
173type BpPrintable interface {
174 bpPrintable()
175}
176
177// BpPrintableBase must be embedded within any struct that is added as a
178// property value.
179type BpPrintableBase struct {
180}
181
182func (b BpPrintableBase) bpPrintable() {
183}
184
185var _ BpPrintable = BpPrintableBase{}
186
Paul Duffinf04033b2021-09-22 11:51:09 +0100187// sdkRegisterable defines the interface that must be implemented by objects that can be registered
188// in an sdkRegistry.
189type sdkRegisterable interface {
190 // SdkPropertyName returns the name of the corresponding property on an sdk module.
191 SdkPropertyName() string
192}
193
194// sdkRegistry provides support for registering and retrieving objects that define properties for
195// use by sdk and module_exports module types.
196type sdkRegistry struct {
197 // The list of registered objects sorted by property name.
198 list []sdkRegisterable
199}
200
201// copyAndAppend creates a new sdkRegistry that includes all the traits registered in
202// this registry plus the supplied trait.
203func (r *sdkRegistry) copyAndAppend(registerable sdkRegisterable) *sdkRegistry {
204 oldList := r.list
205
Paul Duffin581f2e52021-09-22 13:25:23 +0100206 // Make sure that list does not already contain the property. Uses a simple linear search instead
207 // of a binary search even though the list is sorted. That is because the number of items in the
208 // list is small and so not worth the overhead of a binary search.
209 found := false
210 newPropertyName := registerable.SdkPropertyName()
211 for _, r := range oldList {
212 if r.SdkPropertyName() == newPropertyName {
213 found = true
214 break
215 }
216 }
217 if found {
218 names := []string{}
219 for _, r := range oldList {
220 names = append(names, r.SdkPropertyName())
221 }
222 panic(fmt.Errorf("duplicate properties found, %q already exists in %q", newPropertyName, names))
223 }
224
Paul Duffinf04033b2021-09-22 11:51:09 +0100225 // Copy the slice just in case this is being read while being modified, e.g. when testing.
226 list := make([]sdkRegisterable, 0, len(oldList)+1)
227 list = append(list, oldList...)
228 list = append(list, registerable)
229
230 // Sort the registered objects by their property name to ensure that registry order has no effect
231 // on behavior.
232 sort.Slice(list, func(i1, i2 int) bool {
233 t1 := list[i1]
234 t2 := list[i2]
235
236 return t1.SdkPropertyName() < t2.SdkPropertyName()
237 })
238
239 // Create a new registry so the pointer uniquely identifies the set of registered types.
240 return &sdkRegistry{
241 list: list,
242 }
243}
244
245// registeredObjects returns the list of registered instances.
246func (r *sdkRegistry) registeredObjects() []sdkRegisterable {
247 return r.list
248}
249
250// uniqueOnceKey returns a key that uniquely identifies this instance and can be used with
251// OncePer.Once
252func (r *sdkRegistry) uniqueOnceKey() OnceKey {
253 // Use the pointer to the registry as the unique key. The pointer is used because it is guaranteed
254 // to uniquely identify the contained list. The list itself cannot be used as slices are not
255 // comparable. Using the pointer does mean that two separate registries with identical lists would
256 // have different keys and so cause whatever information is cached to be created multiple times.
257 // However, that is not an issue in practice as it should not occur outside tests. Constructing a
258 // string representation of the list to use instead would avoid that but is an unnecessary
259 // complication that provides no significant benefit.
260 return NewCustomOnceKey(r)
261}
262
Paul Duffind19f8942021-07-14 12:08:37 +0100263// SdkMemberTrait represents a trait that members of an sdk module can contribute to the sdk
264// snapshot.
265//
266// A trait is simply a characteristic of sdk member that is not required by default which may be
267// required for some members but not others. Traits can cause additional information to be output
268// to the sdk snapshot or replace the default information exported for a member with something else.
269// e.g.
Colin Crossd079e0b2022-08-16 10:27:33 -0700270// - By default cc libraries only export the default image variants to the SDK. However, for some
271// members it may be necessary to export specific image variants, e.g. vendor, or recovery.
272// - By default cc libraries export all the configured architecture variants except for the native
273// bridge architecture variants. However, for some members it may be necessary to export the
274// native bridge architecture variants as well.
275// - By default cc libraries export the platform variant (i.e. sdk:). However, for some members it
276// may be necessary to export the sdk variant (i.e. sdk:sdk).
Paul Duffind19f8942021-07-14 12:08:37 +0100277//
278// A sdk can request a module to provide no traits, one trait or a collection of traits. The exact
279// behavior of a trait is determined by how SdkMemberType implementations handle the traits. A trait
280// could be specific to one SdkMemberType or many. Some trait combinations could be incompatible.
281//
282// The sdk module type will create a special traits structure that contains a property for each
283// trait registered with RegisterSdkMemberTrait(). The property names are those returned from
284// SdkPropertyName(). Each property contains a list of modules that are required to have that trait.
285// e.g. something like this:
286//
Colin Crossd079e0b2022-08-16 10:27:33 -0700287// sdk {
288// name: "sdk",
289// ...
290// traits: {
291// recovery_image: ["module1", "module4", "module5"],
292// native_bridge: ["module1", "module2"],
293// native_sdk: ["module1", "module3"],
294// ...
295// },
296// ...
297// }
Paul Duffind19f8942021-07-14 12:08:37 +0100298type SdkMemberTrait interface {
299 // SdkPropertyName returns the name of the traits property on an sdk module.
300 SdkPropertyName() string
301}
302
Paul Duffinf04033b2021-09-22 11:51:09 +0100303var _ sdkRegisterable = (SdkMemberTrait)(nil)
304
Paul Duffind19f8942021-07-14 12:08:37 +0100305// SdkMemberTraitBase is the base struct that must be embedded within any type that implements
306// SdkMemberTrait.
307type SdkMemberTraitBase struct {
308 // PropertyName is the name of the property
309 PropertyName string
310}
311
312func (b *SdkMemberTraitBase) SdkPropertyName() string {
313 return b.PropertyName
314}
315
316// SdkMemberTraitSet is a set of SdkMemberTrait instances.
317type SdkMemberTraitSet interface {
318 // Empty returns true if this set is empty.
319 Empty() bool
320
321 // Contains returns true if this set contains the specified trait.
322 Contains(trait SdkMemberTrait) bool
323
324 // Subtract returns a new set containing all elements of this set except for those in the
325 // other set.
326 Subtract(other SdkMemberTraitSet) SdkMemberTraitSet
327
328 // String returns a string representation of the set and its contents.
329 String() string
330}
331
332func NewSdkMemberTraitSet(traits []SdkMemberTrait) SdkMemberTraitSet {
333 if len(traits) == 0 {
334 return EmptySdkMemberTraitSet()
335 }
336
337 m := sdkMemberTraitSet{}
338 for _, trait := range traits {
339 m[trait] = true
340 }
341 return m
342}
343
344func EmptySdkMemberTraitSet() SdkMemberTraitSet {
345 return (sdkMemberTraitSet)(nil)
346}
347
348type sdkMemberTraitSet map[SdkMemberTrait]bool
349
350var _ SdkMemberTraitSet = (sdkMemberTraitSet{})
351
352func (s sdkMemberTraitSet) Empty() bool {
353 return len(s) == 0
354}
355
356func (s sdkMemberTraitSet) Contains(trait SdkMemberTrait) bool {
357 return s[trait]
358}
359
360func (s sdkMemberTraitSet) Subtract(other SdkMemberTraitSet) SdkMemberTraitSet {
361 if other.Empty() {
362 return s
363 }
364
365 var remainder []SdkMemberTrait
366 for trait, _ := range s {
367 if !other.Contains(trait) {
368 remainder = append(remainder, trait)
369 }
370 }
371
372 return NewSdkMemberTraitSet(remainder)
373}
374
375func (s sdkMemberTraitSet) String() string {
376 list := []string{}
377 for trait, _ := range s {
378 list = append(list, trait.SdkPropertyName())
379 }
380 sort.Strings(list)
381 return fmt.Sprintf("[%s]", strings.Join(list, ","))
382}
383
Paul Duffinf04033b2021-09-22 11:51:09 +0100384var registeredSdkMemberTraits = &sdkRegistry{}
Paul Duffin30c830b2021-09-22 11:49:47 +0100385
386// RegisteredSdkMemberTraits returns a OnceKey and a sorted list of registered traits.
387//
388// The key uniquely identifies the array of traits and can be used with OncePer.Once() to cache
389// information derived from the array of traits.
390func RegisteredSdkMemberTraits() (OnceKey, []SdkMemberTrait) {
Paul Duffinf04033b2021-09-22 11:51:09 +0100391 registerables := registeredSdkMemberTraits.registeredObjects()
392 traits := make([]SdkMemberTrait, len(registerables))
393 for i, registerable := range registerables {
394 traits[i] = registerable.(SdkMemberTrait)
395 }
396 return registeredSdkMemberTraits.uniqueOnceKey(), traits
Paul Duffin30c830b2021-09-22 11:49:47 +0100397}
Paul Duffind19f8942021-07-14 12:08:37 +0100398
399// RegisterSdkMemberTrait registers an SdkMemberTrait object to allow them to be used in the
400// module_exports, module_exports_snapshot, sdk and sdk_snapshot module types.
401func RegisterSdkMemberTrait(trait SdkMemberTrait) {
Paul Duffin30c830b2021-09-22 11:49:47 +0100402 registeredSdkMemberTraits = registeredSdkMemberTraits.copyAndAppend(trait)
Paul Duffind19f8942021-07-14 12:08:37 +0100403}
404
Paul Duffin94289702021-09-09 15:38:32 +0100405// SdkMember is an individual member of the SDK.
406//
407// It includes all of the variants that the SDK depends upon.
Paul Duffin13879572019-11-28 14:31:38 +0000408type SdkMember interface {
Paul Duffin94289702021-09-09 15:38:32 +0100409 // Name returns the name of the member.
Paul Duffin13879572019-11-28 14:31:38 +0000410 Name() string
411
Paul Duffin94289702021-09-09 15:38:32 +0100412 // Variants returns all the variants of this module depended upon by the SDK.
Paul Duffin5e71e682022-11-23 18:09:54 +0000413 Variants() []Module
Paul Duffin13879572019-11-28 14:31:38 +0000414}
415
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100416// SdkMemberDependencyTag is the interface that a tag must implement in order to allow the
Paul Duffin2d3da312021-05-06 12:02:27 +0100417// dependent module to be automatically added to the sdk.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100418type SdkMemberDependencyTag interface {
Paul Duffinf8539922019-11-19 19:44:10 +0000419 blueprint.DependencyTag
420
Paul Duffina7208112021-04-23 21:20:20 +0100421 // SdkMemberType returns the SdkMemberType that will be used to automatically add the child module
422 // to the sdk.
Paul Duffin5cca7c42021-05-26 10:16:01 +0100423 //
424 // Returning nil will prevent the module being added to the sdk.
Paul Duffineee466e2021-04-27 23:17:56 +0100425 SdkMemberType(child Module) SdkMemberType
Paul Duffina7208112021-04-23 21:20:20 +0100426
427 // ExportMember determines whether a module added to the sdk through this tag will be exported
428 // from the sdk or not.
429 //
430 // An exported member is added to the sdk using its own name, e.g. if "foo" was exported from sdk
431 // "bar" then its prebuilt would be simply called "foo". A member can be added to the sdk via
432 // multiple tags and if any of those tags returns true from this method then the membe will be
433 // exported. Every module added directly to the sdk via one of the member type specific
434 // properties, e.g. java_libs, will automatically be exported.
435 //
436 // If a member is not exported then it is treated as an internal implementation detail of the
437 // sdk and so will be added with an sdk specific name. e.g. if "foo" was an internal member of sdk
438 // "bar" then its prebuilt would be called "bar_foo". Additionally its visibility will be set to
439 // "//visibility:private" so it will not be accessible from outside its Android.bp file.
440 ExportMember() bool
Paul Duffinf8539922019-11-19 19:44:10 +0000441}
442
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100443var _ SdkMemberDependencyTag = (*sdkMemberDependencyTag)(nil)
444var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil)
Paul Duffincee7e662020-07-09 17:32:57 +0100445
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100446type sdkMemberDependencyTag struct {
Paul Duffinf8539922019-11-19 19:44:10 +0000447 blueprint.BaseDependencyTag
448 memberType SdkMemberType
Paul Duffina7208112021-04-23 21:20:20 +0100449 export bool
Paul Duffinf8539922019-11-19 19:44:10 +0000450}
451
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100452func (t *sdkMemberDependencyTag) SdkMemberType(_ Module) SdkMemberType {
Paul Duffinf8539922019-11-19 19:44:10 +0000453 return t.memberType
454}
455
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100456func (t *sdkMemberDependencyTag) ExportMember() bool {
Paul Duffina7208112021-04-23 21:20:20 +0100457 return t.export
458}
459
Paul Duffin94289702021-09-09 15:38:32 +0100460// ReplaceSourceWithPrebuilt prevents dependencies from the sdk/module_exports onto their members
461// from being replaced with a preferred prebuilt.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100462func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool {
Paul Duffincee7e662020-07-09 17:32:57 +0100463 return false
464}
465
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100466// DependencyTagForSdkMemberType creates an SdkMemberDependencyTag that will cause any
Paul Duffina7208112021-04-23 21:20:20 +0100467// dependencies added by the tag to be added to the sdk as the specified SdkMemberType and exported
468// (or not) as specified by the export parameter.
Paul Duffinf7b3d0d2021-09-02 14:29:21 +0100469func DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMemberDependencyTag {
470 return &sdkMemberDependencyTag{memberType: memberType, export: export}
Paul Duffinf8539922019-11-19 19:44:10 +0000471}
472
Paul Duffin94289702021-09-09 15:38:32 +0100473// 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 +0000474// sdk.
475//
476// The basic implementation should look something like this, where ModuleType is
477// the name of the module type being supported.
478//
Colin Crossd079e0b2022-08-16 10:27:33 -0700479// type moduleTypeSdkMemberType struct {
480// android.SdkMemberTypeBase
481// }
Paul Duffin13879572019-11-28 14:31:38 +0000482//
Colin Crossd079e0b2022-08-16 10:27:33 -0700483// func init() {
484// android.RegisterSdkMemberType(&moduleTypeSdkMemberType{
485// SdkMemberTypeBase: android.SdkMemberTypeBase{
486// PropertyName: "module_types",
487// },
488// }
489// }
Paul Duffin13879572019-11-28 14:31:38 +0000490//
Colin Crossd079e0b2022-08-16 10:27:33 -0700491// ...methods...
Paul Duffin13879572019-11-28 14:31:38 +0000492type SdkMemberType interface {
Paul Duffin94289702021-09-09 15:38:32 +0100493 // SdkPropertyName returns the name of the member type property on an sdk module.
Paul Duffin255f18e2019-12-13 11:22:16 +0000494 SdkPropertyName() string
495
Paul Duffin13082052021-05-11 00:31:38 +0100496 // RequiresBpProperty returns true if this member type requires its property to be usable within
497 // an Android.bp file.
498 RequiresBpProperty() bool
499
Paul Duffinf861df72022-07-01 15:56:06 +0000500 // SupportedBuildReleases returns the string representation of a set of target build releases that
501 // support this member type.
502 SupportedBuildReleases() string
503
Paul Duffin94289702021-09-09 15:38:32 +0100504 // UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot,
505 // false otherwise.
Paul Duffine6029182019-12-16 17:43:48 +0000506 UsableWithSdkAndSdkSnapshot() bool
507
Paul Duffin94289702021-09-09 15:38:32 +0100508 // IsHostOsDependent returns true if prebuilt host artifacts may be specific to the host OS. Only
509 // applicable to modules where HostSupported() is true. If this is true, snapshots will list each
510 // host OS variant explicitly and disable all other host OS'es.
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100511 IsHostOsDependent() bool
512
Liz Kammer96320df2022-05-12 20:40:00 -0400513 // SupportedLinkages returns the names of the linkage variants supported by this module.
514 SupportedLinkages() []string
515
Alyssa Ketpreechasawat59ec0fa2024-07-04 19:51:17 +0000516 // DisablesStrip returns true if the stripping needs to be disabled for this module.
517 DisablesStrip() bool
518
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000519 // ArePrebuiltsRequired returns true if prebuilts are required in the sdk snapshot, false
520 // otherwise.
521 ArePrebuiltsRequired() bool
522
Paul Duffin94289702021-09-09 15:38:32 +0100523 // AddDependencies adds dependencies from the SDK module to all the module variants the member
524 // type contributes to the SDK. `names` is the list of module names given in the member type
525 // property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants
526 // required is determined by the SDK and its properties. The dependencies must be added with the
527 // supplied tag.
Paul Duffin13879572019-11-28 14:31:38 +0000528 //
529 // The BottomUpMutatorContext provided is for the SDK module.
Paul Duffin296701e2021-07-14 10:29:36 +0100530 AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string)
Paul Duffin13879572019-11-28 14:31:38 +0000531
Paul Duffin94289702021-09-09 15:38:32 +0100532 // IsInstance returns true if the supplied module is an instance of this member type.
Paul Duffin13879572019-11-28 14:31:38 +0000533 //
Paul Duffin94289702021-09-09 15:38:32 +0100534 // This is used to check the type of each variant before added to the SdkMember. Returning false
535 // will cause an error to be logged explaining that the module is not allowed in whichever sdk
536 // property it was added.
Paul Duffin13879572019-11-28 14:31:38 +0000537 IsInstance(module Module) bool
538
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100539 // UsesSourceModuleTypeInSnapshot returns true when the AddPrebuiltModule() method returns a
540 // source module type.
541 UsesSourceModuleTypeInSnapshot() bool
542
Paul Duffin94289702021-09-09 15:38:32 +0100543 // AddPrebuiltModule is called to add a prebuilt module that the sdk will populate.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000544 //
Paul Duffin425b0ea2020-05-06 12:41:39 +0100545 // The sdk module code generates the snapshot as follows:
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000546 //
547 // * A properties struct of type SdkMemberProperties is created for each variant and
Paul Duffin5e71e682022-11-23 18:09:54 +0000548 // populated with information from the variant by calling PopulateFromVariant(Module)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000549 // on the struct.
550 //
551 // * An additional properties struct is created into which the common properties will be
552 // added.
553 //
554 // * The variant property structs are analysed to find exported (capitalized) fields which
555 // have common values. Those fields are cleared and the common value added to the common
Paul Duffin864e1b42020-05-06 10:23:19 +0100556 // properties.
557 //
Paul Duffin02e25c82022-09-22 15:30:58 +0100558 // A field annotated with a tag of `sdk:"ignore"` will be treated as if it
559 // was not capitalized, i.e. ignored and not optimized for common values.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000560 //
Paul Duffinbfdca962022-09-22 16:21:54 +0100561 // A field annotated with a tag of `sdk:"keep"` will not be cleared even if the value is common
562 // across multiple structs. Common values will still be copied into the common property struct.
563 // So, if the same value is placed in all structs populated from variants that value would be
564 // copied into all common property structs and so be available in every instance.
565 //
Paul Duffin864e1b42020-05-06 10:23:19 +0100566 // A field annotated with a tag of `android:"arch_variant"` will be allowed to have
567 // values that differ by arch, fields not tagged as such must have common values across
568 // all variants.
569 //
Paul Duffinc459f892020-04-30 18:08:29 +0100570 // * Additional field tags can be specified on a field that will ignore certain values
571 // for the purpose of common value optimization. A value that is ignored must have the
572 // default value for the property type. This is to ensure that significant value are not
573 // ignored by accident. The purpose of this is to allow the snapshot generation to reflect
574 // the behavior of the runtime. e.g. if a property is ignored on the host then a property
575 // that is common for android can be treated as if it was common for android and host as
576 // the setting for host is ignored anyway.
577 // * `sdk:"ignored-on-host" - this indicates the property is ignored on the host variant.
578 //
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000579 // * The sdk module type populates the BpModule structure, creating the arch specific
580 // structure and calls AddToPropertySet(...) on the properties struct to add the member
581 // specific properties in the correct place in the structure.
582 //
Paul Duffin3a4eb502020-03-19 16:11:18 +0000583 AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000584
Paul Duffin94289702021-09-09 15:38:32 +0100585 // CreateVariantPropertiesStruct creates a structure into which variant specific properties can be
586 // added.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000587 CreateVariantPropertiesStruct() SdkMemberProperties
Paul Duffind19f8942021-07-14 12:08:37 +0100588
589 // SupportedTraits returns the set of traits supported by this member type.
590 SupportedTraits() SdkMemberTraitSet
Liz Kammer96320df2022-05-12 20:40:00 -0400591
592 // Overrides returns whether type overrides other SdkMemberType
593 Overrides(SdkMemberType) bool
Paul Duffin13879572019-11-28 14:31:38 +0000594}
Paul Duffin255f18e2019-12-13 11:22:16 +0000595
Paul Duffinf04033b2021-09-22 11:51:09 +0100596var _ sdkRegisterable = (SdkMemberType)(nil)
597
Paul Duffin296701e2021-07-14 10:29:36 +0100598// SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies()
599// implementations.
600type SdkDependencyContext interface {
601 BottomUpMutatorContext
Paul Duffind19f8942021-07-14 12:08:37 +0100602
603 // RequiredTraits returns the set of SdkMemberTrait instances that the sdk requires the named
604 // member to provide.
605 RequiredTraits(name string) SdkMemberTraitSet
606
607 // RequiresTrait returns true if the sdk requires the member with the supplied name to provide the
608 // supplied trait.
609 RequiresTrait(name string, trait SdkMemberTrait) bool
Paul Duffin296701e2021-07-14 10:29:36 +0100610}
611
Paul Duffin94289702021-09-09 15:38:32 +0100612// SdkMemberTypeBase is the base type for SdkMemberType implementations and must be embedded in any
613// struct that implements SdkMemberType.
Paul Duffin255f18e2019-12-13 11:22:16 +0000614type SdkMemberTypeBase struct {
Paul Duffin13082052021-05-11 00:31:38 +0100615 PropertyName string
616
Liz Kammer96320df2022-05-12 20:40:00 -0400617 // Property names that this SdkMemberTypeBase can override, this is useful when a module type is a
618 // superset of another module type.
619 OverridesPropertyNames map[string]bool
620
621 // The names of linkage variants supported by this module.
622 SupportedLinkageNames []string
623
Alyssa Ketpreechasawat59ec0fa2024-07-04 19:51:17 +0000624 // StripDisabled returns true if the stripping needs to be disabled for this module.
625 StripDisabled bool
626
Paul Duffin13082052021-05-11 00:31:38 +0100627 // When set to true BpPropertyNotRequired indicates that the member type does not require the
628 // property to be specifiable in an Android.bp file.
629 BpPropertyNotRequired bool
630
Paul Duffinf861df72022-07-01 15:56:06 +0000631 // The name of the first targeted build release.
632 //
633 // If not specified then it is assumed to be available on all targeted build releases.
634 SupportedBuildReleaseSpecification string
635
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000636 // Set to true if this must be usable with the sdk/sdk_snapshot module types. Otherwise, it will
637 // only be usable with module_exports/module_exports_snapshots module types.
638 SupportsSdk bool
639
640 // Set to true if prebuilt host artifacts of this member may be specific to the host OS. Only
641 // applicable to modules where HostSupported() is true.
Paul Duffin2d3da312021-05-06 12:02:27 +0100642 HostOsDependent bool
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100643
644 // When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source
645 // module type in its SdkMemberType.AddPrebuiltModule() method. That prevents the sdk snapshot
646 // code from automatically adding a prefer: true flag.
647 UseSourceModuleTypeInSnapshot bool
Paul Duffind19f8942021-07-14 12:08:37 +0100648
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000649 // Set to proptools.BoolPtr(false) if this member does not generate prebuilts but is only provided
650 // to allow the sdk to gather members from this member's dependencies. If not specified then
651 // defaults to true.
652 PrebuiltsRequired *bool
653
Paul Duffind19f8942021-07-14 12:08:37 +0100654 // The list of supported traits.
655 Traits []SdkMemberTrait
Paul Duffin255f18e2019-12-13 11:22:16 +0000656}
657
658func (b *SdkMemberTypeBase) SdkPropertyName() string {
659 return b.PropertyName
660}
661
Paul Duffin13082052021-05-11 00:31:38 +0100662func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
663 return !b.BpPropertyNotRequired
664}
665
Paul Duffinf861df72022-07-01 15:56:06 +0000666func (b *SdkMemberTypeBase) SupportedBuildReleases() string {
667 return b.SupportedBuildReleaseSpecification
668}
669
Paul Duffine6029182019-12-16 17:43:48 +0000670func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
671 return b.SupportsSdk
672}
673
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100674func (b *SdkMemberTypeBase) IsHostOsDependent() bool {
675 return b.HostOsDependent
676}
677
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000678func (b *SdkMemberTypeBase) ArePrebuiltsRequired() bool {
679 return proptools.BoolDefault(b.PrebuiltsRequired, true)
680}
681
Paul Duffin0d4ed0a2021-05-10 23:58:40 +0100682func (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool {
683 return b.UseSourceModuleTypeInSnapshot
684}
685
Paul Duffind19f8942021-07-14 12:08:37 +0100686func (b *SdkMemberTypeBase) SupportedTraits() SdkMemberTraitSet {
687 return NewSdkMemberTraitSet(b.Traits)
688}
689
Liz Kammer96320df2022-05-12 20:40:00 -0400690func (b *SdkMemberTypeBase) Overrides(other SdkMemberType) bool {
691 return b.OverridesPropertyNames[other.SdkPropertyName()]
692}
693
694func (b *SdkMemberTypeBase) SupportedLinkages() []string {
695 return b.SupportedLinkageNames
696}
697
Alyssa Ketpreechasawat59ec0fa2024-07-04 19:51:17 +0000698func (b *SdkMemberTypeBase) DisablesStrip() bool {
699 return b.StripDisabled
700}
701
Paul Duffin30c830b2021-09-22 11:49:47 +0100702// registeredModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports
703// modules.
Paul Duffinf04033b2021-09-22 11:51:09 +0100704var registeredModuleExportsMemberTypes = &sdkRegistry{}
Paul Duffin62782de2021-07-14 12:05:16 +0100705
Paul Duffinf04033b2021-09-22 11:51:09 +0100706// registeredSdkMemberTypes is the set of registered registeredSdkMemberTypes for sdk modules.
707var registeredSdkMemberTypes = &sdkRegistry{}
Paul Duffin30c830b2021-09-22 11:49:47 +0100708
709// RegisteredSdkMemberTypes returns a OnceKey and a sorted list of registered types.
710//
711// If moduleExports is true then the slice of types includes all registered types that can be used
712// with the module_exports and module_exports_snapshot module types. Otherwise, the slice of types
713// only includes those registered types that can be used with the sdk and sdk_snapshot module
714// types.
715//
716// The key uniquely identifies the array of types and can be used with OncePer.Once() to cache
717// information derived from the array of types.
718func RegisteredSdkMemberTypes(moduleExports bool) (OnceKey, []SdkMemberType) {
Paul Duffinf04033b2021-09-22 11:51:09 +0100719 var registry *sdkRegistry
Paul Duffin30c830b2021-09-22 11:49:47 +0100720 if moduleExports {
721 registry = registeredModuleExportsMemberTypes
722 } else {
723 registry = registeredSdkMemberTypes
724 }
725
Paul Duffinf04033b2021-09-22 11:51:09 +0100726 registerables := registry.registeredObjects()
727 types := make([]SdkMemberType, len(registerables))
728 for i, registerable := range registerables {
729 types[i] = registerable.(SdkMemberType)
730 }
731 return registry.uniqueOnceKey(), types
Paul Duffin30c830b2021-09-22 11:49:47 +0100732}
Paul Duffine6029182019-12-16 17:43:48 +0000733
Paul Duffin94289702021-09-09 15:38:32 +0100734// RegisterSdkMemberType registers an SdkMemberType object to allow them to be used in the
735// module_exports, module_exports_snapshot and (depending on the value returned from
736// SdkMemberType.UsableWithSdkAndSdkSnapshot) the sdk and sdk_snapshot module types.
Paul Duffine6029182019-12-16 17:43:48 +0000737func RegisterSdkMemberType(memberType SdkMemberType) {
738 // All member types are usable with module_exports.
Paul Duffin30c830b2021-09-22 11:49:47 +0100739 registeredModuleExportsMemberTypes = registeredModuleExportsMemberTypes.copyAndAppend(memberType)
Paul Duffine6029182019-12-16 17:43:48 +0000740
741 // Only those that explicitly indicate it are usable with sdk.
742 if memberType.UsableWithSdkAndSdkSnapshot() {
Paul Duffin30c830b2021-09-22 11:49:47 +0100743 registeredSdkMemberTypes = registeredSdkMemberTypes.copyAndAppend(memberType)
Paul Duffine6029182019-12-16 17:43:48 +0000744 }
745}
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000746
Paul Duffin94289702021-09-09 15:38:32 +0100747// SdkMemberPropertiesBase is the base structure for all implementations of SdkMemberProperties and
748// must be embedded in any struct that implements SdkMemberProperties.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000749//
Martin Stjernholm89238f42020-07-10 00:14:03 +0100750// Contains common properties that apply across many different member types.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000751type SdkMemberPropertiesBase struct {
Paul Duffina04c1072020-03-02 10:16:35 +0000752 // The number of unique os types supported by the member variants.
Paul Duffina551a1c2020-03-17 21:04:24 +0000753 //
754 // If a member has a variant with more than one os type then it will need to differentiate
755 // the locations of any of their prebuilt files in the snapshot by os type to prevent them
756 // from colliding. See OsPrefix().
757 //
Paul Duffin02e25c82022-09-22 15:30:58 +0100758 // Ignore this property during optimization. This is needed because this property is the same for
759 // all variants of a member and so would be optimized away if it was not ignored.
760 Os_count int `sdk:"ignore"`
Paul Duffina04c1072020-03-02 10:16:35 +0000761
762 // The os type for which these properties refer.
Paul Duffina551a1c2020-03-17 21:04:24 +0000763 //
764 // Provided to allow a member to differentiate between os types in the locations of their
765 // prebuilt files when it supports more than one os type.
766 //
Paul Duffin02e25c82022-09-22 15:30:58 +0100767 // Ignore this property during optimization. This is needed because this property is the same for
768 // all variants of a member and so would be optimized away if it was not ignored.
769 Os OsType `sdk:"ignore"`
Paul Duffina551a1c2020-03-17 21:04:24 +0000770
771 // The setting to use for the compile_multilib property.
Martin Stjernholm89238f42020-07-10 00:14:03 +0100772 Compile_multilib string `android:"arch_variant"`
Paul Duffina04c1072020-03-02 10:16:35 +0000773}
774
Paul Duffin94289702021-09-09 15:38:32 +0100775// OsPrefix returns the os prefix to use for any file paths in the sdk.
Paul Duffina04c1072020-03-02 10:16:35 +0000776//
777// Is an empty string if the member only provides variants for a single os type, otherwise
778// is the OsType.Name.
779func (b *SdkMemberPropertiesBase) OsPrefix() string {
780 if b.Os_count == 1 {
781 return ""
782 } else {
783 return b.Os.Name
784 }
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000785}
786
787func (b *SdkMemberPropertiesBase) Base() *SdkMemberPropertiesBase {
788 return b
789}
790
Paul Duffin94289702021-09-09 15:38:32 +0100791// SdkMemberProperties is the interface to be implemented on top of a structure that contains
792// variant specific information.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000793//
Paul Duffin94289702021-09-09 15:38:32 +0100794// Struct fields that are capitalized are examined for common values to extract. Fields that are not
795// capitalized are assumed to be arch specific.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000796type SdkMemberProperties interface {
Paul Duffin94289702021-09-09 15:38:32 +0100797 // Base returns the base structure.
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000798 Base() *SdkMemberPropertiesBase
799
Paul Duffin94289702021-09-09 15:38:32 +0100800 // PopulateFromVariant populates this structure with information from a module variant.
801 //
802 // 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 +0000803 PopulateFromVariant(ctx SdkMemberContext, variant Module)
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000804
Paul Duffin94289702021-09-09 15:38:32 +0100805 // AddToPropertySet adds the information from this structure to the property set.
806 //
807 // This will be called for each instance of this structure on which the PopulateFromVariant method
808 // was called and also on a number of different instances of this structure into which properties
809 // common to one or more variants have been copied. Therefore, implementations of this must handle
810 // the case when this structure is only partially populated.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000811 AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet)
812}
813
Paul Duffin94289702021-09-09 15:38:32 +0100814// SdkMemberContext provides access to information common to a specific member.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000815type SdkMemberContext interface {
816
Paul Duffin94289702021-09-09 15:38:32 +0100817 // SdkModuleContext returns the module context of the sdk common os variant which is creating the
818 // snapshot.
819 //
820 // This is common to all members of the sdk and is not specific to the member being processed.
821 // If information about the member being processed needs to be obtained from this ModuleContext it
822 // must be obtained using one of the OtherModule... methods not the Module... methods.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000823 SdkModuleContext() ModuleContext
824
Paul Duffin94289702021-09-09 15:38:32 +0100825 // SnapshotBuilder the builder of the snapshot.
Paul Duffin3a4eb502020-03-19 16:11:18 +0000826 SnapshotBuilder() SnapshotBuilder
Paul Duffina551a1c2020-03-17 21:04:24 +0000827
Paul Duffin94289702021-09-09 15:38:32 +0100828 // MemberType returns the type of the member currently being processed.
Paul Duffina551a1c2020-03-17 21:04:24 +0000829 MemberType() SdkMemberType
830
Paul Duffin94289702021-09-09 15:38:32 +0100831 // Name returns the name of the member currently being processed.
Paul Duffina551a1c2020-03-17 21:04:24 +0000832 //
833 // Provided for use by sdk members to create a member specific location within the snapshot
834 // into which to copy the prebuilt files.
835 Name() string
Paul Duffind19f8942021-07-14 12:08:37 +0100836
837 // RequiresTrait returns true if this member is expected to provide the specified trait.
838 RequiresTrait(trait SdkMemberTrait) bool
Paul Duffin13648912022-07-15 13:12:35 +0000839
840 // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is
841 // being generated is before Tiramisu, i.e. S.
842 IsTargetBuildBeforeTiramisu() bool
Cole Faust34867402023-04-28 12:32:27 -0700843
844 // ModuleErrorf reports an error at the line number of the module type in the module definition.
845 ModuleErrorf(fmt string, args ...interface{})
Paul Duffin88f2fbe2020-02-27 16:00:53 +0000846}
Paul Duffinb97b1572021-04-29 21:50:40 +0100847
848// ExportedComponentsInfo contains information about the components that this module exports to an
849// sdk snapshot.
850//
851// A component of a module is a child module that the module creates and which forms an integral
852// part of the functionality that the creating module provides. A component module is essentially
853// owned by its creator and is tightly coupled to the creator and other components.
854//
855// e.g. the child modules created by prebuilt_apis are not components because they are not tightly
856// coupled to the prebuilt_apis module. Once they are created the prebuilt_apis ignores them. The
857// child impl and stub library created by java_sdk_library (and corresponding import) are components
858// because the creating module depends upon them in order to provide some of its own functionality.
859//
860// A component is exported if it is part of an sdk snapshot. e.g. The xml and impl child modules are
861// components but they are not exported as they are not part of an sdk snapshot.
862//
863// This information is used by the sdk snapshot generation code to ensure that it does not create
864// an sdk snapshot that contains a declaration of the component module and the module that creates
865// it as that would result in duplicate modules when attempting to use the snapshot. e.g. a snapshot
866// that included the java_sdk_library_import "foo" and also a java_import "foo.stubs" would fail
867// as there would be two modules called "foo.stubs".
868type ExportedComponentsInfo struct {
869 // The names of the exported components.
870 Components []string
871}
872
Colin Crossbc7d76c2023-12-12 16:39:03 -0800873var ExportedComponentsInfoProvider = blueprint.NewProvider[ExportedComponentsInfo]()
Paul Duffin958806b2022-05-16 13:10:47 +0000874
875// AdditionalSdkInfo contains additional properties to add to the generated SDK info file.
876type AdditionalSdkInfo struct {
877 Properties map[string]interface{}
878}
879
Colin Crossbc7d76c2023-12-12 16:39:03 -0800880var AdditionalSdkInfoProvider = blueprint.NewProvider[AdditionalSdkInfo]()
Inseob Kim8fa54da2024-03-19 16:48:59 +0900881
882var apiFingerprintPathKey = NewOnceKey("apiFingerprintPathKey")
883
884func ApiFingerprintPath(ctx PathContext) OutputPath {
885 return ctx.Config().Once(apiFingerprintPathKey, func() interface{} {
886 return PathForOutput(ctx, "api_fingerprint.txt")
887 }).(OutputPath)
888}