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