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