Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 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 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 18 | "fmt" |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 19 | "slices" |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 20 | "sort" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 21 | "strconv" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 22 | "strings" |
| 23 | |
| 24 | "android/soong/android" |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 25 | "android/soong/dexpreopt" |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 26 | "android/soong/filesystem" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 27 | "android/soong/java" |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 28 | "android/soong/provenance" |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 29 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 30 | "github.com/google/blueprint" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 31 | "github.com/google/blueprint/proptools" |
| 32 | ) |
| 33 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 34 | var ( |
| 35 | extractMatchingApex = pctx.StaticRule( |
| 36 | "extractMatchingApex", |
| 37 | blueprint.RuleParams{ |
| 38 | Command: `rm -rf "$out" && ` + |
| 39 | `${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` + |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 40 | `-sdk-version=${sdk-version} -skip-sdk-check=${skip-sdk-check} -abis=${abis} ` + |
| 41 | `-screen-densities=all -extract-single ` + |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 42 | `${in}`, |
| 43 | CommandDeps: []string{"${extract_apks}"}, |
| 44 | }, |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 45 | "abis", "allow-prereleased", "sdk-version", "skip-sdk-check") |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 46 | decompressApex = pctx.StaticRule("decompressApex", blueprint.RuleParams{ |
Jooyung Han | 8fa6116 | 2024-08-08 10:42:47 +0900 | [diff] [blame] | 47 | Command: `rm -rf $out && ${deapexer} decompress --copy-if-uncompressed --input ${in} --output ${out}`, |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 48 | CommandDeps: []string{"${deapexer}"}, |
Jooyung Han | 8fa6116 | 2024-08-08 10:42:47 +0900 | [diff] [blame] | 49 | Description: "decompress $out", |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 50 | }) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 51 | ) |
| 52 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 53 | type prebuilt interface { |
| 54 | isForceDisabled() bool |
| 55 | InstallFilename() string |
| 56 | } |
| 57 | |
| 58 | type prebuiltCommon struct { |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 59 | android.ModuleBase |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 60 | java.Dexpreopter |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 61 | prebuilt android.Prebuilt |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 62 | |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 63 | // Properties common to both prebuilt_apex and apex_set. |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 64 | prebuiltCommonProperties *PrebuiltCommonProperties |
| 65 | |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 66 | installDir android.InstallPath |
| 67 | installFilename string |
| 68 | installedFile android.InstallPath |
| 69 | extraInstalledFiles android.InstallPaths |
| 70 | extraInstalledPairs installPairs |
| 71 | outputApex android.WritablePath |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 72 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 73 | // fragment for this apex for apexkeys.txt |
| 74 | apexKeysPath android.WritablePath |
| 75 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 76 | // Installed locations of symlinks for backward compatibility. |
| 77 | compatSymlinks android.InstallPaths |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 78 | |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 79 | // systemServerDexpreoptInstalls stores the list of dexpreopt artifacts for a system server jar. |
| 80 | systemServerDexpreoptInstalls []java.DexpreopterInstall |
| 81 | |
| 82 | // systemServerDexJars stores the list of dexjars for system server jars in the prebuilt for use when |
| 83 | // dexpreopting system server jars that are later in the system server classpath. |
| 84 | systemServerDexJars android.Paths |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 85 | |
| 86 | // Certificate information of any apk packaged inside the prebuilt apex. |
| 87 | // This will be nil if the prebuilt apex does not contain any apk. |
| 88 | apkCertsFile android.WritablePath |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 89 | } |
| 90 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 91 | type sanitizedPrebuilt interface { |
| 92 | hasSanitizedSource(sanitizer string) bool |
| 93 | } |
| 94 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 95 | type PrebuiltCommonProperties struct { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 96 | SelectedApexProperties |
| 97 | |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 98 | // Canonical name of this APEX. Used to determine the path to the activated APEX on |
| 99 | // device (/apex/<apex_name>). If unspecified, follows the name property. |
| 100 | Apex_name *string |
| 101 | |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 102 | // Name of the source APEX that gets shadowed by this prebuilt |
| 103 | // e.g. com.mycompany.android.myapex |
| 104 | // If unspecified, follows the naming convention that the source apex of |
| 105 | // the prebuilt is Name() without "prebuilt_" prefix |
| 106 | Source_apex_name *string |
| 107 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 108 | ForceDisable bool `blueprint:"mutated"` |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 109 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 110 | // whether the extracted apex file is installable. |
| 111 | Installable *bool |
| 112 | |
| 113 | // optional name for the installed apex. If unspecified, name of the |
| 114 | // module is used as the file name |
| 115 | Filename *string |
| 116 | |
| 117 | // names of modules to be overridden. Listed modules can only be other binaries |
| 118 | // (in Make or Soong). |
| 119 | // This does not completely prevent installation of the overridden binaries, but if both |
| 120 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 121 | // from PRODUCT_PACKAGES. |
| 122 | Overrides []string |
| 123 | |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 124 | // List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX |
| 125 | // bundle will create an APEX variant. |
| 126 | Exported_bootclasspath_fragments []string |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 127 | |
| 128 | // List of systemserverclasspath fragments inside this prebuilt APEX bundle and for which this |
| 129 | // APEX bundle will create an APEX variant. |
| 130 | Exported_systemserverclasspath_fragments []string |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 131 | |
| 132 | // Path to the .prebuilt_info file of the prebuilt apex. |
| 133 | // In case of mainline modules, the .prebuilt_info file contains the build_id that was used to |
| 134 | // generate the prebuilt. |
| 135 | Prebuilt_info *string `android:"path"` |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 136 | } |
| 137 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 138 | // initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the |
| 139 | // module that is common to Prebuilt and ApexSet. |
| 140 | func (p *prebuiltCommon) initPrebuiltCommon(module android.Module, properties *PrebuiltCommonProperties) { |
| 141 | p.prebuiltCommonProperties = properties |
| 142 | android.InitSingleSourcePrebuiltModule(module.(android.PrebuiltInterface), properties, "Selected_apex") |
| 143 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 144 | } |
| 145 | |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 146 | func (p *prebuiltCommon) ApexVariationName() string { |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 147 | return proptools.StringDefault(p.prebuiltCommonProperties.Apex_name, p.BaseModuleName()) |
| 148 | } |
| 149 | |
| 150 | func (p *prebuiltCommon) BaseModuleName() string { |
| 151 | return proptools.StringDefault(p.prebuiltCommonProperties.Source_apex_name, p.ModuleBase.BaseModuleName()) |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 154 | func (p *prebuiltCommon) Prebuilt() *android.Prebuilt { |
| 155 | return &p.prebuilt |
| 156 | } |
| 157 | |
| 158 | func (p *prebuiltCommon) isForceDisabled() bool { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 159 | return p.prebuiltCommonProperties.ForceDisable |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool { |
Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 163 | forceDisable := false |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 164 | |
| 165 | // Force disable the prebuilts when we are doing unbundled build. We do unbundled build |
| 166 | // to build the prebuilts themselves. |
| 167 | forceDisable = forceDisable || ctx.Config().UnbundledBuild() |
| 168 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 169 | // b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source |
| 170 | sanitized := ctx.Module().(sanitizedPrebuilt) |
| 171 | forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address")) |
| 172 | forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress")) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 173 | |
| 174 | if forceDisable && p.prebuilt.SourceExists() { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 175 | p.prebuiltCommonProperties.ForceDisable = true |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 176 | return true |
| 177 | } |
| 178 | return false |
| 179 | } |
| 180 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 181 | func (p *prebuiltCommon) InstallFilename() string { |
| 182 | return proptools.StringDefault(p.prebuiltCommonProperties.Filename, p.BaseModuleName()+imageApexSuffix) |
| 183 | } |
| 184 | |
| 185 | func (p *prebuiltCommon) Name() string { |
| 186 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 187 | } |
| 188 | |
| 189 | func (p *prebuiltCommon) Overrides() []string { |
| 190 | return p.prebuiltCommonProperties.Overrides |
| 191 | } |
| 192 | |
| 193 | func (p *prebuiltCommon) installable() bool { |
| 194 | return proptools.BoolDefault(p.prebuiltCommonProperties.Installable, true) |
| 195 | } |
| 196 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 197 | // To satisfy java.DexpreopterInterface |
| 198 | func (p *prebuiltCommon) IsInstallable() bool { |
| 199 | return p.installable() |
| 200 | } |
| 201 | |
| 202 | // initApexFilesForAndroidMk initializes the prebuiltCommon.requiredModuleNames field with the install only deps of the prebuilt apex |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 203 | func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) { |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 204 | // If this apex contains a system server jar, then the dexpreopt artifacts should be added as required |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 205 | p.systemServerDexpreoptInstalls = append(p.systemServerDexpreoptInstalls, p.Dexpreopter.ApexSystemServerDexpreoptInstalls()...) |
| 206 | p.systemServerDexJars = append(p.systemServerDexJars, p.Dexpreopter.ApexSystemServerDexJars()...) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 207 | } |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 208 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 209 | // If this prebuilt has system server jar, create the rules to dexpreopt it and install it alongside the prebuilt apex |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 210 | func (p *prebuiltCommon) dexpreoptSystemServerJars(ctx android.ModuleContext, di *android.DeapexerInfo) { |
| 211 | if di == nil { |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 212 | return |
| 213 | } |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 214 | // If this prebuilt apex has not been selected, return |
| 215 | if p.IsHideFromMake() { |
| 216 | return |
| 217 | } |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 218 | // Use apex_name to determine the api domain of this prebuilt apex |
| 219 | apexName := p.ApexVariationName() |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 220 | // TODO: do not compute twice |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 221 | dc := dexpreopt.GetGlobalConfig(ctx) |
| 222 | systemServerJarList := dc.AllApexSystemServerJars(ctx) |
| 223 | |
| 224 | for i := 0; i < systemServerJarList.Len(); i++ { |
| 225 | sscpApex := systemServerJarList.Apex(i) |
| 226 | sscpJar := systemServerJarList.Jar(i) |
| 227 | if apexName != sscpApex { |
| 228 | continue |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 229 | } |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 230 | p.Dexpreopter.DexpreoptPrebuiltApexSystemServerJars(ctx, sscpJar, di) |
| 231 | } |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 234 | // installApexSystemServerFiles installs dexpreopt files for system server classpath entries |
| 235 | // provided by the apex. They are installed here instead of in library module because there may be multiple |
| 236 | // variants of the library, generally one for the "main" apex and another with a different min_sdk_version |
| 237 | // for the Android Go version of the apex. Both variants would attempt to install to the same locations, |
| 238 | // and the library variants cannot determine which one should. The apex module is better equipped to determine |
| 239 | // if it is "selected". |
| 240 | // This assumes that the jars produced by different min_sdk_version values are identical, which is currently |
| 241 | // true but may not be true if the min_sdk_version difference between the variants spans version that changed |
| 242 | // the dex format. |
| 243 | func (p *prebuiltCommon) installApexSystemServerFiles(ctx android.ModuleContext) { |
| 244 | performInstalls := android.IsModulePreferred(ctx.Module()) |
| 245 | |
| 246 | for _, install := range p.systemServerDexpreoptInstalls { |
| 247 | var installedFile android.InstallPath |
| 248 | if performInstalls { |
| 249 | installedFile = ctx.InstallFile(install.InstallDirOnDevice, install.InstallFileOnDevice, install.OutputPathOnHost) |
| 250 | } else { |
| 251 | installedFile = install.InstallDirOnDevice.Join(ctx, install.InstallFileOnDevice) |
| 252 | } |
| 253 | p.extraInstalledFiles = append(p.extraInstalledFiles, installedFile) |
| 254 | p.extraInstalledPairs = append(p.extraInstalledPairs, installPair{install.OutputPathOnHost, installedFile}) |
Kiyoung Kim | a3904c8 | 2025-02-24 10:30:42 +0900 | [diff] [blame] | 255 | ctx.PackageFile(install.InstallDirOnDevice, install.InstallFileOnDevice, install.OutputPathOnHost) |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | for _, dexJar := range p.systemServerDexJars { |
| 259 | // Copy the system server dex jar to a predefined location where dex2oat will find it. |
| 260 | android.CopyFileRule(ctx, dexJar, |
| 261 | android.PathForOutput(ctx, dexpreopt.SystemServerDexjarsDir, dexJar.Base())) |
| 262 | } |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 265 | func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 266 | entriesList := []android.AndroidMkEntries{ |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 267 | { |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 268 | Class: "ETC", |
| 269 | OutputFile: android.OptionalPathForPath(p.outputApex), |
| 270 | Include: "$(BUILD_PREBUILT)", |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 271 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 272 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 273 | entries.SetString("LOCAL_MODULE_PATH", p.installDir.String()) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 274 | entries.SetString("LOCAL_MODULE_STEM", p.installFilename) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 275 | entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", p.installedFile) |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 276 | installPairs := append(installPairs{{p.outputApex, p.installedFile}}, p.extraInstalledPairs...) |
| 277 | entries.SetString("LOCAL_SOONG_INSTALL_PAIRS", installPairs.String()) |
Cole Faust | d22afe9 | 2023-08-18 16:05:44 -0700 | [diff] [blame] | 278 | entries.AddStrings("LOCAL_SOONG_INSTALL_SYMLINKS", p.compatSymlinks.Strings()...) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 279 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 280 | entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.prebuiltCommonProperties.Overrides...) |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 281 | entries.SetString("LOCAL_APEX_KEY_PATH", p.apexKeysPath.String()) |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 282 | if p.apkCertsFile != nil { |
| 283 | entries.SetString("LOCAL_APKCERTS_FILE", p.apkCertsFile.String()) |
| 284 | } |
| 285 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 286 | }, |
| 287 | }, |
| 288 | }, |
| 289 | } |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 290 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 291 | return entriesList |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 292 | } |
| 293 | |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 294 | func (p *prebuiltCommon) hasExportedDeps() bool { |
Spandan Das | 1896fd6 | 2024-09-18 21:49:14 +0000 | [diff] [blame] | 295 | return len(p.prebuiltCommonProperties.Exported_bootclasspath_fragments) > 0 || |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 296 | len(p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments) > 0 |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 299 | type appInPrebuiltApexDepTag struct { |
| 300 | blueprint.BaseDependencyTag |
| 301 | } |
| 302 | |
| 303 | func (appInPrebuiltApexDepTag) ExcludeFromVisibilityEnforcement() {} |
| 304 | |
| 305 | var appInPrebuiltApexTag = appInPrebuiltApexDepTag{} |
| 306 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 307 | // prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents. |
| 308 | func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) { |
| 309 | module := ctx.Module() |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 310 | |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 311 | for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments { |
| 312 | prebuiltDep := android.PrebuiltNameFromSource(dep) |
| 313 | ctx.AddDependency(module, exportedBootclasspathFragmentTag, prebuiltDep) |
Colin Cross | bdd344b | 2025-01-14 16:01:03 -0800 | [diff] [blame] | 314 | ctx.AddDependency(module, fragmentInApexTag, prebuiltDep) |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | for _, dep := range p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments { |
| 318 | prebuiltDep := android.PrebuiltNameFromSource(dep) |
| 319 | ctx.AddDependency(module, exportedSystemserverclasspathFragmentTag, prebuiltDep) |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 320 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 321 | } |
| 322 | |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 323 | // Implements android.DepInInSameApex |
Yu Liu | f180603 | 2025-02-07 00:23:34 +0000 | [diff] [blame] | 324 | func (m *prebuiltCommon) GetDepInSameApexChecker() android.DepInSameApexChecker { |
| 325 | return ApexPrebuiltDepInSameApexChecker{} |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Yu Liu | f180603 | 2025-02-07 00:23:34 +0000 | [diff] [blame] | 328 | type ApexPrebuiltDepInSameApexChecker struct { |
| 329 | android.BaseDepInSameApexChecker |
| 330 | } |
| 331 | |
| 332 | func (m ApexPrebuiltDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool { |
| 333 | _, ok := tag.(exportedDependencyTag) |
| 334 | return ok |
Colin Cross | f7bbd2f | 2024-12-05 13:57:10 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 337 | func (p *prebuiltCommon) checkExportedDependenciesArePrebuilts(ctx android.ModuleContext) { |
| 338 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 339 | tag := ctx.OtherModuleDependencyTag(dep) |
| 340 | depName := ctx.OtherModuleName(dep) |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 341 | if exportedTag, ok := tag.(exportedDependencyTag); ok { |
| 342 | propertyName := exportedTag.name |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 343 | |
| 344 | // It is an error if the other module is not a prebuilt. |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 345 | if !android.IsModulePrebuilt(dep) { |
| 346 | ctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName) |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | // It is an error if the other module is not an ApexModule. |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 350 | if _, ok := dep.(android.ApexModule); !ok { |
| 351 | ctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName) |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 352 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 353 | } |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 354 | |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 355 | }) |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 356 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 357 | |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 358 | // generateApexInfo returns an android.ApexInfo configuration suitable for dependencies of this apex. |
| 359 | func (p *prebuiltCommon) generateApexInfo(ctx generateApexInfoContext) android.ApexInfo { |
| 360 | return android.ApexInfo{ |
| 361 | ApexVariationName: "prebuilt_" + p.ApexVariationName(), |
| 362 | BaseApexName: p.ApexVariationName(), |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 363 | ForPrebuiltApex: true, |
| 364 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 367 | type Prebuilt struct { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 368 | prebuiltCommon |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 369 | |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 370 | properties PrebuiltProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 371 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 372 | inputApex android.Path |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 373 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 374 | provenanceMetaDataFile android.Path |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 375 | } |
| 376 | |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 377 | type ApexFileProperties struct { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 378 | // the path to the prebuilt .apex file to import. |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 379 | // |
| 380 | // This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated |
| 381 | // for android_common. That is so that it will have the same arch variant as, and so be compatible |
| 382 | // with, the source `apex` module type that it replaces. |
Cole Faust | 642e720 | 2024-08-14 17:46:12 -0700 | [diff] [blame] | 383 | Src proptools.Configurable[string] `android:"path,replace_instead_of_append"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 384 | Arch struct { |
| 385 | Arm struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 386 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 387 | } |
| 388 | Arm64 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 389 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 390 | } |
Chen Guoyin | 401f298 | 2022-10-12 19:28:48 +0800 | [diff] [blame] | 391 | Riscv64 struct { |
| 392 | Src *string `android:"path"` |
| 393 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 394 | X86 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 395 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 396 | } |
| 397 | X86_64 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 398 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 399 | } |
| 400 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 403 | // prebuiltApexSelector selects the correct prebuilt APEX file for the build target. |
| 404 | // |
| 405 | // The ctx parameter can be for any module not just the prebuilt module so care must be taken not |
| 406 | // to use methods on it that are specific to the current module. |
| 407 | // |
| 408 | // See the ApexFileProperties.Src property. |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame] | 409 | func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) string { |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 410 | multiTargets := prebuilt.MultiTargets() |
| 411 | if len(multiTargets) != 1 { |
| 412 | ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex") |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame] | 413 | return "" |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 414 | } |
| 415 | var src string |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 416 | switch multiTargets[0].Arch.ArchType { |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 417 | case android.Arm: |
| 418 | src = String(p.Arch.Arm.Src) |
| 419 | case android.Arm64: |
| 420 | src = String(p.Arch.Arm64.Src) |
Chen Guoyin | 401f298 | 2022-10-12 19:28:48 +0800 | [diff] [blame] | 421 | case android.Riscv64: |
| 422 | src = String(p.Arch.Riscv64.Src) |
Colin Cross | abacbe8 | 2022-11-01 09:26:51 -0700 | [diff] [blame] | 423 | // HACK: fall back to arm64 prebuilts, the riscv64 ones don't exist yet. |
| 424 | if src == "" { |
| 425 | src = String(p.Arch.Arm64.Src) |
| 426 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 427 | case android.X86: |
| 428 | src = String(p.Arch.X86.Src) |
| 429 | case android.X86_64: |
| 430 | src = String(p.Arch.X86_64.Src) |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 431 | } |
| 432 | if src == "" { |
Cole Faust | 642e720 | 2024-08-14 17:46:12 -0700 | [diff] [blame] | 433 | src = p.Src.GetOrDefault(ctx, "") |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 434 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 435 | |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 436 | if src == "" { |
Colin Cross | 553a31b | 2022-10-03 22:02:09 -0700 | [diff] [blame] | 437 | if ctx.Config().AllowMissingDependencies() { |
| 438 | ctx.AddMissingDependencies([]string{ctx.OtherModuleName(prebuilt)}) |
| 439 | } else { |
| 440 | ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String()) |
| 441 | } |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 442 | // Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt |
| 443 | // logic from reporting a more general, less useful message. |
| 444 | } |
| 445 | |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame] | 446 | return src |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | type PrebuiltProperties struct { |
| 450 | ApexFileProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 451 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 452 | PrebuiltCommonProperties |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 453 | |
| 454 | // List of apps that are bundled inside this prebuilt apex. |
| 455 | // This will be used to create the certificate info of those apps for apkcerts.txt |
| 456 | // This dependency will only be used for apkcerts.txt processing. |
| 457 | // Notably, building the prebuilt apex will not build the source app. |
| 458 | Apps []string |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 459 | } |
| 460 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 461 | func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool { |
| 462 | return false |
| 463 | } |
| 464 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 465 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 466 | func PrebuiltFactory() android.Module { |
| 467 | module := &Prebuilt{} |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 468 | module.AddProperties(&module.properties) |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame] | 469 | module.prebuiltCommon.prebuiltCommonProperties = &module.properties.PrebuiltCommonProperties |
| 470 | |
| 471 | // init the module as a prebuilt |
| 472 | // even though this module type has srcs, use `InitPrebuiltModuleWithoutSrcs`, since the existing |
| 473 | // InitPrebuiltModule* are not friendly with Sources of Configurable type. |
| 474 | // The actual src will be evaluated in GenerateAndroidBuildActions. |
| 475 | android.InitPrebuiltModuleWithoutSrcs(module) |
| 476 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 477 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 478 | return module |
| 479 | } |
| 480 | |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 481 | func (p *prebuiltCommon) getDeapexerPropertiesIfNeeded(ctx android.ModuleContext) DeapexerProperties { |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 482 | // Compute the deapexer properties from the transitive dependencies of this module. |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 483 | commonModules := []string{} |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 484 | dexpreoptProfileGuidedModules := []string{} |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 485 | exportedFiles := []string{} |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 486 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 487 | tag := ctx.OtherModuleDependencyTag(child) |
| 488 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 489 | // If the child is not in the same apex as the parent then ignore it and all its children. |
| 490 | if !android.IsDepInSameApex(ctx, parent, child) { |
| 491 | return false |
| 492 | } |
| 493 | |
Spandan Das | 161e468 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 494 | name := java.ModuleStemForDeapexing(child) |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 495 | if _, ok := tag.(android.RequiresFilesFromPrebuiltApexTag); ok { |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 496 | commonModules = append(commonModules, name) |
| 497 | |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 498 | extract := child.(android.RequiredFilesFromPrebuiltApex) |
| 499 | requiredFiles := extract.RequiredFilesFromPrebuiltApex(ctx) |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 500 | exportedFiles = append(exportedFiles, requiredFiles...) |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 501 | |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 502 | if extract.UseProfileGuidedDexpreopt() { |
| 503 | dexpreoptProfileGuidedModules = append(dexpreoptProfileGuidedModules, name) |
| 504 | } |
| 505 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 506 | // Visit the dependencies of this module just in case they also require files from the |
| 507 | // prebuilt apex. |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 508 | return true |
| 509 | } |
| 510 | |
| 511 | return false |
| 512 | }) |
| 513 | |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 514 | // Create properties for deapexer module. |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 515 | deapexerProperties := DeapexerProperties{ |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 516 | // Remove any duplicates from the common modules lists as a module may be included via a direct |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 517 | // dependency as well as transitive ones. |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 518 | CommonModules: android.SortedUniqueStrings(commonModules), |
| 519 | DexpreoptProfileGuidedModules: android.SortedUniqueStrings(dexpreoptProfileGuidedModules), |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | // Populate the exported files property in a fixed order. |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 523 | deapexerProperties.ExportedFiles = android.SortedUniqueStrings(exportedFiles) |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 524 | return deapexerProperties |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 527 | func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string { |
| 528 | // The prebuilt_apex should be depending on prebuilt modules but as this runs after |
| 529 | // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So, |
| 530 | // check to see if the prefixed name is in use first, if it is then use that, otherwise assume |
| 531 | // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module |
| 532 | // and not a renamed prebuilt module then that will be detected and reported as an error when |
| 533 | // processing the dependency in ApexInfoMutator(). |
Paul Duffin | 864116c | 2021-04-02 10:24:13 +0100 | [diff] [blame] | 534 | prebuiltName := android.PrebuiltNameFromSource(name) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 535 | if ctx.OtherModuleExists(prebuiltName) { |
| 536 | name = prebuiltName |
| 537 | } |
| 538 | return name |
| 539 | } |
| 540 | |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 541 | type exportedDependencyTag struct { |
| 542 | blueprint.BaseDependencyTag |
| 543 | name string |
| 544 | } |
| 545 | |
| 546 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. |
| 547 | // |
| 548 | // This does allow any prebuilt_apex to reference any module which does open up a small window for |
| 549 | // restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so |
| 550 | // avoids opening up a much bigger window by widening the visibility of modules that need files |
| 551 | // provided by the prebuilt_apex to include all the possible locations they may be defined, which |
| 552 | // could include everything below vendor/. |
| 553 | // |
| 554 | // A prebuilt_apex that references a module via this tag will have to contain the appropriate files |
| 555 | // corresponding to that module, otherwise it will fail when attempting to retrieve the files from |
| 556 | // the .apex file. It will also have to be included in the module's apex_available property too. |
| 557 | // That makes it highly unlikely that a prebuilt_apex would reference a restricted module |
| 558 | // incorrectly. |
| 559 | func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {} |
| 560 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 561 | func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {} |
| 562 | |
| 563 | var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{} |
| 564 | |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 565 | var ( |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 566 | exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"} |
| 567 | exportedSystemserverclasspathFragmentTag = exportedDependencyTag{name: "exported_systemserverclasspath_fragments"} |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 568 | ) |
| 569 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 570 | func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 571 | p.prebuiltApexContentsDeps(ctx) |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 572 | for _, app := range p.properties.Apps { |
| 573 | ctx.AddDependency(p, appInPrebuiltApexTag, app) |
| 574 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 577 | var _ ApexTransitionMutator = (*Prebuilt)(nil) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 578 | |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 579 | func (p *Prebuilt) ApexTransitionMutatorSplit(ctx android.BaseModuleContext) []android.ApexInfo { |
| 580 | return []android.ApexInfo{p.generateApexInfo(ctx)} |
| 581 | } |
| 582 | |
| 583 | func (p *Prebuilt) ApexTransitionMutatorOutgoing(ctx android.OutgoingTransitionContext, sourceInfo android.ApexInfo) android.ApexInfo { |
| 584 | return sourceInfo |
| 585 | } |
| 586 | |
| 587 | func (p *Prebuilt) ApexTransitionMutatorIncoming(ctx android.IncomingTransitionContext, outgoingInfo android.ApexInfo) android.ApexInfo { |
| 588 | return p.generateApexInfo(ctx) |
| 589 | } |
| 590 | |
| 591 | func (p *Prebuilt) ApexTransitionMutatorMutate(ctx android.BottomUpMutatorContext, info android.ApexInfo) { |
| 592 | android.SetProvider(ctx, android.ApexBundleInfoProvider, android.ApexBundleInfo{}) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 593 | } |
| 594 | |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 595 | // creates the build rules to deapex the prebuilt, and returns a deapexerInfo |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame] | 596 | func (p *prebuiltCommon) getDeapexerInfo(ctx android.ModuleContext, apexFile android.Path) *android.DeapexerInfo { |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 597 | if !p.hasExportedDeps() { |
| 598 | // nothing to do |
| 599 | return nil |
| 600 | } |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 601 | deapexerProps := p.getDeapexerPropertiesIfNeeded(ctx) |
| 602 | return deapex(ctx, apexFile, deapexerProps) |
| 603 | } |
| 604 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 605 | // Set a provider containing information about the jars and .prof provided by the apex |
| 606 | // Apexes built from prebuilts retrieve this information by visiting its internal deapexer module |
| 607 | // Used by dex_bootjars to generate the boot image |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 608 | func (p *prebuiltCommon) provideApexExportsInfo(ctx android.ModuleContext, di *android.DeapexerInfo) { |
| 609 | if di == nil { |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 610 | return |
| 611 | } |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 612 | javaModuleToDexPath := map[string]android.Path{} |
| 613 | for _, commonModule := range di.GetExportedModuleNames() { |
| 614 | if dex := di.PrebuiltExportPath(java.ApexRootRelativePathToJavaLib(commonModule)); dex != nil { |
| 615 | javaModuleToDexPath[commonModule] = dex |
Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 616 | } |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 617 | } |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 618 | |
| 619 | exports := android.ApexExportsInfo{ |
| 620 | ApexName: p.ApexVariationName(), |
| 621 | ProfilePathOnHost: di.PrebuiltExportPath(java.ProfileInstallPathInApex), |
| 622 | LibraryNameToDexJarPathOnHost: javaModuleToDexPath, |
| 623 | } |
| 624 | android.SetProvider(ctx, android.ApexExportsInfoProvider, exports) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 627 | // Set prebuiltInfoProvider. This will be used by `apex_prebuiltinfo_singleton` to print out a metadata file |
| 628 | // with information about whether source or prebuilt of an apex was used during the build. |
| 629 | func (p *prebuiltCommon) providePrebuiltInfo(ctx android.ModuleContext) { |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 630 | info := android.PrebuiltInfo{ |
| 631 | Name: p.BaseModuleName(), |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 632 | Is_prebuilt: true, |
| 633 | } |
| 634 | // If Prebuilt_info information is available in the soong module definition, add it to prebuilt_info.json. |
| 635 | if p.prebuiltCommonProperties.Prebuilt_info != nil { |
| 636 | info.Prebuilt_info_file_path = android.PathForModuleSrc(ctx, *p.prebuiltCommonProperties.Prebuilt_info).String() |
| 637 | } |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 638 | android.SetProvider(ctx, android.PrebuiltInfoProvider, info) |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 641 | // Uses an object provided by its deps to validate that the contents of bcpf have been added to the global |
| 642 | // PRODUCT_APEX_BOOT_JARS |
| 643 | // This validation will only run on the apex which is active for this product/release_config |
| 644 | func validateApexClasspathFragments(ctx android.ModuleContext) { |
| 645 | ctx.VisitDirectDeps(func(m android.Module) { |
| 646 | if info, exists := android.OtherModuleProvider(ctx, m, java.ClasspathFragmentValidationInfoProvider); exists { |
| 647 | ctx.ModuleErrorf("%s in contents of %s must also be declared in PRODUCT_APEX_BOOT_JARS", info.UnknownJars, info.ClasspathFragmentModuleName) |
| 648 | } |
| 649 | }) |
| 650 | } |
| 651 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 652 | func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 653 | // Validate contents of classpath fragments |
Spandan Das | 5f1f940 | 2024-05-21 18:59:23 +0000 | [diff] [blame] | 654 | if !p.IsHideFromMake() { |
| 655 | validateApexClasspathFragments(ctx) |
| 656 | } |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 657 | |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 658 | p.checkExportedDependenciesArePrebuilts(ctx) |
| 659 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 660 | p.apexKeysPath = writeApexKeys(ctx, p) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 661 | // TODO(jungjw): Check the key validity. |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame] | 662 | p.inputApex = android.PathForModuleSrc(ctx, p.properties.prebuiltApexSelector(ctx, ctx.Module())) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 663 | p.installDir = android.PathForModuleInstall(ctx, "apex") |
| 664 | p.installFilename = p.InstallFilename() |
| 665 | if !strings.HasSuffix(p.installFilename, imageApexSuffix) { |
| 666 | ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix) |
| 667 | } |
| 668 | p.outputApex = android.PathForModuleOut(ctx, p.installFilename) |
| 669 | ctx.Build(pctx, android.BuildParams{ |
| 670 | Rule: android.Cp, |
| 671 | Input: p.inputApex, |
| 672 | Output: p.outputApex, |
| 673 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 674 | |
| 675 | if p.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 676 | p.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 677 | return |
| 678 | } |
| 679 | |
Spandan Das | e350e36 | 2024-09-21 01:49:34 +0000 | [diff] [blame] | 680 | deapexerInfo := p.getDeapexerInfo(ctx, p.inputApex) |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 681 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 682 | // dexpreopt any system server jars if present |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 683 | p.dexpreoptSystemServerJars(ctx, deapexerInfo) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 684 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 685 | // provide info used for generating the boot image |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 686 | p.provideApexExportsInfo(ctx, deapexerInfo) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 687 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 688 | p.providePrebuiltInfo(ctx) |
| 689 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 690 | // Save the files that need to be made available to Make. |
| 691 | p.initApexFilesForAndroidMk(ctx) |
| 692 | |
Colin Cross | ccba23d | 2021-11-12 19:01:29 +0000 | [diff] [blame] | 693 | // in case that prebuilt_apex replaces source apex (using prefer: prop) |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 694 | p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx) |
Colin Cross | ccba23d | 2021-11-12 19:01:29 +0000 | [diff] [blame] | 695 | // or that prebuilt_apex overrides other apexes (using overrides: prop) |
| 696 | for _, overridden := range p.prebuiltCommonProperties.Overrides { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 697 | p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | if p.installable() { |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 701 | p.installApexSystemServerFiles(ctx) |
| 702 | installDeps := slices.Concat(p.compatSymlinks, p.extraInstalledFiles) |
| 703 | p.installedFile = ctx.InstallFile(p.installDir, p.installFilename, p.inputApex, installDeps...) |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 704 | p.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, p.inputApex, p.installedFile) |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 705 | } |
mrziwang | 1587b9c | 2024-06-13 11:26:04 -0700 | [diff] [blame] | 706 | |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 707 | p.addApkCertsInfo(ctx) |
| 708 | |
mrziwang | 1587b9c | 2024-06-13 11:26:04 -0700 | [diff] [blame] | 709 | ctx.SetOutputFiles(android.Paths{p.outputApex}, "") |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 710 | |
| 711 | android.SetProvider(ctx, filesystem.ApexKeyPathInfoProvider, filesystem.ApexKeyPathInfo{p.apexKeysPath}) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 712 | } |
| 713 | |
Spandan Das | 37eecea | 2025-03-19 20:15:23 +0000 | [diff] [blame] | 714 | // `addApkCertsInfo` sets a provider that will be used to create apkcerts.txt |
| 715 | func (p *Prebuilt) addApkCertsInfo(ctx android.ModuleContext) { |
| 716 | formatLine := func(cert java.Certificate, name, partition string) string { |
| 717 | pem := cert.AndroidMkString() |
| 718 | var key string |
| 719 | if cert.Key == nil { |
| 720 | key = "" |
| 721 | } else { |
| 722 | key = cert.Key.String() |
| 723 | } |
| 724 | return fmt.Sprintf(`name="%s" certificate="%s" private_key="%s" partition="%s"`, name, pem, key, partition) |
| 725 | } |
| 726 | |
| 727 | // Determine if this prebuilt_apex contains any .apks |
| 728 | var appInfos java.AppInfos |
| 729 | ctx.VisitDirectDepsProxyWithTag(appInPrebuiltApexTag, func(app android.ModuleProxy) { |
| 730 | if appInfo, ok := android.OtherModuleProvider(ctx, app, java.AppInfoProvider); ok { |
| 731 | appInfos = append(appInfos, *appInfo) |
| 732 | } else { |
| 733 | ctx.ModuleErrorf("App %s does not set AppInfoProvider\n", app.Name()) |
| 734 | } |
| 735 | }) |
| 736 | sort.Slice(appInfos, func(i, j int) bool { |
| 737 | return appInfos[i].InstallApkName < appInfos[j].InstallApkName |
| 738 | }) |
| 739 | |
| 740 | if len(appInfos) == 0 { |
| 741 | return |
| 742 | } |
| 743 | |
| 744 | // Set a provider for use by `android_device`. |
| 745 | // `android_device` will create an apkcerts.txt with the list of installed apps for that device. |
| 746 | android.SetProvider(ctx, java.AppInfosProvider, appInfos) |
| 747 | |
| 748 | // Set a Make variable for legacy apkcerts.txt creation |
| 749 | // p.apkCertsFile will become `LOCAL_APKCERTS_FILE` |
| 750 | var lines []string |
| 751 | for _, appInfo := range appInfos { |
| 752 | lines = append(lines, formatLine(appInfo.Certificate, appInfo.InstallApkName+".apk", p.PartitionTag(ctx.DeviceConfig()))) |
| 753 | } |
| 754 | if len(lines) > 0 { |
| 755 | p.apkCertsFile = android.PathForModuleOut(ctx, "apkcerts.txt") |
| 756 | android.WriteFileRule(ctx, p.apkCertsFile, strings.Join(lines, "\n")) |
| 757 | } |
| 758 | } |
| 759 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 760 | func (p *Prebuilt) ProvenanceMetaDataFile() android.Path { |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 761 | return p.provenanceMetaDataFile |
| 762 | } |
| 763 | |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 764 | // extract registers the build actions to extract an apex from .apks file |
| 765 | // returns the path of the extracted apex |
| 766 | func extract(ctx android.ModuleContext, apexSet android.Path, prerelease *bool) android.Path { |
Paul Duffin | 76fdd67 | 2022-12-12 18:00:47 +0000 | [diff] [blame] | 767 | defaultAllowPrerelease := ctx.Config().IsEnvTrue("SOONG_ALLOW_PRERELEASE_APEXES") |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 768 | extractedApex := android.PathForModuleOut(ctx, "extracted", apexSet.Base()) |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 769 | // Filter out NativeBridge archs (b/260115309) |
| 770 | abis := java.SupportedAbis(ctx, true) |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 771 | ctx.Build(pctx, |
| 772 | android.BuildParams{ |
| 773 | Rule: extractMatchingApex, |
| 774 | Description: "Extract an apex from an apex set", |
| 775 | Inputs: android.Paths{apexSet}, |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 776 | Output: extractedApex, |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 777 | Args: map[string]string{ |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 778 | "abis": strings.Join(abis, ","), |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 779 | "allow-prereleased": strconv.FormatBool(proptools.BoolDefault(prerelease, defaultAllowPrerelease)), |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 780 | "sdk-version": ctx.Config().PlatformSdkVersion().String(), |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 781 | "skip-sdk-check": strconv.FormatBool(ctx.Config().IsEnvTrue("SOONG_SKIP_APPSET_SDK_CHECK")), |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 782 | }, |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 783 | }, |
| 784 | ) |
| 785 | return extractedApex |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 786 | } |
| 787 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 788 | type ApexSet struct { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 789 | prebuiltCommon |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 790 | |
| 791 | properties ApexSetProperties |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 794 | type ApexExtractorProperties struct { |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 795 | // the .apks file path that contains prebuilt apex files to be extracted. |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 796 | Set *string `android:"path"` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 797 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 798 | Sanitized struct { |
| 799 | None struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 800 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 801 | } |
| 802 | Address struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 803 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 804 | } |
| 805 | Hwaddress struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 806 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 810 | // apexes in this set use prerelease SDK version |
| 811 | Prerelease *bool |
| 812 | } |
| 813 | |
| 814 | func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string { |
| 815 | var srcs []string |
| 816 | if e.Set != nil { |
| 817 | srcs = append(srcs, *e.Set) |
| 818 | } |
| 819 | |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 820 | sanitizers := ctx.Config().SanitizeDevice() |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 821 | |
| 822 | if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil { |
| 823 | srcs = append(srcs, *e.Sanitized.Address.Set) |
| 824 | } else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil { |
| 825 | srcs = append(srcs, *e.Sanitized.Hwaddress.Set) |
| 826 | } else if e.Sanitized.None.Set != nil { |
| 827 | srcs = append(srcs, *e.Sanitized.None.Set) |
| 828 | } |
| 829 | |
| 830 | return srcs |
| 831 | } |
| 832 | |
| 833 | type ApexSetProperties struct { |
| 834 | ApexExtractorProperties |
| 835 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 836 | PrebuiltCommonProperties |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | func (a *ApexSet) hasSanitizedSource(sanitizer string) bool { |
| 840 | if sanitizer == "address" { |
| 841 | return a.properties.Sanitized.Address.Set != nil |
| 842 | } |
| 843 | if sanitizer == "hwaddress" { |
| 844 | return a.properties.Sanitized.Hwaddress.Set != nil |
| 845 | } |
| 846 | |
| 847 | return false |
| 848 | } |
| 849 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 850 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 851 | func apexSetFactory() android.Module { |
| 852 | module := &ApexSet{} |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 853 | module.AddProperties(&module.properties) |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 854 | module.prebuiltCommon.prebuiltCommonProperties = &module.properties.PrebuiltCommonProperties |
| 855 | |
| 856 | // init the module as a prebuilt |
| 857 | // even though this module type has srcs, use `InitPrebuiltModuleWithoutSrcs`, since the existing |
| 858 | // InitPrebuiltModule* are not friendly with Sources of Configurable type. |
| 859 | // The actual src will be evaluated in GenerateAndroidBuildActions. |
| 860 | android.InitPrebuiltModuleWithoutSrcs(module) |
| 861 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 862 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 863 | return module |
| 864 | } |
| 865 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 866 | func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 867 | a.prebuiltApexContentsDeps(ctx) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 868 | } |
| 869 | |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 870 | var _ ApexTransitionMutator = (*ApexSet)(nil) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 871 | |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame] | 872 | func (a *ApexSet) ApexTransitionMutatorSplit(ctx android.BaseModuleContext) []android.ApexInfo { |
| 873 | return []android.ApexInfo{a.generateApexInfo(ctx)} |
| 874 | } |
| 875 | |
| 876 | func (a *ApexSet) ApexTransitionMutatorOutgoing(ctx android.OutgoingTransitionContext, sourceInfo android.ApexInfo) android.ApexInfo { |
| 877 | return sourceInfo |
| 878 | } |
| 879 | |
| 880 | func (a *ApexSet) ApexTransitionMutatorIncoming(ctx android.IncomingTransitionContext, outgoingInfo android.ApexInfo) android.ApexInfo { |
| 881 | return a.generateApexInfo(ctx) |
| 882 | } |
| 883 | |
| 884 | func (a *ApexSet) ApexTransitionMutatorMutate(ctx android.BottomUpMutatorContext, info android.ApexInfo) { |
| 885 | android.SetProvider(ctx, android.ApexBundleInfoProvider, android.ApexBundleInfo{}) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 886 | } |
| 887 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 888 | func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 889 | // Validate contents of classpath fragments |
Spandan Das | 5f1f940 | 2024-05-21 18:59:23 +0000 | [diff] [blame] | 890 | if !a.IsHideFromMake() { |
| 891 | validateApexClasspathFragments(ctx) |
| 892 | } |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 893 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 894 | a.apexKeysPath = writeApexKeys(ctx, a) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 895 | a.installFilename = a.InstallFilename() |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 896 | if !strings.HasSuffix(a.installFilename, imageApexSuffix) && !strings.HasSuffix(a.installFilename, imageCapexSuffix) { |
| 897 | ctx.ModuleErrorf("filename should end in %s or %s for apex_set", imageApexSuffix, imageCapexSuffix) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 900 | var apexSet android.Path |
| 901 | if srcs := a.properties.prebuiltSrcs(ctx); len(srcs) == 1 { |
| 902 | apexSet = android.PathForModuleSrc(ctx, srcs[0]) |
| 903 | } else { |
| 904 | ctx.ModuleErrorf("Expected exactly one source apex_set file, found %v\n", srcs) |
| 905 | } |
| 906 | |
| 907 | extractedApex := extract(ctx, apexSet, a.properties.Prerelease) |
| 908 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 909 | a.outputApex = android.PathForModuleOut(ctx, a.installFilename) |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 910 | |
| 911 | // Build the output APEX. If compression is not enabled, make sure the output is not compressed even if the input is compressed |
| 912 | buildRule := android.Cp |
| 913 | if !ctx.Config().ApexCompressionEnabled() { |
| 914 | buildRule = decompressApex |
| 915 | } |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 916 | ctx.Build(pctx, android.BuildParams{ |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 917 | Rule: buildRule, |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 918 | Input: extractedApex, |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 919 | Output: a.outputApex, |
| 920 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 921 | |
| 922 | if a.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 923 | a.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 924 | return |
| 925 | } |
| 926 | |
Spandan Das | 9d6e209 | 2024-09-21 02:50:00 +0000 | [diff] [blame] | 927 | deapexerInfo := a.getDeapexerInfo(ctx, extractedApex) |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 928 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 929 | // dexpreopt any system server jars if present |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 930 | a.dexpreoptSystemServerJars(ctx, deapexerInfo) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 931 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 932 | // provide info used for generating the boot image |
Spandan Das | 52c01a1 | 2024-09-20 01:09:48 +0000 | [diff] [blame] | 933 | a.provideApexExportsInfo(ctx, deapexerInfo) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 934 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 935 | a.providePrebuiltInfo(ctx) |
| 936 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 937 | // Save the files that need to be made available to Make. |
| 938 | a.initApexFilesForAndroidMk(ctx) |
| 939 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 940 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 941 | if a.installable() { |
Colin Cross | 388c661 | 2025-01-28 14:00:12 -0800 | [diff] [blame] | 942 | a.installApexSystemServerFiles(ctx) |
| 943 | a.installedFile = ctx.InstallFile(a.installDir, a.installFilename, a.outputApex, a.extraInstalledFiles...) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | // in case that apex_set replaces source apex (using prefer: prop) |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 947 | a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 948 | // or that apex_set overrides other apexes (using overrides: prop) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 949 | for _, overridden := range a.prebuiltCommonProperties.Overrides { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 950 | a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 951 | } |
mrziwang | 1587b9c | 2024-06-13 11:26:04 -0700 | [diff] [blame] | 952 | |
| 953 | ctx.SetOutputFiles(android.Paths{a.outputApex}, "") |
Spandan Das | dad9870 | 2025-02-26 14:32:28 +0000 | [diff] [blame] | 954 | |
| 955 | android.SetProvider(ctx, filesystem.ApexKeyPathInfoProvider, filesystem.ApexKeyPathInfo{a.apexKeysPath}) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 956 | } |