Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1 | // Copyright 2016 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 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 15 | package etc |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 16 | |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 17 | // This file implements module types that install prebuilt artifacts. |
| 18 | // |
| 19 | // There exist two classes of prebuilt modules in the Android tree. The first class are the ones |
| 20 | // based on `android.Prebuilt`, such as `cc_prebuilt_library` and `java_import`. This kind of |
| 21 | // modules may exist both as prebuilts and source at the same time, though only one would be |
| 22 | // installed and the other would be marked disabled. The `prebuilt_postdeps` mutator would select |
| 23 | // the actual modules to be installed. More details in android/prebuilt.go. |
| 24 | // |
| 25 | // The second class is described in this file. Unlike `android.Prebuilt` based module types, |
| 26 | // `prebuilt_etc` exist only as prebuilts and cannot have a same-named source module counterpart. |
| 27 | // This makes the logic of `prebuilt_etc` to be much simpler as they don't need to go through the |
| 28 | // various `prebuilt_*` mutators. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 29 | |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 30 | import ( |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 31 | "encoding/json" |
Jiyong Park | 76a42f5 | 2021-02-16 06:50:37 +0900 | [diff] [blame] | 32 | "fmt" |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 33 | "path/filepath" |
Alix | bbfd538 | 2022-06-09 18:52:05 +0000 | [diff] [blame] | 34 | "reflect" |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 35 | "strings" |
Jiyong Park | 76a42f5 | 2021-02-16 06:50:37 +0900 | [diff] [blame] | 36 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 37 | "github.com/google/blueprint/proptools" |
| 38 | |
| 39 | "android/soong/android" |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 40 | "android/soong/bazel" |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 41 | "android/soong/bazel/cquery" |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 42 | "android/soong/snapshot" |
Liz Kammer | d5d12d0 | 2023-09-05 09:18:50 -0400 | [diff] [blame] | 43 | "android/soong/ui/metrics/bp2build_metrics_proto" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | var pctx = android.NewPackageContext("android/soong/etc") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 47 | |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 48 | // TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 49 | |
| 50 | func init() { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 51 | pctx.Import("android/soong/android") |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 52 | RegisterPrebuiltEtcBuildComponents(android.InitRegistrationContext) |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 53 | snapshot.RegisterSnapshotAction(generatePrebuiltSnapshot) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 54 | } |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 55 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 56 | func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) { |
| 57 | ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory) |
| 58 | ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory) |
Miguel | 32b0280 | 2022-12-01 18:38:26 +0000 | [diff] [blame] | 59 | ctx.RegisterModuleType("prebuilt_etc_cacerts", PrebuiltEtcCaCertsFactory) |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 60 | ctx.RegisterModuleType("prebuilt_root", PrebuiltRootFactory) |
Liz Kammer | e9ecddc | 2022-01-04 17:27:52 -0500 | [diff] [blame] | 61 | ctx.RegisterModuleType("prebuilt_root_host", PrebuiltRootHostFactory) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 62 | ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory) |
| 63 | ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory) |
| 64 | ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory) |
| 65 | ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory) |
| 66 | ctx.RegisterModuleType("prebuilt_dsp", PrebuiltDSPFactory) |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 67 | ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory) |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 68 | |
| 69 | ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory) |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 70 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 71 | } |
| 72 | |
Paul Duffin | 1172fed | 2021-03-08 11:28:18 +0000 | [diff] [blame] | 73 | var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents) |
| 74 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 75 | type prebuiltEtcProperties struct { |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 76 | // Source file of this prebuilt. Can reference a genrule type module with the ":module" syntax. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 77 | Src *string `android:"path,arch_variant"` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 78 | |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 79 | // Optional name for the installed file. If unspecified, name of the module is used as the file |
| 80 | // name. |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 81 | Filename *string `android:"arch_variant"` |
| 82 | |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 83 | // When set to true, and filename property is not set, the name for the installed file |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 84 | // is the same as the file name of the source file. |
| 85 | Filename_from_src *bool `android:"arch_variant"` |
| 86 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 87 | // Make this module available when building for ramdisk. |
Yifan Hong | 39143a9 | 2020-10-26 12:43:12 -0700 | [diff] [blame] | 88 | // On device without a dedicated recovery partition, the module is only |
| 89 | // available after switching root into |
| 90 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 91 | // the recovery variant instead. |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 92 | Ramdisk_available *bool |
| 93 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 94 | // Make this module available when building for vendor ramdisk. |
Yifan Hong | 39143a9 | 2020-10-26 12:43:12 -0700 | [diff] [blame] | 95 | // On device without a dedicated recovery partition, the module is only |
| 96 | // available after switching root into |
| 97 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 98 | // the recovery variant instead. |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 99 | Vendor_ramdisk_available *bool |
| 100 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 101 | // Make this module available when building for debug ramdisk. |
| 102 | Debug_ramdisk_available *bool |
| 103 | |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 104 | // Make this module available when building for recovery. |
| 105 | Recovery_available *bool |
| 106 | |
Jiyong Park | ad9ce04 | 2018-10-31 22:49:57 +0900 | [diff] [blame] | 107 | // Whether this module is directly installable to one of the partitions. Default: true. |
| 108 | Installable *bool |
Yo Chiang | 3d64d49 | 2020-05-27 17:56:39 +0800 | [diff] [blame] | 109 | |
| 110 | // Install symlinks to the installed file. |
| 111 | Symlinks []string `android:"arch_variant"` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 112 | } |
| 113 | |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 114 | type prebuiltSubdirProperties struct { |
| 115 | // Optional subdirectory under which this file is installed into, cannot be specified with |
| 116 | // relative_install_path, prefer relative_install_path. |
| 117 | Sub_dir *string `android:"arch_variant"` |
| 118 | |
| 119 | // Optional subdirectory under which this file is installed into, cannot be specified with |
| 120 | // sub_dir. |
| 121 | Relative_install_path *string `android:"arch_variant"` |
| 122 | } |
| 123 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 124 | type PrebuiltEtcModule interface { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 125 | android.Module |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 126 | |
| 127 | // Returns the base install directory, such as "etc", "usr/share". |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 128 | BaseDir() string |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 129 | |
| 130 | // Returns the sub install directory relative to BaseDir(). |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 131 | SubDir() string |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 132 | |
| 133 | // Returns an android.OutputPath to the intermeidate file, which is the renamed prebuilt source |
| 134 | // file. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 135 | OutputFile() android.OutputPath |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 136 | } |
| 137 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 138 | type PrebuiltEtc struct { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 139 | android.ModuleBase |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 140 | android.DefaultableModuleBase |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 141 | android.BazelModuleBase |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 142 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 143 | snapshot.VendorSnapshotModuleInterface |
| 144 | snapshot.RecoverySnapshotModuleInterface |
| 145 | |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 146 | properties prebuiltEtcProperties |
| 147 | subdirProperties prebuiltSubdirProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 148 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 149 | sourceFilePath android.Path |
| 150 | outputFilePath android.OutputPath |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 151 | // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share. |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 152 | installDirBase string |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 153 | // The base install location when soc_specific property is set to true, e.g. "firmware" for |
| 154 | // prebuilt_firmware. |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 155 | socInstallDirBase string |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 156 | installDirPath android.InstallPath |
| 157 | additionalDependencies *android.Paths |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 158 | } |
| 159 | |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 160 | type Defaults struct { |
| 161 | android.ModuleBase |
| 162 | android.DefaultsModuleBase |
| 163 | } |
| 164 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 165 | func (p *PrebuiltEtc) inRamdisk() bool { |
| 166 | return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk() |
| 167 | } |
| 168 | |
| 169 | func (p *PrebuiltEtc) onlyInRamdisk() bool { |
| 170 | return p.ModuleBase.InstallInRamdisk() |
| 171 | } |
| 172 | |
| 173 | func (p *PrebuiltEtc) InstallInRamdisk() bool { |
| 174 | return p.inRamdisk() |
| 175 | } |
| 176 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 177 | func (p *PrebuiltEtc) inVendorRamdisk() bool { |
| 178 | return p.ModuleBase.InVendorRamdisk() || p.ModuleBase.InstallInVendorRamdisk() |
| 179 | } |
| 180 | |
| 181 | func (p *PrebuiltEtc) onlyInVendorRamdisk() bool { |
| 182 | return p.ModuleBase.InstallInVendorRamdisk() |
| 183 | } |
| 184 | |
| 185 | func (p *PrebuiltEtc) InstallInVendorRamdisk() bool { |
| 186 | return p.inVendorRamdisk() |
| 187 | } |
| 188 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 189 | func (p *PrebuiltEtc) inDebugRamdisk() bool { |
| 190 | return p.ModuleBase.InDebugRamdisk() || p.ModuleBase.InstallInDebugRamdisk() |
| 191 | } |
| 192 | |
| 193 | func (p *PrebuiltEtc) onlyInDebugRamdisk() bool { |
| 194 | return p.ModuleBase.InstallInDebugRamdisk() |
| 195 | } |
| 196 | |
| 197 | func (p *PrebuiltEtc) InstallInDebugRamdisk() bool { |
| 198 | return p.inDebugRamdisk() |
| 199 | } |
| 200 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 201 | func (p *PrebuiltEtc) InRecovery() bool { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 202 | return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery() |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | func (p *PrebuiltEtc) onlyInRecovery() bool { |
| 206 | return p.ModuleBase.InstallInRecovery() |
| 207 | } |
| 208 | |
| 209 | func (p *PrebuiltEtc) InstallInRecovery() bool { |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 210 | return p.InRecovery() |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 213 | var _ android.ImageInterface = (*PrebuiltEtc)(nil) |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 214 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 215 | func (p *PrebuiltEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {} |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 216 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 217 | func (p *PrebuiltEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 218 | return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk() && |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 219 | !p.ModuleBase.InstallInVendorRamdisk() && !p.ModuleBase.InstallInDebugRamdisk() |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 222 | func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 223 | return proptools.Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk() |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 226 | func (p *PrebuiltEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 227 | return proptools.Bool(p.properties.Vendor_ramdisk_available) || p.ModuleBase.InstallInVendorRamdisk() |
| 228 | } |
| 229 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 230 | func (p *PrebuiltEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 231 | return proptools.Bool(p.properties.Debug_ramdisk_available) || p.ModuleBase.InstallInDebugRamdisk() |
| 232 | } |
| 233 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 234 | func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 235 | return proptools.Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery() |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 238 | func (p *PrebuiltEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 239 | return nil |
| 240 | } |
| 241 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 242 | func (p *PrebuiltEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 245 | func (p *PrebuiltEtc) SourceFilePath(ctx android.ModuleContext) android.Path { |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 246 | return android.PathForModuleSrc(ctx, proptools.String(p.properties.Src)) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 247 | } |
| 248 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 249 | func (p *PrebuiltEtc) InstallDirPath() android.InstallPath { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 250 | return p.installDirPath |
| 251 | } |
| 252 | |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 253 | // This allows other derivative modules (e.g. prebuilt_etc_xml) to perform |
| 254 | // additional steps (like validating the src) before the file is installed. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 255 | func (p *PrebuiltEtc) SetAdditionalDependencies(paths android.Paths) { |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 256 | p.additionalDependencies = &paths |
| 257 | } |
| 258 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 259 | func (p *PrebuiltEtc) OutputFile() android.OutputPath { |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 260 | return p.outputFilePath |
| 261 | } |
| 262 | |
Jiyong Park | 76a42f5 | 2021-02-16 06:50:37 +0900 | [diff] [blame] | 263 | var _ android.OutputFileProducer = (*PrebuiltEtc)(nil) |
| 264 | |
| 265 | func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) { |
| 266 | switch tag { |
| 267 | case "": |
| 268 | return android.Paths{p.outputFilePath}, nil |
| 269 | default: |
| 270 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 271 | } |
| 272 | } |
| 273 | |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 274 | func (p *PrebuiltEtc) SubDir() string { |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 275 | if subDir := proptools.String(p.subdirProperties.Sub_dir); subDir != "" { |
Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 276 | return subDir |
| 277 | } |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 278 | return proptools.String(p.subdirProperties.Relative_install_path) |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 279 | } |
| 280 | |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 281 | func (p *PrebuiltEtc) BaseDir() string { |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 282 | return p.installDirBase |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 283 | } |
| 284 | |
Jiyong Park | ad9ce04 | 2018-10-31 22:49:57 +0900 | [diff] [blame] | 285 | func (p *PrebuiltEtc) Installable() bool { |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 286 | return p.properties.Installable == nil || proptools.Bool(p.properties.Installable) |
Jiyong Park | ad9ce04 | 2018-10-31 22:49:57 +0900 | [diff] [blame] | 287 | } |
| 288 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 289 | func (p *PrebuiltEtc) InVendor() bool { |
| 290 | return p.ModuleBase.InstallInVendor() |
| 291 | } |
| 292 | |
| 293 | func (p *PrebuiltEtc) ExcludeFromVendorSnapshot() bool { |
| 294 | return false |
| 295 | } |
| 296 | |
| 297 | func (p *PrebuiltEtc) ExcludeFromRecoverySnapshot() bool { |
| 298 | return false |
| 299 | } |
| 300 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 301 | func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 302 | filename := proptools.String(p.properties.Filename) |
| 303 | filenameFromSrc := proptools.Bool(p.properties.Filename_from_src) |
Colin Cross | 725eac6 | 2022-10-03 15:31:29 -0700 | [diff] [blame] | 304 | if p.properties.Src != nil { |
| 305 | p.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(p.properties.Src)) |
| 306 | |
| 307 | // Determine the output file basename. |
| 308 | // If Filename is set, use the name specified by the property. |
| 309 | // If Filename_from_src is set, use the source file name. |
| 310 | // Otherwise use the module name. |
| 311 | if filename != "" { |
| 312 | if filenameFromSrc { |
| 313 | ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") |
| 314 | return |
| 315 | } |
| 316 | } else if filenameFromSrc { |
| 317 | filename = p.sourceFilePath.Base() |
| 318 | } else { |
| 319 | filename = ctx.ModuleName() |
Jiyong Park | 1a7cf08 | 2018-11-13 11:59:12 +0900 | [diff] [blame] | 320 | } |
Colin Cross | 725eac6 | 2022-10-03 15:31:29 -0700 | [diff] [blame] | 321 | } else if ctx.Config().AllowMissingDependencies() { |
| 322 | // If no srcs was set and AllowMissingDependencies is enabled then |
| 323 | // mark the module as missing dependencies and set a fake source path |
| 324 | // and file name. |
| 325 | ctx.AddMissingDependencies([]string{"MISSING_PREBUILT_SRC_FILE"}) |
| 326 | p.sourceFilePath = android.PathForModuleSrc(ctx) |
| 327 | if filename == "" { |
| 328 | filename = ctx.ModuleName() |
| 329 | } |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 330 | } else { |
Colin Cross | 725eac6 | 2022-10-03 15:31:29 -0700 | [diff] [blame] | 331 | ctx.PropertyErrorf("src", "missing prebuilt source file") |
| 332 | return |
Jiyong Park | 139a2e6 | 2018-10-26 21:49:39 +0900 | [diff] [blame] | 333 | } |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 334 | |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 335 | if strings.Contains(filename, "/") { |
| 336 | ctx.PropertyErrorf("filename", "filename cannot contain separator '/'") |
| 337 | return |
| 338 | } |
| 339 | |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 340 | // Check that `sub_dir` and `relative_install_path` are not set at the same time. |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 341 | if p.subdirProperties.Sub_dir != nil && p.subdirProperties.Relative_install_path != nil { |
Liz Kammer | 0449a63 | 2020-06-26 10:12:36 -0700 | [diff] [blame] | 342 | ctx.PropertyErrorf("sub_dir", "relative_install_path is set. Cannot set sub_dir") |
| 343 | } |
| 344 | |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 345 | // If soc install dir was specified and SOC specific is set, set the installDirPath to the |
| 346 | // specified socInstallDirBase. |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 347 | installBaseDir := p.installDirBase |
| 348 | if p.SocSpecific() && p.socInstallDirBase != "" { |
| 349 | installBaseDir = p.socInstallDirBase |
| 350 | } |
| 351 | p.installDirPath = android.PathForModuleInstall(ctx, installBaseDir, p.SubDir()) |
Jiyong Park | c43e0ac | 2018-10-04 20:27:15 +0900 | [diff] [blame] | 352 | |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 353 | // Call InstallFile even when uninstallable to make the module included in the package |
| 354 | ip := installProperties{ |
| 355 | installable: p.Installable(), |
| 356 | filename: filename, |
| 357 | sourceFilePath: p.sourceFilePath, |
| 358 | symlinks: p.properties.Symlinks, |
| 359 | } |
| 360 | p.addInstallRules(ctx, ip) |
| 361 | } |
Jiyong Park | f9f6805 | 2020-09-29 20:15:08 +0900 | [diff] [blame] | 362 | |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 363 | type installProperties struct { |
| 364 | installable bool |
| 365 | filename string |
| 366 | sourceFilePath android.Path |
| 367 | symlinks []string |
| 368 | } |
| 369 | |
| 370 | // utility function to add install rules to the build graph. |
| 371 | // Reduces code duplication between Soong and Mixed build analysis |
| 372 | func (p *PrebuiltEtc) addInstallRules(ctx android.ModuleContext, ip installProperties) { |
| 373 | if !ip.installable { |
Inseob Kim | 916901e | 2021-02-17 15:48:53 +0900 | [diff] [blame] | 374 | p.SkipInstall() |
| 375 | } |
| 376 | |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 377 | // Copy the file from src to a location in out/ with the correct `filename` |
| 378 | // This ensures that outputFilePath has the correct name for others to |
| 379 | // use, as the source file may have a different name. |
| 380 | p.outputFilePath = android.PathForModuleOut(ctx, ip.filename).OutputPath |
| 381 | ctx.Build(pctx, android.BuildParams{ |
| 382 | Rule: android.Cp, |
| 383 | Output: p.outputFilePath, |
| 384 | Input: ip.sourceFilePath, |
| 385 | }) |
| 386 | |
| 387 | installPath := ctx.InstallFile(p.installDirPath, ip.filename, p.outputFilePath) |
| 388 | for _, sl := range ip.symlinks { |
Inseob Kim | 916901e | 2021-02-17 15:48:53 +0900 | [diff] [blame] | 389 | ctx.InstallSymlink(p.installDirPath, sl, installPath) |
Jiyong Park | f9f6805 | 2020-09-29 20:15:08 +0900 | [diff] [blame] | 390 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 391 | } |
| 392 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 393 | func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 394 | nameSuffix := "" |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 395 | if p.inRamdisk() && !p.onlyInRamdisk() { |
| 396 | nameSuffix = ".ramdisk" |
| 397 | } |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 398 | if p.inVendorRamdisk() && !p.onlyInVendorRamdisk() { |
| 399 | nameSuffix = ".vendor_ramdisk" |
| 400 | } |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 401 | if p.inDebugRamdisk() && !p.onlyInDebugRamdisk() { |
| 402 | nameSuffix = ".debug_ramdisk" |
| 403 | } |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 404 | if p.InRecovery() && !p.onlyInRecovery() { |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 405 | nameSuffix = ".recovery" |
| 406 | } |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 407 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 408 | Class: "ETC", |
| 409 | SubName: nameSuffix, |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 410 | OutputFile: android.OptionalPathForPath(p.outputFilePath), |
| 411 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 412 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 413 | entries.SetString("LOCAL_MODULE_TAGS", "optional") |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 414 | entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 415 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) |
Yo Chiang | 3d64d49 | 2020-05-27 17:56:39 +0800 | [diff] [blame] | 416 | if len(p.properties.Symlinks) > 0 { |
| 417 | entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...) |
| 418 | } |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 419 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.Installable()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 420 | if p.additionalDependencies != nil { |
Yo Chiang | 803c40d | 2020-11-16 20:32:51 +0800 | [diff] [blame] | 421 | entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", p.additionalDependencies.Strings()...) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 422 | } |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 423 | }, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 424 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 425 | }} |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 426 | } |
| 427 | |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 428 | func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) { |
| 429 | p.installDirBase = dirBase |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 430 | p.AddProperties(&p.properties) |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 431 | p.AddProperties(&p.subdirProperties) |
| 432 | } |
| 433 | |
| 434 | func InitPrebuiltRootModule(p *PrebuiltEtc) { |
| 435 | p.installDirBase = "." |
| 436 | p.AddProperties(&p.properties) |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 437 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 438 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 439 | // prebuilt_etc is for a prebuilt artifact that is installed in |
| 440 | // <partition>/etc/<sub_dir> directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 441 | func PrebuiltEtcFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 442 | module := &PrebuiltEtc{} |
| 443 | InitPrebuiltEtcModule(module, "etc") |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 444 | // This module is device-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 445 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 446 | android.InitDefaultableModule(module) |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 447 | android.InitBazelModule(module) |
Inseob Kim | 1e27a14 | 2021-05-06 11:46:11 +0000 | [diff] [blame] | 448 | return module |
| 449 | } |
| 450 | |
| 451 | func defaultsFactory() android.Module { |
| 452 | return DefaultsFactory() |
| 453 | } |
| 454 | |
| 455 | func DefaultsFactory(props ...interface{}) android.Module { |
| 456 | module := &Defaults{} |
| 457 | |
| 458 | module.AddProperties(props...) |
| 459 | module.AddProperties( |
| 460 | &prebuiltEtcProperties{}, |
| 461 | &prebuiltSubdirProperties{}, |
| 462 | ) |
| 463 | |
| 464 | android.InitDefaultsModule(module) |
| 465 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 466 | return module |
| 467 | } |
Tao Bao | 0ba5c94 | 2018-08-14 22:20:22 -0700 | [diff] [blame] | 468 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 469 | // prebuilt_etc_host is for a host prebuilt artifact that is installed in |
| 470 | // $(HOST_OUT)/etc/<sub_dir> directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 471 | func PrebuiltEtcHostFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 472 | module := &PrebuiltEtc{} |
| 473 | InitPrebuiltEtcModule(module, "etc") |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 474 | // This module is host-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 475 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 476 | android.InitDefaultableModule(module) |
Liz Kammer | a923442 | 2021-12-22 15:32:18 -0500 | [diff] [blame] | 477 | android.InitBazelModule(module) |
Jaewoong Jung | 2478818 | 2019-02-04 14:34:10 -0800 | [diff] [blame] | 478 | return module |
| 479 | } |
| 480 | |
Miguel | 32b0280 | 2022-12-01 18:38:26 +0000 | [diff] [blame] | 481 | // prebuilt_etc_host is for a host prebuilt artifact that is installed in |
| 482 | // <partition>/etc/<sub_dir> directory. |
| 483 | func PrebuiltEtcCaCertsFactory() android.Module { |
| 484 | module := &PrebuiltEtc{} |
| 485 | InitPrebuiltEtcModule(module, "cacerts") |
| 486 | // This module is device-only |
| 487 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
| 488 | android.InitBazelModule(module) |
| 489 | return module |
| 490 | } |
| 491 | |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 492 | // prebuilt_root is for a prebuilt artifact that is installed in |
| 493 | // <partition>/ directory. Can't have any sub directories. |
| 494 | func PrebuiltRootFactory() android.Module { |
| 495 | module := &PrebuiltEtc{} |
| 496 | InitPrebuiltRootModule(module) |
| 497 | // This module is device-only |
| 498 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 499 | android.InitDefaultableModule(module) |
Inseob Kim | 27408bf | 2021-04-06 21:00:17 +0900 | [diff] [blame] | 500 | return module |
| 501 | } |
| 502 | |
Liz Kammer | e9ecddc | 2022-01-04 17:27:52 -0500 | [diff] [blame] | 503 | // prebuilt_root_host is for a host prebuilt artifact that is installed in $(HOST_OUT)/<sub_dir> |
| 504 | // directory. |
| 505 | func PrebuiltRootHostFactory() android.Module { |
| 506 | module := &PrebuiltEtc{} |
| 507 | InitPrebuiltEtcModule(module, ".") |
| 508 | // This module is host-only |
| 509 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
| 510 | android.InitDefaultableModule(module) |
| 511 | return module |
| 512 | } |
| 513 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 514 | // prebuilt_usr_share is for a prebuilt artifact that is installed in |
| 515 | // <partition>/usr/share/<sub_dir> directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 516 | func PrebuiltUserShareFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 517 | module := &PrebuiltEtc{} |
| 518 | InitPrebuiltEtcModule(module, "usr/share") |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 519 | // This module is device-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 520 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 521 | android.InitDefaultableModule(module) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 522 | android.InitBazelModule(module) |
Jaewoong Jung | c3fcdb4 | 2019-02-13 05:50:33 -0800 | [diff] [blame] | 523 | return module |
| 524 | } |
| 525 | |
Patrice Arruda | 9e14b96 | 2019-03-11 15:58:50 -0700 | [diff] [blame] | 526 | // prebuild_usr_share_host is for a host prebuilt artifact that is installed in |
| 527 | // $(HOST_OUT)/usr/share/<sub_dir> directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 528 | func PrebuiltUserShareHostFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 529 | module := &PrebuiltEtc{} |
| 530 | InitPrebuiltEtcModule(module, "usr/share") |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 531 | // This module is host-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 532 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 533 | android.InitDefaultableModule(module) |
Patrice Arruda | 300cef9 | 2019-02-22 15:47:57 -0800 | [diff] [blame] | 534 | return module |
| 535 | } |
| 536 | |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 537 | // prebuilt_font installs a font in <partition>/fonts directory. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 538 | func PrebuiltFontFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 539 | module := &PrebuiltEtc{} |
| 540 | InitPrebuiltEtcModule(module, "fonts") |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 541 | // This module is device-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 542 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 543 | android.InitDefaultableModule(module) |
Patrice Arruda | 61583eb | 2019-05-14 08:20:45 -0700 | [diff] [blame] | 544 | return module |
| 545 | } |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 546 | |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 547 | // prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system |
| 548 | // image. |
| 549 | // If soc_specific property is set to true, the firmware file is installed to the |
| 550 | // vendor <partition>/firmware directory for vendor image. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 551 | func PrebuiltFirmwareFactory() android.Module { |
Jooyung Han | a017182 | 2019-07-22 15:48:36 +0900 | [diff] [blame] | 552 | module := &PrebuiltEtc{} |
| 553 | module.socInstallDirBase = "firmware" |
| 554 | InitPrebuiltEtcModule(module, "etc/firmware") |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 555 | // This module is device-only |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 556 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 557 | android.InitDefaultableModule(module) |
Patrice Arruda | 057a8b1 | 2019-06-03 15:29:27 -0700 | [diff] [blame] | 558 | return module |
| 559 | } |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 560 | |
| 561 | // prebuilt_dsp installs a DSP related file to <partition>/etc/dsp directory for system image. |
Yo Chiang | f0e19fe | 2020-11-18 15:28:42 +0800 | [diff] [blame] | 562 | // If soc_specific property is set to true, the DSP related file is installed to the |
| 563 | // vendor <partition>/dsp directory for vendor image. |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 564 | func PrebuiltDSPFactory() android.Module { |
| 565 | module := &PrebuiltEtc{} |
| 566 | module.socInstallDirBase = "dsp" |
| 567 | InitPrebuiltEtcModule(module, "etc/dsp") |
| 568 | // This module is device-only |
| 569 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 570 | android.InitDefaultableModule(module) |
Patrice Arruda | 0f68800 | 2020-06-08 21:40:25 +0000 | [diff] [blame] | 571 | return module |
| 572 | } |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 573 | |
| 574 | // prebuilt_rfsa installs a firmware file that will be available through Qualcomm's RFSA |
| 575 | // to the <partition>/lib/rfsa directory. |
| 576 | func PrebuiltRFSAFactory() android.Module { |
| 577 | module := &PrebuiltEtc{} |
| 578 | // Ideally these would go in /vendor/dsp, but the /vendor/lib/rfsa paths are hardcoded in too |
| 579 | // many places outside of the application processor. They could be moved to /vendor/dsp once |
| 580 | // that is cleaned up. |
| 581 | InitPrebuiltEtcModule(module, "lib/rfsa") |
| 582 | // This module is device-only |
| 583 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
Martin Stjernholm | dc6525e | 2021-10-14 00:42:59 +0100 | [diff] [blame] | 584 | android.InitDefaultableModule(module) |
Colin Cross | 83ebf23 | 2021-04-09 09:41:23 -0700 | [diff] [blame] | 585 | return module |
| 586 | } |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 587 | |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 588 | // Copy file into the snapshot |
| 589 | func copyFile(ctx android.SingletonContext, path android.Path, out string, fake bool) android.OutputPath { |
| 590 | if fake { |
| 591 | // Create empty file instead for the fake snapshot |
| 592 | return snapshot.WriteStringToFileRule(ctx, "", out) |
| 593 | } else { |
| 594 | return snapshot.CopyFileRule(pctx, ctx, path, out) |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | // Check if the module is target of the snapshot |
| 599 | func isSnapshotAware(ctx android.SingletonContext, m *PrebuiltEtc, image snapshot.SnapshotImage) bool { |
| 600 | if !m.Enabled() { |
| 601 | return false |
| 602 | } |
| 603 | |
| 604 | // Skip if the module is not included in the image |
| 605 | if !image.InImage(m)() { |
| 606 | return false |
| 607 | } |
| 608 | |
| 609 | // When android/prebuilt.go selects between source and prebuilt, it sets |
| 610 | // HideFromMake on the other one to avoid duplicate install rules in make. |
| 611 | if m.IsHideFromMake() { |
| 612 | return false |
| 613 | } |
| 614 | |
| 615 | // There are some prebuilt_etc module with multiple definition of same name. |
| 616 | // Check if the target would be included from the build |
| 617 | if !m.ExportedToMake() { |
| 618 | return false |
| 619 | } |
| 620 | |
| 621 | // Skip if the module is in the predefined path list to skip |
| 622 | if image.IsProprietaryPath(ctx.ModuleDir(m), ctx.DeviceConfig()) { |
| 623 | return false |
| 624 | } |
| 625 | |
| 626 | // Skip if the module should be excluded |
| 627 | if image.ExcludeFromSnapshot(m) || image.ExcludeFromDirectedSnapshot(ctx.DeviceConfig(), m.BaseModuleName()) { |
| 628 | return false |
| 629 | } |
| 630 | |
| 631 | // Skip from other exceptional cases |
| 632 | if m.Target().Os.Class != android.Device { |
| 633 | return false |
| 634 | } |
| 635 | if m.Target().NativeBridge == android.NativeBridgeEnabled { |
| 636 | return false |
| 637 | } |
| 638 | |
| 639 | return true |
| 640 | } |
| 641 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 642 | func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.SingletonContext, snapshotArchDir string) snapshot.SnapshotPaths { |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 643 | /* |
| 644 | Snapshot zipped artifacts directory structure for etc modules: |
| 645 | {SNAPSHOT_ARCH}/ |
| 646 | arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/ |
| 647 | etc/ |
| 648 | (prebuilt etc files) |
| 649 | arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/ |
| 650 | etc/ |
| 651 | (prebuilt etc files) |
| 652 | NOTICE_FILES/ |
| 653 | (notice files) |
| 654 | */ |
| 655 | var snapshotOutputs android.Paths |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 656 | var snapshotNotices android.Paths |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 657 | installedNotices := make(map[string]bool) |
| 658 | |
| 659 | ctx.VisitAllModules(func(module android.Module) { |
| 660 | m, ok := module.(*PrebuiltEtc) |
| 661 | if !ok { |
| 662 | return |
| 663 | } |
| 664 | |
| 665 | if !isSnapshotAware(ctx, m, s.Image) { |
| 666 | return |
| 667 | } |
| 668 | |
| 669 | targetArch := "arch-" + m.Target().Arch.ArchType.String() |
| 670 | |
| 671 | snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, "etc", m.BaseModuleName()) |
| 672 | snapshotOutputs = append(snapshotOutputs, copyFile(ctx, m.OutputFile(), snapshotLibOut, s.Fake)) |
| 673 | |
Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 674 | prop := snapshot.SnapshotJsonFlags{} |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 675 | propOut := snapshotLibOut + ".json" |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 676 | prop.InitBaseSnapshotProps(m) |
Justin Yun | 8bd3afe | 2023-05-12 15:53:06 +0900 | [diff] [blame] | 677 | prop.RelativeInstallPath = m.SubDir() |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 678 | |
| 679 | if m.properties.Filename != nil { |
| 680 | prop.Filename = *m.properties.Filename |
| 681 | } |
| 682 | |
| 683 | j, err := json.Marshal(prop) |
| 684 | if err != nil { |
| 685 | ctx.Errorf("json marshal to %q failed: %#v", propOut, err) |
| 686 | return |
| 687 | } |
| 688 | snapshotOutputs = append(snapshotOutputs, snapshot.WriteStringToFileRule(ctx, string(j), propOut)) |
| 689 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 690 | for _, notice := range m.EffectiveLicenseFiles() { |
| 691 | if _, ok := installedNotices[notice.String()]; !ok { |
| 692 | installedNotices[notice.String()] = true |
| 693 | snapshotNotices = append(snapshotNotices, notice) |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
| 697 | }) |
| 698 | |
Justin Yun | 1db9748 | 2023-04-11 18:20:07 +0900 | [diff] [blame] | 699 | return snapshot.SnapshotPaths{OutputFiles: snapshotOutputs, NoticeFiles: snapshotNotices} |
Kiyoung Kim | ae11c23 | 2021-07-19 11:38:04 +0900 | [diff] [blame] | 700 | } |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 701 | |
| 702 | // For Bazel / bp2build |
| 703 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 704 | type bazelPrebuiltFileAttributes struct { |
Alix | 993872a | 2022-06-15 17:42:14 +0000 | [diff] [blame] | 705 | Src bazel.LabelAttribute |
| 706 | Filename bazel.LabelAttribute |
| 707 | Dir string |
| 708 | Installable bazel.BoolAttribute |
| 709 | Filename_from_src bazel.BoolAttribute |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 710 | } |
| 711 | |
Alix | 5918d64 | 2022-06-27 20:57:44 +0000 | [diff] [blame] | 712 | // Bp2buildHelper returns a bazelPrebuiltFileAttributes used for the conversion |
| 713 | // of prebuilt_* modules. bazelPrebuiltFileAttributes has the common attributes |
| 714 | // used by both prebuilt_etc_xml and other prebuilt_* moodules |
Liz Kammer | d5d12d0 | 2023-09-05 09:18:50 -0400 | [diff] [blame] | 715 | func (module *PrebuiltEtc) Bp2buildHelper(ctx android.TopDownMutatorContext) (*bazelPrebuiltFileAttributes, bool) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 716 | var src bazel.LabelAttribute |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 717 | for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltEtcProperties{}) { |
| 718 | for config, p := range configToProps { |
| 719 | props, ok := p.(*prebuiltEtcProperties) |
| 720 | if !ok { |
| 721 | continue |
| 722 | } |
| 723 | if props.Src != nil { |
Liz Kammer | d5d12d0 | 2023-09-05 09:18:50 -0400 | [diff] [blame] | 724 | srcStr := proptools.String(props.Src) |
| 725 | if srcStr == ctx.ModuleName() { |
| 726 | ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "src == name") |
| 727 | return &bazelPrebuiltFileAttributes{}, false |
| 728 | } |
| 729 | label := android.BazelLabelForModuleSrcSingle(ctx, srcStr) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 730 | src.SetSelectValue(axis, config, label) |
Liz Kammer | dff00ea | 2021-10-04 13:44:34 -0400 | [diff] [blame] | 731 | } |
| 732 | } |
Liz Kammer | 9e2a5a7 | 2023-09-19 08:41:14 -0400 | [diff] [blame^] | 733 | productVarProperties, errs := android.ProductVariableProperties(ctx, ctx.Module()) |
| 734 | for _, err := range errs { |
| 735 | ctx.ModuleErrorf("ProductVariableProperties error: %s", err) |
| 736 | } |
| 737 | for propName, productConfigProps := range productVarProperties { |
Alix | bbfd538 | 2022-06-09 18:52:05 +0000 | [diff] [blame] | 738 | for configProp, propVal := range productConfigProps { |
| 739 | if propName == "Src" { |
| 740 | props, ok := propVal.(*string) |
| 741 | if !ok { |
| 742 | ctx.PropertyErrorf(" Expected Property to have type string, but was %s\n", reflect.TypeOf(propVal).String()) |
| 743 | continue |
| 744 | } |
| 745 | if props != nil { |
| 746 | label := android.BazelLabelForModuleSrcSingle(ctx, *props) |
| 747 | src.SetSelectValue(configProp.ConfigurationAxis(), configProp.SelectKey(), label) |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | } |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | var filename string |
Alix | 993872a | 2022-06-15 17:42:14 +0000 | [diff] [blame] | 755 | var filenameFromSrc bool |
| 756 | moduleProps := module.properties |
| 757 | |
| 758 | if moduleProps.Filename != nil && *moduleProps.Filename != "" { |
| 759 | filename = *moduleProps.Filename |
| 760 | } else if moduleProps.Filename_from_src != nil && *moduleProps.Filename_from_src { |
| 761 | if moduleProps.Src != nil { |
| 762 | filename = *moduleProps.Src |
| 763 | } |
| 764 | filenameFromSrc = true |
| 765 | } else { |
| 766 | filename = ctx.ModuleName() |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 769 | var dir = module.installDirBase |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 770 | if subDir := module.subdirProperties.Sub_dir; subDir != nil { |
| 771 | dir = dir + "/" + *subDir |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 772 | } |
| 773 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 774 | var installable bazel.BoolAttribute |
| 775 | if install := module.properties.Installable; install != nil { |
| 776 | installable.Value = install |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 777 | } |
| 778 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 779 | attrs := &bazelPrebuiltFileAttributes{ |
| 780 | Src: src, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c78604e | 2022-02-28 18:22:59 -0500 | [diff] [blame] | 781 | Dir: dir, |
| 782 | Installable: installable, |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 783 | } |
| 784 | |
Alix | 993872a | 2022-06-15 17:42:14 +0000 | [diff] [blame] | 785 | if filename != "" { |
| 786 | attrs.Filename = bazel.LabelAttribute{Value: &bazel.Label{Label: filename}} |
| 787 | } else if filenameFromSrc { |
| 788 | attrs.Filename_from_src = bazel.BoolAttribute{Value: moduleProps.Filename_from_src} |
| 789 | } |
| 790 | |
Liz Kammer | d5d12d0 | 2023-09-05 09:18:50 -0400 | [diff] [blame] | 791 | return attrs, true |
Alix | 5918d64 | 2022-06-27 20:57:44 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | // ConvertWithBp2build performs bp2build conversion of PrebuiltEtc |
| 795 | // prebuilt_* modules (except prebuilt_etc_xml) are PrebuiltEtc, |
| 796 | // which we treat as *PrebuiltFile* |
| 797 | func (module *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext) { |
| 798 | var dir = module.installDirBase |
| 799 | // prebuilt_file supports only `etc` or `usr/share` |
| 800 | if !(dir == "etc" || dir == "usr/share") { |
| 801 | return |
| 802 | } |
| 803 | |
Liz Kammer | d5d12d0 | 2023-09-05 09:18:50 -0400 | [diff] [blame] | 804 | attrs, convertible := module.Bp2buildHelper(ctx) |
| 805 | if !convertible { |
| 806 | return |
| 807 | } |
Alix | 5918d64 | 2022-06-27 20:57:44 +0000 | [diff] [blame] | 808 | |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 809 | props := bazel.BazelTargetModuleProperties{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | b81f77e | 2022-02-28 17:38:34 -0500 | [diff] [blame] | 810 | Rule_class: "prebuilt_file", |
| 811 | Bzl_load_location: "//build/bazel/rules:prebuilt_file.bzl", |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 812 | } |
| 813 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 814 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs) |
Rupert Shuttleworth | 378fc1b | 2021-07-28 08:03:16 -0400 | [diff] [blame] | 815 | } |
Spandan Das | 756d340 | 2023-06-05 22:49:50 +0000 | [diff] [blame] | 816 | |
| 817 | var _ android.MixedBuildBuildable = (*PrebuiltEtc)(nil) |
| 818 | |
| 819 | func (pe *PrebuiltEtc) IsMixedBuildSupported(ctx android.BaseModuleContext) bool { |
| 820 | return true |
| 821 | } |
| 822 | |
| 823 | func (pe *PrebuiltEtc) QueueBazelCall(ctx android.BaseModuleContext) { |
| 824 | ctx.Config().BazelContext.QueueBazelRequest( |
| 825 | pe.GetBazelLabel(ctx, pe), |
| 826 | cquery.GetPrebuiltFileInfo, |
| 827 | android.GetConfigKey(ctx), |
| 828 | ) |
| 829 | } |
| 830 | |
| 831 | func (pe *PrebuiltEtc) ProcessBazelQueryResponse(ctx android.ModuleContext) { |
| 832 | bazelCtx := ctx.Config().BazelContext |
| 833 | pfi, err := bazelCtx.GetPrebuiltFileInfo(pe.GetBazelLabel(ctx, pe), android.GetConfigKey(ctx)) |
| 834 | if err != nil { |
| 835 | ctx.ModuleErrorf(err.Error()) |
| 836 | return |
| 837 | } |
| 838 | |
| 839 | // Set properties for androidmk |
| 840 | pe.installDirPath = android.PathForModuleInstall(ctx, pfi.Dir) |
| 841 | |
| 842 | // Installation rules |
| 843 | ip := installProperties{ |
| 844 | installable: pfi.Installable, |
| 845 | filename: pfi.Filename, |
| 846 | sourceFilePath: android.PathForSource(ctx, pfi.Src), |
| 847 | // symlinks: pe.properties.Symlinks, // TODO: b/207489266 - Fully support all properties in prebuilt_file |
| 848 | } |
| 849 | pe.addInstallRules(ctx, ip) |
| 850 | } |