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 ( |
| 18 | "fmt" |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 19 | "io" |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 20 | "path/filepath" |
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" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 26 | "android/soong/java" |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 27 | "android/soong/provenance" |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 28 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 29 | "github.com/google/blueprint" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" |
| 31 | ) |
| 32 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 33 | var ( |
| 34 | extractMatchingApex = pctx.StaticRule( |
| 35 | "extractMatchingApex", |
| 36 | blueprint.RuleParams{ |
| 37 | Command: `rm -rf "$out" && ` + |
| 38 | `${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` + |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 39 | `-sdk-version=${sdk-version} -skip-sdk-check=${skip-sdk-check} -abis=${abis} ` + |
| 40 | `-screen-densities=all -extract-single ` + |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 41 | `${in}`, |
| 42 | CommandDeps: []string{"${extract_apks}"}, |
| 43 | }, |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 44 | "abis", "allow-prereleased", "sdk-version", "skip-sdk-check") |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 45 | decompressApex = pctx.StaticRule("decompressApex", blueprint.RuleParams{ |
Jooyung Han | 8fa6116 | 2024-08-08 10:42:47 +0900 | [diff] [blame] | 46 | 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] | 47 | CommandDeps: []string{"${deapexer}"}, |
Jooyung Han | 8fa6116 | 2024-08-08 10:42:47 +0900 | [diff] [blame] | 48 | Description: "decompress $out", |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 49 | }) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 50 | ) |
| 51 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 52 | type prebuilt interface { |
| 53 | isForceDisabled() bool |
| 54 | InstallFilename() string |
| 55 | } |
| 56 | |
| 57 | type prebuiltCommon struct { |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 58 | android.ModuleBase |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 59 | java.Dexpreopter |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 60 | prebuilt android.Prebuilt |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 61 | |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 62 | // Properties common to both prebuilt_apex and apex_set. |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 63 | prebuiltCommonProperties *PrebuiltCommonProperties |
| 64 | |
| 65 | installDir android.InstallPath |
| 66 | installFilename string |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 67 | installedFile android.InstallPath |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 68 | outputApex android.WritablePath |
| 69 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 70 | // fragment for this apex for apexkeys.txt |
| 71 | apexKeysPath android.WritablePath |
| 72 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 73 | // A list of apexFile objects created in prebuiltCommon.initApexFilesForAndroidMk which are used |
| 74 | // to create make modules in prebuiltCommon.AndroidMkEntries. |
| 75 | apexFilesForAndroidMk []apexFile |
| 76 | |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 77 | // Installed locations of symlinks for backward compatibility. |
| 78 | compatSymlinks android.InstallPaths |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 79 | |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 80 | hostRequired []string |
| 81 | requiredModuleNames []string |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 82 | } |
| 83 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 84 | type sanitizedPrebuilt interface { |
| 85 | hasSanitizedSource(sanitizer string) bool |
| 86 | } |
| 87 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 88 | type PrebuiltCommonProperties struct { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 89 | SelectedApexProperties |
| 90 | |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 91 | // Canonical name of this APEX. Used to determine the path to the activated APEX on |
| 92 | // device (/apex/<apex_name>). If unspecified, follows the name property. |
| 93 | Apex_name *string |
| 94 | |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 95 | // Name of the source APEX that gets shadowed by this prebuilt |
| 96 | // e.g. com.mycompany.android.myapex |
| 97 | // If unspecified, follows the naming convention that the source apex of |
| 98 | // the prebuilt is Name() without "prebuilt_" prefix |
| 99 | Source_apex_name *string |
| 100 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 101 | ForceDisable bool `blueprint:"mutated"` |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 102 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 103 | // whether the extracted apex file is installable. |
| 104 | Installable *bool |
| 105 | |
| 106 | // optional name for the installed apex. If unspecified, name of the |
| 107 | // module is used as the file name |
| 108 | Filename *string |
| 109 | |
| 110 | // names of modules to be overridden. Listed modules can only be other binaries |
| 111 | // (in Make or Soong). |
| 112 | // This does not completely prevent installation of the overridden binaries, but if both |
| 113 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 114 | // from PRODUCT_PACKAGES. |
| 115 | Overrides []string |
| 116 | |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 117 | // List of java libraries that are embedded inside this prebuilt APEX bundle and for which this |
| 118 | // APEX bundle will create an APEX variant and provide dex implementation jars for use by |
| 119 | // dexpreopt and boot jars package check. |
| 120 | Exported_java_libs []string |
| 121 | |
| 122 | // List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX |
| 123 | // bundle will create an APEX variant. |
| 124 | Exported_bootclasspath_fragments []string |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 125 | |
| 126 | // List of systemserverclasspath fragments inside this prebuilt APEX bundle and for which this |
| 127 | // APEX bundle will create an APEX variant. |
| 128 | Exported_systemserverclasspath_fragments []string |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 129 | |
| 130 | // Path to the .prebuilt_info file of the prebuilt apex. |
| 131 | // In case of mainline modules, the .prebuilt_info file contains the build_id that was used to |
| 132 | // generate the prebuilt. |
| 133 | Prebuilt_info *string `android:"path"` |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 134 | } |
| 135 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 136 | // initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the |
| 137 | // module that is common to Prebuilt and ApexSet. |
| 138 | func (p *prebuiltCommon) initPrebuiltCommon(module android.Module, properties *PrebuiltCommonProperties) { |
| 139 | p.prebuiltCommonProperties = properties |
| 140 | android.InitSingleSourcePrebuiltModule(module.(android.PrebuiltInterface), properties, "Selected_apex") |
| 141 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 142 | } |
| 143 | |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 144 | func (p *prebuiltCommon) ApexVariationName() string { |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 145 | return proptools.StringDefault(p.prebuiltCommonProperties.Apex_name, p.BaseModuleName()) |
| 146 | } |
| 147 | |
| 148 | func (p *prebuiltCommon) BaseModuleName() string { |
| 149 | return proptools.StringDefault(p.prebuiltCommonProperties.Source_apex_name, p.ModuleBase.BaseModuleName()) |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 152 | func (p *prebuiltCommon) Prebuilt() *android.Prebuilt { |
| 153 | return &p.prebuilt |
| 154 | } |
| 155 | |
| 156 | func (p *prebuiltCommon) isForceDisabled() bool { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 157 | return p.prebuiltCommonProperties.ForceDisable |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool { |
Jooyung Han | eec1b3f | 2023-06-20 16:25:59 +0900 | [diff] [blame] | 161 | forceDisable := false |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 162 | |
| 163 | // Force disable the prebuilts when we are doing unbundled build. We do unbundled build |
| 164 | // to build the prebuilts themselves. |
| 165 | forceDisable = forceDisable || ctx.Config().UnbundledBuild() |
| 166 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 167 | // b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source |
| 168 | sanitized := ctx.Module().(sanitizedPrebuilt) |
| 169 | forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address")) |
| 170 | forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress")) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 171 | |
| 172 | if forceDisable && p.prebuilt.SourceExists() { |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 173 | p.prebuiltCommonProperties.ForceDisable = true |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 174 | return true |
| 175 | } |
| 176 | return false |
| 177 | } |
| 178 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 179 | func (p *prebuiltCommon) InstallFilename() string { |
| 180 | return proptools.StringDefault(p.prebuiltCommonProperties.Filename, p.BaseModuleName()+imageApexSuffix) |
| 181 | } |
| 182 | |
| 183 | func (p *prebuiltCommon) Name() string { |
| 184 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 185 | } |
| 186 | |
| 187 | func (p *prebuiltCommon) Overrides() []string { |
| 188 | return p.prebuiltCommonProperties.Overrides |
| 189 | } |
| 190 | |
| 191 | func (p *prebuiltCommon) installable() bool { |
| 192 | return proptools.BoolDefault(p.prebuiltCommonProperties.Installable, true) |
| 193 | } |
| 194 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 195 | // To satisfy java.DexpreopterInterface |
| 196 | func (p *prebuiltCommon) IsInstallable() bool { |
| 197 | return p.installable() |
| 198 | } |
| 199 | |
| 200 | // 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] | 201 | func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) { |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 202 | // If this apex contains a system server jar, then the dexpreopt artifacts should be added as required |
| 203 | for _, install := range p.Dexpreopter.DexpreoptBuiltInstalledForApex() { |
| 204 | p.requiredModuleNames = append(p.requiredModuleNames, install.FullModuleName()) |
Justin Yun | 613bdc5 | 2024-06-12 21:32:10 +0900 | [diff] [blame] | 205 | install.PackageFile(ctx) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 206 | } |
| 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 |
| 210 | func (p *prebuiltCommon) dexpreoptSystemServerJars(ctx android.ModuleContext) { |
| 211 | // If this apex does not export anything, return |
| 212 | if !p.hasExportedDeps() { |
| 213 | return |
| 214 | } |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 215 | // If this prebuilt apex has not been selected, return |
| 216 | if p.IsHideFromMake() { |
| 217 | return |
| 218 | } |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 219 | // Use apex_name to determine the api domain of this prebuilt apex |
| 220 | apexName := p.ApexVariationName() |
Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 221 | di, err := android.FindDeapexerProviderForModule(ctx) |
| 222 | if err != nil { |
| 223 | ctx.ModuleErrorf(err.Error()) |
| 224 | } |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 225 | dc := dexpreopt.GetGlobalConfig(ctx) |
| 226 | systemServerJarList := dc.AllApexSystemServerJars(ctx) |
| 227 | |
| 228 | for i := 0; i < systemServerJarList.Len(); i++ { |
| 229 | sscpApex := systemServerJarList.Apex(i) |
| 230 | sscpJar := systemServerJarList.Jar(i) |
| 231 | if apexName != sscpApex { |
| 232 | continue |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 233 | } |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 234 | p.Dexpreopter.DexpreoptPrebuiltApexSystemServerJars(ctx, sscpJar, di) |
| 235 | } |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 238 | func (p *prebuiltCommon) addRequiredModules(entries *android.AndroidMkEntries) { |
| 239 | for _, fi := range p.apexFilesForAndroidMk { |
| 240 | entries.AddStrings("LOCAL_REQUIRED_MODULES", fi.requiredModuleNames...) |
| 241 | entries.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", fi.targetRequiredModuleNames...) |
| 242 | entries.AddStrings("LOCAL_HOST_REQUIRED_MODULES", fi.hostRequiredModuleNames...) |
| 243 | } |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 244 | entries.AddStrings("LOCAL_REQUIRED_MODULES", p.requiredModuleNames...) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 247 | func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 248 | entriesList := []android.AndroidMkEntries{ |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 249 | { |
| 250 | Class: "ETC", |
| 251 | OutputFile: android.OptionalPathForPath(p.outputApex), |
| 252 | Include: "$(BUILD_PREBUILT)", |
| 253 | Host_required: p.hostRequired, |
| 254 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 255 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 256 | entries.SetString("LOCAL_MODULE_PATH", p.installDir.String()) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 257 | entries.SetString("LOCAL_MODULE_STEM", p.installFilename) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 258 | entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", p.installedFile) |
| 259 | entries.SetString("LOCAL_SOONG_INSTALL_PAIRS", p.outputApex.String()+":"+p.installedFile.String()) |
Cole Faust | d22afe9 | 2023-08-18 16:05:44 -0700 | [diff] [blame] | 260 | entries.AddStrings("LOCAL_SOONG_INSTALL_SYMLINKS", p.compatSymlinks.Strings()...) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 261 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 262 | entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.prebuiltCommonProperties.Overrides...) |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 263 | entries.SetString("LOCAL_APEX_KEY_PATH", p.apexKeysPath.String()) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 264 | p.addRequiredModules(entries) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 265 | }, |
| 266 | }, |
| 267 | }, |
| 268 | } |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 269 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 270 | // Add the dexpreopt artifacts to androidmk |
| 271 | for _, install := range p.Dexpreopter.DexpreoptBuiltInstalledForApex() { |
| 272 | entriesList = append(entriesList, install.ToMakeEntries()) |
| 273 | } |
| 274 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 275 | // Iterate over the apexFilesForAndroidMk list and create an AndroidMkEntries struct for each |
| 276 | // file. This provides similar behavior to that provided in apexBundle.AndroidMk() as it makes the |
| 277 | // apex specific variants of the exported java modules available for use from within make. |
| 278 | apexName := p.BaseModuleName() |
| 279 | for _, fi := range p.apexFilesForAndroidMk { |
Paul Duffin | 9dc8c54 | 2021-06-17 13:33:09 +0100 | [diff] [blame] | 280 | entries := p.createEntriesForApexFile(fi, apexName) |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 281 | entriesList = append(entriesList, entries) |
| 282 | } |
| 283 | |
| 284 | return entriesList |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Paul Duffin | 9dc8c54 | 2021-06-17 13:33:09 +0100 | [diff] [blame] | 287 | // createEntriesForApexFile creates an AndroidMkEntries for the supplied apexFile |
| 288 | func (p *prebuiltCommon) createEntriesForApexFile(fi apexFile, apexName string) android.AndroidMkEntries { |
| 289 | moduleName := fi.androidMkModuleName + "." + apexName |
| 290 | entries := android.AndroidMkEntries{ |
| 291 | Class: fi.class.nameInMake(), |
| 292 | OverrideName: moduleName, |
| 293 | OutputFile: android.OptionalPathForPath(fi.builtFile), |
| 294 | Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", |
| 295 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 296 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 297 | entries.SetString("LOCAL_MODULE_PATH", p.installDir.String()) |
Martin Stjernholm | ae44fd8 | 2021-11-23 23:17:33 +0000 | [diff] [blame] | 298 | entries.SetString("LOCAL_SOONG_INSTALLED_MODULE", filepath.Join(p.installDir.String(), fi.stem())) |
| 299 | entries.SetString("LOCAL_SOONG_INSTALL_PAIRS", |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 300 | fi.builtFile.String()+":"+filepath.Join(p.installDir.String(), fi.stem())) |
Paul Duffin | 9dc8c54 | 2021-06-17 13:33:09 +0100 | [diff] [blame] | 301 | |
| 302 | // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore |
| 303 | // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise |
| 304 | // we will have foo.jar.jar |
| 305 | entries.SetString("LOCAL_MODULE_STEM", strings.TrimSuffix(fi.stem(), ".jar")) |
Paul Duffin | 9dc8c54 | 2021-06-17 13:33:09 +0100 | [diff] [blame] | 306 | entries.SetString("LOCAL_SOONG_DEX_JAR", fi.builtFile.String()) |
| 307 | entries.SetString("LOCAL_DEX_PREOPT", "false") |
| 308 | }, |
| 309 | }, |
| 310 | ExtraFooters: []android.AndroidMkExtraFootersFunc{ |
| 311 | func(w io.Writer, name, prefix, moduleDir string) { |
| 312 | // m <module_name> will build <module_name>.<apex_name> as well. |
| 313 | if fi.androidMkModuleName != moduleName { |
| 314 | fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName) |
| 315 | fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName) |
| 316 | } |
| 317 | }, |
| 318 | }, |
| 319 | } |
| 320 | return entries |
| 321 | } |
| 322 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 323 | // prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and |
| 324 | // apex_set in order to create the modules needed to provide access to the prebuilt .apex file. |
| 325 | type prebuiltApexModuleCreator interface { |
| 326 | createPrebuiltApexModules(ctx android.TopDownMutatorContext) |
| 327 | } |
| 328 | |
| 329 | // prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the |
| 330 | // prebuiltApexModuleCreator's createPrebuiltApexModules method. |
| 331 | // |
| 332 | // It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it |
| 333 | // will need to access dependencies added by that (exported modules) but must run before the |
| 334 | // DepsMutator so that the deapexer module it creates can add dependencies onto itself from the |
| 335 | // exported modules. |
| 336 | func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) { |
| 337 | module := ctx.Module() |
| 338 | if creator, ok := module.(prebuiltApexModuleCreator); ok { |
| 339 | creator.createPrebuiltApexModules(ctx) |
| 340 | } |
| 341 | } |
| 342 | |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 343 | func (p *prebuiltCommon) hasExportedDeps() bool { |
| 344 | return len(p.prebuiltCommonProperties.Exported_java_libs) > 0 || |
| 345 | len(p.prebuiltCommonProperties.Exported_bootclasspath_fragments) > 0 || |
| 346 | len(p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments) > 0 |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 349 | // prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents. |
| 350 | func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) { |
| 351 | module := ctx.Module() |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 352 | |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 353 | for _, dep := range p.prebuiltCommonProperties.Exported_java_libs { |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 354 | prebuiltDep := android.PrebuiltNameFromSource(dep) |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 355 | ctx.AddDependency(module, exportedJavaLibTag, prebuiltDep) |
| 356 | } |
| 357 | |
| 358 | for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments { |
| 359 | prebuiltDep := android.PrebuiltNameFromSource(dep) |
| 360 | ctx.AddDependency(module, exportedBootclasspathFragmentTag, prebuiltDep) |
| 361 | } |
| 362 | |
| 363 | for _, dep := range p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments { |
| 364 | prebuiltDep := android.PrebuiltNameFromSource(dep) |
| 365 | ctx.AddDependency(module, exportedSystemserverclasspathFragmentTag, prebuiltDep) |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 366 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 369 | // Implements android.DepInInSameApex |
| 370 | func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 371 | tag := ctx.OtherModuleDependencyTag(dep) |
| 372 | _, ok := tag.(exportedDependencyTag) |
| 373 | return ok |
| 374 | } |
| 375 | |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 376 | // apexInfoMutator marks any modules for which this apex exports a file as requiring an apex |
| 377 | // specific variant and checks that they are supported. |
| 378 | // |
| 379 | // The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are |
| 380 | // associated with the apex specific variant using the ApexInfoProvider for later retrieval. |
| 381 | // |
| 382 | // Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants |
| 383 | // across prebuilt_apex modules. That is because there is no way to determine whether two |
| 384 | // prebuilt_apex modules that export files for the same module are compatible. e.g. they could have |
| 385 | // been built from different source at different times or they could have been built with different |
| 386 | // build options that affect the libraries. |
| 387 | // |
| 388 | // While it may be possible to provide sufficient information to determine whether two prebuilt_apex |
| 389 | // modules were compatible it would be a lot of work and would not provide much benefit for a couple |
| 390 | // of reasons: |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 391 | // - The number of prebuilt_apex modules that will be exporting files for the same module will be |
| 392 | // low as the prebuilt_apex only exports files for the direct dependencies that require it and |
| 393 | // very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a |
| 394 | // few com.android.art* apex files that contain the same contents and could export files for the |
| 395 | // same modules but only one of them needs to do so. Contrast that with source apex modules which |
| 396 | // need apex specific variants for every module that contributes code to the apex, whether direct |
| 397 | // or indirect. |
| 398 | // - The build cost of a prebuilt_apex variant is generally low as at worst it will involve some |
| 399 | // extra copying of files. Contrast that with source apex modules that has to build each variant |
| 400 | // from source. |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 401 | func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) { |
| 402 | |
| 403 | // Collect direct dependencies into contents. |
| 404 | contents := make(map[string]android.ApexMembership) |
| 405 | |
| 406 | // Collect the list of dependencies. |
| 407 | var dependencies []android.ApexModule |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 408 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 409 | // If the child is not in the same apex as the parent then exit immediately and do not visit |
| 410 | // any of the child's dependencies. |
| 411 | if !android.IsDepInSameApex(mctx, parent, child) { |
| 412 | return false |
| 413 | } |
| 414 | |
| 415 | tag := mctx.OtherModuleDependencyTag(child) |
| 416 | depName := mctx.OtherModuleName(child) |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 417 | if exportedTag, ok := tag.(exportedDependencyTag); ok { |
| 418 | propertyName := exportedTag.name |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 419 | |
| 420 | // It is an error if the other module is not a prebuilt. |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 421 | if !android.IsModulePrebuilt(child) { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 422 | mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName) |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 423 | return false |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | // It is an error if the other module is not an ApexModule. |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 427 | if _, ok := child.(android.ApexModule); !ok { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 428 | mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName) |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 429 | return false |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 430 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 431 | } |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 432 | |
Paul Duffin | fee8cf3 | 2021-06-29 18:38:38 +0100 | [diff] [blame] | 433 | // Ignore any modules that do not implement ApexModule as they cannot have an APEX specific |
| 434 | // variant. |
| 435 | if _, ok := child.(android.ApexModule); !ok { |
| 436 | return false |
| 437 | } |
| 438 | |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 439 | // Strip off the prebuilt_ prefix if present before storing content to ensure consistent |
| 440 | // behavior whether there is a corresponding source module present or not. |
| 441 | depName = android.RemoveOptionalPrebuiltPrefix(depName) |
| 442 | |
| 443 | // Remember if this module was added as a direct dependency. |
| 444 | direct := parent == mctx.Module() |
| 445 | contents[depName] = contents[depName].Add(direct) |
| 446 | |
| 447 | // Add the module to the list of dependencies that need to have an APEX variant. |
| 448 | dependencies = append(dependencies, child.(android.ApexModule)) |
| 449 | |
| 450 | return true |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 451 | }) |
| 452 | |
| 453 | // Create contents for the prebuilt_apex and store it away for later use. |
| 454 | apexContents := android.NewApexContents(contents) |
Spandan Das | f5e03f1 | 2024-01-25 19:25:42 +0000 | [diff] [blame] | 455 | android.SetProvider(mctx, android.ApexBundleInfoProvider, android.ApexBundleInfo{ |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 456 | Contents: apexContents, |
| 457 | }) |
| 458 | |
| 459 | // Create an ApexInfo for the prebuilt_apex. |
Martin Stjernholm | d8da28e | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 460 | apexVariationName := p.ApexVariationName() |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 461 | apexInfo := android.ApexInfo{ |
Martin Stjernholm | c4f4ced | 2021-05-27 11:17:00 +0000 | [diff] [blame] | 462 | ApexVariationName: apexVariationName, |
| 463 | InApexVariants: []string{apexVariationName}, |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 464 | InApexModules: []string{p.BaseModuleName()}, // BaseModuleName() to avoid the prebuilt_ prefix. |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 465 | ApexContents: []*android.ApexContents{apexContents}, |
| 466 | ForPrebuiltApex: true, |
| 467 | } |
| 468 | |
| 469 | // Mark the dependencies of this module as requiring a variant for this module. |
| 470 | for _, am := range dependencies { |
| 471 | am.BuildForApex(apexInfo) |
| 472 | } |
| 473 | } |
| 474 | |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 475 | // prebuiltApexSelectorModule is a private module type that is only created by the prebuilt_apex |
| 476 | // module. It selects the apex to use and makes it available for use by prebuilt_apex and the |
| 477 | // deapexer. |
| 478 | type prebuiltApexSelectorModule struct { |
| 479 | android.ModuleBase |
| 480 | |
| 481 | apexFileProperties ApexFileProperties |
| 482 | |
| 483 | inputApex android.Path |
| 484 | } |
| 485 | |
| 486 | func privateApexSelectorModuleFactory() android.Module { |
| 487 | module := &prebuiltApexSelectorModule{} |
| 488 | module.AddProperties( |
| 489 | &module.apexFileProperties, |
| 490 | ) |
| 491 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 492 | return module |
| 493 | } |
| 494 | |
| 495 | func (p *prebuiltApexSelectorModule) Srcs() android.Paths { |
| 496 | return android.Paths{p.inputApex} |
| 497 | } |
| 498 | |
| 499 | func (p *prebuiltApexSelectorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 500 | p.inputApex = android.SingleSourcePathFromSupplier(ctx, p.apexFileProperties.prebuiltApexSelector, "src") |
| 501 | } |
| 502 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 503 | type Prebuilt struct { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 504 | prebuiltCommon |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 505 | |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 506 | properties PrebuiltProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 507 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 508 | inputApex android.Path |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 509 | |
| 510 | provenanceMetaDataFile android.OutputPath |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 511 | } |
| 512 | |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 513 | type ApexFileProperties struct { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 514 | // the path to the prebuilt .apex file to import. |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 515 | // |
| 516 | // This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated |
| 517 | // for android_common. That is so that it will have the same arch variant as, and so be compatible |
| 518 | // with, the source `apex` module type that it replaces. |
Cole Faust | 642e720 | 2024-08-14 17:46:12 -0700 | [diff] [blame^] | 519 | Src proptools.Configurable[string] `android:"path,replace_instead_of_append"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 520 | Arch struct { |
| 521 | Arm struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 522 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 523 | } |
| 524 | Arm64 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 525 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 526 | } |
Chen Guoyin | 401f298 | 2022-10-12 19:28:48 +0800 | [diff] [blame] | 527 | Riscv64 struct { |
| 528 | Src *string `android:"path"` |
| 529 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 530 | X86 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 531 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 532 | } |
| 533 | X86_64 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 534 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 535 | } |
| 536 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 539 | // prebuiltApexSelector selects the correct prebuilt APEX file for the build target. |
| 540 | // |
| 541 | // The ctx parameter can be for any module not just the prebuilt module so care must be taken not |
| 542 | // to use methods on it that are specific to the current module. |
| 543 | // |
| 544 | // See the ApexFileProperties.Src property. |
| 545 | func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) []string { |
| 546 | multiTargets := prebuilt.MultiTargets() |
| 547 | if len(multiTargets) != 1 { |
| 548 | ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex") |
| 549 | return nil |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 550 | } |
| 551 | var src string |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 552 | switch multiTargets[0].Arch.ArchType { |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 553 | case android.Arm: |
| 554 | src = String(p.Arch.Arm.Src) |
| 555 | case android.Arm64: |
| 556 | src = String(p.Arch.Arm64.Src) |
Chen Guoyin | 401f298 | 2022-10-12 19:28:48 +0800 | [diff] [blame] | 557 | case android.Riscv64: |
| 558 | src = String(p.Arch.Riscv64.Src) |
Colin Cross | abacbe8 | 2022-11-01 09:26:51 -0700 | [diff] [blame] | 559 | // HACK: fall back to arm64 prebuilts, the riscv64 ones don't exist yet. |
| 560 | if src == "" { |
| 561 | src = String(p.Arch.Arm64.Src) |
| 562 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 563 | case android.X86: |
| 564 | src = String(p.Arch.X86.Src) |
| 565 | case android.X86_64: |
| 566 | src = String(p.Arch.X86_64.Src) |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 567 | } |
| 568 | if src == "" { |
Cole Faust | 642e720 | 2024-08-14 17:46:12 -0700 | [diff] [blame^] | 569 | src = p.Src.GetOrDefault(ctx, "") |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 570 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 571 | |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 572 | if src == "" { |
Colin Cross | 553a31b | 2022-10-03 22:02:09 -0700 | [diff] [blame] | 573 | if ctx.Config().AllowMissingDependencies() { |
| 574 | ctx.AddMissingDependencies([]string{ctx.OtherModuleName(prebuilt)}) |
| 575 | } else { |
| 576 | ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String()) |
| 577 | } |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 578 | // Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt |
| 579 | // logic from reporting a more general, less useful message. |
| 580 | } |
| 581 | |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 582 | return []string{src} |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | type PrebuiltProperties struct { |
| 586 | ApexFileProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 587 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 588 | PrebuiltCommonProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 589 | } |
| 590 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 591 | func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool { |
| 592 | return false |
| 593 | } |
| 594 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 595 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 596 | func PrebuiltFactory() android.Module { |
| 597 | module := &Prebuilt{} |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 598 | module.AddProperties(&module.properties) |
| 599 | module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 600 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 601 | return module |
| 602 | } |
| 603 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 604 | func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, apexFileProperties *ApexFileProperties) { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 605 | props := struct { |
| 606 | Name *string |
| 607 | }{ |
| 608 | Name: proptools.StringPtr(name), |
| 609 | } |
| 610 | |
| 611 | ctx.CreateModule(privateApexSelectorModuleFactory, |
| 612 | &props, |
| 613 | apexFileProperties, |
| 614 | ) |
| 615 | } |
| 616 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 617 | // createDeapexerModuleIfNeeded will create a deapexer module if it is needed. |
| 618 | // |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 619 | // A deapexer module is only needed when the prebuilt apex specifies one or more modules in either |
| 620 | // the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that |
| 621 | // the listed modules need access to files from within the prebuilt .apex file. |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 622 | func (p *prebuiltCommon) createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string) { |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 623 | // Only create the deapexer module if it is needed. |
Liz Kammer | 2dc7244 | 2023-04-20 10:10:48 -0400 | [diff] [blame] | 624 | if !p.hasExportedDeps() { |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 625 | return |
| 626 | } |
| 627 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 628 | // Compute the deapexer properties from the transitive dependencies of this module. |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 629 | commonModules := []string{} |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 630 | dexpreoptProfileGuidedModules := []string{} |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 631 | exportedFiles := []string{} |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 632 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 633 | tag := ctx.OtherModuleDependencyTag(child) |
| 634 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 635 | // If the child is not in the same apex as the parent then ignore it and all its children. |
| 636 | if !android.IsDepInSameApex(ctx, parent, child) { |
| 637 | return false |
| 638 | } |
| 639 | |
Spandan Das | 161e468 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 640 | name := java.ModuleStemForDeapexing(child) |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 641 | if _, ok := tag.(android.RequiresFilesFromPrebuiltApexTag); ok { |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 642 | commonModules = append(commonModules, name) |
| 643 | |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 644 | extract := child.(android.RequiredFilesFromPrebuiltApex) |
| 645 | requiredFiles := extract.RequiredFilesFromPrebuiltApex(ctx) |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 646 | exportedFiles = append(exportedFiles, requiredFiles...) |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 647 | |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 648 | if extract.UseProfileGuidedDexpreopt() { |
| 649 | dexpreoptProfileGuidedModules = append(dexpreoptProfileGuidedModules, name) |
| 650 | } |
| 651 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 652 | // Visit the dependencies of this module just in case they also require files from the |
| 653 | // prebuilt apex. |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 654 | return true |
| 655 | } |
| 656 | |
| 657 | return false |
| 658 | }) |
| 659 | |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 660 | // Create properties for deapexer module. |
| 661 | deapexerProperties := &DeapexerProperties{ |
Paul Duffin | b508405 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 662 | // 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] | 663 | // dependency as well as transitive ones. |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 664 | CommonModules: android.SortedUniqueStrings(commonModules), |
| 665 | DexpreoptProfileGuidedModules: android.SortedUniqueStrings(dexpreoptProfileGuidedModules), |
Paul Duffin | 3bae068 | 2021-05-05 18:03:47 +0100 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | // Populate the exported files property in a fixed order. |
Paul Duffin | 034196d | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 669 | deapexerProperties.ExportedFiles = android.SortedUniqueStrings(exportedFiles) |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 670 | |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 671 | props := struct { |
| 672 | Name *string |
| 673 | Selected_apex *string |
| 674 | }{ |
| 675 | Name: proptools.StringPtr(deapexerName), |
| 676 | Selected_apex: proptools.StringPtr(apexFileSource), |
| 677 | } |
| 678 | ctx.CreateModule(privateDeapexerFactory, |
| 679 | &props, |
| 680 | deapexerProperties, |
| 681 | ) |
| 682 | } |
| 683 | |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 684 | func apexSelectorModuleName(baseModuleName string) string { |
| 685 | return baseModuleName + ".apex.selector" |
| 686 | } |
| 687 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 688 | func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string { |
| 689 | // The prebuilt_apex should be depending on prebuilt modules but as this runs after |
| 690 | // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So, |
| 691 | // check to see if the prefixed name is in use first, if it is then use that, otherwise assume |
| 692 | // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module |
| 693 | // and not a renamed prebuilt module then that will be detected and reported as an error when |
| 694 | // processing the dependency in ApexInfoMutator(). |
Paul Duffin | 864116c | 2021-04-02 10:24:13 +0100 | [diff] [blame] | 695 | prebuiltName := android.PrebuiltNameFromSource(name) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 696 | if ctx.OtherModuleExists(prebuiltName) { |
| 697 | name = prebuiltName |
| 698 | } |
| 699 | return name |
| 700 | } |
| 701 | |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 702 | type exportedDependencyTag struct { |
| 703 | blueprint.BaseDependencyTag |
| 704 | name string |
| 705 | } |
| 706 | |
| 707 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. |
| 708 | // |
| 709 | // This does allow any prebuilt_apex to reference any module which does open up a small window for |
| 710 | // restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so |
| 711 | // avoids opening up a much bigger window by widening the visibility of modules that need files |
| 712 | // provided by the prebuilt_apex to include all the possible locations they may be defined, which |
| 713 | // could include everything below vendor/. |
| 714 | // |
| 715 | // A prebuilt_apex that references a module via this tag will have to contain the appropriate files |
| 716 | // corresponding to that module, otherwise it will fail when attempting to retrieve the files from |
| 717 | // the .apex file. It will also have to be included in the module's apex_available property too. |
| 718 | // That makes it highly unlikely that a prebuilt_apex would reference a restricted module |
| 719 | // incorrectly. |
| 720 | func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {} |
| 721 | |
Paul Duffin | 7db57e0 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 722 | func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {} |
| 723 | |
| 724 | var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{} |
| 725 | |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 726 | var ( |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 727 | exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"} |
| 728 | exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"} |
| 729 | exportedSystemserverclasspathFragmentTag = exportedDependencyTag{name: "exported_systemserverclasspath_fragments"} |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 730 | ) |
| 731 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 732 | var _ prebuiltApexModuleCreator = (*Prebuilt)(nil) |
| 733 | |
| 734 | // createPrebuiltApexModules creates modules necessary to export files from the prebuilt apex to the |
| 735 | // build. |
| 736 | // |
| 737 | // If this needs to make files from within a `.apex` file available for use by other Soong modules, |
| 738 | // e.g. make dex implementation jars available for java_import modules listed in exported_java_libs, |
| 739 | // it does so as follows: |
| 740 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 741 | // 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and |
| 742 | // makes them available for use by other modules, at both Soong and ninja levels. |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 743 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 744 | // 2. It adds a dependency onto those modules and creates an apex specific variant similar to what |
| 745 | // an `apex` module does. That ensures that code which looks for specific apex variant, e.g. |
| 746 | // dexpreopt, will work the same way from source and prebuilt. |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 747 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 748 | // 3. The `deapexer` module adds a dependency from the modules that require the exported files onto |
| 749 | // itself so that they can retrieve the file paths to those files. |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 750 | // |
| 751 | // It also creates a child module `selector` that is responsible for selecting the appropriate |
| 752 | // input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons: |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 753 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 754 | // 1. To dedup the selection logic so it only runs in one module. |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 755 | // |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 756 | // 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an |
| 757 | // `apex_set`. |
| 758 | // |
| 759 | // prebuilt_apex |
| 760 | // / | \ |
| 761 | // / | \ |
| 762 | // V V V |
| 763 | // selector <--- deapexer <--- exported java lib |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 764 | func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) { |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 765 | apexSelectorModuleName := apexSelectorModuleName(p.Name()) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 766 | createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties) |
| 767 | |
| 768 | apexFileSource := ":" + apexSelectorModuleName |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 769 | p.createDeapexerModuleIfNeeded(ctx, deapexerModuleName(p.Name()), apexFileSource) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 770 | |
| 771 | // Add a source reference to retrieve the selected apex from the selector module. |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 772 | p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 773 | } |
| 774 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 775 | func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 776 | p.prebuiltApexContentsDeps(ctx) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 779 | func (p *prebuiltCommon) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 780 | if p.hasExportedDeps() { |
| 781 | // Create a dependency from the prebuilt apex (prebuilt_apex/apex_set) to the internal deapexer module |
| 782 | // The deapexer will return a provider that will be bubbled up to the rdeps of apexes (e.g. dex_bootjars) |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 783 | ctx.AddDependency(ctx.Module(), android.DeapexerTag, deapexerModuleName(p.Name())) |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 787 | var _ ApexInfoMutator = (*Prebuilt)(nil) |
| 788 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 789 | func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) { |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 790 | p.apexInfoMutator(mctx) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 791 | } |
| 792 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 793 | // Set a provider containing information about the jars and .prof provided by the apex |
| 794 | // Apexes built from prebuilts retrieve this information by visiting its internal deapexer module |
| 795 | // Used by dex_bootjars to generate the boot image |
| 796 | func (p *prebuiltCommon) provideApexExportsInfo(ctx android.ModuleContext) { |
| 797 | if !p.hasExportedDeps() { |
| 798 | // nothing to do |
| 799 | return |
| 800 | } |
| 801 | if di, err := android.FindDeapexerProviderForModule(ctx); err == nil { |
Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 802 | javaModuleToDexPath := map[string]android.Path{} |
| 803 | for _, commonModule := range di.GetExportedModuleNames() { |
| 804 | if dex := di.PrebuiltExportPath(java.ApexRootRelativePathToJavaLib(commonModule)); dex != nil { |
| 805 | javaModuleToDexPath[commonModule] = dex |
| 806 | } |
| 807 | } |
| 808 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 809 | exports := android.ApexExportsInfo{ |
Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 810 | ApexName: p.ApexVariationName(), |
| 811 | ProfilePathOnHost: di.PrebuiltExportPath(java.ProfileInstallPathInApex), |
| 812 | LibraryNameToDexJarPathOnHost: javaModuleToDexPath, |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 813 | } |
Spandan Das | a41b8ec | 2023-12-22 00:05:04 +0000 | [diff] [blame] | 814 | android.SetProvider(ctx, android.ApexExportsInfoProvider, exports) |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 815 | } else { |
| 816 | ctx.ModuleErrorf(err.Error()) |
| 817 | } |
| 818 | } |
| 819 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 820 | // Set prebuiltInfoProvider. This will be used by `apex_prebuiltinfo_singleton` to print out a metadata file |
| 821 | // with information about whether source or prebuilt of an apex was used during the build. |
| 822 | func (p *prebuiltCommon) providePrebuiltInfo(ctx android.ModuleContext) { |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 823 | info := android.PrebuiltInfo{ |
| 824 | Name: p.BaseModuleName(), |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 825 | Is_prebuilt: true, |
| 826 | } |
| 827 | // If Prebuilt_info information is available in the soong module definition, add it to prebuilt_info.json. |
| 828 | if p.prebuiltCommonProperties.Prebuilt_info != nil { |
| 829 | info.Prebuilt_info_file_path = android.PathForModuleSrc(ctx, *p.prebuiltCommonProperties.Prebuilt_info).String() |
| 830 | } |
Spandan Das | 3490dfd | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 831 | android.SetProvider(ctx, android.PrebuiltInfoProvider, info) |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 834 | // Uses an object provided by its deps to validate that the contents of bcpf have been added to the global |
| 835 | // PRODUCT_APEX_BOOT_JARS |
| 836 | // This validation will only run on the apex which is active for this product/release_config |
| 837 | func validateApexClasspathFragments(ctx android.ModuleContext) { |
| 838 | ctx.VisitDirectDeps(func(m android.Module) { |
| 839 | if info, exists := android.OtherModuleProvider(ctx, m, java.ClasspathFragmentValidationInfoProvider); exists { |
| 840 | ctx.ModuleErrorf("%s in contents of %s must also be declared in PRODUCT_APEX_BOOT_JARS", info.UnknownJars, info.ClasspathFragmentModuleName) |
| 841 | } |
| 842 | }) |
| 843 | } |
| 844 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 845 | func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 846 | // Validate contents of classpath fragments |
Spandan Das | 5f1f940 | 2024-05-21 18:59:23 +0000 | [diff] [blame] | 847 | if !p.IsHideFromMake() { |
| 848 | validateApexClasspathFragments(ctx) |
| 849 | } |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 850 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 851 | p.apexKeysPath = writeApexKeys(ctx, p) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 852 | // TODO(jungjw): Check the key validity. |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 853 | p.inputApex = android.OptionalPathForModuleSrc(ctx, p.prebuiltCommonProperties.Selected_apex).Path() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 854 | p.installDir = android.PathForModuleInstall(ctx, "apex") |
| 855 | p.installFilename = p.InstallFilename() |
| 856 | if !strings.HasSuffix(p.installFilename, imageApexSuffix) { |
| 857 | ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix) |
| 858 | } |
| 859 | p.outputApex = android.PathForModuleOut(ctx, p.installFilename) |
| 860 | ctx.Build(pctx, android.BuildParams{ |
| 861 | Rule: android.Cp, |
| 862 | Input: p.inputApex, |
| 863 | Output: p.outputApex, |
| 864 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 865 | |
| 866 | if p.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 867 | p.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 868 | return |
| 869 | } |
| 870 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 871 | // dexpreopt any system server jars if present |
| 872 | p.dexpreoptSystemServerJars(ctx) |
| 873 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 874 | // provide info used for generating the boot image |
| 875 | p.provideApexExportsInfo(ctx) |
| 876 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 877 | p.providePrebuiltInfo(ctx) |
| 878 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 879 | // Save the files that need to be made available to Make. |
| 880 | p.initApexFilesForAndroidMk(ctx) |
| 881 | |
Colin Cross | ccba23d | 2021-11-12 19:01:29 +0000 | [diff] [blame] | 882 | // in case that prebuilt_apex replaces source apex (using prefer: prop) |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 883 | p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx) |
Colin Cross | ccba23d | 2021-11-12 19:01:29 +0000 | [diff] [blame] | 884 | // or that prebuilt_apex overrides other apexes (using overrides: prop) |
| 885 | for _, overridden := range p.prebuiltCommonProperties.Overrides { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 886 | p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
Colin Cross | 6340ea5 | 2021-11-04 12:01:18 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | if p.installable() { |
Colin Cross | 09ad3a6 | 2023-11-15 12:29:33 -0800 | [diff] [blame] | 890 | p.installedFile = ctx.InstallFile(p.installDir, p.installFilename, p.inputApex, p.compatSymlinks...) |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 891 | p.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, p.inputApex, p.installedFile) |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 892 | } |
mrziwang | 1587b9c | 2024-06-13 11:26:04 -0700 | [diff] [blame] | 893 | |
| 894 | ctx.SetOutputFiles(android.Paths{p.outputApex}, "") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 895 | } |
| 896 | |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 897 | func (p *Prebuilt) ProvenanceMetaDataFile() android.OutputPath { |
| 898 | return p.provenanceMetaDataFile |
| 899 | } |
| 900 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 901 | // prebuiltApexExtractorModule is a private module type that is only created by the prebuilt_apex |
| 902 | // module. It extracts the correct apex to use and makes it available for use by apex_set. |
| 903 | type prebuiltApexExtractorModule struct { |
| 904 | android.ModuleBase |
| 905 | |
| 906 | properties ApexExtractorProperties |
| 907 | |
| 908 | extractedApex android.WritablePath |
| 909 | } |
| 910 | |
| 911 | func privateApexExtractorModuleFactory() android.Module { |
| 912 | module := &prebuiltApexExtractorModule{} |
| 913 | module.AddProperties( |
| 914 | &module.properties, |
| 915 | ) |
| 916 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 917 | return module |
| 918 | } |
| 919 | |
| 920 | func (p *prebuiltApexExtractorModule) Srcs() android.Paths { |
| 921 | return android.Paths{p.extractedApex} |
| 922 | } |
| 923 | |
| 924 | func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 925 | srcsSupplier := func(ctx android.BaseModuleContext, prebuilt android.Module) []string { |
| 926 | return p.properties.prebuiltSrcs(ctx) |
| 927 | } |
Paul Duffin | 76fdd67 | 2022-12-12 18:00:47 +0000 | [diff] [blame] | 928 | defaultAllowPrerelease := ctx.Config().IsEnvTrue("SOONG_ALLOW_PRERELEASE_APEXES") |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 929 | apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set") |
| 930 | p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base()) |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 931 | // Filter out NativeBridge archs (b/260115309) |
| 932 | abis := java.SupportedAbis(ctx, true) |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 933 | ctx.Build(pctx, |
| 934 | android.BuildParams{ |
| 935 | Rule: extractMatchingApex, |
| 936 | Description: "Extract an apex from an apex set", |
| 937 | Inputs: android.Paths{apexSet}, |
| 938 | Output: p.extractedApex, |
| 939 | Args: map[string]string{ |
Anton Hansson | 805e0a5 | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 940 | "abis": strings.Join(abis, ","), |
Paul Duffin | 76fdd67 | 2022-12-12 18:00:47 +0000 | [diff] [blame] | 941 | "allow-prereleased": strconv.FormatBool(proptools.BoolDefault(p.properties.Prerelease, defaultAllowPrerelease)), |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 942 | "sdk-version": ctx.Config().PlatformSdkVersion().String(), |
Pranav Gupta | 51645ff | 2023-03-20 16:19:53 -0700 | [diff] [blame] | 943 | "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] | 944 | }, |
| 945 | }) |
| 946 | } |
| 947 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 948 | type ApexSet struct { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 949 | prebuiltCommon |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 950 | |
| 951 | properties ApexSetProperties |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 954 | type ApexExtractorProperties struct { |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 955 | // the .apks file path that contains prebuilt apex files to be extracted. |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 956 | Set *string `android:"path"` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 957 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 958 | Sanitized struct { |
| 959 | None struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 960 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 961 | } |
| 962 | Address struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 963 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 964 | } |
| 965 | Hwaddress struct { |
Pranav Gupta | eba03b0 | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 966 | Set *string `android:"path"` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 970 | // apexes in this set use prerelease SDK version |
| 971 | Prerelease *bool |
| 972 | } |
| 973 | |
| 974 | func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string { |
| 975 | var srcs []string |
| 976 | if e.Set != nil { |
| 977 | srcs = append(srcs, *e.Set) |
| 978 | } |
| 979 | |
Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 980 | sanitizers := ctx.Config().SanitizeDevice() |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 981 | |
| 982 | if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil { |
| 983 | srcs = append(srcs, *e.Sanitized.Address.Set) |
| 984 | } else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil { |
| 985 | srcs = append(srcs, *e.Sanitized.Hwaddress.Set) |
| 986 | } else if e.Sanitized.None.Set != nil { |
| 987 | srcs = append(srcs, *e.Sanitized.None.Set) |
| 988 | } |
| 989 | |
| 990 | return srcs |
| 991 | } |
| 992 | |
| 993 | type ApexSetProperties struct { |
| 994 | ApexExtractorProperties |
| 995 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 996 | PrebuiltCommonProperties |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | func (a *ApexSet) hasSanitizedSource(sanitizer string) bool { |
| 1000 | if sanitizer == "address" { |
| 1001 | return a.properties.Sanitized.Address.Set != nil |
| 1002 | } |
| 1003 | if sanitizer == "hwaddress" { |
| 1004 | return a.properties.Sanitized.Hwaddress.Set != nil |
| 1005 | } |
| 1006 | |
| 1007 | return false |
| 1008 | } |
| 1009 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1010 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 1011 | func apexSetFactory() android.Module { |
| 1012 | module := &ApexSet{} |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 1013 | module.AddProperties(&module.properties) |
| 1014 | module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties) |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 1015 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 1016 | return module |
| 1017 | } |
| 1018 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 1019 | func createApexExtractorModule(ctx android.TopDownMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) { |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 1020 | props := struct { |
| 1021 | Name *string |
| 1022 | }{ |
| 1023 | Name: proptools.StringPtr(name), |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 1026 | ctx.CreateModule(privateApexExtractorModuleFactory, |
| 1027 | &props, |
| 1028 | apexExtractorProperties, |
| 1029 | ) |
| 1030 | } |
| 1031 | |
| 1032 | func apexExtractorModuleName(baseModuleName string) string { |
| 1033 | return baseModuleName + ".apex.extractor" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 1036 | var _ prebuiltApexModuleCreator = (*ApexSet)(nil) |
| 1037 | |
| 1038 | // createPrebuiltApexModules creates modules necessary to export files from the apex set to other |
| 1039 | // modules. |
| 1040 | // |
| 1041 | // This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a |
| 1042 | // prebuilt_apex except that instead of creating a selector module which selects one .apex file |
| 1043 | // from those provided this creates an extractor module which extracts the appropriate .apex file |
| 1044 | // from the zip file containing them. |
| 1045 | func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) { |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 1046 | apexExtractorModuleName := apexExtractorModuleName(a.Name()) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 1047 | createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties) |
| 1048 | |
| 1049 | apexFileSource := ":" + apexExtractorModuleName |
Spandan Das | 3576e76 | 2024-01-03 18:57:03 +0000 | [diff] [blame] | 1050 | a.createDeapexerModuleIfNeeded(ctx, deapexerModuleName(a.Name()), apexFileSource) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 1051 | |
| 1052 | // After passing the arch specific src properties to the creating the apex selector module |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 1053 | a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource) |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame] | 1056 | func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 1057 | a.prebuiltApexContentsDeps(ctx) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | var _ ApexInfoMutator = (*ApexSet)(nil) |
| 1061 | |
| 1062 | func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) { |
| 1063 | a.apexInfoMutator(mctx) |
| 1064 | } |
| 1065 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1066 | func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 1067 | // Validate contents of classpath fragments |
Spandan Das | 5f1f940 | 2024-05-21 18:59:23 +0000 | [diff] [blame] | 1068 | if !a.IsHideFromMake() { |
| 1069 | validateApexClasspathFragments(ctx) |
| 1070 | } |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 1071 | |
Jooyung Han | 286957d | 2023-10-30 16:17:56 +0900 | [diff] [blame] | 1072 | a.apexKeysPath = writeApexKeys(ctx, a) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1073 | a.installFilename = a.InstallFilename() |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 1074 | if !strings.HasSuffix(a.installFilename, imageApexSuffix) && !strings.HasSuffix(a.installFilename, imageCapexSuffix) { |
| 1075 | 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] | 1076 | } |
| 1077 | |
Paul Duffin | bb0dc13 | 2021-05-05 16:58:08 +0100 | [diff] [blame] | 1078 | inputApex := android.OptionalPathForModuleSrc(ctx, a.prebuiltCommonProperties.Selected_apex).Path() |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1079 | a.outputApex = android.PathForModuleOut(ctx, a.installFilename) |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 1080 | |
| 1081 | // Build the output APEX. If compression is not enabled, make sure the output is not compressed even if the input is compressed |
| 1082 | buildRule := android.Cp |
| 1083 | if !ctx.Config().ApexCompressionEnabled() { |
| 1084 | buildRule = decompressApex |
| 1085 | } |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 1086 | ctx.Build(pctx, android.BuildParams{ |
Jooyung Han | 26ec848 | 2024-07-31 15:04:05 +0900 | [diff] [blame] | 1087 | Rule: buildRule, |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 1088 | Input: inputApex, |
| 1089 | Output: a.outputApex, |
| 1090 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 1091 | |
| 1092 | if a.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 1093 | a.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 1094 | return |
| 1095 | } |
| 1096 | |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 1097 | // dexpreopt any system server jars if present |
| 1098 | a.dexpreoptSystemServerJars(ctx) |
| 1099 | |
Spandan Das | da739a3 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 1100 | // provide info used for generating the boot image |
| 1101 | a.provideApexExportsInfo(ctx) |
| 1102 | |
Spandan Das | a747d2e | 2024-03-11 21:37:25 +0000 | [diff] [blame] | 1103 | a.providePrebuiltInfo(ctx) |
| 1104 | |
Paul Duffin | c30aea2 | 2021-06-15 19:10:11 +0100 | [diff] [blame] | 1105 | // Save the files that need to be made available to Make. |
| 1106 | a.initApexFilesForAndroidMk(ctx) |
| 1107 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1108 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 1109 | if a.installable() { |
Colin Cross | 730e3f6 | 2021-12-08 21:09:04 -0800 | [diff] [blame] | 1110 | a.installedFile = ctx.InstallFile(a.installDir, a.installFilename, a.outputApex) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | // in case that apex_set replaces source apex (using prefer: prop) |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 1114 | a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1115 | // or that apex_set overrides other apexes (using overrides: prop) |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 1116 | for _, overridden := range a.prebuiltCommonProperties.Overrides { |
Jooyung Han | 06a8a1c | 2023-08-23 11:11:43 +0900 | [diff] [blame] | 1117 | a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1118 | } |
mrziwang | 1587b9c | 2024-06-13 11:26:04 -0700 | [diff] [blame] | 1119 | |
| 1120 | ctx.SetOutputFiles(android.Paths{a.outputApex}, "") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
Paul Duffin | ef6b695 | 2021-06-15 11:34:01 +0100 | [diff] [blame] | 1123 | type systemExtContext struct { |
| 1124 | android.ModuleContext |
| 1125 | } |
| 1126 | |
| 1127 | func (*systemExtContext) SystemExtSpecific() bool { |
| 1128 | return true |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 1129 | } |