Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/genrule" |
| 20 | ) |
| 21 | |
| 22 | func init() { |
| 23 | android.RegisterModuleType("cc_genrule", genRuleFactory) |
| 24 | } |
| 25 | |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 26 | type GenruleExtraProperties struct { |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 27 | Vendor_available *bool |
Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame^] | 28 | Odm_available *bool |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 29 | Product_available *bool |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 30 | Ramdisk_available *bool |
| 31 | Vendor_ramdisk_available *bool |
| 32 | Recovery_available *bool |
| 33 | Sdk_version *string |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 34 | } |
| 35 | |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 36 | // cc_genrule is a genrule that can depend on other cc_* objects. |
| 37 | // The cmd may be run multiple times, once for each of the different arch/etc |
| 38 | // variations. |
| 39 | func genRuleFactory() android.Module { |
| 40 | module := genrule.NewGenRule() |
| 41 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 42 | extra := &GenruleExtraProperties{} |
| 43 | module.Extra = extra |
| 44 | module.ImageInterface = extra |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 45 | module.AddProperties(module.Extra) |
| 46 | |
| 47 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth) |
| 48 | |
Jiyong Park | fc752ca | 2019-06-12 13:27:29 +0900 | [diff] [blame] | 49 | android.InitApexModule(module) |
| 50 | |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 51 | return module |
| 52 | } |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 53 | |
| 54 | var _ android.ImageInterface = (*GenruleExtraProperties)(nil) |
| 55 | |
| 56 | func (g *GenruleExtraProperties) ImageMutatorBegin(ctx android.BaseModuleContext) {} |
| 57 | |
| 58 | func (g *GenruleExtraProperties) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 59 | if ctx.DeviceConfig().VndkVersion() == "" { |
| 60 | return true |
| 61 | } |
| 62 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 63 | if ctx.DeviceConfig().ProductVndkVersion() != "" && ctx.ProductSpecific() { |
| 64 | return false |
| 65 | } |
| 66 | |
Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame^] | 67 | return !(ctx.SocSpecific() || ctx.DeviceSpecific()) |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 70 | func (g *GenruleExtraProperties) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 71 | return Bool(g.Ramdisk_available) |
| 72 | } |
| 73 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 74 | func (g *GenruleExtraProperties) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 75 | return Bool(g.Vendor_ramdisk_available) |
| 76 | } |
| 77 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 78 | func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
Jose Galmes | 6f843bc | 2020-12-11 13:36:29 -0800 | [diff] [blame] | 79 | // If the build is using a snapshot, the recovery variant under AOSP directories |
| 80 | // is not needed. |
| 81 | recoverySnapshotVersion := ctx.DeviceConfig().RecoverySnapshotVersion() |
| 82 | if recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && |
| 83 | !isRecoveryProprietaryModule(ctx) { |
| 84 | return false |
| 85 | } else { |
| 86 | return Bool(g.Recovery_available) |
| 87 | } |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
| 91 | if ctx.DeviceConfig().VndkVersion() == "" { |
| 92 | return nil |
| 93 | } |
| 94 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 95 | var variants []string |
Justin Yun | ebcf0c5 | 2021-01-08 18:00:19 +0900 | [diff] [blame^] | 96 | if Bool(g.Vendor_available) || Bool(g.Odm_available) || ctx.SocSpecific() || ctx.DeviceSpecific() { |
Inseob Kim | 8570880 | 2020-06-02 00:06:15 +0900 | [diff] [blame] | 97 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 98 | // If vndkVersion is current, we can always use PlatformVndkVersion. |
| 99 | // If not, we assume modules under proprietary paths are compatible for |
| 100 | // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, that is |
| 101 | // PLATFORM_VNDK_VERSION. |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 102 | if vndkVersion == "current" || !isVendorProprietaryModule(ctx) { |
Inseob Kim | 8570880 | 2020-06-02 00:06:15 +0900 | [diff] [blame] | 103 | variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) |
| 104 | } else { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 105 | variants = append(variants, VendorVariationPrefix+vndkVersion) |
| 106 | } |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | if ctx.DeviceConfig().ProductVndkVersion() == "" { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 110 | return variants |
| 111 | } |
| 112 | |
Justin Yun | 6977e8a | 2020-10-29 18:24:11 +0900 | [diff] [blame] | 113 | if Bool(g.Product_available) || ctx.ProductSpecific() { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 114 | variants = append(variants, ProductVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) |
| 115 | if vndkVersion := ctx.DeviceConfig().ProductVndkVersion(); vndkVersion != "current" { |
| 116 | variants = append(variants, ProductVariationPrefix+vndkVersion) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return variants |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | func (g *GenruleExtraProperties) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
| 124 | } |