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