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