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