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