Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 18 | "fmt" |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 19 | "sort" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 20 | "strings" |
| 21 | |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
| 24 | ) |
| 25 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 26 | // sdkAwareWithoutModule is provided simply to improve code navigation with the IDE. |
Paul Duffin | 50f0da4 | 2020-07-22 13:52:01 +0100 | [diff] [blame] | 27 | type sdkAwareWithoutModule interface { |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 28 | // SdkMemberComponentName will return the name to use for a component of this module based on the |
| 29 | // base name of this module. |
| 30 | // |
| 31 | // The baseName is the name returned by ModuleBase.BaseModuleName(), i.e. the name specified in |
| 32 | // the name property in the .bp file so will not include the prebuilt_ prefix. |
| 33 | // |
| 34 | // The componentNameCreator is a func for creating the name of a component from the base name of |
| 35 | // the module, e.g. it could just append ".component" to the name passed in. |
| 36 | // |
| 37 | // This is intended to be called by prebuilt modules that create component models. It is because |
| 38 | // prebuilt module base names come in a variety of different forms: |
| 39 | // * unversioned - this is the same as the source module. |
| 40 | // * internal to an sdk - this is the unversioned name prefixed by the base name of the sdk |
| 41 | // module. |
| 42 | // * versioned - this is the same as the internal with the addition of an "@<version>" suffix. |
| 43 | // |
| 44 | // While this can be called from a source module in that case it will behave the same way as the |
| 45 | // unversioned name and return the result of calling the componentNameCreator func on the supplied |
| 46 | // base name. |
| 47 | // |
| 48 | // e.g. Assuming the componentNameCreator func simply appends ".component" to the name passed in |
| 49 | // then this will work as follows: |
| 50 | // * An unversioned name of "foo" will return "foo.component". |
| 51 | // * An internal to the sdk name of "sdk_foo" will return "sdk_foo.component". |
| 52 | // * A versioned name of "sdk_foo@current" will return "sdk_foo.component@current". |
| 53 | // |
| 54 | // Note that in the latter case the ".component" suffix is added before the version. Adding it |
| 55 | // after would change the version. |
| 56 | SdkMemberComponentName(baseName string, componentNameCreator func(string) string) string |
| 57 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 58 | sdkBase() *SdkBase |
| 59 | MakeMemberOf(sdk SdkRef) |
| 60 | IsInAnySdk() bool |
Paul Duffin | b9e7a3c | 2021-05-06 15:53:19 +0100 | [diff] [blame] | 61 | |
| 62 | // IsVersioned determines whether the module is versioned, i.e. has a name of the form |
| 63 | // <name>@<version> |
| 64 | IsVersioned() bool |
| 65 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 66 | ContainingSdk() SdkRef |
| 67 | MemberName() string |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 68 | } |
| 69 | |
Paul Duffin | 50f0da4 | 2020-07-22 13:52:01 +0100 | [diff] [blame] | 70 | // SdkAware is the interface that must be supported by any module to become a member of SDK or to be |
| 71 | // built with SDK |
| 72 | type SdkAware interface { |
| 73 | Module |
| 74 | sdkAwareWithoutModule |
| 75 | } |
| 76 | |
Paul Duffin | 1938dba | 2022-07-26 23:53:00 +0000 | [diff] [blame] | 77 | // minApiLevelForSdkSnapshot provides access to the min_sdk_version for MinApiLevelForSdkSnapshot |
| 78 | type minApiLevelForSdkSnapshot interface { |
| 79 | MinSdkVersion(ctx EarlyModuleContext) SdkSpec |
| 80 | } |
| 81 | |
| 82 | // MinApiLevelForSdkSnapshot returns the ApiLevel of the min_sdk_version of the supplied module. |
| 83 | // |
| 84 | // If the module does not provide a min_sdk_version then it defaults to 1. |
| 85 | func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel { |
| 86 | minApiLevel := NoneApiLevel |
| 87 | if m, ok := module.(minApiLevelForSdkSnapshot); ok { |
| 88 | minApiLevel = m.MinSdkVersion(ctx).ApiLevel |
| 89 | } |
| 90 | if minApiLevel == NoneApiLevel { |
| 91 | // The default min API level is 1. |
| 92 | minApiLevel = uncheckedFinalApiLevel(1) |
| 93 | } |
| 94 | return minApiLevel |
| 95 | } |
| 96 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 97 | // SdkRef refers to a version of an SDK |
| 98 | type SdkRef struct { |
| 99 | Name string |
| 100 | Version string |
| 101 | } |
| 102 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 103 | // Unversioned determines if the SdkRef is referencing to the unversioned SDK module |
| 104 | func (s SdkRef) Unversioned() bool { |
| 105 | return s.Version == "" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 106 | } |
| 107 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 108 | // String returns string representation of this SdkRef for debugging purpose |
| 109 | func (s SdkRef) String() string { |
| 110 | if s.Name == "" { |
| 111 | return "(No Sdk)" |
| 112 | } |
| 113 | if s.Unversioned() { |
| 114 | return s.Name |
| 115 | } |
| 116 | return s.Name + string(SdkVersionSeparator) + s.Version |
| 117 | } |
| 118 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 119 | // SdkVersionSeparator is a character used to separate an sdk name and its version |
| 120 | const SdkVersionSeparator = '@' |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 121 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 122 | // ParseSdkRef parses a `name@version` style string into a corresponding SdkRef struct |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 123 | func ParseSdkRef(ctx BaseModuleContext, str string, property string) SdkRef { |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 124 | tokens := strings.Split(str, string(SdkVersionSeparator)) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 125 | if len(tokens) < 1 || len(tokens) > 2 { |
Paul Duffin | 525a590 | 2021-05-06 16:33:52 +0100 | [diff] [blame] | 126 | ctx.PropertyErrorf(property, "%q does not follow name@version syntax", str) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 127 | return SdkRef{Name: "invalid sdk name", Version: "invalid sdk version"} |
| 128 | } |
| 129 | |
| 130 | name := tokens[0] |
| 131 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 132 | var version string |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 133 | if len(tokens) == 2 { |
| 134 | version = tokens[1] |
| 135 | } |
| 136 | |
| 137 | return SdkRef{Name: name, Version: version} |
| 138 | } |
| 139 | |
| 140 | type SdkRefs []SdkRef |
| 141 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 142 | // Contains tells if the given SdkRef is in this list of SdkRef's |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 143 | func (refs SdkRefs) Contains(s SdkRef) bool { |
| 144 | for _, r := range refs { |
| 145 | if r == s { |
| 146 | return true |
| 147 | } |
| 148 | } |
| 149 | return false |
| 150 | } |
| 151 | |
| 152 | type sdkProperties struct { |
| 153 | // The SDK that this module is a member of. nil if it is not a member of any SDK |
| 154 | ContainingSdk *SdkRef `blueprint:"mutated"` |
| 155 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 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. |
| 162 | type SdkBase struct { |
| 163 | properties sdkProperties |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 164 | module SdkAware |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | func (s *SdkBase) sdkBase() *SdkBase { |
| 168 | return s |
| 169 | } |
| 170 | |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 171 | func (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 Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 183 | // MakeMemberOf sets this module to be a member of a specific SDK |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 184 | func (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 |
| 189 | func (s *SdkBase) IsInAnySdk() bool { |
| 190 | return s.properties.ContainingSdk != nil |
| 191 | } |
| 192 | |
Paul Duffin | b9e7a3c | 2021-05-06 15:53:19 +0100 | [diff] [blame] | 193 | // IsVersioned returns true if this module is versioned. |
| 194 | func (s *SdkBase) IsVersioned() bool { |
| 195 | return strings.Contains(s.module.Name(), "@") |
| 196 | } |
| 197 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 198 | // ContainingSdk returns the SDK that this module is a member of |
| 199 | func (s *SdkBase) ContainingSdk() SdkRef { |
| 200 | if s.properties.ContainingSdk != nil { |
| 201 | return *s.properties.ContainingSdk |
| 202 | } |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 203 | return SdkRef{Name: "", Version: ""} |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 204 | } |
| 205 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 206 | // MemberName returns the name of the module that this SDK member is overriding |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 207 | func (s *SdkBase) MemberName() string { |
| 208 | return proptools.String(s.properties.Sdk_member_name) |
| 209 | } |
| 210 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 211 | // InitSdkAwareModule initializes the SdkBase struct. This must be called by all modules including |
| 212 | // SdkBase. |
| 213 | func InitSdkAwareModule(m SdkAware) { |
| 214 | base := m.sdkBase() |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 215 | base.module = m |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 216 | m.AddProperties(&base.properties) |
| 217 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 218 | |
Paul Duffin | 0c2e083 | 2021-04-28 00:39:52 +0100 | [diff] [blame] | 219 | // IsModuleInVersionedSdk returns true if the module is an versioned sdk. |
| 220 | func IsModuleInVersionedSdk(module Module) bool { |
| 221 | if s, ok := module.(SdkAware); ok { |
| 222 | if !s.ContainingSdk().Unversioned() { |
| 223 | return true |
| 224 | } |
| 225 | } |
| 226 | return false |
| 227 | } |
| 228 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 229 | // SnapshotBuilder provides support for generating the build rules which will build the snapshot. |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 230 | type SnapshotBuilder interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 231 | // CopyToSnapshot generates a rule that will copy the src to the dest (which is a snapshot |
| 232 | // relative path) and add the dest to the zip. |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 233 | CopyToSnapshot(src Path, dest string) |
| 234 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 235 | // EmptyFile returns the path to an empty file. |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 236 | // |
| 237 | // This can be used by sdk member types that need to create an empty file in the snapshot, simply |
| 238 | // pass the value returned from this to the CopyToSnapshot() method. |
| 239 | EmptyFile() Path |
| 240 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 241 | // UnzipToSnapshot generates a rule that will unzip the supplied zip into the snapshot relative |
| 242 | // directory destDir. |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 243 | UnzipToSnapshot(zipPath Path, destDir string) |
| 244 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 245 | // AddPrebuiltModule adds a new prebuilt module to the snapshot. |
| 246 | // |
| 247 | // It is intended to be called from SdkMemberType.AddPrebuiltModule which can add module type |
| 248 | // specific properties that are not variant specific. The following properties will be |
| 249 | // automatically populated before returning. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 250 | // |
| 251 | // * name |
| 252 | // * sdk_member_name |
| 253 | // * prefer |
| 254 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 255 | // Properties that are variant specific will be handled by SdkMemberProperties structure. |
| 256 | // |
| 257 | // Each module created by this method can be output to the generated Android.bp file in two |
| 258 | // different forms, depending on the setting of the SOONG_SDK_SNAPSHOT_VERSION build property. |
| 259 | // The two forms are: |
| 260 | // 1. A versioned Soong module that is referenced from a corresponding similarly versioned |
| 261 | // snapshot module. |
| 262 | // 2. An unversioned Soong module that. |
| 263 | // |
| 264 | // See sdk/update.go for more information. |
Paul Duffin | 9d8d609 | 2019-12-05 18:19:29 +0000 | [diff] [blame] | 265 | AddPrebuiltModule(member SdkMember, moduleType string) BpModule |
Paul Duffin | 7b81f5e | 2020-01-13 21:03:22 +0000 | [diff] [blame] | 266 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 267 | // SdkMemberReferencePropertyTag returns a property tag to use when adding a property to a |
| 268 | // BpModule that contains references to other sdk members. |
Paul Duffin | 7b81f5e | 2020-01-13 21:03:22 +0000 | [diff] [blame] | 269 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 270 | // Using this will ensure that the reference is correctly output for both versioned and |
| 271 | // unversioned prebuilts in the snapshot. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 272 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 273 | // "required: true" means that the property must only contain references to other members of the |
| 274 | // sdk. Passing a reference to a module that is not a member of the sdk will result in a build |
| 275 | // error. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 276 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 277 | // "required: false" means that the property can contain references to modules that are either |
| 278 | // members or not members of the sdk. If a reference is to a module that is a non member then the |
| 279 | // reference is left unchanged, i.e. it is not transformed as references to members are. |
| 280 | // |
| 281 | // The handling of the member names is dependent on whether it is an internal or exported member. |
| 282 | // An exported member is one whose name is specified in one of the member type specific |
| 283 | // properties. An internal member is one that is added due to being a part of an exported (or |
| 284 | // other internal) member and is not itself an exported member. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 285 | // |
| 286 | // Member names are handled as follows: |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 287 | // * When creating the unversioned form of the module the name is left unchecked unless the member |
| 288 | // is internal in which case it is transformed into an sdk specific name, i.e. by prefixing with |
| 289 | // the sdk name. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 290 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 291 | // * When creating the versioned form of the module the name is transformed into a versioned sdk |
| 292 | // specific name, i.e. by prefixing with the sdk name and suffixing with the version. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 293 | // |
Paul Duffin | 7b81f5e | 2020-01-13 21:03:22 +0000 | [diff] [blame] | 294 | // e.g. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 295 | // bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag(true)) |
| 296 | SdkMemberReferencePropertyTag(required bool) BpPropertyTag |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 299 | // BpPropertyTag is a marker interface that can be associated with properties in a BpPropertySet to |
| 300 | // provide additional information which can be used to customize their behavior. |
Paul Duffin | 5b511a2 | 2020-01-15 14:23:52 +0000 | [diff] [blame] | 301 | type BpPropertyTag interface{} |
| 302 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 303 | // BpPropertySet is a set of properties for use in a .bp file. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 304 | type BpPropertySet interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 305 | // AddProperty adds a property. |
| 306 | // |
| 307 | // The value can be one of the following types: |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 308 | // * string |
| 309 | // * array of the above |
| 310 | // * bool |
Martin Stjernholm | 191c25f | 2020-09-10 00:40:37 +0100 | [diff] [blame] | 311 | // For these types it is an error if multiple properties with the same name |
| 312 | // are added. |
| 313 | // |
| 314 | // * pointer to a struct |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 315 | // * BpPropertySet |
| 316 | // |
Martin Stjernholm | 191c25f | 2020-09-10 00:40:37 +0100 | [diff] [blame] | 317 | // A pointer to a Blueprint-style property struct is first converted into a |
| 318 | // BpPropertySet by traversing the fields and adding their values as |
| 319 | // properties in a BpPropertySet. A field with a struct value is itself |
| 320 | // converted into a BpPropertySet before adding. |
| 321 | // |
| 322 | // Adding a BpPropertySet is done as follows: |
| 323 | // * If no property with the name exists then the BpPropertySet is added |
| 324 | // directly to this property. Care must be taken to ensure that it does not |
| 325 | // introduce a cycle. |
| 326 | // * If a property exists with the name and the current value is a |
| 327 | // BpPropertySet then every property of the new BpPropertySet is added to |
| 328 | // the existing BpPropertySet. |
| 329 | // * Otherwise, if a property exists with the name then it is an error. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 330 | AddProperty(name string, value interface{}) |
| 331 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 332 | // AddPropertyWithTag adds a property with an associated property tag. |
Paul Duffin | 5b511a2 | 2020-01-15 14:23:52 +0000 | [diff] [blame] | 333 | AddPropertyWithTag(name string, value interface{}, tag BpPropertyTag) |
| 334 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 335 | // AddPropertySet adds a property set with the specified name and returns it so that additional |
| 336 | // properties can be added to it. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 337 | AddPropertySet(name string) BpPropertySet |
Paul Duffin | 0df4968 | 2021-05-07 01:10:01 +0100 | [diff] [blame] | 338 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 339 | // AddCommentForProperty adds a comment for the named property (or property set). |
Paul Duffin | 0df4968 | 2021-05-07 01:10:01 +0100 | [diff] [blame] | 340 | AddCommentForProperty(name, text string) |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 343 | // BpModule represents a module definition in a .bp file. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 344 | type BpModule interface { |
| 345 | BpPropertySet |
Paul Duffin | 0df4968 | 2021-05-07 01:10:01 +0100 | [diff] [blame] | 346 | |
| 347 | // ModuleType returns the module type of the module |
| 348 | ModuleType() string |
| 349 | |
| 350 | // Name returns the name of the module or "" if no name has been specified. |
| 351 | Name() string |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 352 | } |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 353 | |
Paul Duffin | 51227d8 | 2021-05-18 12:54:27 +0100 | [diff] [blame] | 354 | // BpPrintable is a marker interface that must be implemented by any struct that is added as a |
| 355 | // property value. |
| 356 | type BpPrintable interface { |
| 357 | bpPrintable() |
| 358 | } |
| 359 | |
| 360 | // BpPrintableBase must be embedded within any struct that is added as a |
| 361 | // property value. |
| 362 | type BpPrintableBase struct { |
| 363 | } |
| 364 | |
| 365 | func (b BpPrintableBase) bpPrintable() { |
| 366 | } |
| 367 | |
| 368 | var _ BpPrintable = BpPrintableBase{} |
| 369 | |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 370 | // sdkRegisterable defines the interface that must be implemented by objects that can be registered |
| 371 | // in an sdkRegistry. |
| 372 | type sdkRegisterable interface { |
| 373 | // SdkPropertyName returns the name of the corresponding property on an sdk module. |
| 374 | SdkPropertyName() string |
| 375 | } |
| 376 | |
| 377 | // sdkRegistry provides support for registering and retrieving objects that define properties for |
| 378 | // use by sdk and module_exports module types. |
| 379 | type sdkRegistry struct { |
| 380 | // The list of registered objects sorted by property name. |
| 381 | list []sdkRegisterable |
| 382 | } |
| 383 | |
| 384 | // copyAndAppend creates a new sdkRegistry that includes all the traits registered in |
| 385 | // this registry plus the supplied trait. |
| 386 | func (r *sdkRegistry) copyAndAppend(registerable sdkRegisterable) *sdkRegistry { |
| 387 | oldList := r.list |
| 388 | |
Paul Duffin | 581f2e5 | 2021-09-22 13:25:23 +0100 | [diff] [blame] | 389 | // Make sure that list does not already contain the property. Uses a simple linear search instead |
| 390 | // of a binary search even though the list is sorted. That is because the number of items in the |
| 391 | // list is small and so not worth the overhead of a binary search. |
| 392 | found := false |
| 393 | newPropertyName := registerable.SdkPropertyName() |
| 394 | for _, r := range oldList { |
| 395 | if r.SdkPropertyName() == newPropertyName { |
| 396 | found = true |
| 397 | break |
| 398 | } |
| 399 | } |
| 400 | if found { |
| 401 | names := []string{} |
| 402 | for _, r := range oldList { |
| 403 | names = append(names, r.SdkPropertyName()) |
| 404 | } |
| 405 | panic(fmt.Errorf("duplicate properties found, %q already exists in %q", newPropertyName, names)) |
| 406 | } |
| 407 | |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 408 | // Copy the slice just in case this is being read while being modified, e.g. when testing. |
| 409 | list := make([]sdkRegisterable, 0, len(oldList)+1) |
| 410 | list = append(list, oldList...) |
| 411 | list = append(list, registerable) |
| 412 | |
| 413 | // Sort the registered objects by their property name to ensure that registry order has no effect |
| 414 | // on behavior. |
| 415 | sort.Slice(list, func(i1, i2 int) bool { |
| 416 | t1 := list[i1] |
| 417 | t2 := list[i2] |
| 418 | |
| 419 | return t1.SdkPropertyName() < t2.SdkPropertyName() |
| 420 | }) |
| 421 | |
| 422 | // Create a new registry so the pointer uniquely identifies the set of registered types. |
| 423 | return &sdkRegistry{ |
| 424 | list: list, |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | // registeredObjects returns the list of registered instances. |
| 429 | func (r *sdkRegistry) registeredObjects() []sdkRegisterable { |
| 430 | return r.list |
| 431 | } |
| 432 | |
| 433 | // uniqueOnceKey returns a key that uniquely identifies this instance and can be used with |
| 434 | // OncePer.Once |
| 435 | func (r *sdkRegistry) uniqueOnceKey() OnceKey { |
| 436 | // Use the pointer to the registry as the unique key. The pointer is used because it is guaranteed |
| 437 | // to uniquely identify the contained list. The list itself cannot be used as slices are not |
| 438 | // comparable. Using the pointer does mean that two separate registries with identical lists would |
| 439 | // have different keys and so cause whatever information is cached to be created multiple times. |
| 440 | // However, that is not an issue in practice as it should not occur outside tests. Constructing a |
| 441 | // string representation of the list to use instead would avoid that but is an unnecessary |
| 442 | // complication that provides no significant benefit. |
| 443 | return NewCustomOnceKey(r) |
| 444 | } |
| 445 | |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 446 | // SdkMemberTrait represents a trait that members of an sdk module can contribute to the sdk |
| 447 | // snapshot. |
| 448 | // |
| 449 | // A trait is simply a characteristic of sdk member that is not required by default which may be |
| 450 | // required for some members but not others. Traits can cause additional information to be output |
| 451 | // to the sdk snapshot or replace the default information exported for a member with something else. |
| 452 | // e.g. |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 453 | // - By default cc libraries only export the default image variants to the SDK. However, for some |
| 454 | // members it may be necessary to export specific image variants, e.g. vendor, or recovery. |
| 455 | // - By default cc libraries export all the configured architecture variants except for the native |
| 456 | // bridge architecture variants. However, for some members it may be necessary to export the |
| 457 | // native bridge architecture variants as well. |
| 458 | // - By default cc libraries export the platform variant (i.e. sdk:). However, for some members it |
| 459 | // may be necessary to export the sdk variant (i.e. sdk:sdk). |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 460 | // |
| 461 | // A sdk can request a module to provide no traits, one trait or a collection of traits. The exact |
| 462 | // behavior of a trait is determined by how SdkMemberType implementations handle the traits. A trait |
| 463 | // could be specific to one SdkMemberType or many. Some trait combinations could be incompatible. |
| 464 | // |
| 465 | // The sdk module type will create a special traits structure that contains a property for each |
| 466 | // trait registered with RegisterSdkMemberTrait(). The property names are those returned from |
| 467 | // SdkPropertyName(). Each property contains a list of modules that are required to have that trait. |
| 468 | // e.g. something like this: |
| 469 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 470 | // sdk { |
| 471 | // name: "sdk", |
| 472 | // ... |
| 473 | // traits: { |
| 474 | // recovery_image: ["module1", "module4", "module5"], |
| 475 | // native_bridge: ["module1", "module2"], |
| 476 | // native_sdk: ["module1", "module3"], |
| 477 | // ... |
| 478 | // }, |
| 479 | // ... |
| 480 | // } |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 481 | type SdkMemberTrait interface { |
| 482 | // SdkPropertyName returns the name of the traits property on an sdk module. |
| 483 | SdkPropertyName() string |
| 484 | } |
| 485 | |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 486 | var _ sdkRegisterable = (SdkMemberTrait)(nil) |
| 487 | |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 488 | // SdkMemberTraitBase is the base struct that must be embedded within any type that implements |
| 489 | // SdkMemberTrait. |
| 490 | type SdkMemberTraitBase struct { |
| 491 | // PropertyName is the name of the property |
| 492 | PropertyName string |
| 493 | } |
| 494 | |
| 495 | func (b *SdkMemberTraitBase) SdkPropertyName() string { |
| 496 | return b.PropertyName |
| 497 | } |
| 498 | |
| 499 | // SdkMemberTraitSet is a set of SdkMemberTrait instances. |
| 500 | type SdkMemberTraitSet interface { |
| 501 | // Empty returns true if this set is empty. |
| 502 | Empty() bool |
| 503 | |
| 504 | // Contains returns true if this set contains the specified trait. |
| 505 | Contains(trait SdkMemberTrait) bool |
| 506 | |
| 507 | // Subtract returns a new set containing all elements of this set except for those in the |
| 508 | // other set. |
| 509 | Subtract(other SdkMemberTraitSet) SdkMemberTraitSet |
| 510 | |
| 511 | // String returns a string representation of the set and its contents. |
| 512 | String() string |
| 513 | } |
| 514 | |
| 515 | func NewSdkMemberTraitSet(traits []SdkMemberTrait) SdkMemberTraitSet { |
| 516 | if len(traits) == 0 { |
| 517 | return EmptySdkMemberTraitSet() |
| 518 | } |
| 519 | |
| 520 | m := sdkMemberTraitSet{} |
| 521 | for _, trait := range traits { |
| 522 | m[trait] = true |
| 523 | } |
| 524 | return m |
| 525 | } |
| 526 | |
| 527 | func EmptySdkMemberTraitSet() SdkMemberTraitSet { |
| 528 | return (sdkMemberTraitSet)(nil) |
| 529 | } |
| 530 | |
| 531 | type sdkMemberTraitSet map[SdkMemberTrait]bool |
| 532 | |
| 533 | var _ SdkMemberTraitSet = (sdkMemberTraitSet{}) |
| 534 | |
| 535 | func (s sdkMemberTraitSet) Empty() bool { |
| 536 | return len(s) == 0 |
| 537 | } |
| 538 | |
| 539 | func (s sdkMemberTraitSet) Contains(trait SdkMemberTrait) bool { |
| 540 | return s[trait] |
| 541 | } |
| 542 | |
| 543 | func (s sdkMemberTraitSet) Subtract(other SdkMemberTraitSet) SdkMemberTraitSet { |
| 544 | if other.Empty() { |
| 545 | return s |
| 546 | } |
| 547 | |
| 548 | var remainder []SdkMemberTrait |
| 549 | for trait, _ := range s { |
| 550 | if !other.Contains(trait) { |
| 551 | remainder = append(remainder, trait) |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | return NewSdkMemberTraitSet(remainder) |
| 556 | } |
| 557 | |
| 558 | func (s sdkMemberTraitSet) String() string { |
| 559 | list := []string{} |
| 560 | for trait, _ := range s { |
| 561 | list = append(list, trait.SdkPropertyName()) |
| 562 | } |
| 563 | sort.Strings(list) |
| 564 | return fmt.Sprintf("[%s]", strings.Join(list, ",")) |
| 565 | } |
| 566 | |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 567 | var registeredSdkMemberTraits = &sdkRegistry{} |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 568 | |
| 569 | // RegisteredSdkMemberTraits returns a OnceKey and a sorted list of registered traits. |
| 570 | // |
| 571 | // The key uniquely identifies the array of traits and can be used with OncePer.Once() to cache |
| 572 | // information derived from the array of traits. |
| 573 | func RegisteredSdkMemberTraits() (OnceKey, []SdkMemberTrait) { |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 574 | registerables := registeredSdkMemberTraits.registeredObjects() |
| 575 | traits := make([]SdkMemberTrait, len(registerables)) |
| 576 | for i, registerable := range registerables { |
| 577 | traits[i] = registerable.(SdkMemberTrait) |
| 578 | } |
| 579 | return registeredSdkMemberTraits.uniqueOnceKey(), traits |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 580 | } |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 581 | |
| 582 | // RegisterSdkMemberTrait registers an SdkMemberTrait object to allow them to be used in the |
| 583 | // module_exports, module_exports_snapshot, sdk and sdk_snapshot module types. |
| 584 | func RegisterSdkMemberTrait(trait SdkMemberTrait) { |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 585 | registeredSdkMemberTraits = registeredSdkMemberTraits.copyAndAppend(trait) |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 588 | // SdkMember is an individual member of the SDK. |
| 589 | // |
| 590 | // It includes all of the variants that the SDK depends upon. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 591 | type SdkMember interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 592 | // Name returns the name of the member. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 593 | Name() string |
| 594 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 595 | // Variants returns all the variants of this module depended upon by the SDK. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 596 | Variants() []SdkAware |
| 597 | } |
| 598 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 599 | // SdkMemberDependencyTag is the interface that a tag must implement in order to allow the |
Paul Duffin | 2d3da31 | 2021-05-06 12:02:27 +0100 | [diff] [blame] | 600 | // dependent module to be automatically added to the sdk. |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 601 | type SdkMemberDependencyTag interface { |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 602 | blueprint.DependencyTag |
| 603 | |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 604 | // SdkMemberType returns the SdkMemberType that will be used to automatically add the child module |
| 605 | // to the sdk. |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 606 | // |
| 607 | // Returning nil will prevent the module being added to the sdk. |
Paul Duffin | eee466e | 2021-04-27 23:17:56 +0100 | [diff] [blame] | 608 | SdkMemberType(child Module) SdkMemberType |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 609 | |
| 610 | // ExportMember determines whether a module added to the sdk through this tag will be exported |
| 611 | // from the sdk or not. |
| 612 | // |
| 613 | // An exported member is added to the sdk using its own name, e.g. if "foo" was exported from sdk |
| 614 | // "bar" then its prebuilt would be simply called "foo". A member can be added to the sdk via |
| 615 | // multiple tags and if any of those tags returns true from this method then the membe will be |
| 616 | // exported. Every module added directly to the sdk via one of the member type specific |
| 617 | // properties, e.g. java_libs, will automatically be exported. |
| 618 | // |
| 619 | // If a member is not exported then it is treated as an internal implementation detail of the |
| 620 | // sdk and so will be added with an sdk specific name. e.g. if "foo" was an internal member of sdk |
| 621 | // "bar" then its prebuilt would be called "bar_foo". Additionally its visibility will be set to |
| 622 | // "//visibility:private" so it will not be accessible from outside its Android.bp file. |
| 623 | ExportMember() bool |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 626 | var _ SdkMemberDependencyTag = (*sdkMemberDependencyTag)(nil) |
| 627 | var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil) |
Paul Duffin | cee7e66 | 2020-07-09 17:32:57 +0100 | [diff] [blame] | 628 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 629 | type sdkMemberDependencyTag struct { |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 630 | blueprint.BaseDependencyTag |
| 631 | memberType SdkMemberType |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 632 | export bool |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 635 | func (t *sdkMemberDependencyTag) SdkMemberType(_ Module) SdkMemberType { |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 636 | return t.memberType |
| 637 | } |
| 638 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 639 | func (t *sdkMemberDependencyTag) ExportMember() bool { |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 640 | return t.export |
| 641 | } |
| 642 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 643 | // ReplaceSourceWithPrebuilt prevents dependencies from the sdk/module_exports onto their members |
| 644 | // from being replaced with a preferred prebuilt. |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 645 | func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool { |
Paul Duffin | cee7e66 | 2020-07-09 17:32:57 +0100 | [diff] [blame] | 646 | return false |
| 647 | } |
| 648 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 649 | // DependencyTagForSdkMemberType creates an SdkMemberDependencyTag that will cause any |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 650 | // dependencies added by the tag to be added to the sdk as the specified SdkMemberType and exported |
| 651 | // (or not) as specified by the export parameter. |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 652 | func DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMemberDependencyTag { |
| 653 | return &sdkMemberDependencyTag{memberType: memberType, export: export} |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 656 | // SdkMemberType is the interface that must be implemented for every type that can be a member of an |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 657 | // sdk. |
| 658 | // |
| 659 | // The basic implementation should look something like this, where ModuleType is |
| 660 | // the name of the module type being supported. |
| 661 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 662 | // type moduleTypeSdkMemberType struct { |
| 663 | // android.SdkMemberTypeBase |
| 664 | // } |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 665 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 666 | // func init() { |
| 667 | // android.RegisterSdkMemberType(&moduleTypeSdkMemberType{ |
| 668 | // SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 669 | // PropertyName: "module_types", |
| 670 | // }, |
| 671 | // } |
| 672 | // } |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 673 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 674 | // ...methods... |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 675 | type SdkMemberType interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 676 | // SdkPropertyName returns the name of the member type property on an sdk module. |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 677 | SdkPropertyName() string |
| 678 | |
Paul Duffin | 1308205 | 2021-05-11 00:31:38 +0100 | [diff] [blame] | 679 | // RequiresBpProperty returns true if this member type requires its property to be usable within |
| 680 | // an Android.bp file. |
| 681 | RequiresBpProperty() bool |
| 682 | |
Paul Duffin | f861df7 | 2022-07-01 15:56:06 +0000 | [diff] [blame] | 683 | // SupportedBuildReleases returns the string representation of a set of target build releases that |
| 684 | // support this member type. |
| 685 | SupportedBuildReleases() string |
| 686 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 687 | // UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot, |
| 688 | // false otherwise. |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 689 | UsableWithSdkAndSdkSnapshot() bool |
| 690 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 691 | // IsHostOsDependent returns true if prebuilt host artifacts may be specific to the host OS. Only |
| 692 | // applicable to modules where HostSupported() is true. If this is true, snapshots will list each |
| 693 | // host OS variant explicitly and disable all other host OS'es. |
Martin Stjernholm | caa47d7 | 2020-07-11 04:52:24 +0100 | [diff] [blame] | 694 | IsHostOsDependent() bool |
| 695 | |
Liz Kammer | 96320df | 2022-05-12 20:40:00 -0400 | [diff] [blame] | 696 | // SupportedLinkages returns the names of the linkage variants supported by this module. |
| 697 | SupportedLinkages() []string |
| 698 | |
Paul Duffin | 4e7d1c4 | 2022-05-13 13:12:19 +0000 | [diff] [blame] | 699 | // ArePrebuiltsRequired returns true if prebuilts are required in the sdk snapshot, false |
| 700 | // otherwise. |
| 701 | ArePrebuiltsRequired() bool |
| 702 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 703 | // AddDependencies adds dependencies from the SDK module to all the module variants the member |
| 704 | // type contributes to the SDK. `names` is the list of module names given in the member type |
| 705 | // property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants |
| 706 | // required is determined by the SDK and its properties. The dependencies must be added with the |
| 707 | // supplied tag. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 708 | // |
| 709 | // The BottomUpMutatorContext provided is for the SDK module. |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 710 | AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 711 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 712 | // IsInstance returns true if the supplied module is an instance of this member type. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 713 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 714 | // This is used to check the type of each variant before added to the SdkMember. Returning false |
| 715 | // will cause an error to be logged explaining that the module is not allowed in whichever sdk |
| 716 | // property it was added. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 717 | IsInstance(module Module) bool |
| 718 | |
Paul Duffin | 0d4ed0a | 2021-05-10 23:58:40 +0100 | [diff] [blame] | 719 | // UsesSourceModuleTypeInSnapshot returns true when the AddPrebuiltModule() method returns a |
| 720 | // source module type. |
| 721 | UsesSourceModuleTypeInSnapshot() bool |
| 722 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 723 | // AddPrebuiltModule is called to add a prebuilt module that the sdk will populate. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 724 | // |
Paul Duffin | 425b0ea | 2020-05-06 12:41:39 +0100 | [diff] [blame] | 725 | // The sdk module code generates the snapshot as follows: |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 726 | // |
| 727 | // * A properties struct of type SdkMemberProperties is created for each variant and |
| 728 | // populated with information from the variant by calling PopulateFromVariant(SdkAware) |
| 729 | // on the struct. |
| 730 | // |
| 731 | // * An additional properties struct is created into which the common properties will be |
| 732 | // added. |
| 733 | // |
| 734 | // * The variant property structs are analysed to find exported (capitalized) fields which |
| 735 | // have common values. Those fields are cleared and the common value added to the common |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 736 | // properties. |
| 737 | // |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 738 | // A field annotated with a tag of `sdk:"ignore"` will be treated as if it |
| 739 | // was not capitalized, i.e. ignored and not optimized for common values. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 740 | // |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 741 | // A field annotated with a tag of `sdk:"keep"` will not be cleared even if the value is common |
| 742 | // across multiple structs. Common values will still be copied into the common property struct. |
| 743 | // So, if the same value is placed in all structs populated from variants that value would be |
| 744 | // copied into all common property structs and so be available in every instance. |
| 745 | // |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 746 | // A field annotated with a tag of `android:"arch_variant"` will be allowed to have |
| 747 | // values that differ by arch, fields not tagged as such must have common values across |
| 748 | // all variants. |
| 749 | // |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 750 | // * Additional field tags can be specified on a field that will ignore certain values |
| 751 | // for the purpose of common value optimization. A value that is ignored must have the |
| 752 | // default value for the property type. This is to ensure that significant value are not |
| 753 | // ignored by accident. The purpose of this is to allow the snapshot generation to reflect |
| 754 | // the behavior of the runtime. e.g. if a property is ignored on the host then a property |
| 755 | // that is common for android can be treated as if it was common for android and host as |
| 756 | // the setting for host is ignored anyway. |
| 757 | // * `sdk:"ignored-on-host" - this indicates the property is ignored on the host variant. |
| 758 | // |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 759 | // * The sdk module type populates the BpModule structure, creating the arch specific |
| 760 | // structure and calls AddToPropertySet(...) on the properties struct to add the member |
| 761 | // specific properties in the correct place in the structure. |
| 762 | // |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 763 | AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 764 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 765 | // CreateVariantPropertiesStruct creates a structure into which variant specific properties can be |
| 766 | // added. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 767 | CreateVariantPropertiesStruct() SdkMemberProperties |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 768 | |
| 769 | // SupportedTraits returns the set of traits supported by this member type. |
| 770 | SupportedTraits() SdkMemberTraitSet |
Liz Kammer | 96320df | 2022-05-12 20:40:00 -0400 | [diff] [blame] | 771 | |
| 772 | // Overrides returns whether type overrides other SdkMemberType |
| 773 | Overrides(SdkMemberType) bool |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 774 | } |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 775 | |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 776 | var _ sdkRegisterable = (SdkMemberType)(nil) |
| 777 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 778 | // SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies() |
| 779 | // implementations. |
| 780 | type SdkDependencyContext interface { |
| 781 | BottomUpMutatorContext |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 782 | |
| 783 | // RequiredTraits returns the set of SdkMemberTrait instances that the sdk requires the named |
| 784 | // member to provide. |
| 785 | RequiredTraits(name string) SdkMemberTraitSet |
| 786 | |
| 787 | // RequiresTrait returns true if the sdk requires the member with the supplied name to provide the |
| 788 | // supplied trait. |
| 789 | RequiresTrait(name string, trait SdkMemberTrait) bool |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 790 | } |
| 791 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 792 | // SdkMemberTypeBase is the base type for SdkMemberType implementations and must be embedded in any |
| 793 | // struct that implements SdkMemberType. |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 794 | type SdkMemberTypeBase struct { |
Paul Duffin | 1308205 | 2021-05-11 00:31:38 +0100 | [diff] [blame] | 795 | PropertyName string |
| 796 | |
Liz Kammer | 96320df | 2022-05-12 20:40:00 -0400 | [diff] [blame] | 797 | // Property names that this SdkMemberTypeBase can override, this is useful when a module type is a |
| 798 | // superset of another module type. |
| 799 | OverridesPropertyNames map[string]bool |
| 800 | |
| 801 | // The names of linkage variants supported by this module. |
| 802 | SupportedLinkageNames []string |
| 803 | |
Paul Duffin | 1308205 | 2021-05-11 00:31:38 +0100 | [diff] [blame] | 804 | // When set to true BpPropertyNotRequired indicates that the member type does not require the |
| 805 | // property to be specifiable in an Android.bp file. |
| 806 | BpPropertyNotRequired bool |
| 807 | |
Paul Duffin | f861df7 | 2022-07-01 15:56:06 +0000 | [diff] [blame] | 808 | // The name of the first targeted build release. |
| 809 | // |
| 810 | // If not specified then it is assumed to be available on all targeted build releases. |
| 811 | SupportedBuildReleaseSpecification string |
| 812 | |
Paul Duffin | 4e7d1c4 | 2022-05-13 13:12:19 +0000 | [diff] [blame] | 813 | // Set to true if this must be usable with the sdk/sdk_snapshot module types. Otherwise, it will |
| 814 | // only be usable with module_exports/module_exports_snapshots module types. |
| 815 | SupportsSdk bool |
| 816 | |
| 817 | // Set to true if prebuilt host artifacts of this member may be specific to the host OS. Only |
| 818 | // applicable to modules where HostSupported() is true. |
Paul Duffin | 2d3da31 | 2021-05-06 12:02:27 +0100 | [diff] [blame] | 819 | HostOsDependent bool |
Paul Duffin | 0d4ed0a | 2021-05-10 23:58:40 +0100 | [diff] [blame] | 820 | |
| 821 | // When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source |
| 822 | // module type in its SdkMemberType.AddPrebuiltModule() method. That prevents the sdk snapshot |
| 823 | // code from automatically adding a prefer: true flag. |
| 824 | UseSourceModuleTypeInSnapshot bool |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 825 | |
Paul Duffin | 4e7d1c4 | 2022-05-13 13:12:19 +0000 | [diff] [blame] | 826 | // Set to proptools.BoolPtr(false) if this member does not generate prebuilts but is only provided |
| 827 | // to allow the sdk to gather members from this member's dependencies. If not specified then |
| 828 | // defaults to true. |
| 829 | PrebuiltsRequired *bool |
| 830 | |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 831 | // The list of supported traits. |
| 832 | Traits []SdkMemberTrait |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | func (b *SdkMemberTypeBase) SdkPropertyName() string { |
| 836 | return b.PropertyName |
| 837 | } |
| 838 | |
Paul Duffin | 1308205 | 2021-05-11 00:31:38 +0100 | [diff] [blame] | 839 | func (b *SdkMemberTypeBase) RequiresBpProperty() bool { |
| 840 | return !b.BpPropertyNotRequired |
| 841 | } |
| 842 | |
Paul Duffin | f861df7 | 2022-07-01 15:56:06 +0000 | [diff] [blame] | 843 | func (b *SdkMemberTypeBase) SupportedBuildReleases() string { |
| 844 | return b.SupportedBuildReleaseSpecification |
| 845 | } |
| 846 | |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 847 | func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool { |
| 848 | return b.SupportsSdk |
| 849 | } |
| 850 | |
Martin Stjernholm | caa47d7 | 2020-07-11 04:52:24 +0100 | [diff] [blame] | 851 | func (b *SdkMemberTypeBase) IsHostOsDependent() bool { |
| 852 | return b.HostOsDependent |
| 853 | } |
| 854 | |
Paul Duffin | 4e7d1c4 | 2022-05-13 13:12:19 +0000 | [diff] [blame] | 855 | func (b *SdkMemberTypeBase) ArePrebuiltsRequired() bool { |
| 856 | return proptools.BoolDefault(b.PrebuiltsRequired, true) |
| 857 | } |
| 858 | |
Paul Duffin | 0d4ed0a | 2021-05-10 23:58:40 +0100 | [diff] [blame] | 859 | func (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool { |
| 860 | return b.UseSourceModuleTypeInSnapshot |
| 861 | } |
| 862 | |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 863 | func (b *SdkMemberTypeBase) SupportedTraits() SdkMemberTraitSet { |
| 864 | return NewSdkMemberTraitSet(b.Traits) |
| 865 | } |
| 866 | |
Liz Kammer | 96320df | 2022-05-12 20:40:00 -0400 | [diff] [blame] | 867 | func (b *SdkMemberTypeBase) Overrides(other SdkMemberType) bool { |
| 868 | return b.OverridesPropertyNames[other.SdkPropertyName()] |
| 869 | } |
| 870 | |
| 871 | func (b *SdkMemberTypeBase) SupportedLinkages() []string { |
| 872 | return b.SupportedLinkageNames |
| 873 | } |
| 874 | |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 875 | // registeredModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports |
| 876 | // modules. |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 877 | var registeredModuleExportsMemberTypes = &sdkRegistry{} |
Paul Duffin | 62782de | 2021-07-14 12:05:16 +0100 | [diff] [blame] | 878 | |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 879 | // registeredSdkMemberTypes is the set of registered registeredSdkMemberTypes for sdk modules. |
| 880 | var registeredSdkMemberTypes = &sdkRegistry{} |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 881 | |
| 882 | // RegisteredSdkMemberTypes returns a OnceKey and a sorted list of registered types. |
| 883 | // |
| 884 | // If moduleExports is true then the slice of types includes all registered types that can be used |
| 885 | // with the module_exports and module_exports_snapshot module types. Otherwise, the slice of types |
| 886 | // only includes those registered types that can be used with the sdk and sdk_snapshot module |
| 887 | // types. |
| 888 | // |
| 889 | // The key uniquely identifies the array of types and can be used with OncePer.Once() to cache |
| 890 | // information derived from the array of types. |
| 891 | func RegisteredSdkMemberTypes(moduleExports bool) (OnceKey, []SdkMemberType) { |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 892 | var registry *sdkRegistry |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 893 | if moduleExports { |
| 894 | registry = registeredModuleExportsMemberTypes |
| 895 | } else { |
| 896 | registry = registeredSdkMemberTypes |
| 897 | } |
| 898 | |
Paul Duffin | f04033b | 2021-09-22 11:51:09 +0100 | [diff] [blame] | 899 | registerables := registry.registeredObjects() |
| 900 | types := make([]SdkMemberType, len(registerables)) |
| 901 | for i, registerable := range registerables { |
| 902 | types[i] = registerable.(SdkMemberType) |
| 903 | } |
| 904 | return registry.uniqueOnceKey(), types |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 905 | } |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 906 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 907 | // RegisterSdkMemberType registers an SdkMemberType object to allow them to be used in the |
| 908 | // module_exports, module_exports_snapshot and (depending on the value returned from |
| 909 | // SdkMemberType.UsableWithSdkAndSdkSnapshot) the sdk and sdk_snapshot module types. |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 910 | func RegisterSdkMemberType(memberType SdkMemberType) { |
| 911 | // All member types are usable with module_exports. |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 912 | registeredModuleExportsMemberTypes = registeredModuleExportsMemberTypes.copyAndAppend(memberType) |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 913 | |
| 914 | // Only those that explicitly indicate it are usable with sdk. |
| 915 | if memberType.UsableWithSdkAndSdkSnapshot() { |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 916 | registeredSdkMemberTypes = registeredSdkMemberTypes.copyAndAppend(memberType) |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 917 | } |
| 918 | } |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 919 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 920 | // SdkMemberPropertiesBase is the base structure for all implementations of SdkMemberProperties and |
| 921 | // must be embedded in any struct that implements SdkMemberProperties. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 922 | // |
Martin Stjernholm | 89238f4 | 2020-07-10 00:14:03 +0100 | [diff] [blame] | 923 | // Contains common properties that apply across many different member types. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 924 | type SdkMemberPropertiesBase struct { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 925 | // The number of unique os types supported by the member variants. |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 926 | // |
| 927 | // If a member has a variant with more than one os type then it will need to differentiate |
| 928 | // the locations of any of their prebuilt files in the snapshot by os type to prevent them |
| 929 | // from colliding. See OsPrefix(). |
| 930 | // |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 931 | // Ignore this property during optimization. This is needed because this property is the same for |
| 932 | // all variants of a member and so would be optimized away if it was not ignored. |
| 933 | Os_count int `sdk:"ignore"` |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 934 | |
| 935 | // The os type for which these properties refer. |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 936 | // |
| 937 | // Provided to allow a member to differentiate between os types in the locations of their |
| 938 | // prebuilt files when it supports more than one os type. |
| 939 | // |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 940 | // Ignore this property during optimization. This is needed because this property is the same for |
| 941 | // all variants of a member and so would be optimized away if it was not ignored. |
| 942 | Os OsType `sdk:"ignore"` |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 943 | |
| 944 | // The setting to use for the compile_multilib property. |
Martin Stjernholm | 89238f4 | 2020-07-10 00:14:03 +0100 | [diff] [blame] | 945 | Compile_multilib string `android:"arch_variant"` |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 948 | // OsPrefix returns the os prefix to use for any file paths in the sdk. |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 949 | // |
| 950 | // Is an empty string if the member only provides variants for a single os type, otherwise |
| 951 | // is the OsType.Name. |
| 952 | func (b *SdkMemberPropertiesBase) OsPrefix() string { |
| 953 | if b.Os_count == 1 { |
| 954 | return "" |
| 955 | } else { |
| 956 | return b.Os.Name |
| 957 | } |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | func (b *SdkMemberPropertiesBase) Base() *SdkMemberPropertiesBase { |
| 961 | return b |
| 962 | } |
| 963 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 964 | // SdkMemberProperties is the interface to be implemented on top of a structure that contains |
| 965 | // variant specific information. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 966 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 967 | // Struct fields that are capitalized are examined for common values to extract. Fields that are not |
| 968 | // capitalized are assumed to be arch specific. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 969 | type SdkMemberProperties interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 970 | // Base returns the base structure. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 971 | Base() *SdkMemberPropertiesBase |
| 972 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 973 | // PopulateFromVariant populates this structure with information from a module variant. |
| 974 | // |
| 975 | // It will typically be called once for each variant of a member module that the SDK depends upon. |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 976 | PopulateFromVariant(ctx SdkMemberContext, variant Module) |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 977 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 978 | // AddToPropertySet adds the information from this structure to the property set. |
| 979 | // |
| 980 | // This will be called for each instance of this structure on which the PopulateFromVariant method |
| 981 | // was called and also on a number of different instances of this structure into which properties |
| 982 | // common to one or more variants have been copied. Therefore, implementations of this must handle |
| 983 | // the case when this structure is only partially populated. |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 984 | AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet) |
| 985 | } |
| 986 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 987 | // SdkMemberContext provides access to information common to a specific member. |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 988 | type SdkMemberContext interface { |
| 989 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 990 | // SdkModuleContext returns the module context of the sdk common os variant which is creating the |
| 991 | // snapshot. |
| 992 | // |
| 993 | // This is common to all members of the sdk and is not specific to the member being processed. |
| 994 | // If information about the member being processed needs to be obtained from this ModuleContext it |
| 995 | // must be obtained using one of the OtherModule... methods not the Module... methods. |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 996 | SdkModuleContext() ModuleContext |
| 997 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 998 | // SnapshotBuilder the builder of the snapshot. |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 999 | SnapshotBuilder() SnapshotBuilder |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1000 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 1001 | // MemberType returns the type of the member currently being processed. |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1002 | MemberType() SdkMemberType |
| 1003 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame] | 1004 | // Name returns the name of the member currently being processed. |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 1005 | // |
| 1006 | // Provided for use by sdk members to create a member specific location within the snapshot |
| 1007 | // into which to copy the prebuilt files. |
| 1008 | Name() string |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 1009 | |
| 1010 | // RequiresTrait returns true if this member is expected to provide the specified trait. |
| 1011 | RequiresTrait(trait SdkMemberTrait) bool |
Paul Duffin | 1364891 | 2022-07-15 13:12:35 +0000 | [diff] [blame] | 1012 | |
| 1013 | // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is |
| 1014 | // being generated is before Tiramisu, i.e. S. |
| 1015 | IsTargetBuildBeforeTiramisu() bool |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 1016 | } |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1017 | |
| 1018 | // ExportedComponentsInfo contains information about the components that this module exports to an |
| 1019 | // sdk snapshot. |
| 1020 | // |
| 1021 | // A component of a module is a child module that the module creates and which forms an integral |
| 1022 | // part of the functionality that the creating module provides. A component module is essentially |
| 1023 | // owned by its creator and is tightly coupled to the creator and other components. |
| 1024 | // |
| 1025 | // e.g. the child modules created by prebuilt_apis are not components because they are not tightly |
| 1026 | // coupled to the prebuilt_apis module. Once they are created the prebuilt_apis ignores them. The |
| 1027 | // child impl and stub library created by java_sdk_library (and corresponding import) are components |
| 1028 | // because the creating module depends upon them in order to provide some of its own functionality. |
| 1029 | // |
| 1030 | // A component is exported if it is part of an sdk snapshot. e.g. The xml and impl child modules are |
| 1031 | // components but they are not exported as they are not part of an sdk snapshot. |
| 1032 | // |
| 1033 | // This information is used by the sdk snapshot generation code to ensure that it does not create |
| 1034 | // an sdk snapshot that contains a declaration of the component module and the module that creates |
| 1035 | // it as that would result in duplicate modules when attempting to use the snapshot. e.g. a snapshot |
| 1036 | // that included the java_sdk_library_import "foo" and also a java_import "foo.stubs" would fail |
| 1037 | // as there would be two modules called "foo.stubs". |
| 1038 | type ExportedComponentsInfo struct { |
| 1039 | // The names of the exported components. |
| 1040 | Components []string |
| 1041 | } |
| 1042 | |
| 1043 | var ExportedComponentsInfoProvider = blueprint.NewProvider(ExportedComponentsInfo{}) |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1044 | |
| 1045 | // AdditionalSdkInfo contains additional properties to add to the generated SDK info file. |
| 1046 | type AdditionalSdkInfo struct { |
| 1047 | Properties map[string]interface{} |
| 1048 | } |
| 1049 | |
| 1050 | var AdditionalSdkInfoProvider = blueprint.NewProvider(AdditionalSdkInfo{}) |