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