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 | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 18 | "sort" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 19 | "strings" |
| 20 | |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 21 | "github.com/google/blueprint" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
| 23 | ) |
| 24 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 25 | // RequiredSdks provides access to the set of SDKs required by an APEX and its contents. |
| 26 | // |
Paul Duffin | 923e8a5 | 2020-03-30 15:33:32 +0100 | [diff] [blame] | 27 | // Extracted from SdkAware to make it easier to define custom subsets of the |
| 28 | // SdkAware interface and improve code navigation within the IDE. |
| 29 | // |
| 30 | // In addition to its use in SdkAware this interface must also be implemented by |
| 31 | // APEX to specify the SDKs required by that module and its contents. e.g. APEX |
| 32 | // is expected to implement RequiredSdks() by reading its own properties like |
| 33 | // `uses_sdks`. |
| 34 | type RequiredSdks interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 35 | // RequiredSdks returns the set of SDKs required by an APEX and its contents. |
Paul Duffin | 923e8a5 | 2020-03-30 15:33:32 +0100 | [diff] [blame] | 36 | RequiredSdks() SdkRefs |
| 37 | } |
| 38 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 39 | // sdkAwareWithoutModule is provided simply to improve code navigation with the IDE. |
Paul Duffin | 50f0da4 | 2020-07-22 13:52:01 +0100 | [diff] [blame] | 40 | type sdkAwareWithoutModule interface { |
Paul Duffin | 923e8a5 | 2020-03-30 15:33:32 +0100 | [diff] [blame] | 41 | RequiredSdks |
| 42 | |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 43 | // SdkMemberComponentName will return the name to use for a component of this module based on the |
| 44 | // base name of this module. |
| 45 | // |
| 46 | // The baseName is the name returned by ModuleBase.BaseModuleName(), i.e. the name specified in |
| 47 | // the name property in the .bp file so will not include the prebuilt_ prefix. |
| 48 | // |
| 49 | // The componentNameCreator is a func for creating the name of a component from the base name of |
| 50 | // the module, e.g. it could just append ".component" to the name passed in. |
| 51 | // |
| 52 | // This is intended to be called by prebuilt modules that create component models. It is because |
| 53 | // prebuilt module base names come in a variety of different forms: |
| 54 | // * unversioned - this is the same as the source module. |
| 55 | // * internal to an sdk - this is the unversioned name prefixed by the base name of the sdk |
| 56 | // module. |
| 57 | // * versioned - this is the same as the internal with the addition of an "@<version>" suffix. |
| 58 | // |
| 59 | // While this can be called from a source module in that case it will behave the same way as the |
| 60 | // unversioned name and return the result of calling the componentNameCreator func on the supplied |
| 61 | // base name. |
| 62 | // |
| 63 | // e.g. Assuming the componentNameCreator func simply appends ".component" to the name passed in |
| 64 | // then this will work as follows: |
| 65 | // * An unversioned name of "foo" will return "foo.component". |
| 66 | // * An internal to the sdk name of "sdk_foo" will return "sdk_foo.component". |
| 67 | // * A versioned name of "sdk_foo@current" will return "sdk_foo.component@current". |
| 68 | // |
| 69 | // Note that in the latter case the ".component" suffix is added before the version. Adding it |
| 70 | // after would change the version. |
| 71 | SdkMemberComponentName(baseName string, componentNameCreator func(string) string) string |
| 72 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 73 | sdkBase() *SdkBase |
| 74 | MakeMemberOf(sdk SdkRef) |
| 75 | IsInAnySdk() bool |
Paul Duffin | b9e7a3c | 2021-05-06 15:53:19 +0100 | [diff] [blame] | 76 | |
| 77 | // IsVersioned determines whether the module is versioned, i.e. has a name of the form |
| 78 | // <name>@<version> |
| 79 | IsVersioned() bool |
| 80 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 81 | ContainingSdk() SdkRef |
| 82 | MemberName() string |
| 83 | BuildWithSdks(sdks SdkRefs) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 84 | } |
| 85 | |
Paul Duffin | 50f0da4 | 2020-07-22 13:52:01 +0100 | [diff] [blame] | 86 | // SdkAware is the interface that must be supported by any module to become a member of SDK or to be |
| 87 | // built with SDK |
| 88 | type SdkAware interface { |
| 89 | Module |
| 90 | sdkAwareWithoutModule |
| 91 | } |
| 92 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 93 | // SdkRef refers to a version of an SDK |
| 94 | type SdkRef struct { |
| 95 | Name string |
| 96 | Version string |
| 97 | } |
| 98 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 99 | // Unversioned determines if the SdkRef is referencing to the unversioned SDK module |
| 100 | func (s SdkRef) Unversioned() bool { |
| 101 | return s.Version == "" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 104 | // String returns string representation of this SdkRef for debugging purpose |
| 105 | func (s SdkRef) String() string { |
| 106 | if s.Name == "" { |
| 107 | return "(No Sdk)" |
| 108 | } |
| 109 | if s.Unversioned() { |
| 110 | return s.Name |
| 111 | } |
| 112 | return s.Name + string(SdkVersionSeparator) + s.Version |
| 113 | } |
| 114 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 115 | // SdkVersionSeparator is a character used to separate an sdk name and its version |
| 116 | const SdkVersionSeparator = '@' |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 117 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 118 | // ParseSdkRef parses a `name@version` style string into a corresponding SdkRef struct |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 119 | func ParseSdkRef(ctx BaseModuleContext, str string, property string) SdkRef { |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 120 | tokens := strings.Split(str, string(SdkVersionSeparator)) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 121 | if len(tokens) < 1 || len(tokens) > 2 { |
Paul Duffin | 525a590 | 2021-05-06 16:33:52 +0100 | [diff] [blame] | 122 | ctx.PropertyErrorf(property, "%q does not follow name@version syntax", str) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 123 | return SdkRef{Name: "invalid sdk name", Version: "invalid sdk version"} |
| 124 | } |
| 125 | |
| 126 | name := tokens[0] |
| 127 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 128 | var version string |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 129 | if len(tokens) == 2 { |
| 130 | version = tokens[1] |
| 131 | } |
| 132 | |
| 133 | return SdkRef{Name: name, Version: version} |
| 134 | } |
| 135 | |
| 136 | type SdkRefs []SdkRef |
| 137 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 138 | // 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] | 139 | func (refs SdkRefs) Contains(s SdkRef) bool { |
| 140 | for _, r := range refs { |
| 141 | if r == s { |
| 142 | return true |
| 143 | } |
| 144 | } |
| 145 | return false |
| 146 | } |
| 147 | |
| 148 | type sdkProperties struct { |
| 149 | // The SDK that this module is a member of. nil if it is not a member of any SDK |
| 150 | ContainingSdk *SdkRef `blueprint:"mutated"` |
| 151 | |
| 152 | // The list of SDK names and versions that are used to build this module |
| 153 | RequiredSdks SdkRefs `blueprint:"mutated"` |
| 154 | |
| 155 | // Name of the module that this sdk member is representing |
| 156 | Sdk_member_name *string |
| 157 | } |
| 158 | |
| 159 | // SdkBase is a struct that is expected to be included in module types to implement the SdkAware |
| 160 | // interface. InitSdkAwareModule should be called to initialize this struct. |
| 161 | type SdkBase struct { |
| 162 | properties sdkProperties |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 163 | module SdkAware |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | func (s *SdkBase) sdkBase() *SdkBase { |
| 167 | return s |
| 168 | } |
| 169 | |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 170 | func (s *SdkBase) SdkMemberComponentName(baseName string, componentNameCreator func(string) string) string { |
| 171 | if s.MemberName() == "" { |
| 172 | return componentNameCreator(baseName) |
| 173 | } else { |
| 174 | index := strings.LastIndex(baseName, "@") |
| 175 | unversionedName := baseName[:index] |
| 176 | unversionedComponentName := componentNameCreator(unversionedName) |
| 177 | versionSuffix := baseName[index:] |
| 178 | return unversionedComponentName + versionSuffix |
| 179 | } |
| 180 | } |
| 181 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 182 | // MakeMemberOf sets this module to be a member of a specific SDK |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 183 | func (s *SdkBase) MakeMemberOf(sdk SdkRef) { |
| 184 | s.properties.ContainingSdk = &sdk |
| 185 | } |
| 186 | |
| 187 | // IsInAnySdk returns true if this module is a member of any SDK |
| 188 | func (s *SdkBase) IsInAnySdk() bool { |
| 189 | return s.properties.ContainingSdk != nil |
| 190 | } |
| 191 | |
Paul Duffin | b9e7a3c | 2021-05-06 15:53:19 +0100 | [diff] [blame] | 192 | // IsVersioned returns true if this module is versioned. |
| 193 | func (s *SdkBase) IsVersioned() bool { |
| 194 | return strings.Contains(s.module.Name(), "@") |
| 195 | } |
| 196 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 197 | // ContainingSdk returns the SDK that this module is a member of |
| 198 | func (s *SdkBase) ContainingSdk() SdkRef { |
| 199 | if s.properties.ContainingSdk != nil { |
| 200 | return *s.properties.ContainingSdk |
| 201 | } |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 202 | return SdkRef{Name: "", Version: ""} |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 203 | } |
| 204 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 205 | // 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] | 206 | func (s *SdkBase) MemberName() string { |
| 207 | return proptools.String(s.properties.Sdk_member_name) |
| 208 | } |
| 209 | |
| 210 | // BuildWithSdks is used to mark that this module has to be built with the given SDK(s). |
| 211 | func (s *SdkBase) BuildWithSdks(sdks SdkRefs) { |
| 212 | s.properties.RequiredSdks = sdks |
| 213 | } |
| 214 | |
| 215 | // RequiredSdks returns the SDK(s) that this module has to be built with |
| 216 | func (s *SdkBase) RequiredSdks() SdkRefs { |
| 217 | return s.properties.RequiredSdks |
| 218 | } |
| 219 | |
| 220 | // InitSdkAwareModule initializes the SdkBase struct. This must be called by all modules including |
| 221 | // SdkBase. |
| 222 | func InitSdkAwareModule(m SdkAware) { |
| 223 | base := m.sdkBase() |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 224 | base.module = m |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 225 | m.AddProperties(&base.properties) |
| 226 | } |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 227 | |
Paul Duffin | 0c2e083 | 2021-04-28 00:39:52 +0100 | [diff] [blame] | 228 | // IsModuleInVersionedSdk returns true if the module is an versioned sdk. |
| 229 | func IsModuleInVersionedSdk(module Module) bool { |
| 230 | if s, ok := module.(SdkAware); ok { |
| 231 | if !s.ContainingSdk().Unversioned() { |
| 232 | return true |
| 233 | } |
| 234 | } |
| 235 | return false |
| 236 | } |
| 237 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 238 | // 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] | 239 | type SnapshotBuilder interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 240 | // CopyToSnapshot generates a rule that will copy the src to the dest (which is a snapshot |
| 241 | // relative path) and add the dest to the zip. |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 242 | CopyToSnapshot(src Path, dest string) |
| 243 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 244 | // EmptyFile returns the path to an empty file. |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 245 | // |
| 246 | // This can be used by sdk member types that need to create an empty file in the snapshot, simply |
| 247 | // pass the value returned from this to the CopyToSnapshot() method. |
| 248 | EmptyFile() Path |
| 249 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 250 | // UnzipToSnapshot generates a rule that will unzip the supplied zip into the snapshot relative |
| 251 | // directory destDir. |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 252 | UnzipToSnapshot(zipPath Path, destDir string) |
| 253 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 254 | // AddPrebuiltModule adds a new prebuilt module to the snapshot. |
| 255 | // |
| 256 | // It is intended to be called from SdkMemberType.AddPrebuiltModule which can add module type |
| 257 | // specific properties that are not variant specific. The following properties will be |
| 258 | // automatically populated before returning. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 259 | // |
| 260 | // * name |
| 261 | // * sdk_member_name |
| 262 | // * prefer |
| 263 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 264 | // Properties that are variant specific will be handled by SdkMemberProperties structure. |
| 265 | // |
| 266 | // Each module created by this method can be output to the generated Android.bp file in two |
| 267 | // different forms, depending on the setting of the SOONG_SDK_SNAPSHOT_VERSION build property. |
| 268 | // The two forms are: |
| 269 | // 1. A versioned Soong module that is referenced from a corresponding similarly versioned |
| 270 | // snapshot module. |
| 271 | // 2. An unversioned Soong module that. |
| 272 | // |
| 273 | // See sdk/update.go for more information. |
Paul Duffin | 9d8d609 | 2019-12-05 18:19:29 +0000 | [diff] [blame] | 274 | AddPrebuiltModule(member SdkMember, moduleType string) BpModule |
Paul Duffin | 7b81f5e | 2020-01-13 21:03:22 +0000 | [diff] [blame] | 275 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 276 | // SdkMemberReferencePropertyTag returns a property tag to use when adding a property to a |
| 277 | // BpModule that contains references to other sdk members. |
Paul Duffin | 7b81f5e | 2020-01-13 21:03:22 +0000 | [diff] [blame] | 278 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 279 | // Using this will ensure that the reference is correctly output for both versioned and |
| 280 | // unversioned prebuilts in the snapshot. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 281 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 282 | // "required: true" means that the property must only contain references to other members of the |
| 283 | // sdk. Passing a reference to a module that is not a member of the sdk will result in a build |
| 284 | // error. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 285 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 286 | // "required: false" means that the property can contain references to modules that are either |
| 287 | // members or not members of the sdk. If a reference is to a module that is a non member then the |
| 288 | // reference is left unchanged, i.e. it is not transformed as references to members are. |
| 289 | // |
| 290 | // The handling of the member names is dependent on whether it is an internal or exported member. |
| 291 | // An exported member is one whose name is specified in one of the member type specific |
| 292 | // properties. An internal member is one that is added due to being a part of an exported (or |
| 293 | // other internal) member and is not itself an exported member. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 294 | // |
| 295 | // Member names are handled as follows: |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 296 | // * When creating the unversioned form of the module the name is left unchecked unless the member |
| 297 | // is internal in which case it is transformed into an sdk specific name, i.e. by prefixing with |
| 298 | // the sdk name. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 299 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 300 | // * When creating the versioned form of the module the name is transformed into a versioned sdk |
| 301 | // 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] | 302 | // |
Paul Duffin | 7b81f5e | 2020-01-13 21:03:22 +0000 | [diff] [blame] | 303 | // e.g. |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 304 | // bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag(true)) |
| 305 | SdkMemberReferencePropertyTag(required bool) BpPropertyTag |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 308 | // BpPropertyTag is a marker interface that can be associated with properties in a BpPropertySet to |
| 309 | // provide additional information which can be used to customize their behavior. |
Paul Duffin | 5b511a2 | 2020-01-15 14:23:52 +0000 | [diff] [blame] | 310 | type BpPropertyTag interface{} |
| 311 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 312 | // BpPropertySet is a set of properties for use in a .bp file. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 313 | type BpPropertySet interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 314 | // AddProperty adds a property. |
| 315 | // |
| 316 | // The value can be one of the following types: |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 317 | // * string |
| 318 | // * array of the above |
| 319 | // * bool |
Martin Stjernholm | 191c25f | 2020-09-10 00:40:37 +0100 | [diff] [blame] | 320 | // For these types it is an error if multiple properties with the same name |
| 321 | // are added. |
| 322 | // |
| 323 | // * pointer to a struct |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 324 | // * BpPropertySet |
| 325 | // |
Martin Stjernholm | 191c25f | 2020-09-10 00:40:37 +0100 | [diff] [blame] | 326 | // A pointer to a Blueprint-style property struct is first converted into a |
| 327 | // BpPropertySet by traversing the fields and adding their values as |
| 328 | // properties in a BpPropertySet. A field with a struct value is itself |
| 329 | // converted into a BpPropertySet before adding. |
| 330 | // |
| 331 | // Adding a BpPropertySet is done as follows: |
| 332 | // * If no property with the name exists then the BpPropertySet is added |
| 333 | // directly to this property. Care must be taken to ensure that it does not |
| 334 | // introduce a cycle. |
| 335 | // * If a property exists with the name and the current value is a |
| 336 | // BpPropertySet then every property of the new BpPropertySet is added to |
| 337 | // the existing BpPropertySet. |
| 338 | // * 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] | 339 | AddProperty(name string, value interface{}) |
| 340 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 341 | // AddPropertyWithTag adds a property with an associated property tag. |
Paul Duffin | 5b511a2 | 2020-01-15 14:23:52 +0000 | [diff] [blame] | 342 | AddPropertyWithTag(name string, value interface{}, tag BpPropertyTag) |
| 343 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 344 | // AddPropertySet adds a property set with the specified name and returns it so that additional |
| 345 | // properties can be added to it. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 346 | AddPropertySet(name string) BpPropertySet |
Paul Duffin | 0df4968 | 2021-05-07 01:10:01 +0100 | [diff] [blame] | 347 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 348 | // AddCommentForProperty adds a comment for the named property (or property set). |
Paul Duffin | 0df4968 | 2021-05-07 01:10:01 +0100 | [diff] [blame] | 349 | AddCommentForProperty(name, text string) |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 352 | // BpModule represents a module definition in a .bp file. |
Paul Duffin | b645ec8 | 2019-11-27 17:43:54 +0000 | [diff] [blame] | 353 | type BpModule interface { |
| 354 | BpPropertySet |
Paul Duffin | 0df4968 | 2021-05-07 01:10:01 +0100 | [diff] [blame] | 355 | |
| 356 | // ModuleType returns the module type of the module |
| 357 | ModuleType() string |
| 358 | |
| 359 | // Name returns the name of the module or "" if no name has been specified. |
| 360 | Name() string |
Paul Duffin | 0e0cf1d | 2019-11-12 19:39:25 +0000 | [diff] [blame] | 361 | } |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 362 | |
Paul Duffin | 51227d8 | 2021-05-18 12:54:27 +0100 | [diff] [blame] | 363 | // BpPrintable is a marker interface that must be implemented by any struct that is added as a |
| 364 | // property value. |
| 365 | type BpPrintable interface { |
| 366 | bpPrintable() |
| 367 | } |
| 368 | |
| 369 | // BpPrintableBase must be embedded within any struct that is added as a |
| 370 | // property value. |
| 371 | type BpPrintableBase struct { |
| 372 | } |
| 373 | |
| 374 | func (b BpPrintableBase) bpPrintable() { |
| 375 | } |
| 376 | |
| 377 | var _ BpPrintable = BpPrintableBase{} |
| 378 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 379 | // SdkMember is an individual member of the SDK. |
| 380 | // |
| 381 | // It includes all of the variants that the SDK depends upon. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 382 | type SdkMember interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 383 | // Name returns the name of the member. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 384 | Name() string |
| 385 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 386 | // 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] | 387 | Variants() []SdkAware |
| 388 | } |
| 389 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 390 | // 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] | 391 | // dependent module to be automatically added to the sdk. |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 392 | type SdkMemberDependencyTag interface { |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 393 | blueprint.DependencyTag |
| 394 | |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 395 | // SdkMemberType returns the SdkMemberType that will be used to automatically add the child module |
| 396 | // to the sdk. |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 397 | // |
| 398 | // Returning nil will prevent the module being added to the sdk. |
Paul Duffin | eee466e | 2021-04-27 23:17:56 +0100 | [diff] [blame] | 399 | SdkMemberType(child Module) SdkMemberType |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 400 | |
| 401 | // ExportMember determines whether a module added to the sdk through this tag will be exported |
| 402 | // from the sdk or not. |
| 403 | // |
| 404 | // An exported member is added to the sdk using its own name, e.g. if "foo" was exported from sdk |
| 405 | // "bar" then its prebuilt would be simply called "foo". A member can be added to the sdk via |
| 406 | // multiple tags and if any of those tags returns true from this method then the membe will be |
| 407 | // exported. Every module added directly to the sdk via one of the member type specific |
| 408 | // properties, e.g. java_libs, will automatically be exported. |
| 409 | // |
| 410 | // If a member is not exported then it is treated as an internal implementation detail of the |
| 411 | // sdk and so will be added with an sdk specific name. e.g. if "foo" was an internal member of sdk |
| 412 | // "bar" then its prebuilt would be called "bar_foo". Additionally its visibility will be set to |
| 413 | // "//visibility:private" so it will not be accessible from outside its Android.bp file. |
| 414 | ExportMember() bool |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 417 | var _ SdkMemberDependencyTag = (*sdkMemberDependencyTag)(nil) |
| 418 | var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil) |
Paul Duffin | cee7e66 | 2020-07-09 17:32:57 +0100 | [diff] [blame] | 419 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 420 | type sdkMemberDependencyTag struct { |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 421 | blueprint.BaseDependencyTag |
| 422 | memberType SdkMemberType |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 423 | export bool |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 426 | func (t *sdkMemberDependencyTag) SdkMemberType(_ Module) SdkMemberType { |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 427 | return t.memberType |
| 428 | } |
| 429 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 430 | func (t *sdkMemberDependencyTag) ExportMember() bool { |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 431 | return t.export |
| 432 | } |
| 433 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 434 | // ReplaceSourceWithPrebuilt prevents dependencies from the sdk/module_exports onto their members |
| 435 | // from being replaced with a preferred prebuilt. |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 436 | func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool { |
Paul Duffin | cee7e66 | 2020-07-09 17:32:57 +0100 | [diff] [blame] | 437 | return false |
| 438 | } |
| 439 | |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 440 | // DependencyTagForSdkMemberType creates an SdkMemberDependencyTag that will cause any |
Paul Duffin | a720811 | 2021-04-23 21:20:20 +0100 | [diff] [blame] | 441 | // dependencies added by the tag to be added to the sdk as the specified SdkMemberType and exported |
| 442 | // (or not) as specified by the export parameter. |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 443 | func DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMemberDependencyTag { |
| 444 | return &sdkMemberDependencyTag{memberType: memberType, export: export} |
Paul Duffin | f853992 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 447 | // 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] | 448 | // sdk. |
| 449 | // |
| 450 | // The basic implementation should look something like this, where ModuleType is |
| 451 | // the name of the module type being supported. |
| 452 | // |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 453 | // type moduleTypeSdkMemberType struct { |
| 454 | // android.SdkMemberTypeBase |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 455 | // } |
| 456 | // |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 457 | // func init() { |
| 458 | // android.RegisterSdkMemberType(&moduleTypeSdkMemberType{ |
| 459 | // SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 460 | // PropertyName: "module_types", |
| 461 | // }, |
| 462 | // } |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 463 | // } |
| 464 | // |
| 465 | // ...methods... |
| 466 | // |
| 467 | type SdkMemberType interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 468 | // 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] | 469 | SdkPropertyName() string |
| 470 | |
Paul Duffin | 1308205 | 2021-05-11 00:31:38 +0100 | [diff] [blame] | 471 | // RequiresBpProperty returns true if this member type requires its property to be usable within |
| 472 | // an Android.bp file. |
| 473 | RequiresBpProperty() bool |
| 474 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 475 | // UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot, |
| 476 | // false otherwise. |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 477 | UsableWithSdkAndSdkSnapshot() bool |
| 478 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 479 | // IsHostOsDependent returns true if prebuilt host artifacts may be specific to the host OS. Only |
| 480 | // applicable to modules where HostSupported() is true. If this is true, snapshots will list each |
| 481 | // host OS variant explicitly and disable all other host OS'es. |
Martin Stjernholm | caa47d7 | 2020-07-11 04:52:24 +0100 | [diff] [blame] | 482 | IsHostOsDependent() bool |
| 483 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 484 | // AddDependencies adds dependencies from the SDK module to all the module variants the member |
| 485 | // type contributes to the SDK. `names` is the list of module names given in the member type |
| 486 | // property (as returned by SdkPropertyName()) in the SDK module. The exact set of variants |
| 487 | // required is determined by the SDK and its properties. The dependencies must be added with the |
| 488 | // supplied tag. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 489 | // |
| 490 | // The BottomUpMutatorContext provided is for the SDK module. |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 491 | AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 492 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 493 | // 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] | 494 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 495 | // This is used to check the type of each variant before added to the SdkMember. Returning false |
| 496 | // will cause an error to be logged explaining that the module is not allowed in whichever sdk |
| 497 | // property it was added. |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 498 | IsInstance(module Module) bool |
| 499 | |
Paul Duffin | 0d4ed0a | 2021-05-10 23:58:40 +0100 | [diff] [blame] | 500 | // UsesSourceModuleTypeInSnapshot returns true when the AddPrebuiltModule() method returns a |
| 501 | // source module type. |
| 502 | UsesSourceModuleTypeInSnapshot() bool |
| 503 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 504 | // 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] | 505 | // |
Paul Duffin | 425b0ea | 2020-05-06 12:41:39 +0100 | [diff] [blame] | 506 | // The sdk module code generates the snapshot as follows: |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 507 | // |
| 508 | // * A properties struct of type SdkMemberProperties is created for each variant and |
| 509 | // populated with information from the variant by calling PopulateFromVariant(SdkAware) |
| 510 | // on the struct. |
| 511 | // |
| 512 | // * An additional properties struct is created into which the common properties will be |
| 513 | // added. |
| 514 | // |
| 515 | // * The variant property structs are analysed to find exported (capitalized) fields which |
| 516 | // 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] | 517 | // properties. |
| 518 | // |
| 519 | // A field annotated with a tag of `sdk:"keep"` will be treated as if it |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 520 | // was not capitalized, i.e. not optimized for common values. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 521 | // |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 522 | // A field annotated with a tag of `android:"arch_variant"` will be allowed to have |
| 523 | // values that differ by arch, fields not tagged as such must have common values across |
| 524 | // all variants. |
| 525 | // |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 526 | // * Additional field tags can be specified on a field that will ignore certain values |
| 527 | // for the purpose of common value optimization. A value that is ignored must have the |
| 528 | // default value for the property type. This is to ensure that significant value are not |
| 529 | // ignored by accident. The purpose of this is to allow the snapshot generation to reflect |
| 530 | // the behavior of the runtime. e.g. if a property is ignored on the host then a property |
| 531 | // that is common for android can be treated as if it was common for android and host as |
| 532 | // the setting for host is ignored anyway. |
| 533 | // * `sdk:"ignored-on-host" - this indicates the property is ignored on the host variant. |
| 534 | // |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 535 | // * The sdk module type populates the BpModule structure, creating the arch specific |
| 536 | // structure and calls AddToPropertySet(...) on the properties struct to add the member |
| 537 | // specific properties in the correct place in the structure. |
| 538 | // |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 539 | AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 540 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 541 | // CreateVariantPropertiesStruct creates a structure into which variant specific properties can be |
| 542 | // added. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 543 | CreateVariantPropertiesStruct() SdkMemberProperties |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 544 | } |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 545 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 546 | // SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies() |
| 547 | // implementations. |
| 548 | type SdkDependencyContext interface { |
| 549 | BottomUpMutatorContext |
| 550 | } |
| 551 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 552 | // SdkMemberTypeBase is the base type for SdkMemberType implementations and must be embedded in any |
| 553 | // struct that implements SdkMemberType. |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 554 | type SdkMemberTypeBase struct { |
Paul Duffin | 1308205 | 2021-05-11 00:31:38 +0100 | [diff] [blame] | 555 | PropertyName string |
| 556 | |
| 557 | // When set to true BpPropertyNotRequired indicates that the member type does not require the |
| 558 | // property to be specifiable in an Android.bp file. |
| 559 | BpPropertyNotRequired bool |
| 560 | |
Paul Duffin | 2d3da31 | 2021-05-06 12:02:27 +0100 | [diff] [blame] | 561 | SupportsSdk bool |
| 562 | HostOsDependent bool |
Paul Duffin | 0d4ed0a | 2021-05-10 23:58:40 +0100 | [diff] [blame] | 563 | |
| 564 | // When set to true UseSourceModuleTypeInSnapshot indicates that the member type creates a source |
| 565 | // module type in its SdkMemberType.AddPrebuiltModule() method. That prevents the sdk snapshot |
| 566 | // code from automatically adding a prefer: true flag. |
| 567 | UseSourceModuleTypeInSnapshot bool |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | func (b *SdkMemberTypeBase) SdkPropertyName() string { |
| 571 | return b.PropertyName |
| 572 | } |
| 573 | |
Paul Duffin | 1308205 | 2021-05-11 00:31:38 +0100 | [diff] [blame] | 574 | func (b *SdkMemberTypeBase) RequiresBpProperty() bool { |
| 575 | return !b.BpPropertyNotRequired |
| 576 | } |
| 577 | |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 578 | func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool { |
| 579 | return b.SupportsSdk |
| 580 | } |
| 581 | |
Martin Stjernholm | caa47d7 | 2020-07-11 04:52:24 +0100 | [diff] [blame] | 582 | func (b *SdkMemberTypeBase) IsHostOsDependent() bool { |
| 583 | return b.HostOsDependent |
| 584 | } |
| 585 | |
Paul Duffin | 0d4ed0a | 2021-05-10 23:58:40 +0100 | [diff] [blame] | 586 | func (b *SdkMemberTypeBase) UsesSourceModuleTypeInSnapshot() bool { |
| 587 | return b.UseSourceModuleTypeInSnapshot |
| 588 | } |
| 589 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 590 | // SdkMemberTypesRegistry encapsulates the information about registered SdkMemberTypes. |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 591 | type SdkMemberTypesRegistry struct { |
| 592 | // The list of types sorted by property name. |
| 593 | list []SdkMemberType |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 596 | func (r *SdkMemberTypesRegistry) copyAndAppend(memberType SdkMemberType) *SdkMemberTypesRegistry { |
| 597 | oldList := r.list |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 598 | |
| 599 | // Copy the slice just in case this is being read while being modified, e.g. when testing. |
| 600 | list := make([]SdkMemberType, 0, len(oldList)+1) |
| 601 | list = append(list, oldList...) |
| 602 | list = append(list, memberType) |
| 603 | |
| 604 | // Sort the member types by their property name to ensure that registry order has no effect |
| 605 | // on behavior. |
| 606 | sort.Slice(list, func(i1, i2 int) bool { |
| 607 | t1 := list[i1] |
| 608 | t2 := list[i2] |
| 609 | |
| 610 | return t1.SdkPropertyName() < t2.SdkPropertyName() |
| 611 | }) |
| 612 | |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 613 | // Create a new registry so the pointer uniquely identifies the set of registered types. |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 614 | return &SdkMemberTypesRegistry{ |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 615 | list: list, |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 618 | |
| 619 | func (r *SdkMemberTypesRegistry) RegisteredTypes() []SdkMemberType { |
| 620 | return r.list |
| 621 | } |
| 622 | |
| 623 | func (r *SdkMemberTypesRegistry) UniqueOnceKey() OnceKey { |
| 624 | // Use the pointer to the registry as the unique key. |
| 625 | return NewCustomOnceKey(r) |
| 626 | } |
| 627 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 628 | // ModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports modules. |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 629 | var ModuleExportsMemberTypes = &SdkMemberTypesRegistry{} |
Paul Duffin | 62782de | 2021-07-14 12:05:16 +0100 | [diff] [blame] | 630 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 631 | // SdkMemberTypes is the set of registered SdkMemberTypes for sdk modules. |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 632 | var SdkMemberTypes = &SdkMemberTypesRegistry{} |
| 633 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 634 | // RegisterSdkMemberType registers an SdkMemberType object to allow them to be used in the |
| 635 | // module_exports, module_exports_snapshot and (depending on the value returned from |
| 636 | // SdkMemberType.UsableWithSdkAndSdkSnapshot) the sdk and sdk_snapshot module types. |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 637 | func RegisterSdkMemberType(memberType SdkMemberType) { |
| 638 | // All member types are usable with module_exports. |
| 639 | ModuleExportsMemberTypes = ModuleExportsMemberTypes.copyAndAppend(memberType) |
| 640 | |
| 641 | // Only those that explicitly indicate it are usable with sdk. |
| 642 | if memberType.UsableWithSdkAndSdkSnapshot() { |
| 643 | SdkMemberTypes = SdkMemberTypes.copyAndAppend(memberType) |
| 644 | } |
| 645 | } |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 646 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 647 | // SdkMemberPropertiesBase is the base structure for all implementations of SdkMemberProperties and |
| 648 | // must be embedded in any struct that implements SdkMemberProperties. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 649 | // |
Martin Stjernholm | 89238f4 | 2020-07-10 00:14:03 +0100 | [diff] [blame] | 650 | // Contains common properties that apply across many different member types. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 651 | type SdkMemberPropertiesBase struct { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 652 | // The number of unique os types supported by the member variants. |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 653 | // |
| 654 | // If a member has a variant with more than one os type then it will need to differentiate |
| 655 | // the locations of any of their prebuilt files in the snapshot by os type to prevent them |
| 656 | // from colliding. See OsPrefix(). |
| 657 | // |
| 658 | // This property is the same for all variants of a member and so would be optimized away |
| 659 | // if it was not explicitly kept. |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 660 | Os_count int `sdk:"keep"` |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 661 | |
| 662 | // The os type for which these properties refer. |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 663 | // |
| 664 | // Provided to allow a member to differentiate between os types in the locations of their |
| 665 | // prebuilt files when it supports more than one os type. |
| 666 | // |
| 667 | // This property is the same for all os type specific variants of a member and so would be |
| 668 | // optimized away if it was not explicitly kept. |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 669 | Os OsType `sdk:"keep"` |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 670 | |
| 671 | // The setting to use for the compile_multilib property. |
Martin Stjernholm | 89238f4 | 2020-07-10 00:14:03 +0100 | [diff] [blame] | 672 | Compile_multilib string `android:"arch_variant"` |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 675 | // 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] | 676 | // |
| 677 | // Is an empty string if the member only provides variants for a single os type, otherwise |
| 678 | // is the OsType.Name. |
| 679 | func (b *SdkMemberPropertiesBase) OsPrefix() string { |
| 680 | if b.Os_count == 1 { |
| 681 | return "" |
| 682 | } else { |
| 683 | return b.Os.Name |
| 684 | } |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | func (b *SdkMemberPropertiesBase) Base() *SdkMemberPropertiesBase { |
| 688 | return b |
| 689 | } |
| 690 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 691 | // SdkMemberProperties is the interface to be implemented on top of a structure that contains |
| 692 | // variant specific information. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 693 | // |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 694 | // Struct fields that are capitalized are examined for common values to extract. Fields that are not |
| 695 | // capitalized are assumed to be arch specific. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 696 | type SdkMemberProperties interface { |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 697 | // Base returns the base structure. |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 698 | Base() *SdkMemberPropertiesBase |
| 699 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 700 | // PopulateFromVariant populates this structure with information from a module variant. |
| 701 | // |
| 702 | // 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] | 703 | PopulateFromVariant(ctx SdkMemberContext, variant Module) |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 704 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 705 | // AddToPropertySet adds the information from this structure to the property set. |
| 706 | // |
| 707 | // This will be called for each instance of this structure on which the PopulateFromVariant method |
| 708 | // was called and also on a number of different instances of this structure into which properties |
| 709 | // common to one or more variants have been copied. Therefore, implementations of this must handle |
| 710 | // the case when this structure is only partially populated. |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 711 | AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet) |
| 712 | } |
| 713 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 714 | // SdkMemberContext provides access to information common to a specific member. |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 715 | type SdkMemberContext interface { |
| 716 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 717 | // SdkModuleContext returns the module context of the sdk common os variant which is creating the |
| 718 | // snapshot. |
| 719 | // |
| 720 | // This is common to all members of the sdk and is not specific to the member being processed. |
| 721 | // If information about the member being processed needs to be obtained from this ModuleContext it |
| 722 | // 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] | 723 | SdkModuleContext() ModuleContext |
| 724 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 725 | // SnapshotBuilder the builder of the snapshot. |
Paul Duffin | 3a4eb50 | 2020-03-19 16:11:18 +0000 | [diff] [blame] | 726 | SnapshotBuilder() SnapshotBuilder |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 727 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 728 | // MemberType returns the type of the member currently being processed. |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 729 | MemberType() SdkMemberType |
| 730 | |
Paul Duffin | 9428970 | 2021-09-09 15:38:32 +0100 | [diff] [blame^] | 731 | // Name returns the name of the member currently being processed. |
Paul Duffin | a551a1c | 2020-03-17 21:04:24 +0000 | [diff] [blame] | 732 | // |
| 733 | // Provided for use by sdk members to create a member specific location within the snapshot |
| 734 | // into which to copy the prebuilt files. |
| 735 | Name() string |
Paul Duffin | 88f2fbe | 2020-02-27 16:00:53 +0000 | [diff] [blame] | 736 | } |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 737 | |
| 738 | // ExportedComponentsInfo contains information about the components that this module exports to an |
| 739 | // sdk snapshot. |
| 740 | // |
| 741 | // A component of a module is a child module that the module creates and which forms an integral |
| 742 | // part of the functionality that the creating module provides. A component module is essentially |
| 743 | // owned by its creator and is tightly coupled to the creator and other components. |
| 744 | // |
| 745 | // e.g. the child modules created by prebuilt_apis are not components because they are not tightly |
| 746 | // coupled to the prebuilt_apis module. Once they are created the prebuilt_apis ignores them. The |
| 747 | // child impl and stub library created by java_sdk_library (and corresponding import) are components |
| 748 | // because the creating module depends upon them in order to provide some of its own functionality. |
| 749 | // |
| 750 | // A component is exported if it is part of an sdk snapshot. e.g. The xml and impl child modules are |
| 751 | // components but they are not exported as they are not part of an sdk snapshot. |
| 752 | // |
| 753 | // This information is used by the sdk snapshot generation code to ensure that it does not create |
| 754 | // an sdk snapshot that contains a declaration of the component module and the module that creates |
| 755 | // it as that would result in duplicate modules when attempting to use the snapshot. e.g. a snapshot |
| 756 | // that included the java_sdk_library_import "foo" and also a java_import "foo.stubs" would fail |
| 757 | // as there would be two modules called "foo.stubs". |
| 758 | type ExportedComponentsInfo struct { |
| 759 | // The names of the exported components. |
| 760 | Components []string |
| 761 | } |
| 762 | |
| 763 | var ExportedComponentsInfoProvider = blueprint.NewProvider(ExportedComponentsInfo{}) |