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 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | 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" |
| 23 | ) |
| 24 | |
| 25 | var _ android.ImageInterface = (*Module)(nil) |
| 26 | |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 27 | type imageVariantType string |
| 28 | |
| 29 | const ( |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 30 | coreImageVariant imageVariantType = "core" |
| 31 | vendorImageVariant imageVariantType = "vendor" |
| 32 | productImageVariant imageVariantType = "product" |
| 33 | ramdiskImageVariant imageVariantType = "ramdisk" |
| 34 | vendorRamdiskImageVariant imageVariantType = "vendor_ramdisk" |
| 35 | recoveryImageVariant imageVariantType = "recovery" |
| 36 | hostImageVariant imageVariantType = "host" |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | func (c *Module) getImageVariantType() imageVariantType { |
| 40 | if c.Host() { |
| 41 | return hostImageVariant |
| 42 | } else if c.inVendor() { |
| 43 | return vendorImageVariant |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 44 | } else if c.InProduct() { |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 45 | return productImageVariant |
| 46 | } else if c.InRamdisk() { |
| 47 | return ramdiskImageVariant |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 48 | } else if c.InVendorRamdisk() { |
| 49 | return vendorRamdiskImageVariant |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 50 | } else if c.InRecovery() { |
| 51 | return recoveryImageVariant |
| 52 | } else { |
| 53 | return coreImageVariant |
| 54 | } |
| 55 | } |
| 56 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 57 | const ( |
| 58 | // VendorVariationPrefix is the variant prefix used for /vendor code that compiles |
| 59 | // against the VNDK. |
| 60 | VendorVariationPrefix = "vendor." |
| 61 | |
| 62 | // ProductVariationPrefix is the variant prefix used for /product code that compiles |
| 63 | // against the VNDK. |
| 64 | ProductVariationPrefix = "product." |
| 65 | ) |
| 66 | |
| 67 | func (ctx *moduleContext) ProductSpecific() bool { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 68 | //TODO(b/150902910): Replace HasNonSystemVariants() with HasProductVariant() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 69 | return ctx.ModuleContext.ProductSpecific() || |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 70 | (ctx.mod.HasNonSystemVariants() && ctx.mod.InProduct()) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | func (ctx *moduleContext) SocSpecific() bool { |
| 74 | return ctx.ModuleContext.SocSpecific() || |
Justin Yun | 543f60b | 2020-10-18 10:54:31 +0900 | [diff] [blame] | 75 | (ctx.mod.HasVendorVariant() && ctx.mod.inVendor()) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | func (ctx *moduleContextImpl) inProduct() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 79 | return ctx.mod.InProduct() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | func (ctx *moduleContextImpl) inVendor() bool { |
| 83 | return ctx.mod.inVendor() |
| 84 | } |
| 85 | |
| 86 | func (ctx *moduleContextImpl) inRamdisk() bool { |
| 87 | return ctx.mod.InRamdisk() |
| 88 | } |
| 89 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 90 | func (ctx *moduleContextImpl) inVendorRamdisk() bool { |
| 91 | return ctx.mod.InVendorRamdisk() |
| 92 | } |
| 93 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 94 | func (ctx *moduleContextImpl) inRecovery() bool { |
| 95 | return ctx.mod.InRecovery() |
| 96 | } |
| 97 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 98 | // 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] | 99 | func (c *Module) HasVendorVariant() bool { |
| 100 | return c.IsVndk() || Bool(c.VendorProperties.Vendor_available) |
| 101 | } |
| 102 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 103 | // Returns true when this module is configured to have core and product variants. |
| 104 | func (c *Module) HasProductVariant() bool { |
| 105 | return c.IsVndk() || Bool(c.VendorProperties.Product_available) |
| 106 | } |
| 107 | |
| 108 | // Returns true when this module is configured to have core and either product or vendor variants. |
| 109 | func (c *Module) HasNonSystemVariants() bool { |
| 110 | return c.IsVndk() || Bool(c.VendorProperties.Vendor_available) || Bool(c.VendorProperties.Product_available) |
| 111 | } |
| 112 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 113 | // 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] | 114 | func (c *Module) InProduct() bool { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 115 | return c.Properties.ImageVariationPrefix == ProductVariationPrefix |
| 116 | } |
| 117 | |
| 118 | // Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor |
| 119 | func (c *Module) inVendor() bool { |
| 120 | return c.Properties.ImageVariationPrefix == VendorVariationPrefix |
| 121 | } |
| 122 | |
| 123 | func (c *Module) InRamdisk() bool { |
| 124 | return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk() |
| 125 | } |
| 126 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 127 | func (c *Module) InVendorRamdisk() bool { |
| 128 | return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk() |
| 129 | } |
| 130 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 131 | func (c *Module) InRecovery() bool { |
| 132 | return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery() |
| 133 | } |
| 134 | |
| 135 | func (c *Module) OnlyInRamdisk() bool { |
| 136 | return c.ModuleBase.InstallInRamdisk() |
| 137 | } |
| 138 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 139 | func (c *Module) OnlyInVendorRamdisk() bool { |
| 140 | return c.ModuleBase.InstallInVendorRamdisk() |
| 141 | } |
| 142 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 143 | func (c *Module) OnlyInRecovery() bool { |
| 144 | return c.ModuleBase.InstallInRecovery() |
| 145 | } |
| 146 | |
| 147 | func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { |
| 148 | // Validation check |
| 149 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() |
| 150 | productSpecific := mctx.ProductSpecific() |
| 151 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 152 | if m.VendorProperties.Vendor_available != nil { |
| 153 | if vendorSpecific { |
| 154 | mctx.PropertyErrorf("vendor_available", |
| 155 | "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`") |
| 156 | } |
| 157 | // If defined, make sure vendor_available and product_available has the |
| 158 | // same value since `false` for these properties means the module is |
| 159 | // for system only but provides the variant. |
| 160 | if m.VendorProperties.Product_available != nil { |
| 161 | if Bool(m.VendorProperties.Vendor_available) != Bool(m.VendorProperties.Product_available) { |
| 162 | mctx.PropertyErrorf("product_available", "may not have different value than `vendor_available`") |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | if m.VendorProperties.Product_available != nil { |
| 168 | if productSpecific { |
| 169 | mctx.PropertyErrorf("product_available", |
| 170 | "doesn't make sense at the same time as `product_specific: true`") |
| 171 | } |
| 172 | if vendorSpecific { |
| 173 | mctx.PropertyErrorf("product_available", |
| 174 | "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`") |
| 175 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | if vndkdep := m.vndkdep; vndkdep != nil { |
| 179 | if vndkdep.isVndk() { |
| 180 | if vendorSpecific || productSpecific { |
| 181 | if !vndkdep.isVndkExt() { |
| 182 | mctx.PropertyErrorf("vndk", |
| 183 | "must set `extends: \"...\"` to vndk extension") |
| 184 | } else if m.VendorProperties.Vendor_available != nil { |
| 185 | mctx.PropertyErrorf("vendor_available", |
| 186 | "must not set at the same time as `vndk: {extends: \"...\"}`") |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 187 | } else if m.VendorProperties.Product_available != nil { |
| 188 | mctx.PropertyErrorf("product_available", |
| 189 | "must not set at the same time as `vndk: {extends: \"...\"}`") |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 190 | } |
| 191 | } else { |
| 192 | if vndkdep.isVndkExt() { |
| 193 | mctx.PropertyErrorf("vndk", |
| 194 | "must set `vendor: true` or `product_specific: true` to set `extends: %q`", |
| 195 | m.getVndkExtendsModuleName()) |
| 196 | } |
| 197 | if m.VendorProperties.Vendor_available == nil { |
| 198 | mctx.PropertyErrorf("vndk", |
| 199 | "vendor_available must be set to either true or false when `vndk: {enabled: true}`") |
| 200 | } |
| 201 | } |
| 202 | } else { |
| 203 | if vndkdep.isVndkSp() { |
| 204 | mctx.PropertyErrorf("vndk", |
| 205 | "must set `enabled: true` to set `support_system_process: true`") |
| 206 | } |
| 207 | if vndkdep.isVndkExt() { |
| 208 | mctx.PropertyErrorf("vndk", |
| 209 | "must set `enabled: true` to set `extends: %q`", |
| 210 | m.getVndkExtendsModuleName()) |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | var coreVariantNeeded bool = false |
| 216 | var ramdiskVariantNeeded bool = false |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 217 | var vendorRamdiskVariantNeeded bool = false |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 218 | var recoveryVariantNeeded bool = false |
| 219 | |
| 220 | var vendorVariants []string |
| 221 | var productVariants []string |
| 222 | |
| 223 | platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion() |
| 224 | boardVndkVersion := mctx.DeviceConfig().VndkVersion() |
| 225 | productVndkVersion := mctx.DeviceConfig().ProductVndkVersion() |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame^] | 226 | recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion() |
| 227 | usingRecoverySnapshot := recoverySnapshotVersion != "current" && |
| 228 | recoverySnapshotVersion != "" |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 229 | if boardVndkVersion == "current" { |
| 230 | boardVndkVersion = platformVndkVersion |
| 231 | } |
| 232 | if productVndkVersion == "current" { |
| 233 | productVndkVersion = platformVndkVersion |
| 234 | } |
| 235 | |
| 236 | if boardVndkVersion == "" { |
| 237 | // If the device isn't compiling against the VNDK, we always |
| 238 | // use the core mode. |
| 239 | coreVariantNeeded = true |
| 240 | } else if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 241 | // LL-NDK stubs only exist in the vendor and product variants, |
| 242 | // since the real libraries will be used in the core variant. |
| 243 | vendorVariants = append(vendorVariants, |
| 244 | platformVndkVersion, |
| 245 | boardVndkVersion, |
| 246 | ) |
| 247 | productVariants = append(productVariants, |
| 248 | platformVndkVersion, |
| 249 | productVndkVersion, |
| 250 | ) |
| 251 | } else if _, ok := m.linker.(*llndkHeadersDecorator); ok { |
| 252 | // ... and LL-NDK headers as well |
| 253 | vendorVariants = append(vendorVariants, |
| 254 | platformVndkVersion, |
| 255 | boardVndkVersion, |
| 256 | ) |
| 257 | productVariants = append(productVariants, |
| 258 | platformVndkVersion, |
| 259 | productVndkVersion, |
| 260 | ) |
| 261 | } else if m.isSnapshotPrebuilt() { |
| 262 | // Make vendor variants only for the versions in BOARD_VNDK_VERSION and |
| 263 | // PRODUCT_EXTRA_VNDK_VERSIONS. |
| 264 | if snapshot, ok := m.linker.(interface { |
| 265 | version() string |
| 266 | }); ok { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame^] | 267 | if m.InstallInRecovery() { |
| 268 | recoveryVariantNeeded = true |
| 269 | } else { |
| 270 | vendorVariants = append(vendorVariants, snapshot.version()) |
| 271 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 272 | } else { |
| 273 | mctx.ModuleErrorf("version is unknown for snapshot prebuilt") |
| 274 | } |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 275 | } else if m.HasNonSystemVariants() && !m.IsVndkExt() { |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 276 | // This will be available to /system unless it is product_specific |
| 277 | // which will be handled later. |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 278 | coreVariantNeeded = true |
| 279 | |
| 280 | // We assume that modules under proprietary paths are compatible for |
| 281 | // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or |
| 282 | // PLATFORM_VNDK_VERSION. |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 283 | if m.HasVendorVariant() { |
| 284 | if isVendorProprietaryModule(mctx) { |
| 285 | vendorVariants = append(vendorVariants, boardVndkVersion) |
| 286 | } else { |
| 287 | vendorVariants = append(vendorVariants, platformVndkVersion) |
| 288 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | // vendor_available modules are also available to /product. |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 292 | // TODO(b/150902910): product variant will be created only if |
| 293 | // m.HasProductVariant() is true. |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 294 | productVariants = append(productVariants, platformVndkVersion) |
| 295 | // VNDK is always PLATFORM_VNDK_VERSION |
| 296 | if !m.IsVndk() { |
| 297 | productVariants = append(productVariants, productVndkVersion) |
| 298 | } |
| 299 | } else if vendorSpecific && String(m.Properties.Sdk_version) == "" { |
| 300 | // This will be available in /vendor (or /odm) only |
| 301 | |
| 302 | // kernel_headers is a special module type whose exported headers |
| 303 | // are coming from DeviceKernelHeaders() which is always vendor |
| 304 | // dependent. They'll always have both vendor variants. |
| 305 | // For other modules, we assume that modules under proprietary |
| 306 | // paths are compatible for BOARD_VNDK_VERSION. The other modules |
| 307 | // are regarded as AOSP, which is PLATFORM_VNDK_VERSION. |
| 308 | if _, ok := m.linker.(*kernelHeadersDecorator); ok { |
| 309 | vendorVariants = append(vendorVariants, |
| 310 | platformVndkVersion, |
| 311 | boardVndkVersion, |
| 312 | ) |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 313 | } else if isVendorProprietaryModule(mctx) { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 314 | vendorVariants = append(vendorVariants, boardVndkVersion) |
| 315 | } else { |
| 316 | vendorVariants = append(vendorVariants, platformVndkVersion) |
| 317 | } |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 318 | } else if lib := moduleLibraryInterface(m); lib != nil && lib.hasLLNDKStubs() { |
| 319 | // This is an LLNDK library. The implementation of the library will be on /system, |
| 320 | // and vendor and product variants will be created with LLNDK stubs. |
| 321 | coreVariantNeeded = true |
| 322 | vendorVariants = append(vendorVariants, |
| 323 | platformVndkVersion, |
| 324 | boardVndkVersion, |
| 325 | ) |
| 326 | productVariants = append(productVariants, |
| 327 | platformVndkVersion, |
| 328 | productVndkVersion, |
| 329 | ) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 330 | } else { |
| 331 | // This is either in /system (or similar: /data), or is a |
| 332 | // modules built with the NDK. Modules built with the NDK |
| 333 | // will be restricted using the existing link type checks. |
| 334 | coreVariantNeeded = true |
| 335 | } |
| 336 | |
| 337 | if boardVndkVersion != "" && productVndkVersion != "" { |
| 338 | if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" { |
| 339 | // The module has "product_specific: true" that does not create core variant. |
| 340 | coreVariantNeeded = false |
| 341 | productVariants = append(productVariants, productVndkVersion) |
| 342 | } |
| 343 | } else { |
| 344 | // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no |
| 345 | // restriction to use system libs. |
| 346 | // No product variants defined in this case. |
| 347 | productVariants = []string{} |
| 348 | } |
| 349 | |
| 350 | if Bool(m.Properties.Ramdisk_available) { |
| 351 | ramdiskVariantNeeded = true |
| 352 | } |
| 353 | |
| 354 | if m.ModuleBase.InstallInRamdisk() { |
| 355 | ramdiskVariantNeeded = true |
| 356 | coreVariantNeeded = false |
| 357 | } |
| 358 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 359 | if Bool(m.Properties.Vendor_ramdisk_available) { |
| 360 | vendorRamdiskVariantNeeded = true |
| 361 | } |
| 362 | |
| 363 | if m.ModuleBase.InstallInVendorRamdisk() { |
| 364 | vendorRamdiskVariantNeeded = true |
| 365 | coreVariantNeeded = false |
| 366 | } |
| 367 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 368 | if Bool(m.Properties.Recovery_available) { |
| 369 | recoveryVariantNeeded = true |
| 370 | } |
| 371 | |
| 372 | if m.ModuleBase.InstallInRecovery() { |
| 373 | recoveryVariantNeeded = true |
| 374 | coreVariantNeeded = false |
| 375 | } |
| 376 | |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame^] | 377 | // If using a snapshot, the recovery variant under AOSP directories is not needed, |
| 378 | // except for kernel headers, which needs all variants. |
| 379 | if _, ok := m.linker.(*kernelHeadersDecorator); !ok && |
| 380 | !m.isSnapshotPrebuilt() && |
| 381 | usingRecoverySnapshot && |
| 382 | !isRecoveryProprietaryModule(mctx) { |
| 383 | recoveryVariantNeeded = false |
| 384 | } |
| 385 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 386 | for _, variant := range android.FirstUniqueStrings(vendorVariants) { |
| 387 | m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant) |
| 388 | } |
| 389 | |
| 390 | for _, variant := range android.FirstUniqueStrings(productVariants) { |
| 391 | m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant) |
| 392 | } |
| 393 | |
| 394 | m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 395 | m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 396 | m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded |
| 397 | m.Properties.CoreVariantNeeded = coreVariantNeeded |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame^] | 398 | |
| 399 | // Disable the module if no variants are needed. |
| 400 | if !ramdiskVariantNeeded && |
| 401 | !recoveryVariantNeeded && |
| 402 | !coreVariantNeeded && |
| 403 | len(m.Properties.ExtraVariants) == 0 { |
| 404 | m.Disable() |
| 405 | } |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 409 | return c.Properties.CoreVariantNeeded |
| 410 | } |
| 411 | |
| 412 | func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 413 | return c.Properties.RamdiskVariantNeeded |
| 414 | } |
| 415 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 416 | func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 417 | return c.Properties.VendorRamdiskVariantNeeded |
| 418 | } |
| 419 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 420 | func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 421 | return c.Properties.RecoveryVariantNeeded |
| 422 | } |
| 423 | |
| 424 | func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
| 425 | return c.Properties.ExtraVariants |
| 426 | } |
| 427 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 428 | func squashVendorSrcs(m *Module) { |
| 429 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 430 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 431 | lib.baseCompiler.Properties.Target.Vendor.Srcs...) |
| 432 | |
| 433 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 434 | lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) |
| 435 | |
| 436 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 437 | lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...) |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | func squashProductSrcs(m *Module) { |
| 442 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 443 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 444 | lib.baseCompiler.Properties.Target.Product.Srcs...) |
| 445 | |
| 446 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 447 | lib.baseCompiler.Properties.Target.Product.Exclude_srcs...) |
| 448 | |
| 449 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 450 | lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...) |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | func squashRecoverySrcs(m *Module) { |
| 455 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 456 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 457 | lib.baseCompiler.Properties.Target.Recovery.Srcs...) |
| 458 | |
| 459 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 460 | lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) |
| 461 | |
| 462 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 463 | lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...) |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | func squashVendorRamdiskSrcs(m *Module) { |
| 468 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 469 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...) |
| 470 | } |
| 471 | } |
| 472 | |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 473 | func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { |
| 474 | m := module.(*Module) |
Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 475 | if variant == android.RamdiskVariation { |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 476 | m.MakeAsPlatform() |
Yifan Hong | 6da33c2 | 2020-10-27 15:01:21 -0700 | [diff] [blame] | 477 | } else if variant == android.VendorRamdiskVariation { |
| 478 | m.MakeAsPlatform() |
| 479 | squashVendorRamdiskSrcs(m) |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 480 | } else if variant == android.RecoveryVariation { |
| 481 | m.MakeAsPlatform() |
| 482 | squashRecoverySrcs(m) |
| 483 | } else if strings.HasPrefix(variant, VendorVariationPrefix) { |
| 484 | m.Properties.ImageVariationPrefix = VendorVariationPrefix |
| 485 | m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix) |
| 486 | squashVendorSrcs(m) |
| 487 | |
| 488 | // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION. |
| 489 | // Hide other vendor variants to avoid collision. |
| 490 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 491 | if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion { |
| 492 | m.Properties.HideFromMake = true |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 493 | m.HideFromMake() |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 494 | } |
| 495 | } else if strings.HasPrefix(variant, ProductVariationPrefix) { |
| 496 | m.Properties.ImageVariationPrefix = ProductVariationPrefix |
| 497 | m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix) |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 498 | // TODO (b/150902910): This will be replaced with squashProductSrcs(m). |
Inseob Kim | e498dd9 | 2020-08-04 09:24:04 +0900 | [diff] [blame] | 499 | squashVendorSrcs(m) |
| 500 | } |
| 501 | } |