Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 1 | // Copyright 2024 Google Inc. All rights reserved. |
| 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 ( |
| 18 | "reflect" |
| 19 | "slices" |
| 20 | |
| 21 | "github.com/google/blueprint" |
| 22 | ) |
| 23 | |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 24 | // ---------------------------------------------------------------------------- |
| 25 | // Start of the definitions of exception functions and the lookup table. |
| 26 | // |
| 27 | // Functions cannot be used as a value passed in providers, because functions are not |
| 28 | // hashable. As a workaround, the [exceptionHandleFuncLabel] enum values are passed using providers, |
| 29 | // and the corresponding functions are called from [exceptionHandleFunctionsTable] map. |
| 30 | // ---------------------------------------------------------------------------- |
| 31 | |
| 32 | type exceptionHandleFunc func(ModuleContext, Module, Module) bool |
| 33 | |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 34 | type StubsAvailableModule interface { |
| 35 | IsStubsModule() bool |
| 36 | } |
| 37 | |
| 38 | // Returns true if the dependency module is a stubs module |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 39 | var depIsStubsModule exceptionHandleFunc = func(_ ModuleContext, _, dep Module) bool { |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 40 | if stubsModule, ok := dep.(StubsAvailableModule); ok { |
| 41 | return stubsModule.IsStubsModule() |
| 42 | } |
| 43 | return false |
| 44 | } |
| 45 | |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 46 | // Returns true if the dependency module belongs to any of the apexes. |
| 47 | var depIsApexModule exceptionHandleFunc = func(mctx ModuleContext, _, dep Module) bool { |
| 48 | depContainersInfo, _ := getContainerModuleInfo(mctx, dep) |
| 49 | return InList(ApexContainer, depContainersInfo.belongingContainers) |
| 50 | } |
| 51 | |
| 52 | // Returns true if the module and the dependent module belongs to common apexes. |
| 53 | var belongsToCommonApexes exceptionHandleFunc = func(mctx ModuleContext, m, dep Module) bool { |
| 54 | mContainersInfo, _ := getContainerModuleInfo(mctx, m) |
| 55 | depContainersInfo, _ := getContainerModuleInfo(mctx, dep) |
| 56 | |
| 57 | return HasIntersection(mContainersInfo.ApexNames(), depContainersInfo.ApexNames()) |
| 58 | } |
| 59 | |
| 60 | // Returns true when all apexes that the module belongs to are non updatable. |
| 61 | // For an apex module to be allowed to depend on a non-apex partition module, |
| 62 | // all apexes that the module belong to must be non updatable. |
| 63 | var belongsToNonUpdatableApex exceptionHandleFunc = func(mctx ModuleContext, m, _ Module) bool { |
| 64 | mContainersInfo, _ := getContainerModuleInfo(mctx, m) |
| 65 | |
| 66 | return !mContainersInfo.UpdatableApex() |
| 67 | } |
| 68 | |
| 69 | // Returns true if the dependency is added via dependency tags that are not used to tag dynamic |
| 70 | // dependency tags. |
| 71 | var depIsNotDynamicDepTag exceptionHandleFunc = func(ctx ModuleContext, m, dep Module) bool { |
| 72 | mInstallable, _ := m.(InstallableModule) |
| 73 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 74 | return !InList(depTag, mInstallable.DynamicDependencyTags()) |
| 75 | } |
| 76 | |
| 77 | // Returns true if the dependency is added via dependency tags that are not used to tag static |
| 78 | // or dynamic dependency tags. These dependencies do not affect the module in compile time or in |
| 79 | // runtime, thus are not significant enough to raise an error. |
| 80 | var depIsNotStaticOrDynamicDepTag exceptionHandleFunc = func(ctx ModuleContext, m, dep Module) bool { |
| 81 | mInstallable, _ := m.(InstallableModule) |
| 82 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 83 | return !InList(depTag, append(mInstallable.StaticDependencyTags(), mInstallable.DynamicDependencyTags()...)) |
| 84 | } |
| 85 | |
| 86 | var globallyAllowlistedDependencies = []string{ |
| 87 | // Modules that provide annotations used within the platform and apexes. |
| 88 | "aconfig-annotations-lib", |
| 89 | "framework-annotations-lib", |
| 90 | "unsupportedappusage", |
| 91 | |
| 92 | // framework-res provides core resources essential for building apps and system UI. |
| 93 | // This module is implicitly added as a dependency for java modules even when the |
| 94 | // dependency specifies sdk_version. |
| 95 | "framework-res", |
| 96 | } |
| 97 | |
| 98 | // Returns true when the dependency is globally allowlisted for inter-container dependency |
| 99 | var depIsGloballyAllowlisted exceptionHandleFunc = func(_ ModuleContext, _, dep Module) bool { |
| 100 | return InList(dep.Name(), globallyAllowlistedDependencies) |
| 101 | } |
| 102 | |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 103 | // Labels of exception functions, which are used to determine special dependencies that allow |
| 104 | // otherwise restricted inter-container dependencies |
| 105 | type exceptionHandleFuncLabel int |
| 106 | |
| 107 | const ( |
| 108 | checkStubs exceptionHandleFuncLabel = iota |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 109 | checkApexModule |
| 110 | checkInCommonApexes |
| 111 | checkApexIsNonUpdatable |
| 112 | checkNotDynamicDepTag |
| 113 | checkNotStaticOrDynamicDepTag |
| 114 | checkGlobalAllowlistedDep |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 115 | ) |
| 116 | |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 117 | // Map of [exceptionHandleFuncLabel] to the [exceptionHandleFunc] |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 118 | var exceptionHandleFunctionsTable = map[exceptionHandleFuncLabel]exceptionHandleFunc{ |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 119 | checkStubs: depIsStubsModule, |
| 120 | checkApexModule: depIsApexModule, |
| 121 | checkInCommonApexes: belongsToCommonApexes, |
| 122 | checkApexIsNonUpdatable: belongsToNonUpdatableApex, |
| 123 | checkNotDynamicDepTag: depIsNotDynamicDepTag, |
| 124 | checkNotStaticOrDynamicDepTag: depIsNotStaticOrDynamicDepTag, |
| 125 | checkGlobalAllowlistedDep: depIsGloballyAllowlisted, |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 128 | // ---------------------------------------------------------------------------- |
| 129 | // Start of the definitions of container determination functions. |
| 130 | // |
| 131 | // Similar to the above section, below defines the functions used to determine |
| 132 | // the container of each modules. |
| 133 | // ---------------------------------------------------------------------------- |
| 134 | |
| 135 | type containerBoundaryFunc func(mctx ModuleContext) bool |
| 136 | |
| 137 | var vendorContainerBoundaryFunc containerBoundaryFunc = func(mctx ModuleContext) bool { |
| 138 | m, ok := mctx.Module().(ImageInterface) |
| 139 | return mctx.Module().InstallInVendor() || (ok && m.VendorVariantNeeded(mctx)) |
| 140 | } |
| 141 | |
| 142 | var systemContainerBoundaryFunc containerBoundaryFunc = func(mctx ModuleContext) bool { |
| 143 | module := mctx.Module() |
| 144 | |
| 145 | return !module.InstallInTestcases() && |
| 146 | !module.InstallInData() && |
| 147 | !module.InstallInRamdisk() && |
| 148 | !module.InstallInVendorRamdisk() && |
| 149 | !module.InstallInDebugRamdisk() && |
| 150 | !module.InstallInRecovery() && |
| 151 | !module.InstallInVendor() && |
| 152 | !module.InstallInOdm() && |
| 153 | !module.InstallInProduct() && |
| 154 | determineModuleKind(module.base(), mctx.blueprintBaseModuleContext()) == platformModule |
| 155 | } |
| 156 | |
| 157 | var productContainerBoundaryFunc containerBoundaryFunc = func(mctx ModuleContext) bool { |
| 158 | m, ok := mctx.Module().(ImageInterface) |
| 159 | return mctx.Module().InstallInProduct() || (ok && m.ProductVariantNeeded(mctx)) |
| 160 | } |
| 161 | |
| 162 | var apexContainerBoundaryFunc containerBoundaryFunc = func(mctx ModuleContext) bool { |
| 163 | _, ok := ModuleProvider(mctx, AllApexInfoProvider) |
| 164 | return ok |
| 165 | } |
| 166 | |
| 167 | var ctsContainerBoundaryFunc containerBoundaryFunc = func(mctx ModuleContext) bool { |
| 168 | props := mctx.Module().GetProperties() |
| 169 | for _, prop := range props { |
| 170 | val := reflect.ValueOf(prop).Elem() |
| 171 | if val.Kind() == reflect.Struct { |
| 172 | testSuites := val.FieldByName("Test_suites") |
| 173 | if testSuites.IsValid() && testSuites.Kind() == reflect.Slice && slices.Contains(testSuites.Interface().([]string), "cts") { |
| 174 | return true |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | return false |
| 179 | } |
| 180 | |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame^] | 181 | type unstableInfo struct { |
| 182 | // Determines if the module contains the private APIs of the platform. |
| 183 | ContainsPlatformPrivateApis bool |
| 184 | } |
| 185 | |
| 186 | var unstableInfoProvider = blueprint.NewProvider[unstableInfo]() |
| 187 | |
| 188 | func determineUnstableModule(mctx ModuleContext) bool { |
| 189 | module := mctx.Module() |
| 190 | unstableModule := module.Name() == "framework-minus-apex" |
| 191 | if installable, ok := module.(InstallableModule); ok { |
| 192 | for _, staticDepTag := range installable.StaticDependencyTags() { |
| 193 | mctx.VisitDirectDepsWithTag(staticDepTag, func(dep Module) { |
| 194 | if unstableInfo, ok := OtherModuleProvider(mctx, dep, unstableInfoProvider); ok { |
| 195 | unstableModule = unstableModule || unstableInfo.ContainsPlatformPrivateApis |
| 196 | } |
| 197 | }) |
| 198 | } |
| 199 | } |
| 200 | return unstableModule |
| 201 | } |
| 202 | |
| 203 | var unstableContainerBoundaryFunc containerBoundaryFunc = func(mctx ModuleContext) bool { |
| 204 | return determineUnstableModule(mctx) |
| 205 | } |
| 206 | |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 207 | // Map of [*container] to the [containerBoundaryFunc] |
| 208 | var containerBoundaryFunctionsTable = map[*container]containerBoundaryFunc{ |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame^] | 209 | VendorContainer: vendorContainerBoundaryFunc, |
| 210 | SystemContainer: systemContainerBoundaryFunc, |
| 211 | ProductContainer: productContainerBoundaryFunc, |
| 212 | ApexContainer: apexContainerBoundaryFunc, |
| 213 | CtsContainer: ctsContainerBoundaryFunc, |
| 214 | UnstableContainer: unstableContainerBoundaryFunc, |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // ---------------------------------------------------------------------------- |
| 218 | // End of the definitions of container determination functions. |
| 219 | // ---------------------------------------------------------------------------- |
| 220 | |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 221 | type InstallableModule interface { |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 222 | ContainersInfo() ContainersInfo |
| 223 | StaticDependencyTags() []blueprint.DependencyTag |
| 224 | DynamicDependencyTags() []blueprint.DependencyTag |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | type restriction struct { |
| 228 | // container of the dependency |
| 229 | dependency *container |
| 230 | |
| 231 | // Error message to be emitted to the user when the dependency meets this restriction |
| 232 | errorMessage string |
| 233 | |
| 234 | // List of labels of allowed exception functions that allows bypassing this restriction. |
| 235 | // If any of the functions mapped to each labels returns true, this dependency would be |
| 236 | // considered allowed and an error will not be thrown. |
| 237 | allowedExceptions []exceptionHandleFuncLabel |
| 238 | } |
| 239 | type container struct { |
| 240 | // The name of the container i.e. partition, api domain |
| 241 | name string |
| 242 | |
| 243 | // Map of dependency restricted containers. |
| 244 | restricted []restriction |
| 245 | } |
| 246 | |
| 247 | var ( |
| 248 | VendorContainer = &container{ |
| 249 | name: VendorVariation, |
| 250 | restricted: nil, |
| 251 | } |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 252 | |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 253 | SystemContainer = &container{ |
| 254 | name: "system", |
| 255 | restricted: []restriction{ |
| 256 | { |
| 257 | dependency: VendorContainer, |
| 258 | errorMessage: "Module belonging to the system partition other than HALs is " + |
| 259 | "not allowed to depend on the vendor partition module, in order to support " + |
| 260 | "independent development/update cycles and to support the Generic System " + |
| 261 | "Image. Try depending on HALs, VNDK or AIDL instead.", |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 262 | allowedExceptions: []exceptionHandleFuncLabel{ |
| 263 | checkStubs, |
| 264 | checkNotDynamicDepTag, |
| 265 | checkGlobalAllowlistedDep, |
| 266 | }, |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 267 | }, |
| 268 | }, |
| 269 | } |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 270 | |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 271 | ProductContainer = &container{ |
| 272 | name: ProductVariation, |
| 273 | restricted: []restriction{ |
| 274 | { |
| 275 | dependency: VendorContainer, |
| 276 | errorMessage: "Module belonging to the product partition is not allowed to " + |
| 277 | "depend on the vendor partition module, as this may lead to security " + |
| 278 | "vulnerabilities. Try depending on the HALs or utilize AIDL instead.", |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 279 | allowedExceptions: []exceptionHandleFuncLabel{ |
| 280 | checkStubs, |
| 281 | checkNotDynamicDepTag, |
| 282 | checkGlobalAllowlistedDep, |
| 283 | }, |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 284 | }, |
| 285 | }, |
| 286 | } |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 287 | |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 288 | ApexContainer = initializeApexContainer() |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 289 | |
| 290 | CtsContainer = &container{ |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 291 | name: "cts", |
| 292 | restricted: []restriction{ |
| 293 | { |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame^] | 294 | dependency: UnstableContainer, |
| 295 | errorMessage: "CTS module should not depend on the modules that contain the " + |
| 296 | "platform implementation details, including \"framework\". Depending on these " + |
| 297 | "modules may lead to disclosure of implementation details and regression " + |
| 298 | "due to API changes across platform versions. Try depending on the stubs instead " + |
| 299 | "and ensure that the module sets an appropriate 'sdk_version'.", |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 300 | allowedExceptions: []exceptionHandleFuncLabel{ |
| 301 | checkStubs, |
| 302 | checkNotStaticOrDynamicDepTag, |
| 303 | checkGlobalAllowlistedDep, |
| 304 | }, |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 305 | }, |
| 306 | }, |
| 307 | } |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 308 | |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame^] | 309 | // Container signifying that the module contains unstable platform private APIs |
| 310 | UnstableContainer = &container{ |
| 311 | name: "unstable", |
| 312 | restricted: nil, |
| 313 | } |
| 314 | |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 315 | allContainers = []*container{ |
| 316 | VendorContainer, |
| 317 | SystemContainer, |
| 318 | ProductContainer, |
| 319 | ApexContainer, |
| 320 | CtsContainer, |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame^] | 321 | UnstableContainer, |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 322 | } |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 323 | ) |
| 324 | |
| 325 | func initializeApexContainer() *container { |
| 326 | apexContainer := &container{ |
| 327 | name: "apex", |
| 328 | restricted: []restriction{ |
| 329 | { |
| 330 | dependency: SystemContainer, |
| 331 | errorMessage: "Module belonging to Apex(es) is not allowed to depend on the " + |
| 332 | "modules belonging to the system partition. Either statically depend on the " + |
| 333 | "module or convert the depending module to java_sdk_library and depend on " + |
| 334 | "the stubs.", |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 335 | allowedExceptions: []exceptionHandleFuncLabel{ |
| 336 | checkStubs, |
| 337 | checkApexModule, |
| 338 | checkInCommonApexes, |
| 339 | checkApexIsNonUpdatable, |
| 340 | checkNotStaticOrDynamicDepTag, |
| 341 | checkGlobalAllowlistedDep, |
| 342 | }, |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 343 | }, |
| 344 | }, |
| 345 | } |
| 346 | |
| 347 | apexContainer.restricted = append(apexContainer.restricted, restriction{ |
| 348 | dependency: apexContainer, |
| 349 | errorMessage: "Module belonging to Apex(es) is not allowed to depend on the " + |
| 350 | "modules belonging to other Apex(es). Either include the depending " + |
| 351 | "module in the Apex or convert the depending module to java_sdk_library " + |
| 352 | "and depend on its stubs.", |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 353 | allowedExceptions: []exceptionHandleFuncLabel{ |
| 354 | checkStubs, |
| 355 | checkInCommonApexes, |
| 356 | checkNotStaticOrDynamicDepTag, |
| 357 | checkGlobalAllowlistedDep, |
| 358 | }, |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 359 | }) |
| 360 | |
| 361 | return apexContainer |
| 362 | } |
| 363 | |
| 364 | type ContainersInfo struct { |
| 365 | belongingContainers []*container |
| 366 | |
| 367 | belongingApexes []ApexInfo |
| 368 | } |
| 369 | |
| 370 | func (c *ContainersInfo) BelongingContainers() []*container { |
| 371 | return c.belongingContainers |
| 372 | } |
| 373 | |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 374 | func (c *ContainersInfo) ApexNames() (ret []string) { |
| 375 | for _, apex := range c.belongingApexes { |
| 376 | ret = append(ret, apex.InApexModules...) |
| 377 | } |
| 378 | slices.Sort(ret) |
| 379 | return ret |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 382 | // Returns true if any of the apex the module belongs to is updatable. |
| 383 | func (c *ContainersInfo) UpdatableApex() bool { |
| 384 | for _, apex := range c.belongingApexes { |
| 385 | if apex.Updatable { |
| 386 | return true |
| 387 | } |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 388 | } |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 389 | return false |
| 390 | } |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 391 | |
Jihoon Kang | 17a61d7 | 2024-08-12 22:26:52 +0000 | [diff] [blame] | 392 | var ContainersInfoProvider = blueprint.NewProvider[ContainersInfo]() |
| 393 | |
| 394 | func generateContainerInfo(ctx ModuleContext) ContainersInfo { |
| 395 | var containers []*container |
| 396 | |
| 397 | for _, cnt := range allContainers { |
| 398 | if containerBoundaryFunctionsTable[cnt](ctx) { |
| 399 | containers = append(containers, cnt) |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
| 403 | var belongingApexes []ApexInfo |
| 404 | if apexInfo, ok := ModuleProvider(ctx, AllApexInfoProvider); ok { |
| 405 | belongingApexes = apexInfo.ApexInfos |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | return ContainersInfo{ |
| 409 | belongingContainers: containers, |
| 410 | belongingApexes: belongingApexes, |
| 411 | } |
| 412 | } |
| 413 | |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 414 | func getContainerModuleInfo(ctx ModuleContext, module Module) (ContainersInfo, bool) { |
| 415 | if ctx.Module() == module { |
| 416 | return module.ContainersInfo(), true |
| 417 | } |
| 418 | |
| 419 | return OtherModuleProvider(ctx, module, ContainersInfoProvider) |
| 420 | } |
| 421 | |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 422 | func setContainerInfo(ctx ModuleContext) { |
Jihoon Kang | 0f3b1a7 | 2024-08-12 22:47:01 +0000 | [diff] [blame^] | 423 | // Required to determine the unstable container. This provider is set here instead of the |
| 424 | // unstableContainerBoundaryFunc in order to prevent setting the provider multiple times. |
| 425 | SetProvider(ctx, unstableInfoProvider, unstableInfo{ |
| 426 | ContainsPlatformPrivateApis: determineUnstableModule(ctx), |
| 427 | }) |
| 428 | |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 429 | if _, ok := ctx.Module().(InstallableModule); ok { |
| 430 | containersInfo := generateContainerInfo(ctx) |
Jihoon Kang | 224ea08 | 2024-08-12 22:38:16 +0000 | [diff] [blame] | 431 | ctx.Module().base().containersInfo = containersInfo |
Jihoon Kang | c3d4e11 | 2024-06-24 22:16:27 +0000 | [diff] [blame] | 432 | SetProvider(ctx, ContainersInfoProvider, containersInfo) |
| 433 | } |
| 434 | } |