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. |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 180 | SnapshotVersion(mctx android.ImageInterfaceContext) string |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 181 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 182 | // ExtraVariants returns the list of extra variants this module requires. |
| 183 | ExtraVariants() []string |
| 184 | |
| 185 | // AppendExtraVariant returns an extra variant to the list of extra variants this module requires. |
| 186 | AppendExtraVariant(extraVariant string) |
| 187 | |
| 188 | // SetRamdiskVariantNeeded sets whether the Ramdisk Variant is needed. |
| 189 | SetRamdiskVariantNeeded(b bool) |
| 190 | |
| 191 | // SetVendorRamdiskVariantNeeded sets whether the Vendor Ramdisk Variant is needed. |
| 192 | SetVendorRamdiskVariantNeeded(b bool) |
| 193 | |
| 194 | // SetRecoveryVariantNeeded sets whether the Recovery Variant is needed. |
| 195 | SetRecoveryVariantNeeded(b bool) |
| 196 | |
| 197 | // SetCoreVariantNeeded sets whether the Core Variant is needed. |
| 198 | SetCoreVariantNeeded(b bool) |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 199 | |
| 200 | // SetProductVariantNeeded sets whether the Product Variant is needed. |
| 201 | SetProductVariantNeeded(b bool) |
| 202 | |
| 203 | // SetVendorVariantNeeded sets whether the Vendor Variant is needed. |
| 204 | SetVendorVariantNeeded(b bool) |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | var _ ImageMutatableModule = (*Module)(nil) |
| 208 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 209 | func (m *Module) ImageMutatorBegin(mctx android.ImageInterfaceContext) { |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 210 | MutateImage(mctx, m) |
| 211 | } |
| 212 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 213 | func (m *Module) VendorAvailable() bool { |
| 214 | return Bool(m.VendorProperties.Vendor_available) |
| 215 | } |
| 216 | |
| 217 | func (m *Module) OdmAvailable() bool { |
| 218 | return Bool(m.VendorProperties.Odm_available) |
| 219 | } |
| 220 | |
| 221 | func (m *Module) ProductAvailable() bool { |
| 222 | return Bool(m.VendorProperties.Product_available) |
| 223 | } |
| 224 | |
| 225 | func (m *Module) RamdiskAvailable() bool { |
| 226 | return Bool(m.Properties.Ramdisk_available) |
| 227 | } |
| 228 | |
| 229 | func (m *Module) VendorRamdiskAvailable() bool { |
| 230 | return Bool(m.Properties.Vendor_ramdisk_available) |
| 231 | } |
| 232 | |
| 233 | func (m *Module) AndroidModuleBase() *android.ModuleBase { |
| 234 | return &m.ModuleBase |
| 235 | } |
| 236 | |
| 237 | func (m *Module) RecoveryAvailable() bool { |
| 238 | return Bool(m.Properties.Recovery_available) |
| 239 | } |
| 240 | |
| 241 | func (m *Module) ExtraVariants() []string { |
Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 242 | return m.Properties.ExtraVersionedImageVariations |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | func (m *Module) AppendExtraVariant(extraVariant string) { |
Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 246 | m.Properties.ExtraVersionedImageVariations = append(m.Properties.ExtraVersionedImageVariations, extraVariant) |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | func (m *Module) SetRamdiskVariantNeeded(b bool) { |
| 250 | m.Properties.RamdiskVariantNeeded = b |
| 251 | } |
| 252 | |
| 253 | func (m *Module) SetVendorRamdiskVariantNeeded(b bool) { |
| 254 | m.Properties.VendorRamdiskVariantNeeded = b |
| 255 | } |
| 256 | |
| 257 | func (m *Module) SetRecoveryVariantNeeded(b bool) { |
| 258 | m.Properties.RecoveryVariantNeeded = b |
| 259 | } |
| 260 | |
| 261 | func (m *Module) SetCoreVariantNeeded(b bool) { |
| 262 | m.Properties.CoreVariantNeeded = b |
| 263 | } |
| 264 | |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 265 | func (m *Module) SetProductVariantNeeded(b bool) { |
| 266 | m.Properties.ProductVariantNeeded = b |
| 267 | } |
| 268 | |
| 269 | func (m *Module) SetVendorVariantNeeded(b bool) { |
| 270 | m.Properties.VendorVariantNeeded = b |
| 271 | } |
| 272 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 273 | func (m *Module) SnapshotVersion(mctx android.ImageInterfaceContext) string { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 274 | if snapshot, ok := m.linker.(SnapshotInterface); ok { |
| 275 | return snapshot.Version() |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 276 | } else { |
| 277 | mctx.ModuleErrorf("version is unknown for snapshot prebuilt") |
| 278 | // Should we be panicking here instead? |
| 279 | return "" |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | func (m *Module) KernelHeadersDecorator() bool { |
| 284 | if _, ok := m.linker.(*kernelHeadersDecorator); ok { |
| 285 | return true |
| 286 | } |
| 287 | return false |
| 288 | } |
| 289 | |
| 290 | // MutateImage handles common image mutations for ImageMutatableModule interfaces. |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 291 | func MutateImage(mctx android.ImageInterfaceContext, m ImageMutatableModule) { |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 292 | // Validation check |
| 293 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() |
| 294 | productSpecific := mctx.ProductSpecific() |
| 295 | |
| 296 | if m.VendorAvailable() { |
| 297 | if vendorSpecific { |
| 298 | mctx.PropertyErrorf("vendor_available", |
| 299 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") |
| 300 | } |
| 301 | if m.OdmAvailable() { |
| 302 | mctx.PropertyErrorf("vendor_available", |
| 303 | "doesn't make sense at the same time as `odm_available: true`") |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | if m.OdmAvailable() { |
| 308 | if vendorSpecific { |
| 309 | mctx.PropertyErrorf("odm_available", |
| 310 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | if m.ProductAvailable() { |
| 315 | if productSpecific { |
| 316 | mctx.PropertyErrorf("product_available", |
| 317 | "doesn't make sense at the same time as `product_specific: true`") |
| 318 | } |
| 319 | if vendorSpecific { |
| 320 | mctx.PropertyErrorf("product_available", |
| 321 | "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`") |
| 322 | } |
| 323 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 324 | |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 325 | var vendorVariantNeeded bool = false |
| 326 | var productVariantNeeded bool = false |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 327 | var coreVariantNeeded bool = false |
| 328 | var ramdiskVariantNeeded bool = false |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 329 | var vendorRamdiskVariantNeeded bool = false |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 330 | var recoveryVariantNeeded bool = false |
| 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 |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 337 | vendorVariantNeeded = true |
| 338 | productVariantNeeded = true |
| 339 | |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 340 | } else if m.NeedsVendorPublicLibraryVariants() { |
| 341 | // A vendor public library has the implementation on /vendor, with stub variants |
| 342 | // for system and product. |
| 343 | coreVariantNeeded = true |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 344 | vendorVariantNeeded = true |
| 345 | productVariantNeeded = true |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 346 | } else if m.IsSnapshotPrebuilt() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 347 | // Make vendor variants only for the versions in BOARD_VNDK_VERSION and |
| 348 | // PRODUCT_EXTRA_VNDK_VERSIONS. |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 349 | if m.InstallInRecovery() { |
| 350 | recoveryVariantNeeded = true |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 351 | } else { |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 352 | m.AppendExtraVariant(VendorVariationPrefix + m.SnapshotVersion(mctx)) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 353 | } |
Kiyoung Kim | 9f26fcf | 2024-05-27 17:25:52 +0900 | [diff] [blame] | 354 | } else if m.HasNonSystemVariants() { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 355 | // This will be available to /system unless it is product_specific |
| 356 | // which will be handled later. |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 357 | coreVariantNeeded = true |
| 358 | |
| 359 | // We assume that modules under proprietary paths are compatible for |
| 360 | // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or |
| 361 | // PLATFORM_VNDK_VERSION. |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 362 | if m.HasVendorVariant() { |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 363 | vendorVariantNeeded = true |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 364 | } |
| 365 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 366 | // product_available modules are available to /product. |
| 367 | if m.HasProductVariant() { |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 368 | productVariantNeeded = true |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 369 | } |
Inseob Kim | 69c6510 | 2024-11-12 16:59:20 +0900 | [diff] [blame] | 370 | } else if vendorSpecific { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 371 | // This will be available in /vendor (or /odm) only |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 372 | vendorVariantNeeded = true |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 373 | } else { |
| 374 | // This is either in /system (or similar: /data), or is a |
jiajia tang | cd1c27b | 2022-07-21 18:04:37 +0800 | [diff] [blame] | 375 | // module built with the NDK. Modules built with the NDK |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 376 | // will be restricted using the existing link type checks. |
| 377 | coreVariantNeeded = true |
| 378 | } |
| 379 | |
Inseob Kim | 69c6510 | 2024-11-12 16:59:20 +0900 | [diff] [blame] | 380 | if coreVariantNeeded && productSpecific { |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 381 | // The module has "product_specific: true" that does not create core variant. |
| 382 | coreVariantNeeded = false |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 383 | productVariantNeeded = true |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 384 | } |
| 385 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 386 | if m.RamdiskAvailable() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 387 | ramdiskVariantNeeded = true |
| 388 | } |
| 389 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 390 | if m.AndroidModuleBase().InstallInRamdisk() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 391 | ramdiskVariantNeeded = true |
| 392 | coreVariantNeeded = false |
| 393 | } |
| 394 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 395 | if m.VendorRamdiskAvailable() { |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 396 | vendorRamdiskVariantNeeded = true |
| 397 | } |
| 398 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 399 | if m.AndroidModuleBase().InstallInVendorRamdisk() { |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 400 | vendorRamdiskVariantNeeded = true |
| 401 | coreVariantNeeded = false |
| 402 | } |
| 403 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 404 | if m.RecoveryAvailable() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 405 | recoveryVariantNeeded = true |
| 406 | } |
| 407 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 408 | if m.AndroidModuleBase().InstallInRecovery() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 409 | recoveryVariantNeeded = true |
| 410 | coreVariantNeeded = false |
| 411 | } |
| 412 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 413 | m.SetRamdiskVariantNeeded(ramdiskVariantNeeded) |
| 414 | m.SetVendorRamdiskVariantNeeded(vendorRamdiskVariantNeeded) |
| 415 | m.SetRecoveryVariantNeeded(recoveryVariantNeeded) |
| 416 | m.SetCoreVariantNeeded(coreVariantNeeded) |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 417 | m.SetProductVariantNeeded(productVariantNeeded) |
| 418 | m.SetVendorVariantNeeded(vendorVariantNeeded) |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 419 | |
| 420 | // Disable the module if no variants are needed. |
| 421 | if !ramdiskVariantNeeded && |
| 422 | !recoveryVariantNeeded && |
| 423 | !coreVariantNeeded && |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 424 | !productVariantNeeded && |
| 425 | !vendorVariantNeeded && |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 426 | len(m.ExtraVariants()) == 0 { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 427 | m.Disable() |
| 428 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 429 | } |
| 430 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 431 | func (c *Module) VendorVariantNeeded(ctx android.ImageInterfaceContext) bool { |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 432 | return c.Properties.VendorVariantNeeded |
| 433 | } |
| 434 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 435 | func (c *Module) ProductVariantNeeded(ctx android.ImageInterfaceContext) bool { |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 436 | return c.Properties.ProductVariantNeeded |
| 437 | } |
| 438 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 439 | func (c *Module) CoreVariantNeeded(ctx android.ImageInterfaceContext) bool { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 440 | return c.Properties.CoreVariantNeeded |
| 441 | } |
| 442 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 443 | func (c *Module) RamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 444 | return c.Properties.RamdiskVariantNeeded |
| 445 | } |
| 446 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 447 | func (c *Module) VendorRamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool { |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 448 | return c.Properties.VendorRamdiskVariantNeeded |
| 449 | } |
| 450 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 451 | func (c *Module) DebugRamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool { |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 452 | return false |
| 453 | } |
| 454 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 455 | func (c *Module) RecoveryVariantNeeded(ctx android.ImageInterfaceContext) bool { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 456 | return c.Properties.RecoveryVariantNeeded |
| 457 | } |
| 458 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 459 | func (c *Module) ExtraImageVariations(ctx android.ImageInterfaceContext) []string { |
Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 460 | return c.Properties.ExtraVersionedImageVariations |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 461 | } |
| 462 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 463 | func squashVendorSrcs(m *Module) { |
| 464 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
Cole Faust | 96a692b | 2024-08-08 14:47:51 -0700 | [diff] [blame] | 465 | lib.baseCompiler.Properties.Srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Vendor.Srcs) |
| 466 | lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 467 | |
| 468 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 469 | lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...) |
Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 470 | |
| 471 | if lib.Properties.Target.Vendor.No_stubs { |
| 472 | proptools.Clear(&lib.Properties.Stubs) |
| 473 | } |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | func squashProductSrcs(m *Module) { |
| 478 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
Cole Faust | 96a692b | 2024-08-08 14:47:51 -0700 | [diff] [blame] | 479 | lib.baseCompiler.Properties.Srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Product.Srcs) |
| 480 | lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Product.Exclude_srcs) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 481 | |
| 482 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 483 | lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...) |
Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 484 | |
| 485 | if lib.Properties.Target.Product.No_stubs { |
| 486 | proptools.Clear(&lib.Properties.Stubs) |
| 487 | } |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
| 491 | func squashRecoverySrcs(m *Module) { |
| 492 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
Cole Faust | 96a692b | 2024-08-08 14:47:51 -0700 | [diff] [blame] | 493 | lib.baseCompiler.Properties.Srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Recovery.Srcs) |
| 494 | lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 495 | |
| 496 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 497 | lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...) |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | func squashVendorRamdiskSrcs(m *Module) { |
| 502 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
Cole Faust | 96a692b | 2024-08-08 14:47:51 -0700 | [diff] [blame] | 503 | lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Christopher Ferris | e0202c4 | 2023-07-27 17:06:46 -0700 | [diff] [blame] | 507 | func squashRamdiskSrcs(m *Module) { |
| 508 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
Cole Faust | 96a692b | 2024-08-08 14:47:51 -0700 | [diff] [blame] | 509 | lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Ramdisk.Exclude_srcs) |
Christopher Ferris | e0202c4 | 2023-07-27 17:06:46 -0700 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
Cole Faust | fa6e0fd | 2024-10-15 15:22:57 -0700 | [diff] [blame] | 513 | func (c *Module) SetImageVariation(ctx android.ImageInterfaceContext, variant string) { |
Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 514 | if variant == android.RamdiskVariation { |
Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 515 | c.MakeAsPlatform() |
| 516 | squashRamdiskSrcs(c) |
Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 517 | } else if variant == android.VendorRamdiskVariation { |
Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 518 | c.MakeAsPlatform() |
| 519 | squashVendorRamdiskSrcs(c) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 520 | } else if variant == android.RecoveryVariation { |
Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 521 | c.MakeAsPlatform() |
| 522 | squashRecoverySrcs(c) |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 523 | } else if strings.HasPrefix(variant, android.VendorVariation) { |
| 524 | c.Properties.ImageVariation = android.VendorVariation |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 525 | |
| 526 | if strings.HasPrefix(variant, VendorVariationPrefix) { |
Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 527 | c.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix) |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 528 | } |
Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 529 | squashVendorSrcs(c) |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 530 | } else if strings.HasPrefix(variant, android.ProductVariation) { |
| 531 | c.Properties.ImageVariation = android.ProductVariation |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 532 | if strings.HasPrefix(variant, ProductVariationPrefix) { |
Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 533 | c.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix) |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 534 | } |
Jihoon Kang | 7583e83 | 2024-06-13 21:25:45 +0000 | [diff] [blame] | 535 | squashProductSrcs(c) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 536 | } |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 537 | |
| 538 | if c.NeedsVendorPublicLibraryVariants() && |
| 539 | (variant == android.CoreVariation || strings.HasPrefix(variant, ProductVariationPrefix)) { |
| 540 | c.VendorProperties.IsVendorPublicLibrary = true |
| 541 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 542 | } |