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