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