blob: b0efc6ca4e6fa750cffda7f1e8120e4abffec3cf [file] [log] [blame]
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001// 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
15package cc
16
17import (
18 "android/soong/android"
19 "android/soong/genrule"
20)
21
22func init() {
23 android.RegisterModuleType("cc_genrule", genRuleFactory)
24}
25
Jiyong Park3f736c92018-05-24 13:36:56 +090026type GenruleExtraProperties struct {
Yifan Hong60e0cfb2020-10-21 15:17:56 -070027 Vendor_available *bool
Justin Yunebcf0c52021-01-08 18:00:19 +090028 Odm_available *bool
Justin Yun63e9ec72020-10-29 16:49:43 +090029 Product_available *bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -070030 Ramdisk_available *bool
31 Vendor_ramdisk_available *bool
32 Recovery_available *bool
33 Sdk_version *string
Jiyong Park3f736c92018-05-24 13:36:56 +090034}
35
Dan Willemsen3e5bdf22017-09-13 18:37:08 -070036// 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.
39func genRuleFactory() android.Module {
40 module := genrule.NewGenRule()
41
Colin Cross7228ecd2019-11-18 16:00:16 -080042 extra := &GenruleExtraProperties{}
43 module.Extra = extra
44 module.ImageInterface = extra
Dan Willemsen3e5bdf22017-09-13 18:37:08 -070045 module.AddProperties(module.Extra)
46
47 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth)
48
Jiyong Parkfc752ca2019-06-12 13:27:29 +090049 android.InitApexModule(module)
50
Dan Willemsen3e5bdf22017-09-13 18:37:08 -070051 return module
52}
Colin Cross7228ecd2019-11-18 16:00:16 -080053
54var _ android.ImageInterface = (*GenruleExtraProperties)(nil)
55
56func (g *GenruleExtraProperties) ImageMutatorBegin(ctx android.BaseModuleContext) {}
57
58func (g *GenruleExtraProperties) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
59 if ctx.DeviceConfig().VndkVersion() == "" {
60 return true
61 }
62
Justin Yun5f7f7e82019-11-18 19:52:14 +090063 if ctx.DeviceConfig().ProductVndkVersion() != "" && ctx.ProductSpecific() {
64 return false
65 }
66
Justin Yunebcf0c52021-01-08 18:00:19 +090067 return !(ctx.SocSpecific() || ctx.DeviceSpecific())
Colin Cross7228ecd2019-11-18 16:00:16 -080068}
69
Yifan Hong1b3348d2020-01-21 15:53:22 -080070func (g *GenruleExtraProperties) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
71 return Bool(g.Ramdisk_available)
72}
73
Yifan Hong60e0cfb2020-10-21 15:17:56 -070074func (g *GenruleExtraProperties) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
75 return Bool(g.Vendor_ramdisk_available)
76}
77
Inseob Kim08758f02021-04-08 21:13:22 +090078func (g *GenruleExtraProperties) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
79 return false
80}
81
Colin Cross7228ecd2019-11-18 16:00:16 -080082func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
Jose Galmes6f843bc2020-12-11 13:36:29 -080083 // If the build is using a snapshot, the recovery variant under AOSP directories
84 // is not needed.
85 recoverySnapshotVersion := ctx.DeviceConfig().RecoverySnapshotVersion()
86 if recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" &&
87 !isRecoveryProprietaryModule(ctx) {
88 return false
89 } else {
90 return Bool(g.Recovery_available)
91 }
Colin Cross7228ecd2019-11-18 16:00:16 -080092}
93
94func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleContext) []string {
95 if ctx.DeviceConfig().VndkVersion() == "" {
96 return nil
97 }
98
Justin Yun5f7f7e82019-11-18 19:52:14 +090099 var variants []string
Justin Yunebcf0c52021-01-08 18:00:19 +0900100 if Bool(g.Vendor_available) || Bool(g.Odm_available) || ctx.SocSpecific() || ctx.DeviceSpecific() {
Inseob Kim85708802020-06-02 00:06:15 +0900101 vndkVersion := ctx.DeviceConfig().VndkVersion()
102 // If vndkVersion is current, we can always use PlatformVndkVersion.
103 // If not, we assume modules under proprietary paths are compatible for
104 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, that is
105 // PLATFORM_VNDK_VERSION.
Ivan Lozanod67a6b02021-05-20 13:01:32 -0400106 if vndkVersion == "current" || !IsVendorProprietaryModule(ctx) {
Inseob Kim85708802020-06-02 00:06:15 +0900107 variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion())
108 } else {
Colin Cross7228ecd2019-11-18 16:00:16 -0800109 variants = append(variants, VendorVariationPrefix+vndkVersion)
110 }
Justin Yun5f7f7e82019-11-18 19:52:14 +0900111 }
112
113 if ctx.DeviceConfig().ProductVndkVersion() == "" {
Colin Cross7228ecd2019-11-18 16:00:16 -0800114 return variants
115 }
116
Justin Yun6977e8a2020-10-29 18:24:11 +0900117 if Bool(g.Product_available) || ctx.ProductSpecific() {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900118 variants = append(variants, ProductVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion())
119 if vndkVersion := ctx.DeviceConfig().ProductVndkVersion(); vndkVersion != "current" {
120 variants = append(variants, ProductVariationPrefix+vndkVersion)
121 }
122 }
123
124 return variants
Colin Cross7228ecd2019-11-18 16:00:16 -0800125}
126
127func (g *GenruleExtraProperties) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
128}