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