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