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