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