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