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 ( |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 20 | "fmt" |
| 21 | "reflect" |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 22 | "strings" |
| 23 | |
| 24 | "android/soong/android" |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 25 | "android/soong/snapshot" |
Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 26 | |
| 27 | "github.com/google/blueprint/proptools" |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | var _ android.ImageInterface = (*Module)(nil) |
| 31 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 32 | type ImageVariantType string |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 33 | |
| 34 | const ( |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 35 | coreImageVariant ImageVariantType = "core" |
| 36 | vendorImageVariant ImageVariantType = "vendor" |
| 37 | productImageVariant ImageVariantType = "product" |
| 38 | ramdiskImageVariant ImageVariantType = "ramdisk" |
| 39 | vendorRamdiskImageVariant ImageVariantType = "vendor_ramdisk" |
| 40 | recoveryImageVariant ImageVariantType = "recovery" |
| 41 | hostImageVariant ImageVariantType = "host" |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 42 | ) |
| 43 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 44 | const ( |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 45 | // VendorVariation is the variant name used for /vendor code that does not |
| 46 | // compile against the VNDK. |
| 47 | VendorVariation = "vendor" |
| 48 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 49 | // VendorVariationPrefix is the variant prefix used for /vendor code that compiles |
| 50 | // against the VNDK. |
| 51 | VendorVariationPrefix = "vendor." |
| 52 | |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 53 | // ProductVariation is the variant name used for /product code that does not |
| 54 | // compile against the VNDK. |
| 55 | ProductVariation = "product" |
| 56 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 57 | // ProductVariationPrefix is the variant prefix used for /product code that compiles |
| 58 | // against the VNDK. |
| 59 | ProductVariationPrefix = "product." |
| 60 | ) |
| 61 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 62 | func (ctx *moduleContextImpl) inProduct() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 63 | return ctx.mod.InProduct() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | func (ctx *moduleContextImpl) inVendor() bool { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 67 | return ctx.mod.InVendor() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | func (ctx *moduleContextImpl) inRamdisk() bool { |
| 71 | return ctx.mod.InRamdisk() |
| 72 | } |
| 73 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 74 | func (ctx *moduleContextImpl) inVendorRamdisk() bool { |
| 75 | return ctx.mod.InVendorRamdisk() |
| 76 | } |
| 77 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 78 | func (ctx *moduleContextImpl) inRecovery() bool { |
| 79 | return ctx.mod.InRecovery() |
| 80 | } |
| 81 | |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 82 | func (c *Module) InstallInProduct() bool { |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 83 | // Additionally check if this module is inProduct() that means it is a "product" variant of a |
| 84 | // module. As well as product specific modules, product variants must be installed to /product. |
| 85 | return c.InProduct() |
| 86 | } |
| 87 | |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 88 | func (c *Module) InstallInVendor() bool { |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 89 | // Additionally check if this module is inVendor() that means it is a "vendor" variant of a |
| 90 | // module. As well as SoC specific modules, vendor variants must be installed to /vendor |
| 91 | // unless they have "odm_available: true". |
| 92 | return c.HasVendorVariant() && c.InVendor() && !c.VendorVariantToOdm() |
| 93 | } |
| 94 | |
Colin Cross | ea30d85 | 2023-11-29 16:00:16 -0800 | [diff] [blame] | 95 | func (c *Module) InstallInOdm() bool { |
Justin Yun | 7f99ec7 | 2021-04-12 13:19:28 +0900 | [diff] [blame] | 96 | // Some vendor variants want to be installed to /odm by setting "odm_available: true". |
| 97 | return c.InVendor() && c.VendorVariantToOdm() |
| 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 vendor variants. |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 101 | func (c *Module) HasVendorVariant() bool { |
Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame] | 102 | return Bool(c.VendorProperties.Vendor_available) || Bool(c.VendorProperties.Odm_available) |
| 103 | } |
| 104 | |
| 105 | // Returns true when this module creates a vendor variant and wants to install the vendor variant |
| 106 | // to the odm partition. |
| 107 | func (c *Module) VendorVariantToOdm() bool { |
| 108 | return Bool(c.VendorProperties.Odm_available) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 109 | } |
| 110 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 111 | // Returns true when this module is configured to have core and product variants. |
| 112 | func (c *Module) HasProductVariant() bool { |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 113 | return Bool(c.VendorProperties.Product_available) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | // Returns true when this module is configured to have core and either product or vendor variants. |
| 117 | func (c *Module) HasNonSystemVariants() bool { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 118 | return c.HasVendorVariant() || c.HasProductVariant() |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 119 | } |
| 120 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 121 | // 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] | 122 | func (c *Module) InProduct() bool { |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 123 | return c.Properties.ImageVariation == ProductVariation |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | // 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] | 127 | func (c *Module) InVendor() bool { |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 128 | return c.Properties.ImageVariation == VendorVariation |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | func (c *Module) InRamdisk() bool { |
| 132 | return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk() |
| 133 | } |
| 134 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 135 | func (c *Module) InVendorRamdisk() bool { |
| 136 | return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk() |
| 137 | } |
| 138 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 139 | func (c *Module) InRecovery() bool { |
| 140 | return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery() |
| 141 | } |
| 142 | |
| 143 | func (c *Module) OnlyInRamdisk() bool { |
| 144 | return c.ModuleBase.InstallInRamdisk() |
| 145 | } |
| 146 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 147 | func (c *Module) OnlyInVendorRamdisk() bool { |
| 148 | return c.ModuleBase.InstallInVendorRamdisk() |
| 149 | } |
| 150 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 151 | func (c *Module) OnlyInRecovery() bool { |
| 152 | return c.ModuleBase.InstallInRecovery() |
| 153 | } |
| 154 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 155 | func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool { |
| 156 | if v.Kind() != reflect.Struct { |
| 157 | return true |
| 158 | } |
| 159 | for i := 0; i < v.NumField(); i++ { |
| 160 | prop := v.Field(i) |
| 161 | if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" { |
| 162 | vendor_prop := prop.FieldByName("Vendor") |
| 163 | product_prop := prop.FieldByName("Product") |
| 164 | if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct { |
| 165 | // Neither Target.Vendor nor Target.Product is defined |
| 166 | continue |
| 167 | } |
| 168 | if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct || |
| 169 | !reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) { |
| 170 | // If only one of either Target.Vendor or Target.Product is |
| 171 | // defined or they have different values, it fails the build |
| 172 | // since VNDK must have the same properties for both vendor |
| 173 | // and product variants. |
| 174 | return false |
| 175 | } |
| 176 | } else if !visitPropsAndCompareVendorAndProductProps(prop) { |
| 177 | // Visit the substructures to find Target.Vendor and Target.Product |
| 178 | return false |
| 179 | } |
| 180 | } |
| 181 | return true |
| 182 | } |
| 183 | |
| 184 | // In the case of VNDK, vendor and product variants must have the same properties. |
| 185 | // VNDK installs only one file and shares it for both vendor and product modules on |
| 186 | // runtime. We may not define different versions of a VNDK lib for each partition. |
| 187 | // This function is used only for the VNDK modules that is available to both vendor |
| 188 | // and product partitions. |
| 189 | func (c *Module) compareVendorAndProductProps() bool { |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 190 | if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) { |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 191 | panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name())) |
| 192 | } |
| 193 | for _, properties := range c.GetProperties() { |
| 194 | if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) { |
| 195 | return false |
| 196 | } |
| 197 | } |
| 198 | return true |
| 199 | } |
| 200 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 201 | // ImageMutatableModule provides a common image mutation interface for LinkableInterface modules. |
| 202 | type ImageMutatableModule interface { |
| 203 | android.Module |
| 204 | LinkableInterface |
| 205 | |
| 206 | // AndroidModuleBase returns the android.ModuleBase for this module |
| 207 | AndroidModuleBase() *android.ModuleBase |
| 208 | |
| 209 | // VendorAvailable returns true if this module is available on the vendor image. |
| 210 | VendorAvailable() bool |
| 211 | |
| 212 | // OdmAvailable returns true if this module is available on the odm image. |
| 213 | OdmAvailable() bool |
| 214 | |
| 215 | // ProductAvailable returns true if this module is available on the product image. |
| 216 | ProductAvailable() bool |
| 217 | |
| 218 | // RamdiskAvailable returns true if this module is available on the ramdisk image. |
| 219 | RamdiskAvailable() bool |
| 220 | |
| 221 | // RecoveryAvailable returns true if this module is available on the recovery image. |
| 222 | RecoveryAvailable() bool |
| 223 | |
| 224 | // VendorRamdiskAvailable returns true if this module is available on the vendor ramdisk image. |
| 225 | VendorRamdiskAvailable() bool |
| 226 | |
| 227 | // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt. |
| 228 | IsSnapshotPrebuilt() bool |
| 229 | |
| 230 | // SnapshotVersion returns the snapshot version for this module. |
| 231 | SnapshotVersion(mctx android.BaseModuleContext) string |
| 232 | |
| 233 | // SdkVersion returns the SDK version for this module. |
| 234 | SdkVersion() string |
| 235 | |
| 236 | // ExtraVariants returns the list of extra variants this module requires. |
| 237 | ExtraVariants() []string |
| 238 | |
| 239 | // AppendExtraVariant returns an extra variant to the list of extra variants this module requires. |
| 240 | AppendExtraVariant(extraVariant string) |
| 241 | |
| 242 | // SetRamdiskVariantNeeded sets whether the Ramdisk Variant is needed. |
| 243 | SetRamdiskVariantNeeded(b bool) |
| 244 | |
| 245 | // SetVendorRamdiskVariantNeeded sets whether the Vendor Ramdisk Variant is needed. |
| 246 | SetVendorRamdiskVariantNeeded(b bool) |
| 247 | |
| 248 | // SetRecoveryVariantNeeded sets whether the Recovery Variant is needed. |
| 249 | SetRecoveryVariantNeeded(b bool) |
| 250 | |
| 251 | // SetCoreVariantNeeded sets whether the Core Variant is needed. |
| 252 | SetCoreVariantNeeded(b bool) |
| 253 | } |
| 254 | |
| 255 | var _ ImageMutatableModule = (*Module)(nil) |
| 256 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 257 | func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 258 | m.CheckVndkProperties(mctx) |
| 259 | MutateImage(mctx, m) |
| 260 | } |
| 261 | |
| 262 | // CheckVndkProperties checks whether the VNDK-related properties are set correctly. |
| 263 | // If properties are not set correctly, results in a module context property error. |
| 264 | func (m *Module) CheckVndkProperties(mctx android.BaseModuleContext) { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 265 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() |
| 266 | productSpecific := mctx.ProductSpecific() |
| 267 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 268 | if vndkdep := m.vndkdep; vndkdep != nil { |
| 269 | if vndkdep.isVndk() { |
| 270 | if vendorSpecific || productSpecific { |
| 271 | if !vndkdep.isVndkExt() { |
| 272 | mctx.PropertyErrorf("vndk", |
| 273 | "must set `extends: \"...\"` to vndk extension") |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 274 | } else if Bool(m.VendorProperties.Vendor_available) { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 275 | mctx.PropertyErrorf("vendor_available", |
| 276 | "must not set at the same time as `vndk: {extends: \"...\"}`") |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 277 | } else if Bool(m.VendorProperties.Product_available) { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 278 | mctx.PropertyErrorf("product_available", |
| 279 | "must not set at the same time as `vndk: {extends: \"...\"}`") |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 280 | } |
| 281 | } else { |
| 282 | if vndkdep.isVndkExt() { |
| 283 | mctx.PropertyErrorf("vndk", |
| 284 | "must set `vendor: true` or `product_specific: true` to set `extends: %q`", |
| 285 | m.getVndkExtendsModuleName()) |
| 286 | } |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 287 | if !Bool(m.VendorProperties.Vendor_available) { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 288 | mctx.PropertyErrorf("vndk", |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 289 | "vendor_available must be set to true when `vndk: {enabled: true}`") |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 290 | } |
Justin Yun | c0d8c49 | 2021-01-07 17:45:31 +0900 | [diff] [blame] | 291 | if Bool(m.VendorProperties.Product_available) { |
Justin Yun | fd9e804 | 2020-12-23 18:23:14 +0900 | [diff] [blame] | 292 | // If a VNDK module creates both product and vendor variants, they |
| 293 | // must have the same properties since they share a single VNDK |
| 294 | // library on runtime. |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 295 | if !m.compareVendorAndProductProps() { |
| 296 | mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules") |
| 297 | } |
| 298 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 299 | } |
| 300 | } else { |
| 301 | if vndkdep.isVndkSp() { |
| 302 | mctx.PropertyErrorf("vndk", |
| 303 | "must set `enabled: true` to set `support_system_process: true`") |
| 304 | } |
| 305 | if vndkdep.isVndkExt() { |
| 306 | mctx.PropertyErrorf("vndk", |
| 307 | "must set `enabled: true` to set `extends: %q`", |
| 308 | m.getVndkExtendsModuleName()) |
| 309 | } |
| 310 | } |
| 311 | } |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | func (m *Module) VendorAvailable() bool { |
| 315 | return Bool(m.VendorProperties.Vendor_available) |
| 316 | } |
| 317 | |
| 318 | func (m *Module) OdmAvailable() bool { |
| 319 | return Bool(m.VendorProperties.Odm_available) |
| 320 | } |
| 321 | |
| 322 | func (m *Module) ProductAvailable() bool { |
| 323 | return Bool(m.VendorProperties.Product_available) |
| 324 | } |
| 325 | |
| 326 | func (m *Module) RamdiskAvailable() bool { |
| 327 | return Bool(m.Properties.Ramdisk_available) |
| 328 | } |
| 329 | |
| 330 | func (m *Module) VendorRamdiskAvailable() bool { |
| 331 | return Bool(m.Properties.Vendor_ramdisk_available) |
| 332 | } |
| 333 | |
| 334 | func (m *Module) AndroidModuleBase() *android.ModuleBase { |
| 335 | return &m.ModuleBase |
| 336 | } |
| 337 | |
| 338 | func (m *Module) RecoveryAvailable() bool { |
| 339 | return Bool(m.Properties.Recovery_available) |
| 340 | } |
| 341 | |
| 342 | func (m *Module) ExtraVariants() []string { |
Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 343 | return m.Properties.ExtraVersionedImageVariations |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | func (m *Module) AppendExtraVariant(extraVariant string) { |
Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 347 | m.Properties.ExtraVersionedImageVariations = append(m.Properties.ExtraVersionedImageVariations, extraVariant) |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | func (m *Module) SetRamdiskVariantNeeded(b bool) { |
| 351 | m.Properties.RamdiskVariantNeeded = b |
| 352 | } |
| 353 | |
| 354 | func (m *Module) SetVendorRamdiskVariantNeeded(b bool) { |
| 355 | m.Properties.VendorRamdiskVariantNeeded = b |
| 356 | } |
| 357 | |
| 358 | func (m *Module) SetRecoveryVariantNeeded(b bool) { |
| 359 | m.Properties.RecoveryVariantNeeded = b |
| 360 | } |
| 361 | |
| 362 | func (m *Module) SetCoreVariantNeeded(b bool) { |
| 363 | m.Properties.CoreVariantNeeded = b |
| 364 | } |
| 365 | |
| 366 | func (m *Module) SnapshotVersion(mctx android.BaseModuleContext) string { |
Ivan Lozano | d1dec54 | 2021-05-26 15:33:11 -0400 | [diff] [blame] | 367 | if snapshot, ok := m.linker.(SnapshotInterface); ok { |
| 368 | return snapshot.Version() |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 369 | } else { |
| 370 | mctx.ModuleErrorf("version is unknown for snapshot prebuilt") |
| 371 | // Should we be panicking here instead? |
| 372 | return "" |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | func (m *Module) KernelHeadersDecorator() bool { |
| 377 | if _, ok := m.linker.(*kernelHeadersDecorator); ok { |
| 378 | return true |
| 379 | } |
| 380 | return false |
| 381 | } |
| 382 | |
| 383 | // MutateImage handles common image mutations for ImageMutatableModule interfaces. |
| 384 | func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) { |
| 385 | // Validation check |
| 386 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() |
| 387 | productSpecific := mctx.ProductSpecific() |
| 388 | |
| 389 | if m.VendorAvailable() { |
| 390 | if vendorSpecific { |
| 391 | mctx.PropertyErrorf("vendor_available", |
| 392 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") |
| 393 | } |
| 394 | if m.OdmAvailable() { |
| 395 | mctx.PropertyErrorf("vendor_available", |
| 396 | "doesn't make sense at the same time as `odm_available: true`") |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if m.OdmAvailable() { |
| 401 | if vendorSpecific { |
| 402 | mctx.PropertyErrorf("odm_available", |
| 403 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`") |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if m.ProductAvailable() { |
| 408 | if productSpecific { |
| 409 | mctx.PropertyErrorf("product_available", |
| 410 | "doesn't make sense at the same time as `product_specific: true`") |
| 411 | } |
| 412 | if vendorSpecific { |
| 413 | mctx.PropertyErrorf("product_available", |
| 414 | "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`") |
| 415 | } |
| 416 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 417 | |
| 418 | var coreVariantNeeded bool = false |
| 419 | var ramdiskVariantNeeded bool = false |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 420 | var vendorRamdiskVariantNeeded bool = false |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 421 | var recoveryVariantNeeded bool = false |
| 422 | |
| 423 | var vendorVariants []string |
| 424 | var productVariants []string |
| 425 | |
| 426 | platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion() |
| 427 | boardVndkVersion := mctx.DeviceConfig().VndkVersion() |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 428 | recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion() |
| 429 | usingRecoverySnapshot := recoverySnapshotVersion != "current" && |
| 430 | recoverySnapshotVersion != "" |
Justin Yun | dee806f | 2021-05-18 23:10:00 +0900 | [diff] [blame] | 431 | needVndkVersionVendorVariantForLlndk := false |
| 432 | if boardVndkVersion != "" { |
| 433 | boardVndkApiLevel, err := android.ApiLevelFromUser(mctx, boardVndkVersion) |
| 434 | if err == nil && !boardVndkApiLevel.IsPreview() { |
| 435 | // VNDK snapshot newer than v30 has LLNDK stub libraries. |
| 436 | // Only the VNDK version less than or equal to v30 requires generating the vendor |
| 437 | // variant of the VNDK version from the source tree. |
| 438 | needVndkVersionVendorVariantForLlndk = boardVndkApiLevel.LessThanOrEqualTo(android.ApiLevelOrPanic(mctx, "30")) |
| 439 | } |
| 440 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 441 | if boardVndkVersion == "current" { |
| 442 | boardVndkVersion = platformVndkVersion |
| 443 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 444 | |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 445 | if m.NeedsLlndkVariants() { |
Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 446 | // This is an LLNDK library. The implementation of the library will be on /system, |
| 447 | // and vendor and product variants will be created with LLNDK stubs. |
| 448 | // The LLNDK libraries need vendor variants even if there is no VNDK. |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 449 | coreVariantNeeded = true |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 450 | vendorVariants = append(vendorVariants, platformVndkVersion) |
| 451 | productVariants = append(productVariants, platformVndkVersion) |
Justin Yun | dee806f | 2021-05-18 23:10:00 +0900 | [diff] [blame] | 452 | // Generate vendor variants for boardVndkVersion only if the VNDK snapshot does not |
| 453 | // provide the LLNDK stub libraries. |
| 454 | if needVndkVersionVendorVariantForLlndk { |
Colin Cross | b5f6fa6 | 2021-01-06 17:05:04 -0800 | [diff] [blame] | 455 | vendorVariants = append(vendorVariants, boardVndkVersion) |
| 456 | } |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 457 | } else if m.NeedsVendorPublicLibraryVariants() { |
| 458 | // A vendor public library has the implementation on /vendor, with stub variants |
| 459 | // for system and product. |
| 460 | coreVariantNeeded = true |
| 461 | vendorVariants = append(vendorVariants, boardVndkVersion) |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 462 | productVariants = append(productVariants, platformVndkVersion) |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 463 | } else if m.IsSnapshotPrebuilt() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 464 | // Make vendor variants only for the versions in BOARD_VNDK_VERSION and |
| 465 | // PRODUCT_EXTRA_VNDK_VERSIONS. |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 466 | if m.InstallInRecovery() { |
| 467 | recoveryVariantNeeded = true |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 468 | } else { |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 469 | vendorVariants = append(vendorVariants, m.SnapshotVersion(mctx)) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 470 | } |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 471 | } else if m.HasNonSystemVariants() && !m.IsVndkExt() { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 472 | // This will be available to /system unless it is product_specific |
| 473 | // which will be handled later. |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 474 | coreVariantNeeded = true |
| 475 | |
| 476 | // We assume that modules under proprietary paths are compatible for |
| 477 | // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or |
| 478 | // PLATFORM_VNDK_VERSION. |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 479 | if m.HasVendorVariant() { |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 480 | if snapshot.IsVendorProprietaryModule(mctx) { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 481 | vendorVariants = append(vendorVariants, boardVndkVersion) |
| 482 | } else { |
| 483 | vendorVariants = append(vendorVariants, platformVndkVersion) |
| 484 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 485 | } |
| 486 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 487 | // product_available modules are available to /product. |
| 488 | if m.HasProductVariant() { |
| 489 | productVariants = append(productVariants, platformVndkVersion) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 490 | } |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 491 | } else if vendorSpecific && m.SdkVersion() == "" { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 492 | // This will be available in /vendor (or /odm) only |
| 493 | |
| 494 | // kernel_headers is a special module type whose exported headers |
| 495 | // are coming from DeviceKernelHeaders() which is always vendor |
| 496 | // dependent. They'll always have both vendor variants. |
| 497 | // For other modules, we assume that modules under proprietary |
| 498 | // paths are compatible for BOARD_VNDK_VERSION. The other modules |
| 499 | // are regarded as AOSP, which is PLATFORM_VNDK_VERSION. |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 500 | if m.KernelHeadersDecorator() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 501 | vendorVariants = append(vendorVariants, |
| 502 | platformVndkVersion, |
| 503 | boardVndkVersion, |
| 504 | ) |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 505 | } else if snapshot.IsVendorProprietaryModule(mctx) { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 506 | vendorVariants = append(vendorVariants, boardVndkVersion) |
| 507 | } else { |
| 508 | vendorVariants = append(vendorVariants, platformVndkVersion) |
| 509 | } |
| 510 | } else { |
| 511 | // This is either in /system (or similar: /data), or is a |
jiajia tang | cd1c27b | 2022-07-21 18:04:37 +0800 | [diff] [blame] | 512 | // module built with the NDK. Modules built with the NDK |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 513 | // will be restricted using the existing link type checks. |
| 514 | coreVariantNeeded = true |
| 515 | } |
| 516 | |
Justin Yun | af1fde4 | 2023-09-27 16:22:10 +0900 | [diff] [blame] | 517 | if coreVariantNeeded && productSpecific && m.SdkVersion() == "" { |
| 518 | // The module has "product_specific: true" that does not create core variant. |
| 519 | coreVariantNeeded = false |
| 520 | productVariants = append(productVariants, platformVndkVersion) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 521 | } |
| 522 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 523 | if m.RamdiskAvailable() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 524 | ramdiskVariantNeeded = true |
| 525 | } |
| 526 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 527 | if m.AndroidModuleBase().InstallInRamdisk() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 528 | ramdiskVariantNeeded = true |
| 529 | coreVariantNeeded = false |
| 530 | } |
| 531 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 532 | if m.VendorRamdiskAvailable() { |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 533 | vendorRamdiskVariantNeeded = true |
| 534 | } |
| 535 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 536 | if m.AndroidModuleBase().InstallInVendorRamdisk() { |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 537 | vendorRamdiskVariantNeeded = true |
| 538 | coreVariantNeeded = false |
| 539 | } |
| 540 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 541 | if m.RecoveryAvailable() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 542 | recoveryVariantNeeded = true |
| 543 | } |
| 544 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 545 | if m.AndroidModuleBase().InstallInRecovery() { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 546 | recoveryVariantNeeded = true |
| 547 | coreVariantNeeded = false |
| 548 | } |
| 549 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 550 | // If using a snapshot, the recovery variant under AOSP directories is not needed, |
| 551 | // except for kernel headers, which needs all variants. |
Jose Galmes | 737d0a1 | 2021-05-25 22:06:41 -0700 | [diff] [blame] | 552 | if !m.KernelHeadersDecorator() && |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 553 | !m.IsSnapshotPrebuilt() && |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 554 | usingRecoverySnapshot && |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 555 | !snapshot.IsRecoveryProprietaryModule(mctx) { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 556 | recoveryVariantNeeded = false |
| 557 | } |
| 558 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 559 | for _, variant := range android.FirstUniqueStrings(vendorVariants) { |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 560 | if variant == "" { |
| 561 | m.AppendExtraVariant(VendorVariation) |
| 562 | } else { |
| 563 | m.AppendExtraVariant(VendorVariationPrefix + variant) |
| 564 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | for _, variant := range android.FirstUniqueStrings(productVariants) { |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 568 | if variant == "" { |
| 569 | m.AppendExtraVariant(ProductVariation) |
| 570 | } else { |
| 571 | m.AppendExtraVariant(ProductVariationPrefix + variant) |
| 572 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 573 | } |
| 574 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 575 | m.SetRamdiskVariantNeeded(ramdiskVariantNeeded) |
| 576 | m.SetVendorRamdiskVariantNeeded(vendorRamdiskVariantNeeded) |
| 577 | m.SetRecoveryVariantNeeded(recoveryVariantNeeded) |
| 578 | m.SetCoreVariantNeeded(coreVariantNeeded) |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 579 | |
| 580 | // Disable the module if no variants are needed. |
| 581 | if !ramdiskVariantNeeded && |
| 582 | !recoveryVariantNeeded && |
| 583 | !coreVariantNeeded && |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 584 | len(m.ExtraVariants()) == 0 { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 585 | m.Disable() |
| 586 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 590 | return c.Properties.CoreVariantNeeded |
| 591 | } |
| 592 | |
| 593 | func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 594 | return c.Properties.RamdiskVariantNeeded |
| 595 | } |
| 596 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 597 | func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 598 | return c.Properties.VendorRamdiskVariantNeeded |
| 599 | } |
| 600 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 601 | func (c *Module) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 602 | return false |
| 603 | } |
| 604 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 605 | func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 606 | return c.Properties.RecoveryVariantNeeded |
| 607 | } |
| 608 | |
| 609 | func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
Lukacs T. Berki | 2f5c340 | 2021-06-15 11:27:56 +0200 | [diff] [blame] | 610 | return c.Properties.ExtraVersionedImageVariations |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 611 | } |
| 612 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 613 | func squashVendorSrcs(m *Module) { |
| 614 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 615 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 616 | lib.baseCompiler.Properties.Target.Vendor.Srcs...) |
| 617 | |
| 618 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 619 | lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) |
| 620 | |
| 621 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 622 | lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...) |
Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 623 | |
| 624 | if lib.Properties.Target.Vendor.No_stubs { |
| 625 | proptools.Clear(&lib.Properties.Stubs) |
| 626 | } |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
| 630 | func squashProductSrcs(m *Module) { |
| 631 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 632 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 633 | lib.baseCompiler.Properties.Target.Product.Srcs...) |
| 634 | |
| 635 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 636 | lib.baseCompiler.Properties.Target.Product.Exclude_srcs...) |
| 637 | |
| 638 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 639 | lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...) |
Jooyung Han | 85707de | 2023-12-01 14:21:13 +0900 | [diff] [blame] | 640 | |
| 641 | if lib.Properties.Target.Product.No_stubs { |
| 642 | proptools.Clear(&lib.Properties.Stubs) |
| 643 | } |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
| 647 | func squashRecoverySrcs(m *Module) { |
| 648 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 649 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 650 | lib.baseCompiler.Properties.Target.Recovery.Srcs...) |
| 651 | |
| 652 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 653 | lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) |
| 654 | |
| 655 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 656 | lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...) |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | func squashVendorRamdiskSrcs(m *Module) { |
| 661 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 662 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...) |
| 663 | } |
| 664 | } |
| 665 | |
Christopher Ferris | e0202c4 | 2023-07-27 17:06:46 -0700 | [diff] [blame] | 666 | func squashRamdiskSrcs(m *Module) { |
| 667 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 668 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Ramdisk.Exclude_srcs...) |
| 669 | } |
| 670 | } |
| 671 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 672 | func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { |
| 673 | m := module.(*Module) |
Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 674 | if variant == android.RamdiskVariation { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 675 | m.MakeAsPlatform() |
Christopher Ferris | e0202c4 | 2023-07-27 17:06:46 -0700 | [diff] [blame] | 676 | squashRamdiskSrcs(m) |
Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 677 | } else if variant == android.VendorRamdiskVariation { |
| 678 | m.MakeAsPlatform() |
| 679 | squashVendorRamdiskSrcs(m) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 680 | } else if variant == android.RecoveryVariation { |
| 681 | m.MakeAsPlatform() |
| 682 | squashRecoverySrcs(m) |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 683 | } else if strings.HasPrefix(variant, VendorVariation) { |
| 684 | m.Properties.ImageVariation = VendorVariation |
| 685 | |
| 686 | if strings.HasPrefix(variant, VendorVariationPrefix) { |
| 687 | m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix) |
| 688 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 689 | squashVendorSrcs(m) |
| 690 | |
| 691 | // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION. |
| 692 | // Hide other vendor variants to avoid collision. |
| 693 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 694 | if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion { |
| 695 | m.Properties.HideFromMake = true |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 696 | m.HideFromMake() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 697 | } |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 698 | } else if strings.HasPrefix(variant, ProductVariation) { |
| 699 | m.Properties.ImageVariation = ProductVariation |
| 700 | if strings.HasPrefix(variant, ProductVariationPrefix) { |
| 701 | m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix) |
| 702 | } |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 703 | squashProductSrcs(m) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 704 | } |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 705 | |
| 706 | if c.NeedsVendorPublicLibraryVariants() && |
| 707 | (variant == android.CoreVariation || strings.HasPrefix(variant, ProductVariationPrefix)) { |
| 708 | c.VendorProperties.IsVendorPublicLibrary = true |
| 709 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 710 | } |