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