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" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 19 | "strconv" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 20 | "strings" |
| 21 | |
| 22 | "android/soong/android" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 23 | "android/soong/java" |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 24 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 26 | |
| 27 | "github.com/google/blueprint/proptools" |
| 28 | ) |
| 29 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 30 | var ( |
| 31 | extractMatchingApex = pctx.StaticRule( |
| 32 | "extractMatchingApex", |
| 33 | blueprint.RuleParams{ |
| 34 | Command: `rm -rf "$out" && ` + |
| 35 | `${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` + |
| 36 | `-sdk-version=${sdk-version} -abis=${abis} -screen-densities=all -extract-single ` + |
| 37 | `${in}`, |
| 38 | CommandDeps: []string{"${extract_apks}"}, |
| 39 | }, |
| 40 | "abis", "allow-prereleased", "sdk-version") |
| 41 | ) |
| 42 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 43 | type prebuilt interface { |
| 44 | isForceDisabled() bool |
| 45 | InstallFilename() string |
| 46 | } |
| 47 | |
| 48 | type prebuiltCommon struct { |
| 49 | prebuilt android.Prebuilt |
| 50 | properties prebuiltCommonProperties |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 51 | |
| 52 | deapexerProperties DeapexerProperties |
| 53 | selectedApexProperties SelectedApexProperties |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 54 | } |
| 55 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 56 | type sanitizedPrebuilt interface { |
| 57 | hasSanitizedSource(sanitizer string) bool |
| 58 | } |
| 59 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 60 | type prebuiltCommonProperties struct { |
| 61 | ForceDisable bool `blueprint:"mutated"` |
| 62 | } |
| 63 | |
| 64 | func (p *prebuiltCommon) Prebuilt() *android.Prebuilt { |
| 65 | return &p.prebuilt |
| 66 | } |
| 67 | |
| 68 | func (p *prebuiltCommon) isForceDisabled() bool { |
| 69 | return p.properties.ForceDisable |
| 70 | } |
| 71 | |
| 72 | func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool { |
| 73 | // If the device is configured to use flattened APEX, force disable the prebuilt because |
| 74 | // the prebuilt is a non-flattened one. |
| 75 | forceDisable := ctx.Config().FlattenApex() |
| 76 | |
| 77 | // Force disable the prebuilts when we are doing unbundled build. We do unbundled build |
| 78 | // to build the prebuilts themselves. |
| 79 | forceDisable = forceDisable || ctx.Config().UnbundledBuild() |
| 80 | |
| 81 | // Force disable the prebuilts when coverage is enabled. |
| 82 | forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled() |
| 83 | forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") |
| 84 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 85 | // b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source |
| 86 | sanitized := ctx.Module().(sanitizedPrebuilt) |
| 87 | forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address")) |
| 88 | forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress")) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 89 | |
| 90 | if forceDisable && p.prebuilt.SourceExists() { |
| 91 | p.properties.ForceDisable = true |
| 92 | return true |
| 93 | } |
| 94 | return false |
| 95 | } |
| 96 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 97 | // prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and |
| 98 | // apex_set in order to create the modules needed to provide access to the prebuilt .apex file. |
| 99 | type prebuiltApexModuleCreator interface { |
| 100 | createPrebuiltApexModules(ctx android.TopDownMutatorContext) |
| 101 | } |
| 102 | |
| 103 | // prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the |
| 104 | // prebuiltApexModuleCreator's createPrebuiltApexModules method. |
| 105 | // |
| 106 | // It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it |
| 107 | // will need to access dependencies added by that (exported modules) but must run before the |
| 108 | // DepsMutator so that the deapexer module it creates can add dependencies onto itself from the |
| 109 | // exported modules. |
| 110 | func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) { |
| 111 | module := ctx.Module() |
| 112 | if creator, ok := module.(prebuiltApexModuleCreator); ok { |
| 113 | creator.createPrebuiltApexModules(ctx) |
| 114 | } |
| 115 | } |
| 116 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame^] | 117 | // prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents. |
| 118 | func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) { |
| 119 | module := ctx.Module() |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 120 | // Add dependencies onto the java modules that represent the java libraries that are provided by |
| 121 | // and exported from this prebuilt apex. |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 122 | for _, exported := range p.deapexerProperties.Exported_java_libs { |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame^] | 123 | dep := android.PrebuiltNameFromSource(exported) |
| 124 | ctx.AddDependency(module, exportedJavaLibTag, dep) |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 125 | } |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 126 | |
| 127 | // Add dependencies onto the bootclasspath fragment modules that are exported from this prebuilt |
| 128 | // apex. |
| 129 | for _, exported := range p.deapexerProperties.Exported_bootclasspath_fragments { |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame^] | 130 | dep := android.PrebuiltNameFromSource(exported) |
| 131 | ctx.AddDependency(module, exportedBootclasspathFragmentTag, dep) |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 132 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 135 | // Implements android.DepInInSameApex |
| 136 | func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 137 | tag := ctx.OtherModuleDependencyTag(dep) |
| 138 | _, ok := tag.(exportedDependencyTag) |
| 139 | return ok |
| 140 | } |
| 141 | |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 142 | // apexInfoMutator marks any modules for which this apex exports a file as requiring an apex |
| 143 | // specific variant and checks that they are supported. |
| 144 | // |
| 145 | // The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are |
| 146 | // associated with the apex specific variant using the ApexInfoProvider for later retrieval. |
| 147 | // |
| 148 | // Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants |
| 149 | // across prebuilt_apex modules. That is because there is no way to determine whether two |
| 150 | // prebuilt_apex modules that export files for the same module are compatible. e.g. they could have |
| 151 | // been built from different source at different times or they could have been built with different |
| 152 | // build options that affect the libraries. |
| 153 | // |
| 154 | // While it may be possible to provide sufficient information to determine whether two prebuilt_apex |
| 155 | // modules were compatible it would be a lot of work and would not provide much benefit for a couple |
| 156 | // of reasons: |
| 157 | // * The number of prebuilt_apex modules that will be exporting files for the same module will be |
| 158 | // low as the prebuilt_apex only exports files for the direct dependencies that require it and |
| 159 | // very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a |
| 160 | // few com.android.art* apex files that contain the same contents and could export files for the |
| 161 | // same modules but only one of them needs to do so. Contrast that with source apex modules which |
| 162 | // need apex specific variants for every module that contributes code to the apex, whether direct |
| 163 | // or indirect. |
| 164 | // * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some |
| 165 | // extra copying of files. Contrast that with source apex modules that has to build each variant |
| 166 | // from source. |
| 167 | func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) { |
| 168 | |
| 169 | // Collect direct dependencies into contents. |
| 170 | contents := make(map[string]android.ApexMembership) |
| 171 | |
| 172 | // Collect the list of dependencies. |
| 173 | var dependencies []android.ApexModule |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 174 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 175 | // If the child is not in the same apex as the parent then exit immediately and do not visit |
| 176 | // any of the child's dependencies. |
| 177 | if !android.IsDepInSameApex(mctx, parent, child) { |
| 178 | return false |
| 179 | } |
| 180 | |
| 181 | tag := mctx.OtherModuleDependencyTag(child) |
| 182 | depName := mctx.OtherModuleName(child) |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 183 | if exportedTag, ok := tag.(exportedDependencyTag); ok { |
| 184 | propertyName := exportedTag.name |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 185 | |
| 186 | // It is an error if the other module is not a prebuilt. |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 187 | if !android.IsModulePrebuilt(child) { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 188 | mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName) |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 189 | return false |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | // It is an error if the other module is not an ApexModule. |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 193 | if _, ok := child.(android.ApexModule); !ok { |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 194 | mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName) |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 195 | return false |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 196 | } |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 197 | } |
Paul Duffin | b17d044 | 2021-05-05 12:07:00 +0100 | [diff] [blame] | 198 | |
| 199 | // Strip off the prebuilt_ prefix if present before storing content to ensure consistent |
| 200 | // behavior whether there is a corresponding source module present or not. |
| 201 | depName = android.RemoveOptionalPrebuiltPrefix(depName) |
| 202 | |
| 203 | // Remember if this module was added as a direct dependency. |
| 204 | direct := parent == mctx.Module() |
| 205 | contents[depName] = contents[depName].Add(direct) |
| 206 | |
| 207 | // Add the module to the list of dependencies that need to have an APEX variant. |
| 208 | dependencies = append(dependencies, child.(android.ApexModule)) |
| 209 | |
| 210 | return true |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 211 | }) |
| 212 | |
| 213 | // Create contents for the prebuilt_apex and store it away for later use. |
| 214 | apexContents := android.NewApexContents(contents) |
| 215 | mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{ |
| 216 | Contents: apexContents, |
| 217 | }) |
| 218 | |
| 219 | // Create an ApexInfo for the prebuilt_apex. |
| 220 | apexInfo := android.ApexInfo{ |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 221 | ApexVariationName: android.RemoveOptionalPrebuiltPrefix(mctx.ModuleName()), |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 222 | InApexes: []string{mctx.ModuleName()}, |
| 223 | ApexContents: []*android.ApexContents{apexContents}, |
| 224 | ForPrebuiltApex: true, |
| 225 | } |
| 226 | |
| 227 | // Mark the dependencies of this module as requiring a variant for this module. |
| 228 | for _, am := range dependencies { |
| 229 | am.BuildForApex(apexInfo) |
| 230 | } |
| 231 | } |
| 232 | |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 233 | // prebuiltApexSelectorModule is a private module type that is only created by the prebuilt_apex |
| 234 | // module. It selects the apex to use and makes it available for use by prebuilt_apex and the |
| 235 | // deapexer. |
| 236 | type prebuiltApexSelectorModule struct { |
| 237 | android.ModuleBase |
| 238 | |
| 239 | apexFileProperties ApexFileProperties |
| 240 | |
| 241 | inputApex android.Path |
| 242 | } |
| 243 | |
| 244 | func privateApexSelectorModuleFactory() android.Module { |
| 245 | module := &prebuiltApexSelectorModule{} |
| 246 | module.AddProperties( |
| 247 | &module.apexFileProperties, |
| 248 | ) |
| 249 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 250 | return module |
| 251 | } |
| 252 | |
| 253 | func (p *prebuiltApexSelectorModule) Srcs() android.Paths { |
| 254 | return android.Paths{p.inputApex} |
| 255 | } |
| 256 | |
| 257 | func (p *prebuiltApexSelectorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 258 | p.inputApex = android.SingleSourcePathFromSupplier(ctx, p.apexFileProperties.prebuiltApexSelector, "src") |
| 259 | } |
| 260 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 261 | type Prebuilt struct { |
| 262 | android.ModuleBase |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 263 | prebuiltCommon |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 264 | |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 265 | properties PrebuiltProperties |
| 266 | selectedApexProperties SelectedApexProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 267 | |
| 268 | inputApex android.Path |
| 269 | installDir android.InstallPath |
| 270 | installFilename string |
| 271 | outputApex android.WritablePath |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 272 | |
| 273 | // list of commands to create symlinks for backward compatibility. |
| 274 | // these commands will be attached as LOCAL_POST_INSTALL_CMD |
| 275 | compatSymlinks []string |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 276 | } |
| 277 | |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 278 | type ApexFileProperties struct { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 279 | // the path to the prebuilt .apex file to import. |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 280 | // |
| 281 | // This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated |
| 282 | // for android_common. That is so that it will have the same arch variant as, and so be compatible |
| 283 | // with, the source `apex` module type that it replaces. |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 284 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 285 | Arch struct { |
| 286 | Arm struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 287 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 288 | } |
| 289 | Arm64 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 290 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 291 | } |
| 292 | X86 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 293 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 294 | } |
| 295 | X86_64 struct { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 296 | Src *string `android:"path"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 297 | } |
| 298 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 301 | // prebuiltApexSelector selects the correct prebuilt APEX file for the build target. |
| 302 | // |
| 303 | // The ctx parameter can be for any module not just the prebuilt module so care must be taken not |
| 304 | // to use methods on it that are specific to the current module. |
| 305 | // |
| 306 | // See the ApexFileProperties.Src property. |
| 307 | func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) []string { |
| 308 | multiTargets := prebuilt.MultiTargets() |
| 309 | if len(multiTargets) != 1 { |
| 310 | ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex") |
| 311 | return nil |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 312 | } |
| 313 | var src string |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 314 | switch multiTargets[0].Arch.ArchType { |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 315 | case android.Arm: |
| 316 | src = String(p.Arch.Arm.Src) |
| 317 | case android.Arm64: |
| 318 | src = String(p.Arch.Arm64.Src) |
| 319 | case android.X86: |
| 320 | src = String(p.Arch.X86.Src) |
| 321 | case android.X86_64: |
| 322 | src = String(p.Arch.X86_64.Src) |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 323 | } |
| 324 | if src == "" { |
| 325 | src = String(p.Src) |
| 326 | } |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 327 | |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 328 | if src == "" { |
| 329 | ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String()) |
| 330 | // Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt |
| 331 | // logic from reporting a more general, less useful message. |
| 332 | } |
| 333 | |
Paul Duffin | c04fb9e | 2021-03-01 12:25:10 +0000 | [diff] [blame] | 334 | return []string{src} |
Paul Duffin | 851f399 | 2021-01-13 17:03:51 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | type PrebuiltProperties struct { |
| 338 | ApexFileProperties |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 339 | |
| 340 | Installable *bool |
| 341 | // Optional name for the installed apex. If unspecified, name of the |
| 342 | // module is used as the file name |
| 343 | Filename *string |
| 344 | |
| 345 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 346 | // (in Make or Soong). |
| 347 | // This does not completely prevent installation of the overridden binaries, but if both |
| 348 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 349 | // from PRODUCT_PACKAGES. |
| 350 | Overrides []string |
| 351 | } |
| 352 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 353 | func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool { |
| 354 | return false |
| 355 | } |
| 356 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 357 | func (p *Prebuilt) installable() bool { |
| 358 | return p.properties.Installable == nil || proptools.Bool(p.properties.Installable) |
| 359 | } |
| 360 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 361 | func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) { |
| 362 | switch tag { |
| 363 | case "": |
| 364 | return android.Paths{p.outputApex}, nil |
| 365 | default: |
| 366 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | func (p *Prebuilt) InstallFilename() string { |
| 371 | return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix) |
| 372 | } |
| 373 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 374 | func (p *Prebuilt) Name() string { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 375 | return p.prebuiltCommon.prebuilt.Name(p.ModuleBase.Name()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 379 | func PrebuiltFactory() android.Module { |
| 380 | module := &Prebuilt{} |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 381 | module.AddProperties(&module.properties, &module.deapexerProperties, &module.selectedApexProperties) |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 382 | android.InitSingleSourcePrebuiltModule(module, &module.selectedApexProperties, "Selected_apex") |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 383 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 384 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 385 | return module |
| 386 | } |
| 387 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 388 | func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, apexFileProperties *ApexFileProperties) { |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 389 | props := struct { |
| 390 | Name *string |
| 391 | }{ |
| 392 | Name: proptools.StringPtr(name), |
| 393 | } |
| 394 | |
| 395 | ctx.CreateModule(privateApexSelectorModuleFactory, |
| 396 | &props, |
| 397 | apexFileProperties, |
| 398 | ) |
| 399 | } |
| 400 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 401 | // createDeapexerModuleIfNeeded will create a deapexer module if it is needed. |
| 402 | // |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame^] | 403 | // A deapexer module is only needed when the prebuilt apex specifies one or more modules in either |
| 404 | // the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that |
| 405 | // the listed modules need access to files from within the prebuilt .apex file. |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 406 | func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string, deapexerProperties *DeapexerProperties) { |
| 407 | // Only create the deapexer module if it is needed. |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame^] | 408 | if len(deapexerProperties.Exported_java_libs)+len(deapexerProperties.Exported_bootclasspath_fragments) == 0 { |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 409 | return |
| 410 | } |
| 411 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame^] | 412 | // Compute the deapexer properties from the transitive dependencies of this module. |
| 413 | deapexerProperties = &DeapexerProperties{} |
| 414 | ctx.WalkDeps(func(child, parent android.Module) bool { |
| 415 | tag := ctx.OtherModuleDependencyTag(child) |
| 416 | |
| 417 | name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child)) |
| 418 | if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag { |
| 419 | deapexerProperties.Exported_java_libs = append(deapexerProperties.Exported_java_libs, name) |
| 420 | } else if tag == exportedBootclasspathFragmentTag { |
| 421 | deapexerProperties.Exported_bootclasspath_fragments = append(deapexerProperties.Exported_bootclasspath_fragments, name) |
| 422 | // Only visit the children of the bootclasspath_fragment for now. |
| 423 | return true |
| 424 | } |
| 425 | |
| 426 | return false |
| 427 | }) |
| 428 | |
| 429 | // Remove any duplicates from the deapexer lists. |
| 430 | deapexerProperties.Exported_bootclasspath_fragments = android.FirstUniqueStrings(deapexerProperties.Exported_bootclasspath_fragments) |
| 431 | deapexerProperties.Exported_java_libs = android.FirstUniqueStrings(deapexerProperties.Exported_java_libs) |
| 432 | |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 433 | props := struct { |
| 434 | Name *string |
| 435 | Selected_apex *string |
| 436 | }{ |
| 437 | Name: proptools.StringPtr(deapexerName), |
| 438 | Selected_apex: proptools.StringPtr(apexFileSource), |
| 439 | } |
| 440 | ctx.CreateModule(privateDeapexerFactory, |
| 441 | &props, |
| 442 | deapexerProperties, |
| 443 | ) |
| 444 | } |
| 445 | |
| 446 | func deapexerModuleName(baseModuleName string) string { |
| 447 | return baseModuleName + ".deapexer" |
| 448 | } |
| 449 | |
| 450 | func apexSelectorModuleName(baseModuleName string) string { |
| 451 | return baseModuleName + ".apex.selector" |
| 452 | } |
| 453 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 454 | func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string { |
| 455 | // The prebuilt_apex should be depending on prebuilt modules but as this runs after |
| 456 | // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So, |
| 457 | // check to see if the prefixed name is in use first, if it is then use that, otherwise assume |
| 458 | // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module |
| 459 | // and not a renamed prebuilt module then that will be detected and reported as an error when |
| 460 | // processing the dependency in ApexInfoMutator(). |
Paul Duffin | 864116c | 2021-04-02 10:24:13 +0100 | [diff] [blame] | 461 | prebuiltName := android.PrebuiltNameFromSource(name) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 462 | if ctx.OtherModuleExists(prebuiltName) { |
| 463 | name = prebuiltName |
| 464 | } |
| 465 | return name |
| 466 | } |
| 467 | |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 468 | type exportedDependencyTag struct { |
| 469 | blueprint.BaseDependencyTag |
| 470 | name string |
| 471 | } |
| 472 | |
| 473 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. |
| 474 | // |
| 475 | // This does allow any prebuilt_apex to reference any module which does open up a small window for |
| 476 | // restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so |
| 477 | // avoids opening up a much bigger window by widening the visibility of modules that need files |
| 478 | // provided by the prebuilt_apex to include all the possible locations they may be defined, which |
| 479 | // could include everything below vendor/. |
| 480 | // |
| 481 | // A prebuilt_apex that references a module via this tag will have to contain the appropriate files |
| 482 | // corresponding to that module, otherwise it will fail when attempting to retrieve the files from |
| 483 | // the .apex file. It will also have to be included in the module's apex_available property too. |
| 484 | // That makes it highly unlikely that a prebuilt_apex would reference a restricted module |
| 485 | // incorrectly. |
| 486 | func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {} |
| 487 | |
| 488 | var ( |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 489 | exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"} |
| 490 | exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"} |
Paul Duffin | a713942 | 2021-02-08 11:01:58 +0000 | [diff] [blame] | 491 | ) |
| 492 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 493 | var _ prebuiltApexModuleCreator = (*Prebuilt)(nil) |
| 494 | |
| 495 | // createPrebuiltApexModules creates modules necessary to export files from the prebuilt apex to the |
| 496 | // build. |
| 497 | // |
| 498 | // If this needs to make files from within a `.apex` file available for use by other Soong modules, |
| 499 | // e.g. make dex implementation jars available for java_import modules listed in exported_java_libs, |
| 500 | // it does so as follows: |
| 501 | // |
| 502 | // 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and |
| 503 | // makes them available for use by other modules, at both Soong and ninja levels. |
| 504 | // |
| 505 | // 2. It adds a dependency onto those modules and creates an apex specific variant similar to what |
| 506 | // an `apex` module does. That ensures that code which looks for specific apex variant, e.g. |
| 507 | // dexpreopt, will work the same way from source and prebuilt. |
| 508 | // |
| 509 | // 3. The `deapexer` module adds a dependency from the modules that require the exported files onto |
| 510 | // itself so that they can retrieve the file paths to those files. |
| 511 | // |
| 512 | // It also creates a child module `selector` that is responsible for selecting the appropriate |
| 513 | // input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons: |
| 514 | // 1. To dedup the selection logic so it only runs in one module. |
| 515 | // 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an |
| 516 | // `apex_set`. |
| 517 | // |
| 518 | // prebuilt_apex |
| 519 | // / | \ |
| 520 | // / | \ |
| 521 | // V V V |
| 522 | // selector <--- deapexer <--- exported java lib |
| 523 | // |
| 524 | func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) { |
| 525 | baseModuleName := p.BaseModuleName() |
| 526 | |
| 527 | apexSelectorModuleName := apexSelectorModuleName(baseModuleName) |
| 528 | createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties) |
| 529 | |
| 530 | apexFileSource := ":" + apexSelectorModuleName |
| 531 | createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, &p.deapexerProperties) |
| 532 | |
| 533 | // Add a source reference to retrieve the selected apex from the selector module. |
| 534 | p.selectedApexProperties.Selected_apex = proptools.StringPtr(apexFileSource) |
| 535 | } |
| 536 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame^] | 537 | func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 538 | p.prebuiltApexContentsDeps(ctx) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | var _ ApexInfoMutator = (*Prebuilt)(nil) |
| 542 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 543 | func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) { |
Paul Duffin | dfd3326 | 2021-04-06 17:02:08 +0100 | [diff] [blame] | 544 | p.apexInfoMutator(mctx) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 548 | // TODO(jungjw): Check the key validity. |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 549 | p.inputApex = android.OptionalPathForModuleSrc(ctx, p.selectedApexProperties.Selected_apex).Path() |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 550 | p.installDir = android.PathForModuleInstall(ctx, "apex") |
| 551 | p.installFilename = p.InstallFilename() |
| 552 | if !strings.HasSuffix(p.installFilename, imageApexSuffix) { |
| 553 | ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix) |
| 554 | } |
| 555 | p.outputApex = android.PathForModuleOut(ctx, p.installFilename) |
| 556 | ctx.Build(pctx, android.BuildParams{ |
| 557 | Rule: android.Cp, |
| 558 | Input: p.inputApex, |
| 559 | Output: p.outputApex, |
| 560 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 561 | |
| 562 | if p.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 563 | p.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 564 | return |
| 565 | } |
| 566 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 567 | if p.installable() { |
| 568 | ctx.InstallFile(p.installDir, p.installFilename, p.inputApex) |
| 569 | } |
| 570 | |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 571 | // in case that prebuilt_apex replaces source apex (using prefer: prop) |
| 572 | p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx) |
| 573 | // or that prebuilt_apex overrides other apexes (using overrides: prop) |
| 574 | for _, overridden := range p.properties.Overrides { |
| 575 | p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
| 576 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 577 | } |
| 578 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 579 | func (p *Prebuilt) AndroidMkEntries() []android.AndroidMkEntries { |
| 580 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 581 | Class: "ETC", |
| 582 | OutputFile: android.OptionalPathForPath(p.inputApex), |
| 583 | Include: "$(BUILD_PREBUILT)", |
| 584 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 585 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 586 | entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String()) |
| 587 | entries.SetString("LOCAL_MODULE_STEM", p.installFilename) |
| 588 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 589 | entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.properties.Overrides...) |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 590 | if len(p.compatSymlinks) > 0 { |
| 591 | entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(p.compatSymlinks, " && ")) |
| 592 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 593 | }, |
| 594 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 595 | }} |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 596 | } |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 597 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 598 | // prebuiltApexExtractorModule is a private module type that is only created by the prebuilt_apex |
| 599 | // module. It extracts the correct apex to use and makes it available for use by apex_set. |
| 600 | type prebuiltApexExtractorModule struct { |
| 601 | android.ModuleBase |
| 602 | |
| 603 | properties ApexExtractorProperties |
| 604 | |
| 605 | extractedApex android.WritablePath |
| 606 | } |
| 607 | |
| 608 | func privateApexExtractorModuleFactory() android.Module { |
| 609 | module := &prebuiltApexExtractorModule{} |
| 610 | module.AddProperties( |
| 611 | &module.properties, |
| 612 | ) |
| 613 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 614 | return module |
| 615 | } |
| 616 | |
| 617 | func (p *prebuiltApexExtractorModule) Srcs() android.Paths { |
| 618 | return android.Paths{p.extractedApex} |
| 619 | } |
| 620 | |
| 621 | func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 622 | srcsSupplier := func(ctx android.BaseModuleContext, prebuilt android.Module) []string { |
| 623 | return p.properties.prebuiltSrcs(ctx) |
| 624 | } |
| 625 | apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set") |
| 626 | p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base()) |
| 627 | ctx.Build(pctx, |
| 628 | android.BuildParams{ |
| 629 | Rule: extractMatchingApex, |
| 630 | Description: "Extract an apex from an apex set", |
| 631 | Inputs: android.Paths{apexSet}, |
| 632 | Output: p.extractedApex, |
| 633 | Args: map[string]string{ |
| 634 | "abis": strings.Join(java.SupportedAbis(ctx), ","), |
| 635 | "allow-prereleased": strconv.FormatBool(proptools.Bool(p.properties.Prerelease)), |
| 636 | "sdk-version": ctx.Config().PlatformSdkVersion().String(), |
| 637 | }, |
| 638 | }) |
| 639 | } |
| 640 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 641 | type ApexSet struct { |
| 642 | android.ModuleBase |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 643 | prebuiltCommon |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 644 | |
| 645 | properties ApexSetProperties |
| 646 | |
| 647 | installDir android.InstallPath |
| 648 | installFilename string |
| 649 | outputApex android.WritablePath |
| 650 | |
| 651 | // list of commands to create symlinks for backward compatibility. |
| 652 | // these commands will be attached as LOCAL_POST_INSTALL_CMD |
| 653 | compatSymlinks []string |
Jooyung Han | 2963716 | 2020-06-30 06:34:23 +0900 | [diff] [blame] | 654 | |
| 655 | hostRequired []string |
| 656 | postInstallCommands []string |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 659 | type ApexExtractorProperties struct { |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 660 | // the .apks file path that contains prebuilt apex files to be extracted. |
| 661 | Set *string |
| 662 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 663 | Sanitized struct { |
| 664 | None struct { |
| 665 | Set *string |
| 666 | } |
| 667 | Address struct { |
| 668 | Set *string |
| 669 | } |
| 670 | Hwaddress struct { |
| 671 | Set *string |
| 672 | } |
| 673 | } |
| 674 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 675 | // apexes in this set use prerelease SDK version |
| 676 | Prerelease *bool |
| 677 | } |
| 678 | |
| 679 | func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string { |
| 680 | var srcs []string |
| 681 | if e.Set != nil { |
| 682 | srcs = append(srcs, *e.Set) |
| 683 | } |
| 684 | |
| 685 | var sanitizers []string |
| 686 | if ctx.Host() { |
| 687 | sanitizers = ctx.Config().SanitizeHost() |
| 688 | } else { |
| 689 | sanitizers = ctx.Config().SanitizeDevice() |
| 690 | } |
| 691 | |
| 692 | if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil { |
| 693 | srcs = append(srcs, *e.Sanitized.Address.Set) |
| 694 | } else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil { |
| 695 | srcs = append(srcs, *e.Sanitized.Hwaddress.Set) |
| 696 | } else if e.Sanitized.None.Set != nil { |
| 697 | srcs = append(srcs, *e.Sanitized.None.Set) |
| 698 | } |
| 699 | |
| 700 | return srcs |
| 701 | } |
| 702 | |
| 703 | type ApexSetProperties struct { |
| 704 | ApexExtractorProperties |
| 705 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 706 | // whether the extracted apex file installable. |
| 707 | Installable *bool |
| 708 | |
| 709 | // optional name for the installed apex. If unspecified, name of the |
| 710 | // module is used as the file name |
| 711 | Filename *string |
| 712 | |
| 713 | // names of modules to be overridden. Listed modules can only be other binaries |
| 714 | // (in Make or Soong). |
| 715 | // This does not completely prevent installation of the overridden binaries, but if both |
| 716 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 717 | // from PRODUCT_PACKAGES. |
| 718 | Overrides []string |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | func (a *ApexSet) hasSanitizedSource(sanitizer string) bool { |
| 722 | if sanitizer == "address" { |
| 723 | return a.properties.Sanitized.Address.Set != nil |
| 724 | } |
| 725 | if sanitizer == "hwaddress" { |
| 726 | return a.properties.Sanitized.Hwaddress.Set != nil |
| 727 | } |
| 728 | |
| 729 | return false |
| 730 | } |
| 731 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 732 | func (a *ApexSet) installable() bool { |
| 733 | return a.properties.Installable == nil || proptools.Bool(a.properties.Installable) |
| 734 | } |
| 735 | |
| 736 | func (a *ApexSet) InstallFilename() string { |
| 737 | return proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+imageApexSuffix) |
| 738 | } |
| 739 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 740 | func (a *ApexSet) Name() string { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 741 | return a.prebuiltCommon.prebuilt.Name(a.ModuleBase.Name()) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 744 | func (a *ApexSet) Overrides() []string { |
| 745 | return a.properties.Overrides |
| 746 | } |
| 747 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 748 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 749 | func apexSetFactory() android.Module { |
| 750 | module := &ApexSet{} |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 751 | module.AddProperties(&module.properties, &module.selectedApexProperties, &module.deapexerProperties) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 752 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 753 | android.InitSingleSourcePrebuiltModule(module, &module.selectedApexProperties, "Selected_apex") |
| 754 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 755 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 756 | return module |
| 757 | } |
| 758 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 759 | func createApexExtractorModule(ctx android.TopDownMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) { |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 760 | props := struct { |
| 761 | Name *string |
| 762 | }{ |
| 763 | Name: proptools.StringPtr(name), |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 766 | ctx.CreateModule(privateApexExtractorModuleFactory, |
| 767 | &props, |
| 768 | apexExtractorProperties, |
| 769 | ) |
| 770 | } |
| 771 | |
| 772 | func apexExtractorModuleName(baseModuleName string) string { |
| 773 | return baseModuleName + ".apex.extractor" |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Paul Duffin | 5dda3e3 | 2021-05-05 14:13:27 +0100 | [diff] [blame] | 776 | var _ prebuiltApexModuleCreator = (*ApexSet)(nil) |
| 777 | |
| 778 | // createPrebuiltApexModules creates modules necessary to export files from the apex set to other |
| 779 | // modules. |
| 780 | // |
| 781 | // This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a |
| 782 | // prebuilt_apex except that instead of creating a selector module which selects one .apex file |
| 783 | // from those provided this creates an extractor module which extracts the appropriate .apex file |
| 784 | // from the zip file containing them. |
| 785 | func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) { |
| 786 | baseModuleName := a.BaseModuleName() |
| 787 | |
| 788 | apexExtractorModuleName := apexExtractorModuleName(baseModuleName) |
| 789 | createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties) |
| 790 | |
| 791 | apexFileSource := ":" + apexExtractorModuleName |
| 792 | createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, &a.deapexerProperties) |
| 793 | |
| 794 | // After passing the arch specific src properties to the creating the apex selector module |
| 795 | a.selectedApexProperties.Selected_apex = proptools.StringPtr(apexFileSource) |
| 796 | } |
| 797 | |
Paul Duffin | 57f8359 | 2021-05-05 15:09:44 +0100 | [diff] [blame^] | 798 | func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
| 799 | a.prebuiltApexContentsDeps(ctx) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | var _ ApexInfoMutator = (*ApexSet)(nil) |
| 803 | |
| 804 | func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) { |
| 805 | a.apexInfoMutator(mctx) |
| 806 | } |
| 807 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 808 | func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 809 | a.installFilename = a.InstallFilename() |
| 810 | if !strings.HasSuffix(a.installFilename, imageApexSuffix) { |
| 811 | ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix) |
| 812 | } |
| 813 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 814 | inputApex := android.OptionalPathForModuleSrc(ctx, a.selectedApexProperties.Selected_apex).Path() |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 815 | a.outputApex = android.PathForModuleOut(ctx, a.installFilename) |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 816 | ctx.Build(pctx, android.BuildParams{ |
| 817 | Rule: android.Cp, |
| 818 | Input: inputApex, |
| 819 | Output: a.outputApex, |
| 820 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 821 | |
| 822 | if a.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 823 | a.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 824 | return |
| 825 | } |
| 826 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 827 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 828 | if a.installable() { |
| 829 | ctx.InstallFile(a.installDir, a.installFilename, a.outputApex) |
| 830 | } |
| 831 | |
| 832 | // in case that apex_set replaces source apex (using prefer: prop) |
| 833 | a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx) |
| 834 | // or that apex_set overrides other apexes (using overrides: prop) |
| 835 | for _, overridden := range a.properties.Overrides { |
| 836 | a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
| 837 | } |
Jooyung Han | 2963716 | 2020-06-30 06:34:23 +0900 | [diff] [blame] | 838 | |
| 839 | if ctx.Config().InstallExtraFlattenedApexes() { |
| 840 | // flattened apex should be in /system_ext/apex |
| 841 | flattenedApexDir := android.PathForModuleInstall(&systemExtContext{ctx}, "apex", a.BaseModuleName()) |
| 842 | a.postInstallCommands = append(a.postInstallCommands, |
| 843 | fmt.Sprintf("$(HOST_OUT_EXECUTABLES)/deapexer --debugfs_path $(HOST_OUT_EXECUTABLES)/debugfs extract %s %s", |
| 844 | a.outputApex.String(), |
| 845 | flattenedApexDir.ToMakePath().String(), |
| 846 | )) |
| 847 | a.hostRequired = []string{"deapexer", "debugfs"} |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | type systemExtContext struct { |
| 852 | android.ModuleContext |
| 853 | } |
| 854 | |
| 855 | func (*systemExtContext) SystemExtSpecific() bool { |
| 856 | return true |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | func (a *ApexSet) AndroidMkEntries() []android.AndroidMkEntries { |
| 860 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jooyung Han | 2963716 | 2020-06-30 06:34:23 +0900 | [diff] [blame] | 861 | Class: "ETC", |
| 862 | OutputFile: android.OptionalPathForPath(a.outputApex), |
| 863 | Include: "$(BUILD_PREBUILT)", |
| 864 | Host_required: a.hostRequired, |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 865 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 866 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 867 | entries.SetString("LOCAL_MODULE_PATH", a.installDir.ToMakePath().String()) |
| 868 | entries.SetString("LOCAL_MODULE_STEM", a.installFilename) |
| 869 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !a.installable()) |
| 870 | entries.AddStrings("LOCAL_OVERRIDES_MODULES", a.properties.Overrides...) |
Jooyung Han | 2963716 | 2020-06-30 06:34:23 +0900 | [diff] [blame] | 871 | postInstallCommands := append([]string{}, a.postInstallCommands...) |
| 872 | postInstallCommands = append(postInstallCommands, a.compatSymlinks...) |
| 873 | if len(postInstallCommands) > 0 { |
| 874 | entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && ")) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 875 | } |
| 876 | }, |
| 877 | }, |
| 878 | }} |
| 879 | } |