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 sdk |
| 16 | |
| 17 | import ( |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 18 | "fmt" |
Paul Duffin | 504b461 | 2019-11-22 14:52:29 +0000 | [diff] [blame] | 19 | "io" |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 20 | "strconv" |
| 21 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Jiyong Park | 100f3fd | 2019-11-06 16:03:32 +0900 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 24 | |
| 25 | "android/soong/android" |
| 26 | // This package doesn't depend on the apex package, but import it to make its mutators to be |
| 27 | // registered before mutators in this package. See RegisterPostDepsMutators for more details. |
| 28 | _ "android/soong/apex" |
| 29 | ) |
| 30 | |
| 31 | func init() { |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 32 | pctx.Import("android/soong/android") |
Paul Duffin | 375058f | 2019-11-29 20:17:53 +0000 | [diff] [blame] | 33 | pctx.Import("android/soong/java/config") |
| 34 | |
Paul Duffin | 6d9108f0 | 2021-03-09 22:59:28 +0000 | [diff] [blame] | 35 | registerSdkBuildComponents(android.InitRegistrationContext) |
| 36 | } |
| 37 | |
| 38 | func registerSdkBuildComponents(ctx android.RegistrationContext) { |
| 39 | ctx.RegisterModuleType("sdk", SdkModuleFactory) |
| 40 | ctx.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory) |
| 41 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | type sdk struct { |
| 45 | android.ModuleBase |
| 46 | android.DefaultableModuleBase |
| 47 | |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 48 | // The dynamically generated information about the registered SdkMemberType |
| 49 | dynamicSdkMemberTypes *dynamicSdkMemberTypes |
| 50 | |
Paul Duffin | 62782de | 2021-07-14 12:05:16 +0100 | [diff] [blame] | 51 | // The dynamically created instance of the properties struct containing the sdk member type |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 52 | // list properties, e.g. java_libs. |
| 53 | dynamicMemberTypeListProperties interface{} |
| 54 | |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 55 | // The dynamically generated information about the registered SdkMemberTrait |
| 56 | dynamicSdkMemberTraits *dynamicSdkMemberTraits |
| 57 | |
| 58 | // The dynamically created instance of the properties struct containing the sdk member trait |
| 59 | // list properties. |
| 60 | dynamicMemberTraitListProperties interface{} |
| 61 | |
Paul Duffin | 2182726 | 2021-04-24 12:16:36 +0100 | [diff] [blame] | 62 | // Information about the OsType specific member variants depended upon by this variant. |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 63 | // |
Paul Duffin | 6a7e953 | 2020-03-20 17:50:07 +0000 | [diff] [blame] | 64 | // Set by OsType specific variants in the collectMembers() method and used by the |
| 65 | // CommonOS variant when building the snapshot. That work is all done on separate |
| 66 | // calls to the sdk.GenerateAndroidBuildActions method which is guaranteed to be |
| 67 | // called for the OsType specific variants before the CommonOS variant (because |
| 68 | // the latter depends on the former). |
Paul Duffin | 2182726 | 2021-04-24 12:16:36 +0100 | [diff] [blame] | 69 | memberVariantDeps []sdkMemberVariantDep |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 70 | |
Paul Duffin | 6a7e953 | 2020-03-20 17:50:07 +0000 | [diff] [blame] | 71 | // The multilib variants that are used by this sdk variant. |
| 72 | multilibUsages multilibUsage |
| 73 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 74 | properties sdkProperties |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 75 | |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 76 | snapshotFile android.OptionalPath |
Paul Duffin | ac37c50 | 2019-11-26 18:02:20 +0000 | [diff] [blame] | 77 | |
Paul Duffin | c6ba182 | 2022-05-06 09:38:02 +0000 | [diff] [blame] | 78 | infoFile android.OptionalPath |
| 79 | |
Paul Duffin | ac37c50 | 2019-11-26 18:02:20 +0000 | [diff] [blame] | 80 | // The builder, preserved for testing. |
| 81 | builderForTests *snapshotBuilder |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | type sdkProperties struct { |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 85 | Snapshot bool `blueprint:"mutated"` |
Paul Duffin | 8150da6 | 2019-12-16 17:21:27 +0000 | [diff] [blame] | 86 | |
| 87 | // True if this is a module_exports (or module_exports_snapshot) module type. |
| 88 | Module_exports bool `blueprint:"mutated"` |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 89 | |
| 90 | // The additional visibility to add to the prebuilt modules to allow them to |
| 91 | // reference each other. |
| 92 | // |
| 93 | // This can only be used to widen the visibility of the members: |
| 94 | // |
| 95 | // * Specifying //visibility:public here will make all members visible and |
| 96 | // essentially ignore their own visibility. |
| 97 | // * Specifying //visibility:private here is an error. |
| 98 | // * Specifying any other rule here will add it to the members visibility and |
| 99 | // be output to the member prebuilt in the snapshot. Duplicates will be |
| 100 | // dropped. Adding a rule to members that have //visibility:private will |
| 101 | // cause the //visibility:private to be discarded. |
| 102 | Prebuilt_visibility []string |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // sdk defines an SDK which is a logical group of modules (e.g. native libs, headers, java libs, etc.) |
| 106 | // which Mainline modules like APEX can choose to build with. |
Paul Duffin | 8150da6 | 2019-12-16 17:21:27 +0000 | [diff] [blame] | 107 | func SdkModuleFactory() android.Module { |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 108 | return newSdkModule(false) |
Paul Duffin | 8150da6 | 2019-12-16 17:21:27 +0000 | [diff] [blame] | 109 | } |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 110 | |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 111 | func newSdkModule(moduleExports bool) *sdk { |
Paul Duffin | 8150da6 | 2019-12-16 17:21:27 +0000 | [diff] [blame] | 112 | s := &sdk{} |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 113 | s.properties.Module_exports = moduleExports |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 114 | // Get the dynamic sdk member type data for the currently registered sdk member types. |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 115 | sdkMemberTypeKey, sdkMemberTypes := android.RegisteredSdkMemberTypes(moduleExports) |
| 116 | s.dynamicSdkMemberTypes = getDynamicSdkMemberTypes(sdkMemberTypeKey, sdkMemberTypes) |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 117 | // Create an instance of the dynamically created struct that contains all the |
| 118 | // properties for the member type specific list properties. |
Paul Duffin | 62782de | 2021-07-14 12:05:16 +0100 | [diff] [blame] | 119 | s.dynamicMemberTypeListProperties = s.dynamicSdkMemberTypes.createMemberTypeListProperties() |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 120 | |
Paul Duffin | 30c830b | 2021-09-22 11:49:47 +0100 | [diff] [blame] | 121 | sdkMemberTraitsKey, sdkMemberTraits := android.RegisteredSdkMemberTraits() |
| 122 | s.dynamicSdkMemberTraits = getDynamicSdkMemberTraits(sdkMemberTraitsKey, sdkMemberTraits) |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 123 | // Create an instance of the dynamically created struct that contains all the properties for the |
| 124 | // member trait specific list properties. |
| 125 | s.dynamicMemberTraitListProperties = s.dynamicSdkMemberTraits.createMemberTraitListProperties() |
| 126 | |
| 127 | // Create a wrapper around the dynamic trait specific properties so that they have to be |
| 128 | // specified within a traits:{} section in the .bp file. |
| 129 | traitsWrapper := struct { |
| 130 | Traits interface{} |
| 131 | }{s.dynamicMemberTraitListProperties} |
| 132 | |
| 133 | s.AddProperties(&s.properties, s.dynamicMemberTypeListProperties, &traitsWrapper) |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 134 | |
| 135 | // Make sure that the prebuilt visibility property is verified for errors. |
| 136 | android.AddVisibilityProperty(s, "prebuilt_visibility", &s.properties.Prebuilt_visibility) |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 137 | android.InitCommonOSAndroidMultiTargetsArchModule(s, android.HostAndDeviceSupported, android.MultilibCommon) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 138 | android.InitDefaultableModule(s) |
Jiyong Park | 100f3fd | 2019-11-06 16:03:32 +0900 | [diff] [blame] | 139 | android.AddLoadHook(s, func(ctx android.LoadHookContext) { |
| 140 | type props struct { |
| 141 | Compile_multilib *string |
| 142 | } |
| 143 | p := &props{Compile_multilib: proptools.StringPtr("both")} |
Martin Stjernholm | 26ab8e8 | 2020-06-30 20:34:00 +0100 | [diff] [blame] | 144 | ctx.PrependProperties(p) |
Jiyong Park | 100f3fd | 2019-11-06 16:03:32 +0900 | [diff] [blame] | 145 | }) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 146 | return s |
| 147 | } |
| 148 | |
Paul Duffin | b01ac4b | 2022-05-24 20:10:05 +0000 | [diff] [blame^] | 149 | // sdk_snapshot is a snapshot of an SDK. This is an auto-generated module. |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 150 | func SnapshotModuleFactory() android.Module { |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 151 | s := newSdkModule(false) |
Paul Duffin | 8150da6 | 2019-12-16 17:21:27 +0000 | [diff] [blame] | 152 | s.properties.Snapshot = true |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 153 | return s |
| 154 | } |
| 155 | |
Paul Duffin | 62782de | 2021-07-14 12:05:16 +0100 | [diff] [blame] | 156 | func (s *sdk) memberTypeListProperties() []*sdkMemberTypeListProperty { |
| 157 | return s.dynamicSdkMemberTypes.memberTypeListProperties |
Paul Duffin | 7291095 | 2020-01-20 18:16:30 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Paul Duffin | 62782de | 2021-07-14 12:05:16 +0100 | [diff] [blame] | 160 | func (s *sdk) memberTypeListProperty(memberType android.SdkMemberType) *sdkMemberTypeListProperty { |
Paul Duffin | cd06467 | 2021-04-24 00:47:29 +0100 | [diff] [blame] | 161 | return s.dynamicSdkMemberTypes.memberTypeToProperty[memberType] |
| 162 | } |
| 163 | |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 164 | // memberTraitListProperties returns the list of *sdkMemberTraitListProperty instances for this sdk. |
| 165 | func (s *sdk) memberTraitListProperties() []*sdkMemberTraitListProperty { |
| 166 | return s.dynamicSdkMemberTraits.memberTraitListProperties |
| 167 | } |
| 168 | |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 169 | func (s *sdk) snapshot() bool { |
| 170 | return s.properties.Snapshot |
| 171 | } |
| 172 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 173 | func (s *sdk) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 174 | if s.snapshot() { |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 175 | // We don't need to create a snapshot out of sdk_snapshot. |
| 176 | // That doesn't make sense. We need a snapshot to create sdk_snapshot. |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 177 | return |
| 178 | } |
| 179 | |
| 180 | // This method is guaranteed to be called on OsType specific variants before it is called |
| 181 | // on their corresponding CommonOS variant. |
| 182 | if !s.IsCommonOSVariant() { |
Paul Duffin | 6a7e953 | 2020-03-20 17:50:07 +0000 | [diff] [blame] | 183 | // Update the OsType specific sdk variant with information about its members. |
| 184 | s.collectMembers(ctx) |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 185 | } else { |
| 186 | // Get the OsType specific variants on which the CommonOS depends. |
| 187 | osSpecificVariants := android.GetOsSpecificVariantsOfCommonOSVariant(ctx) |
| 188 | var sdkVariants []*sdk |
| 189 | for _, m := range osSpecificVariants { |
| 190 | if sdkVariant, ok := m.(*sdk); ok { |
| 191 | sdkVariants = append(sdkVariants, sdkVariant) |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // Generate the snapshot from the member info. |
Paul Duffin | c6ba182 | 2022-05-06 09:38:02 +0000 | [diff] [blame] | 196 | s.buildSnapshot(ctx, sdkVariants) |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 197 | } |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 198 | } |
| 199 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 200 | func (s *sdk) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | c6ba182 | 2022-05-06 09:38:02 +0000 | [diff] [blame] | 201 | if !s.snapshotFile.Valid() != !s.infoFile.Valid() { |
| 202 | panic("Snapshot (%q) and info file (%q) should both be set or neither should be set.") |
| 203 | } else if !s.snapshotFile.Valid() { |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 204 | return []android.AndroidMkEntries{} |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 205 | } |
| 206 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 207 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 208 | Class: "FAKE", |
| 209 | OutputFile: s.snapshotFile, |
Paul Duffin | c6ba182 | 2022-05-06 09:38:02 +0000 | [diff] [blame] | 210 | DistFiles: android.MakeDefaultDistFiles(s.snapshotFile.Path(), s.infoFile.Path()), |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 211 | Include: "$(BUILD_PHONY_PACKAGE)", |
Paul Duffin | 504b461 | 2019-11-22 14:52:29 +0000 | [diff] [blame] | 212 | ExtraFooters: []android.AndroidMkExtraFootersFunc{ |
Jaewoong Jung | 02b11a6 | 2020-12-07 10:23:54 -0800 | [diff] [blame] | 213 | func(w io.Writer, name, prefix, moduleDir string) { |
Paul Duffin | 504b461 | 2019-11-22 14:52:29 +0000 | [diff] [blame] | 214 | // Allow the sdk to be built by simply passing its name on the command line. |
| 215 | fmt.Fprintln(w, ".PHONY:", s.Name()) |
| 216 | fmt.Fprintln(w, s.Name()+":", s.snapshotFile.String()) |
Paul Duffin | c6ba182 | 2022-05-06 09:38:02 +0000 | [diff] [blame] | 217 | |
| 218 | // Allow the sdk info to be built by simply passing its name on the command line. |
| 219 | infoTarget := s.Name() + ".info" |
| 220 | fmt.Fprintln(w, ".PHONY:", infoTarget) |
| 221 | fmt.Fprintln(w, infoTarget+":", s.infoFile.String()) |
Paul Duffin | 504b461 | 2019-11-22 14:52:29 +0000 | [diff] [blame] | 222 | }, |
| 223 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 224 | }} |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 225 | } |
| 226 | |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 227 | // gatherTraits gathers the traits from the dynamically generated trait specific properties. |
| 228 | // |
| 229 | // Returns a map from member name to the set of required traits. |
| 230 | func (s *sdk) gatherTraits() map[string]android.SdkMemberTraitSet { |
| 231 | traitListByMember := map[string][]android.SdkMemberTrait{} |
| 232 | for _, memberListProperty := range s.memberTraitListProperties() { |
| 233 | names := memberListProperty.getter(s.dynamicMemberTraitListProperties) |
| 234 | for _, name := range names { |
| 235 | traitListByMember[name] = append(traitListByMember[name], memberListProperty.memberTrait) |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | traitSetByMember := map[string]android.SdkMemberTraitSet{} |
| 240 | for name, list := range traitListByMember { |
| 241 | traitSetByMember[name] = android.NewSdkMemberTraitSet(list) |
| 242 | } |
| 243 | |
| 244 | return traitSetByMember |
| 245 | } |
| 246 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 247 | // newDependencyContext creates a new SdkDependencyContext for this sdk. |
| 248 | func (s *sdk) newDependencyContext(mctx android.BottomUpMutatorContext) android.SdkDependencyContext { |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 249 | traits := s.gatherTraits() |
| 250 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 251 | return &dependencyContext{ |
| 252 | BottomUpMutatorContext: mctx, |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 253 | requiredTraits: traits, |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | type dependencyContext struct { |
| 258 | android.BottomUpMutatorContext |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 259 | |
| 260 | // Map from member name to the set of traits that the sdk requires the member provides. |
| 261 | requiredTraits map[string]android.SdkMemberTraitSet |
| 262 | } |
| 263 | |
| 264 | func (d *dependencyContext) RequiredTraits(name string) android.SdkMemberTraitSet { |
| 265 | if s, ok := d.requiredTraits[name]; ok { |
| 266 | return s |
| 267 | } else { |
| 268 | return android.EmptySdkMemberTraitSet() |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | func (d *dependencyContext) RequiresTrait(name string, trait android.SdkMemberTrait) bool { |
| 273 | return d.RequiredTraits(name).Contains(trait) |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | var _ android.SdkDependencyContext = (*dependencyContext)(nil) |
| 277 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 278 | // RegisterPreDepsMutators registers pre-deps mutators to support modules implementing SdkAware |
| 279 | // interface and the sdk module type. This function has been made public to be called by tests |
| 280 | // outside of the sdk package |
| 281 | func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) { |
| 282 | ctx.BottomUp("SdkMember", memberMutator).Parallel() |
| 283 | ctx.TopDown("SdkMember_deps", memberDepsMutator).Parallel() |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 284 | } |
| 285 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 286 | type dependencyTag struct { |
| 287 | blueprint.BaseDependencyTag |
| 288 | } |
| 289 | |
Martin Stjernholm | cc77601 | 2020-07-07 03:22:21 +0100 | [diff] [blame] | 290 | // Mark this tag so dependencies that use it are excluded from APEX contents. |
| 291 | func (t dependencyTag) ExcludeFromApexContents() {} |
| 292 | |
| 293 | var _ android.ExcludeFromApexContentsTag = dependencyTag{} |
| 294 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 295 | // Step 1: create dependencies from an SDK module to its members. |
| 296 | func memberMutator(mctx android.BottomUpMutatorContext) { |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 297 | if s, ok := mctx.Module().(*sdk); ok { |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 298 | // Add dependencies from enabled and non CommonOS variants to the sdk member variants. |
| 299 | if s.Enabled() && !s.IsCommonOSVariant() { |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 300 | ctx := s.newDependencyContext(mctx) |
Paul Duffin | 62782de | 2021-07-14 12:05:16 +0100 | [diff] [blame] | 301 | for _, memberListProperty := range s.memberTypeListProperties() { |
Paul Duffin | 1308205 | 2021-05-11 00:31:38 +0100 | [diff] [blame] | 302 | if memberListProperty.getter == nil { |
| 303 | continue |
| 304 | } |
Paul Duffin | 583bf7e | 2020-02-20 13:39:41 +0000 | [diff] [blame] | 305 | names := memberListProperty.getter(s.dynamicMemberTypeListProperties) |
Paul Duffin | cc1b3da | 2020-02-27 13:29:56 +0000 | [diff] [blame] | 306 | if len(names) > 0 { |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 307 | memberType := memberListProperty.memberType |
| 308 | |
| 309 | // Verify that the member type supports the specified traits. |
| 310 | supportedTraits := memberType.SupportedTraits() |
| 311 | for _, name := range names { |
| 312 | requiredTraits := ctx.RequiredTraits(name) |
| 313 | unsupportedTraits := requiredTraits.Subtract(supportedTraits) |
| 314 | if !unsupportedTraits.Empty() { |
| 315 | ctx.ModuleErrorf("sdk member %q has traits %s that are unsupported by its member type %q", name, unsupportedTraits, memberType.SdkPropertyName()) |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // Add dependencies using the appropriate tag. |
Paul Duffin | cc1b3da | 2020-02-27 13:29:56 +0000 | [diff] [blame] | 320 | tag := memberListProperty.dependencyTag |
Paul Duffin | d19f894 | 2021-07-14 12:08:37 +0100 | [diff] [blame] | 321 | memberType.AddDependencies(ctx, tag, names) |
Paul Duffin | cc1b3da | 2020-02-27 13:29:56 +0000 | [diff] [blame] | 322 | } |
Paul Duffin | 583bf7e | 2020-02-20 13:39:41 +0000 | [diff] [blame] | 323 | } |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // Step 2: record that dependencies of SDK modules are members of the SDK modules |
| 329 | func memberDepsMutator(mctx android.TopDownMutatorContext) { |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 330 | if s, ok := mctx.Module().(*sdk); ok { |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 331 | mySdkRef := android.ParseSdkRef(mctx, mctx.ModuleName(), "name") |
Jiyong Park | 9b409bc | 2019-10-11 14:59:13 +0900 | [diff] [blame] | 332 | if s.snapshot() && mySdkRef.Unversioned() { |
| 333 | mctx.PropertyErrorf("name", "sdk_snapshot should be named as <name>@<version>. "+ |
| 334 | "Did you manually modify Android.bp?") |
| 335 | } |
| 336 | if !s.snapshot() && !mySdkRef.Unversioned() { |
| 337 | mctx.PropertyErrorf("name", "sdk shouldn't be named as <name>@<version>.") |
| 338 | } |
| 339 | if mySdkRef.Version != "" && mySdkRef.Version != "current" { |
| 340 | if _, err := strconv.Atoi(mySdkRef.Version); err != nil { |
| 341 | mctx.PropertyErrorf("name", "version %q is neither a number nor \"current\"", mySdkRef.Version) |
| 342 | } |
| 343 | } |
| 344 | |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 345 | mctx.VisitDirectDeps(func(child android.Module) { |
| 346 | if member, ok := child.(android.SdkAware); ok { |
| 347 | member.MakeMemberOf(mySdkRef) |
| 348 | } |
| 349 | }) |
| 350 | } |
| 351 | } |
| 352 | |
Paul Duffin | 4c3e8e2 | 2021-03-18 15:41:29 +0000 | [diff] [blame] | 353 | // An interface that encapsulates all the functionality needed to manage the sdk dependencies. |
| 354 | // |
| 355 | // It is a mixture of apex and sdk module functionality. |
| 356 | type sdkAndApexModule interface { |
| 357 | android.Module |
| 358 | android.DepIsInSameApex |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 359 | } |