| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 1 | // Copyright 2020 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 | // | 
| Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 7 | //	http://www.apache.org/licenses/LICENSE-2.0 | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 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 | package cc | 
|  | 15 |  | 
|  | 16 | // This file contains image variant related things, including image mutator functions, utility | 
|  | 17 | // functions to determine where a module is installed, etc. | 
|  | 18 |  | 
|  | 19 | import ( | 
|  | 20 | "strings" | 
|  | 21 |  | 
|  | 22 | "android/soong/android" | 
| Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 23 |  | 
|  | 24 | "github.com/google/blueprint/proptools" | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 25 | ) | 
|  | 26 |  | 
|  | 27 | var _ android.ImageInterface = (*Module)(nil) | 
|  | 28 |  | 
| Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 29 | type ImageVariantType string | 
| Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 30 |  | 
|  | 31 | const ( | 
| Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 32 | coreImageVariant          ImageVariantType = "core" | 
|  | 33 | vendorImageVariant        ImageVariantType = "vendor" | 
|  | 34 | productImageVariant       ImageVariantType = "product" | 
|  | 35 | ramdiskImageVariant       ImageVariantType = "ramdisk" | 
|  | 36 | vendorRamdiskImageVariant ImageVariantType = "vendor_ramdisk" | 
|  | 37 | recoveryImageVariant      ImageVariantType = "recovery" | 
|  | 38 | hostImageVariant          ImageVariantType = "host" | 
| Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 39 | ) | 
|  | 40 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 41 | const ( | 
|  | 42 | // VendorVariationPrefix is the variant prefix used for /vendor code that compiles | 
|  | 43 | // against the VNDK. | 
|  | 44 | VendorVariationPrefix = "vendor." | 
|  | 45 |  | 
|  | 46 | // ProductVariationPrefix is the variant prefix used for /product code that compiles | 
|  | 47 | // against the VNDK. | 
|  | 48 | ProductVariationPrefix = "product." | 
|  | 49 | ) | 
|  | 50 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 51 | func (ctx *moduleContextImpl) inProduct() bool { | 
| Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 52 | return ctx.mod.InProduct() | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 53 | } | 
|  | 54 |  | 
|  | 55 | func (ctx *moduleContextImpl) inVendor() bool { | 
| Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 56 | return ctx.mod.InVendor() | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 57 | } | 
|  | 58 |  | 
|  | 59 | func (ctx *moduleContextImpl) inRamdisk() bool { | 
|  | 60 | return ctx.mod.InRamdisk() | 
|  | 61 | } | 
|  | 62 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 63 | func (ctx *moduleContextImpl) inVendorRamdisk() bool { | 
|  | 64 | return ctx.mod.InVendorRamdisk() | 
|  | 65 | } | 
|  | 66 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 67 | func (ctx *moduleContextImpl) inRecovery() bool { | 
|  | 68 | return ctx.mod.InRecovery() | 
|  | 69 | } | 
|  | 70 |  | 
| Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 71 | func (c *Module) InstallInProduct() bool { | 
| Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 72 | // Additionally check if this module is inProduct() that means it is a "product" variant of a | 
|  | 73 | // module. As well as product specific modules, product variants must be installed to /product. | 
|  | 74 | return c.InProduct() | 
|  | 75 | } | 
|  | 76 |  | 
| Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 77 | func (c *Module) InstallInVendor() bool { | 
| Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 78 | // Additionally check if this module is inVendor() that means it is a "vendor" variant of a | 
|  | 79 | // module. As well as SoC specific modules, vendor variants must be installed to /vendor | 
|  | 80 | // unless they have "odm_available: true". | 
|  | 81 | return c.HasVendorVariant() && c.InVendor() && !c.VendorVariantToOdm() | 
|  | 82 | } | 
|  | 83 |  | 
| Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 84 | func (c *Module) InstallInOdm() bool { | 
| Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 85 | // Some vendor variants want to be installed to /odm by setting "odm_available: true". | 
|  | 86 | return c.InVendor() && c.VendorVariantToOdm() | 
|  | 87 | } | 
|  | 88 |  | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 89 | // Returns true when this module is configured to have core and vendor variants. | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 90 | func (c *Module) HasVendorVariant() bool { | 
| Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame] | 91 | return Bool(c.VendorProperties.Vendor_available) || Bool(c.VendorProperties.Odm_available) | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | // Returns true when this module creates a vendor variant and wants to install the vendor variant | 
|  | 95 | // to the odm partition. | 
|  | 96 | func (c *Module) VendorVariantToOdm() bool { | 
|  | 97 | return Bool(c.VendorProperties.Odm_available) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 98 | } | 
|  | 99 |  | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 100 | // Returns true when this module is configured to have core and product variants. | 
|  | 101 | func (c *Module) HasProductVariant() bool { | 
| Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 102 | return Bool(c.VendorProperties.Product_available) | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 103 | } | 
|  | 104 |  | 
|  | 105 | // Returns true when this module is configured to have core and either product or vendor variants. | 
|  | 106 | func (c *Module) HasNonSystemVariants() bool { | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 107 | return c.HasVendorVariant() || c.HasProductVariant() | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 108 | } | 
|  | 109 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 110 | // Returns true if the module is "product" variant. Usually these modules are installed in /product | 
| Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 111 | func (c *Module) InProduct() bool { | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 112 | return c.Properties.ImageVariation == android.ProductVariation | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 113 | } | 
|  | 114 |  | 
|  | 115 | // Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor | 
| Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 116 | func (c *Module) InVendor() bool { | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 117 | return c.Properties.ImageVariation == android.VendorVariation | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 118 | } | 
|  | 119 |  | 
| Kiyoung Kim | aa39480 | 2024-01-08 12:55:45 +0900 | [diff] [blame] | 120 | // Returns true if the module is "vendor" or "product" variant. This replaces previous UseVndk usages | 
|  | 121 | // which were misused to check if the module variant is vendor or product. | 
|  | 122 | func (c *Module) InVendorOrProduct() bool { | 
|  | 123 | return c.InVendor() || c.InProduct() | 
|  | 124 | } | 
|  | 125 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 126 | func (c *Module) InRamdisk() bool { | 
|  | 127 | return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk() | 
|  | 128 | } | 
|  | 129 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 130 | func (c *Module) InVendorRamdisk() bool { | 
|  | 131 | return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk() | 
|  | 132 | } | 
|  | 133 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 134 | func (c *Module) InRecovery() bool { | 
|  | 135 | return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery() | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | func (c *Module) OnlyInRamdisk() bool { | 
|  | 139 | return c.ModuleBase.InstallInRamdisk() | 
|  | 140 | } | 
|  | 141 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 142 | func (c *Module) OnlyInVendorRamdisk() bool { | 
|  | 143 | return c.ModuleBase.InstallInVendorRamdisk() | 
|  | 144 | } | 
|  | 145 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 146 | func (c *Module) OnlyInRecovery() bool { | 
|  | 147 | return c.ModuleBase.InstallInRecovery() | 
|  | 148 | } | 
|  | 149 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 150 | // ImageMutatableModule provides a common image mutation interface for  LinkableInterface modules. | 
|  | 151 | type ImageMutatableModule interface { | 
|  | 152 | android.Module | 
|  | 153 | LinkableInterface | 
|  | 154 |  | 
|  | 155 | // AndroidModuleBase returns the android.ModuleBase for this module | 
|  | 156 | AndroidModuleBase() *android.ModuleBase | 
|  | 157 |  | 
|  | 158 | // VendorAvailable returns true if this module is available on the vendor image. | 
|  | 159 | VendorAvailable() bool | 
|  | 160 |  | 
|  | 161 | // OdmAvailable returns true if this module is available on the odm image. | 
|  | 162 | OdmAvailable() bool | 
|  | 163 |  | 
|  | 164 | // ProductAvailable returns true if this module is available on the product image. | 
|  | 165 | ProductAvailable() bool | 
|  | 166 |  | 
|  | 167 | // RamdiskAvailable returns true if this module is available on the ramdisk image. | 
|  | 168 | RamdiskAvailable() bool | 
|  | 169 |  | 
|  | 170 | // RecoveryAvailable returns true if this module is available on the recovery image. | 
|  | 171 | RecoveryAvailable() bool | 
|  | 172 |  | 
|  | 173 | // VendorRamdiskAvailable returns true if this module is available on the vendor ramdisk image. | 
|  | 174 | VendorRamdiskAvailable() bool | 
|  | 175 |  | 
|  | 176 | // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt. | 
|  | 177 | IsSnapshotPrebuilt() bool | 
|  | 178 |  | 
|  | 179 | // SnapshotVersion returns the snapshot version for this module. | 
|  | 180 | SnapshotVersion(mctx android.BaseModuleContext) string | 
|  | 181 |  | 
|  | 182 | // SdkVersion returns the SDK version for this module. | 
|  | 183 | SdkVersion() string | 
|  | 184 |  | 
|  | 185 | // ExtraVariants returns the list of extra variants this module requires. | 
|  | 186 | ExtraVariants() []string | 
|  | 187 |  | 
|  | 188 | // AppendExtraVariant returns an extra variant to the list of extra variants this module requires. | 
|  | 189 | AppendExtraVariant(extraVariant string) | 
|  | 190 |  | 
|  | 191 | // SetRamdiskVariantNeeded sets whether the Ramdisk Variant is needed. | 
|  | 192 | SetRamdiskVariantNeeded(b bool) | 
|  | 193 |  | 
|  | 194 | // SetVendorRamdiskVariantNeeded sets whether the Vendor Ramdisk Variant is needed. | 
|  | 195 | SetVendorRamdiskVariantNeeded(b bool) | 
|  | 196 |  | 
|  | 197 | // SetRecoveryVariantNeeded sets whether the Recovery Variant is needed. | 
|  | 198 | SetRecoveryVariantNeeded(b bool) | 
|  | 199 |  | 
|  | 200 | // SetCoreVariantNeeded sets whether the Core Variant is needed. | 
|  | 201 | SetCoreVariantNeeded(b bool) | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 202 |  | 
|  | 203 | // SetProductVariantNeeded sets whether the Product Variant is needed. | 
|  | 204 | SetProductVariantNeeded(b bool) | 
|  | 205 |  | 
|  | 206 | // SetVendorVariantNeeded sets whether the Vendor Variant is needed. | 
|  | 207 | SetVendorVariantNeeded(b bool) | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 208 | } | 
|  | 209 |  | 
|  | 210 | var _ ImageMutatableModule = (*Module)(nil) | 
|  | 211 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 212 | func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 213 | MutateImage(mctx, m) | 
|  | 214 | } | 
|  | 215 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 216 | func (m *Module) VendorAvailable() bool { | 
|  | 217 | return Bool(m.VendorProperties.Vendor_available) | 
|  | 218 | } | 
|  | 219 |  | 
|  | 220 | func (m *Module) OdmAvailable() bool { | 
|  | 221 | return Bool(m.VendorProperties.Odm_available) | 
|  | 222 | } | 
|  | 223 |  | 
|  | 224 | func (m *Module) ProductAvailable() bool { | 
|  | 225 | return Bool(m.VendorProperties.Product_available) | 
|  | 226 | } | 
|  | 227 |  | 
|  | 228 | func (m *Module) RamdiskAvailable() bool { | 
|  | 229 | return Bool(m.Properties.Ramdisk_available) | 
|  | 230 | } | 
|  | 231 |  | 
|  | 232 | func (m *Module) VendorRamdiskAvailable() bool { | 
|  | 233 | return Bool(m.Properties.Vendor_ramdisk_available) | 
|  | 234 | } | 
|  | 235 |  | 
|  | 236 | func (m *Module) AndroidModuleBase() *android.ModuleBase { | 
|  | 237 | return &m.ModuleBase | 
|  | 238 | } | 
|  | 239 |  | 
|  | 240 | func (m *Module) RecoveryAvailable() bool { | 
|  | 241 | return Bool(m.Properties.Recovery_available) | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | func (m *Module) ExtraVariants() []string { | 
| Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 245 | return m.Properties.ExtraVersionedImageVariations | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 246 | } | 
|  | 247 |  | 
|  | 248 | func (m *Module) AppendExtraVariant(extraVariant string) { | 
| Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 249 | m.Properties.ExtraVersionedImageVariations = append(m.Properties.ExtraVersionedImageVariations, extraVariant) | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 250 | } | 
|  | 251 |  | 
|  | 252 | func (m *Module) SetRamdiskVariantNeeded(b bool) { | 
|  | 253 | m.Properties.RamdiskVariantNeeded = b | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | func (m *Module) SetVendorRamdiskVariantNeeded(b bool) { | 
|  | 257 | m.Properties.VendorRamdiskVariantNeeded = b | 
|  | 258 | } | 
|  | 259 |  | 
|  | 260 | func (m *Module) SetRecoveryVariantNeeded(b bool) { | 
|  | 261 | m.Properties.RecoveryVariantNeeded = b | 
|  | 262 | } | 
|  | 263 |  | 
|  | 264 | func (m *Module) SetCoreVariantNeeded(b bool) { | 
|  | 265 | m.Properties.CoreVariantNeeded = b | 
|  | 266 | } | 
|  | 267 |  | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 268 | func (m *Module) SetProductVariantNeeded(b bool) { | 
|  | 269 | m.Properties.ProductVariantNeeded = b | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 | func (m *Module) SetVendorVariantNeeded(b bool) { | 
|  | 273 | m.Properties.VendorVariantNeeded = b | 
|  | 274 | } | 
|  | 275 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 276 | func (m *Module) SnapshotVersion(mctx android.BaseModuleContext) string { | 
| Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 277 | if snapshot, ok := m.linker.(SnapshotInterface); ok { | 
|  | 278 | return snapshot.Version() | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 279 | } else { | 
|  | 280 | mctx.ModuleErrorf("version is unknown for snapshot prebuilt") | 
|  | 281 | // Should we be panicking here instead? | 
|  | 282 | return "" | 
|  | 283 | } | 
|  | 284 | } | 
|  | 285 |  | 
|  | 286 | func (m *Module) KernelHeadersDecorator() bool { | 
|  | 287 | if _, ok := m.linker.(*kernelHeadersDecorator); ok { | 
|  | 288 | return true | 
|  | 289 | } | 
|  | 290 | return false | 
|  | 291 | } | 
|  | 292 |  | 
|  | 293 | // MutateImage handles common image mutations for ImageMutatableModule interfaces. | 
|  | 294 | func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { | 
|  | 295 | // Validation check | 
|  | 296 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() | 
|  | 297 | productSpecific := mctx.ProductSpecific() | 
|  | 298 |  | 
|  | 299 | if m.VendorAvailable() { | 
|  | 300 | if vendorSpecific { | 
|  | 301 | mctx.PropertyErrorf("vendor_available", | 
|  | 302 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") | 
|  | 303 | } | 
|  | 304 | if m.OdmAvailable() { | 
|  | 305 | mctx.PropertyErrorf("vendor_available", | 
|  | 306 | "doesn't make sense at the same time as `odm_available: true`") | 
|  | 307 | } | 
|  | 308 | } | 
|  | 309 |  | 
|  | 310 | if m.OdmAvailable() { | 
|  | 311 | if vendorSpecific { | 
|  | 312 | mctx.PropertyErrorf("odm_available", | 
|  | 313 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") | 
|  | 314 | } | 
|  | 315 | } | 
|  | 316 |  | 
|  | 317 | if m.ProductAvailable() { | 
|  | 318 | if productSpecific { | 
|  | 319 | mctx.PropertyErrorf("product_available", | 
|  | 320 | "doesn't make sense at the same time as `product_specific: true`") | 
|  | 321 | } | 
|  | 322 | if vendorSpecific { | 
|  | 323 | mctx.PropertyErrorf("product_available", | 
|  | 324 | "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`") | 
|  | 325 | } | 
|  | 326 | } | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 327 |  | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 328 | var vendorVariantNeeded bool = false | 
|  | 329 | var productVariantNeeded bool = false | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 330 | var coreVariantNeeded bool = false | 
|  | 331 | var ramdiskVariantNeeded bool = false | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 332 | var vendorRamdiskVariantNeeded bool = false | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 333 | var recoveryVariantNeeded bool = false | 
|  | 334 |  | 
| Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 335 | if m.NeedsLlndkVariants() { | 
| Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 336 | // This is an LLNDK library.  The implementation of the library will be on /system, | 
|  | 337 | // and vendor and product variants will be created with LLNDK stubs. | 
|  | 338 | // The LLNDK libraries need vendor variants even if there is no VNDK. | 
| Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 339 | coreVariantNeeded = true | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 340 | vendorVariantNeeded = true | 
|  | 341 | productVariantNeeded = true | 
|  | 342 |  | 
| Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 343 | } else if m.NeedsVendorPublicLibraryVariants() { | 
|  | 344 | // A vendor public library has the implementation on /vendor, with stub variants | 
|  | 345 | // for system and product. | 
|  | 346 | coreVariantNeeded = true | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 347 | vendorVariantNeeded = true | 
|  | 348 | productVariantNeeded = true | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 349 | } else if m.IsSnapshotPrebuilt() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 350 | // Make vendor variants only for the versions in BOARD_VNDK_VERSION and | 
|  | 351 | // PRODUCT_EXTRA_VNDK_VERSIONS. | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 352 | if m.InstallInRecovery() { | 
|  | 353 | recoveryVariantNeeded = true | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 354 | } else { | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 355 | m.AppendExtraVariant(VendorVariationPrefix + m.SnapshotVersion(mctx)) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 356 | } | 
| Kiyoung Kim | 9f26fcf | 2024-05-27 17:25:52 +0900 | [diff] [blame] | 357 | } else if m.HasNonSystemVariants() { | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 358 | // This will be available to /system unless it is product_specific | 
|  | 359 | // which will be handled later. | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 360 | coreVariantNeeded = true | 
|  | 361 |  | 
|  | 362 | // We assume that modules under proprietary paths are compatible for | 
|  | 363 | // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or | 
|  | 364 | // PLATFORM_VNDK_VERSION. | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 365 | if m.HasVendorVariant() { | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 366 | vendorVariantNeeded = true | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 367 | } | 
|  | 368 |  | 
| Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 369 | // product_available modules are available to /product. | 
|  | 370 | if m.HasProductVariant() { | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 371 | productVariantNeeded = true | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 372 | } | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 373 | } else if vendorSpecific && m.SdkVersion() == "" { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 374 | // This will be available in /vendor (or /odm) only | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 375 | vendorVariantNeeded = true | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 376 | } else { | 
|  | 377 | // This is either in /system (or similar: /data), or is a | 
| jiajia tang | cd1c27b | 2022-07-21 18:04:37 +0800 | [diff] [blame] | 378 | // module built with the NDK. Modules built with the NDK | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 379 | // will be restricted using the existing link type checks. | 
|  | 380 | coreVariantNeeded = true | 
|  | 381 | } | 
|  | 382 |  | 
| Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 383 | if coreVariantNeeded && productSpecific && m.SdkVersion() == "" { | 
|  | 384 | // The module has "product_specific: true" that does not create core variant. | 
|  | 385 | coreVariantNeeded = false | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 386 | productVariantNeeded = true | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 387 | } | 
|  | 388 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 389 | if m.RamdiskAvailable() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 390 | ramdiskVariantNeeded = true | 
|  | 391 | } | 
|  | 392 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 393 | if m.AndroidModuleBase().InstallInRamdisk() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 394 | ramdiskVariantNeeded = true | 
|  | 395 | coreVariantNeeded = false | 
|  | 396 | } | 
|  | 397 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 398 | if m.VendorRamdiskAvailable() { | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 399 | vendorRamdiskVariantNeeded = true | 
|  | 400 | } | 
|  | 401 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 402 | if m.AndroidModuleBase().InstallInVendorRamdisk() { | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 403 | vendorRamdiskVariantNeeded = true | 
|  | 404 | coreVariantNeeded = false | 
|  | 405 | } | 
|  | 406 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 407 | if m.RecoveryAvailable() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 408 | recoveryVariantNeeded = true | 
|  | 409 | } | 
|  | 410 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 411 | if m.AndroidModuleBase().InstallInRecovery() { | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 412 | recoveryVariantNeeded = true | 
|  | 413 | coreVariantNeeded = false | 
|  | 414 | } | 
|  | 415 |  | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 416 | m.SetRamdiskVariantNeeded(ramdiskVariantNeeded) | 
|  | 417 | m.SetVendorRamdiskVariantNeeded(vendorRamdiskVariantNeeded) | 
|  | 418 | m.SetRecoveryVariantNeeded(recoveryVariantNeeded) | 
|  | 419 | m.SetCoreVariantNeeded(coreVariantNeeded) | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 420 | m.SetProductVariantNeeded(productVariantNeeded) | 
|  | 421 | m.SetVendorVariantNeeded(vendorVariantNeeded) | 
| Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 422 |  | 
|  | 423 | // Disable the module if no variants are needed. | 
|  | 424 | if !ramdiskVariantNeeded && | 
|  | 425 | !recoveryVariantNeeded && | 
|  | 426 | !coreVariantNeeded && | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 427 | !productVariantNeeded && | 
|  | 428 | !vendorVariantNeeded && | 
| Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 429 | len(m.ExtraVariants()) == 0 { | 
| Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 430 | m.Disable() | 
|  | 431 | } | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 432 | } | 
|  | 433 |  | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 434 | func (c *Module) VendorVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 435 | return c.Properties.VendorVariantNeeded | 
|  | 436 | } | 
|  | 437 |  | 
|  | 438 | func (c *Module) ProductVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 439 | return c.Properties.ProductVariantNeeded | 
|  | 440 | } | 
|  | 441 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 442 | func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 443 | return c.Properties.CoreVariantNeeded | 
|  | 444 | } | 
|  | 445 |  | 
|  | 446 | func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 447 | return c.Properties.RamdiskVariantNeeded | 
|  | 448 | } | 
|  | 449 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 450 | func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 451 | return c.Properties.VendorRamdiskVariantNeeded | 
|  | 452 | } | 
|  | 453 |  | 
| Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 454 | func (c *Module) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 455 | return false | 
|  | 456 | } | 
|  | 457 |  | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 458 | func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 459 | return c.Properties.RecoveryVariantNeeded | 
|  | 460 | } | 
|  | 461 |  | 
|  | 462 | func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string { | 
| Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 463 | return c.Properties.ExtraVersionedImageVariations | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 464 | } | 
|  | 465 |  | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 466 | func squashVendorSrcs(m *Module) { | 
|  | 467 | if lib, ok := m.compiler.(*libraryDecorator); ok { | 
|  | 468 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, | 
|  | 469 | lib.baseCompiler.Properties.Target.Vendor.Srcs...) | 
|  | 470 |  | 
|  | 471 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, | 
|  | 472 | lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) | 
|  | 473 |  | 
|  | 474 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, | 
|  | 475 | lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...) | 
| Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 476 |  | 
|  | 477 | if lib.Properties.Target.Vendor.No_stubs { | 
|  | 478 | proptools.Clear(&lib.Properties.Stubs) | 
|  | 479 | } | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 480 | } | 
|  | 481 | } | 
|  | 482 |  | 
|  | 483 | func squashProductSrcs(m *Module) { | 
|  | 484 | if lib, ok := m.compiler.(*libraryDecorator); ok { | 
|  | 485 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, | 
|  | 486 | lib.baseCompiler.Properties.Target.Product.Srcs...) | 
|  | 487 |  | 
|  | 488 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, | 
|  | 489 | lib.baseCompiler.Properties.Target.Product.Exclude_srcs...) | 
|  | 490 |  | 
|  | 491 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, | 
|  | 492 | lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...) | 
| Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 493 |  | 
|  | 494 | if lib.Properties.Target.Product.No_stubs { | 
|  | 495 | proptools.Clear(&lib.Properties.Stubs) | 
|  | 496 | } | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 497 | } | 
|  | 498 | } | 
|  | 499 |  | 
|  | 500 | func squashRecoverySrcs(m *Module) { | 
|  | 501 | if lib, ok := m.compiler.(*libraryDecorator); ok { | 
|  | 502 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, | 
|  | 503 | lib.baseCompiler.Properties.Target.Recovery.Srcs...) | 
|  | 504 |  | 
|  | 505 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, | 
|  | 506 | lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) | 
|  | 507 |  | 
|  | 508 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, | 
|  | 509 | lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...) | 
|  | 510 | } | 
|  | 511 | } | 
|  | 512 |  | 
|  | 513 | func squashVendorRamdiskSrcs(m *Module) { | 
|  | 514 | if lib, ok := m.compiler.(*libraryDecorator); ok { | 
|  | 515 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...) | 
|  | 516 | } | 
|  | 517 | } | 
|  | 518 |  | 
| Christopher Ferris | e0202c4 | 2023-07-27 17:06:46 -0700 | [diff] [blame] | 519 | func squashRamdiskSrcs(m *Module) { | 
|  | 520 | if lib, ok := m.compiler.(*libraryDecorator); ok { | 
|  | 521 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Ramdisk.Exclude_srcs...) | 
|  | 522 | } | 
|  | 523 | } | 
|  | 524 |  | 
| Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 525 | func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string) { | 
| Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 526 | if variant == android.RamdiskVariation { | 
| Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 527 | c.MakeAsPlatform() | 
|  | 528 | squashRamdiskSrcs(c) | 
| Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 529 | } else if variant == android.VendorRamdiskVariation { | 
| Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 530 | c.MakeAsPlatform() | 
|  | 531 | squashVendorRamdiskSrcs(c) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 532 | } else if variant == android.RecoveryVariation { | 
| Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 533 | c.MakeAsPlatform() | 
|  | 534 | squashRecoverySrcs(c) | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 535 | } else if strings.HasPrefix(variant, android.VendorVariation) { | 
|  | 536 | c.Properties.ImageVariation = android.VendorVariation | 
| Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 537 |  | 
|  | 538 | if strings.HasPrefix(variant, VendorVariationPrefix) { | 
| Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 539 | c.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix) | 
| Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 540 | } | 
| Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 541 | squashVendorSrcs(c) | 
| Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 542 | } else if strings.HasPrefix(variant, android.ProductVariation) { | 
|  | 543 | c.Properties.ImageVariation = android.ProductVariation | 
| Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 544 | if strings.HasPrefix(variant, ProductVariationPrefix) { | 
| Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 545 | c.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix) | 
| Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 546 | } | 
| Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 547 | squashProductSrcs(c) | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 548 | } | 
| Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 549 |  | 
|  | 550 | if c.NeedsVendorPublicLibraryVariants() && | 
|  | 551 | (variant == android.CoreVariation || strings.HasPrefix(variant, ProductVariationPrefix)) { | 
|  | 552 | c.VendorProperties.IsVendorPublicLibrary = true | 
|  | 553 | } | 
| Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 554 | } |