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 |
| 51 | } |
| 52 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 53 | type sanitizedPrebuilt interface { |
| 54 | hasSanitizedSource(sanitizer string) bool |
| 55 | } |
| 56 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 57 | type prebuiltCommonProperties struct { |
| 58 | ForceDisable bool `blueprint:"mutated"` |
| 59 | } |
| 60 | |
| 61 | func (p *prebuiltCommon) Prebuilt() *android.Prebuilt { |
| 62 | return &p.prebuilt |
| 63 | } |
| 64 | |
| 65 | func (p *prebuiltCommon) isForceDisabled() bool { |
| 66 | return p.properties.ForceDisable |
| 67 | } |
| 68 | |
| 69 | func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool { |
| 70 | // If the device is configured to use flattened APEX, force disable the prebuilt because |
| 71 | // the prebuilt is a non-flattened one. |
| 72 | forceDisable := ctx.Config().FlattenApex() |
| 73 | |
| 74 | // Force disable the prebuilts when we are doing unbundled build. We do unbundled build |
| 75 | // to build the prebuilts themselves. |
| 76 | forceDisable = forceDisable || ctx.Config().UnbundledBuild() |
| 77 | |
| 78 | // Force disable the prebuilts when coverage is enabled. |
| 79 | forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled() |
| 80 | forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") |
| 81 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 82 | // b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source |
| 83 | sanitized := ctx.Module().(sanitizedPrebuilt) |
| 84 | forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address")) |
| 85 | forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress")) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 86 | |
| 87 | if forceDisable && p.prebuilt.SourceExists() { |
| 88 | p.properties.ForceDisable = true |
| 89 | return true |
| 90 | } |
| 91 | return false |
| 92 | } |
| 93 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 94 | type Prebuilt struct { |
| 95 | android.ModuleBase |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 96 | prebuiltCommon |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 97 | |
| 98 | properties PrebuiltProperties |
| 99 | |
| 100 | inputApex android.Path |
| 101 | installDir android.InstallPath |
| 102 | installFilename string |
| 103 | outputApex android.WritablePath |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 104 | |
| 105 | // list of commands to create symlinks for backward compatibility. |
| 106 | // these commands will be attached as LOCAL_POST_INSTALL_CMD |
| 107 | compatSymlinks []string |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | type PrebuiltProperties struct { |
| 111 | // the path to the prebuilt .apex file to import. |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 112 | Source string `blueprint:"mutated"` |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 113 | |
| 114 | Src *string |
| 115 | Arch struct { |
| 116 | Arm struct { |
| 117 | Src *string |
| 118 | } |
| 119 | Arm64 struct { |
| 120 | Src *string |
| 121 | } |
| 122 | X86 struct { |
| 123 | Src *string |
| 124 | } |
| 125 | X86_64 struct { |
| 126 | Src *string |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | Installable *bool |
| 131 | // Optional name for the installed apex. If unspecified, name of the |
| 132 | // module is used as the file name |
| 133 | Filename *string |
| 134 | |
| 135 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 136 | // (in Make or Soong). |
| 137 | // This does not completely prevent installation of the overridden binaries, but if both |
| 138 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 139 | // from PRODUCT_PACKAGES. |
| 140 | Overrides []string |
| 141 | } |
| 142 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 143 | func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool { |
| 144 | return false |
| 145 | } |
| 146 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 147 | func (p *Prebuilt) installable() bool { |
| 148 | return p.properties.Installable == nil || proptools.Bool(p.properties.Installable) |
| 149 | } |
| 150 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 151 | func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) { |
| 152 | switch tag { |
| 153 | case "": |
| 154 | return android.Paths{p.outputApex}, nil |
| 155 | default: |
| 156 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | func (p *Prebuilt) InstallFilename() string { |
| 161 | return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix) |
| 162 | } |
| 163 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 164 | func (p *Prebuilt) Name() string { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 165 | return p.prebuiltCommon.prebuilt.Name(p.ModuleBase.Name()) |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 169 | func PrebuiltFactory() android.Module { |
| 170 | module := &Prebuilt{} |
| 171 | module.AddProperties(&module.properties) |
| 172 | android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source") |
| 173 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 174 | return module |
| 175 | } |
| 176 | |
| 177 | func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 178 | // This is called before prebuilt_select and prebuilt_postdeps mutators |
| 179 | // The mutators requires that src to be set correctly for each arch so that |
| 180 | // arch variants are disabled when src is not provided for the arch. |
| 181 | if len(ctx.MultiTargets()) != 1 { |
| 182 | ctx.ModuleErrorf("compile_multilib shouldn't be \"both\" for prebuilt_apex") |
| 183 | return |
| 184 | } |
| 185 | var src string |
| 186 | switch ctx.MultiTargets()[0].Arch.ArchType { |
| 187 | case android.Arm: |
| 188 | src = String(p.properties.Arch.Arm.Src) |
| 189 | case android.Arm64: |
| 190 | src = String(p.properties.Arch.Arm64.Src) |
| 191 | case android.X86: |
| 192 | src = String(p.properties.Arch.X86.Src) |
| 193 | case android.X86_64: |
| 194 | src = String(p.properties.Arch.X86_64.Src) |
| 195 | default: |
| 196 | ctx.ModuleErrorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String()) |
| 197 | return |
| 198 | } |
| 199 | if src == "" { |
| 200 | src = String(p.properties.Src) |
| 201 | } |
| 202 | p.properties.Source = src |
| 203 | } |
| 204 | |
| 205 | func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 206 | // TODO(jungjw): Check the key validity. |
| 207 | p.inputApex = p.Prebuilt().SingleSourcePath(ctx) |
| 208 | p.installDir = android.PathForModuleInstall(ctx, "apex") |
| 209 | p.installFilename = p.InstallFilename() |
| 210 | if !strings.HasSuffix(p.installFilename, imageApexSuffix) { |
| 211 | ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix) |
| 212 | } |
| 213 | p.outputApex = android.PathForModuleOut(ctx, p.installFilename) |
| 214 | ctx.Build(pctx, android.BuildParams{ |
| 215 | Rule: android.Cp, |
| 216 | Input: p.inputApex, |
| 217 | Output: p.outputApex, |
| 218 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 219 | |
| 220 | if p.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame^] | 221 | p.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 222 | return |
| 223 | } |
| 224 | |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 225 | if p.installable() { |
| 226 | ctx.InstallFile(p.installDir, p.installFilename, p.inputApex) |
| 227 | } |
| 228 | |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 229 | // in case that prebuilt_apex replaces source apex (using prefer: prop) |
| 230 | p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx) |
| 231 | // or that prebuilt_apex overrides other apexes (using overrides: prop) |
| 232 | for _, overridden := range p.properties.Overrides { |
| 233 | p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
| 234 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 235 | } |
| 236 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 237 | func (p *Prebuilt) AndroidMkEntries() []android.AndroidMkEntries { |
| 238 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 239 | Class: "ETC", |
| 240 | OutputFile: android.OptionalPathForPath(p.inputApex), |
| 241 | Include: "$(BUILD_PREBUILT)", |
| 242 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 243 | func(entries *android.AndroidMkEntries) { |
| 244 | entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String()) |
| 245 | entries.SetString("LOCAL_MODULE_STEM", p.installFilename) |
| 246 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) |
| 247 | entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.properties.Overrides...) |
Jooyung Han | 002ab68 | 2020-01-08 01:57:58 +0900 | [diff] [blame] | 248 | if len(p.compatSymlinks) > 0 { |
| 249 | entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(p.compatSymlinks, " && ")) |
| 250 | } |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 251 | }, |
| 252 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 253 | }} |
Jiyong Park | 09d7752 | 2019-11-18 11:16:27 +0900 | [diff] [blame] | 254 | } |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 255 | |
| 256 | type ApexSet struct { |
| 257 | android.ModuleBase |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 258 | prebuiltCommon |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 259 | |
| 260 | properties ApexSetProperties |
| 261 | |
| 262 | installDir android.InstallPath |
| 263 | installFilename string |
| 264 | outputApex android.WritablePath |
| 265 | |
| 266 | // list of commands to create symlinks for backward compatibility. |
| 267 | // these commands will be attached as LOCAL_POST_INSTALL_CMD |
| 268 | compatSymlinks []string |
Jooyung Han | 2963716 | 2020-06-30 06:34:23 +0900 | [diff] [blame] | 269 | |
| 270 | hostRequired []string |
| 271 | postInstallCommands []string |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | type ApexSetProperties struct { |
| 275 | // the .apks file path that contains prebuilt apex files to be extracted. |
| 276 | Set *string |
| 277 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 278 | Sanitized struct { |
| 279 | None struct { |
| 280 | Set *string |
| 281 | } |
| 282 | Address struct { |
| 283 | Set *string |
| 284 | } |
| 285 | Hwaddress struct { |
| 286 | Set *string |
| 287 | } |
| 288 | } |
| 289 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 290 | // whether the extracted apex file installable. |
| 291 | Installable *bool |
| 292 | |
| 293 | // optional name for the installed apex. If unspecified, name of the |
| 294 | // module is used as the file name |
| 295 | Filename *string |
| 296 | |
| 297 | // names of modules to be overridden. Listed modules can only be other binaries |
| 298 | // (in Make or Soong). |
| 299 | // This does not completely prevent installation of the overridden binaries, but if both |
| 300 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 301 | // from PRODUCT_PACKAGES. |
| 302 | Overrides []string |
| 303 | |
| 304 | // apexes in this set use prerelease SDK version |
| 305 | Prerelease *bool |
| 306 | } |
| 307 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 308 | func (a *ApexSet) prebuiltSrcs(ctx android.BaseModuleContext) []string { |
| 309 | var srcs []string |
| 310 | if a.properties.Set != nil { |
| 311 | srcs = append(srcs, *a.properties.Set) |
| 312 | } |
| 313 | |
| 314 | var sanitizers []string |
| 315 | if ctx.Host() { |
| 316 | sanitizers = ctx.Config().SanitizeHost() |
| 317 | } else { |
| 318 | sanitizers = ctx.Config().SanitizeDevice() |
| 319 | } |
| 320 | |
| 321 | if android.InList("address", sanitizers) && a.properties.Sanitized.Address.Set != nil { |
| 322 | srcs = append(srcs, *a.properties.Sanitized.Address.Set) |
| 323 | } else if android.InList("hwaddress", sanitizers) && a.properties.Sanitized.Hwaddress.Set != nil { |
| 324 | srcs = append(srcs, *a.properties.Sanitized.Hwaddress.Set) |
| 325 | } else if a.properties.Sanitized.None.Set != nil { |
| 326 | srcs = append(srcs, *a.properties.Sanitized.None.Set) |
| 327 | } |
| 328 | |
| 329 | return srcs |
| 330 | } |
| 331 | |
| 332 | func (a *ApexSet) hasSanitizedSource(sanitizer string) bool { |
| 333 | if sanitizer == "address" { |
| 334 | return a.properties.Sanitized.Address.Set != nil |
| 335 | } |
| 336 | if sanitizer == "hwaddress" { |
| 337 | return a.properties.Sanitized.Hwaddress.Set != nil |
| 338 | } |
| 339 | |
| 340 | return false |
| 341 | } |
| 342 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 343 | func (a *ApexSet) installable() bool { |
| 344 | return a.properties.Installable == nil || proptools.Bool(a.properties.Installable) |
| 345 | } |
| 346 | |
| 347 | func (a *ApexSet) InstallFilename() string { |
| 348 | return proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+imageApexSuffix) |
| 349 | } |
| 350 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 351 | func (a *ApexSet) Name() string { |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 352 | return a.prebuiltCommon.prebuilt.Name(a.ModuleBase.Name()) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 355 | func (a *ApexSet) Overrides() []string { |
| 356 | return a.properties.Overrides |
| 357 | } |
| 358 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 359 | // prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex. |
| 360 | func apexSetFactory() android.Module { |
| 361 | module := &ApexSet{} |
| 362 | module.AddProperties(&module.properties) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 363 | |
| 364 | srcsSupplier := func(ctx android.BaseModuleContext) []string { |
| 365 | return module.prebuiltSrcs(ctx) |
| 366 | } |
| 367 | |
| 368 | android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "set") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 369 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 370 | return module |
| 371 | } |
| 372 | |
| 373 | func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 374 | a.installFilename = a.InstallFilename() |
| 375 | if !strings.HasSuffix(a.installFilename, imageApexSuffix) { |
| 376 | ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix) |
| 377 | } |
| 378 | |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 379 | apexSet := a.prebuiltCommon.prebuilt.SingleSourcePath(ctx) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 380 | a.outputApex = android.PathForModuleOut(ctx, a.installFilename) |
| 381 | ctx.Build(pctx, |
| 382 | android.BuildParams{ |
| 383 | Rule: extractMatchingApex, |
| 384 | Description: "Extract an apex from an apex set", |
| 385 | Inputs: android.Paths{apexSet}, |
| 386 | Output: a.outputApex, |
| 387 | Args: map[string]string{ |
| 388 | "abis": strings.Join(java.SupportedAbis(ctx), ","), |
| 389 | "allow-prereleased": strconv.FormatBool(proptools.Bool(a.properties.Prerelease)), |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 390 | "sdk-version": ctx.Config().PlatformSdkVersion().String(), |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 391 | }, |
| 392 | }) |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 393 | |
| 394 | if a.prebuiltCommon.checkForceDisable(ctx) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame^] | 395 | a.HideFromMake() |
Jiyong Park | 10e926b | 2020-07-16 21:38:56 +0900 | [diff] [blame] | 396 | return |
| 397 | } |
| 398 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 399 | a.installDir = android.PathForModuleInstall(ctx, "apex") |
| 400 | if a.installable() { |
| 401 | ctx.InstallFile(a.installDir, a.installFilename, a.outputApex) |
| 402 | } |
| 403 | |
| 404 | // in case that apex_set replaces source apex (using prefer: prop) |
| 405 | a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx) |
| 406 | // or that apex_set overrides other apexes (using overrides: prop) |
| 407 | for _, overridden := range a.properties.Overrides { |
| 408 | a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...) |
| 409 | } |
Jooyung Han | 2963716 | 2020-06-30 06:34:23 +0900 | [diff] [blame] | 410 | |
| 411 | if ctx.Config().InstallExtraFlattenedApexes() { |
| 412 | // flattened apex should be in /system_ext/apex |
| 413 | flattenedApexDir := android.PathForModuleInstall(&systemExtContext{ctx}, "apex", a.BaseModuleName()) |
| 414 | a.postInstallCommands = append(a.postInstallCommands, |
| 415 | fmt.Sprintf("$(HOST_OUT_EXECUTABLES)/deapexer --debugfs_path $(HOST_OUT_EXECUTABLES)/debugfs extract %s %s", |
| 416 | a.outputApex.String(), |
| 417 | flattenedApexDir.ToMakePath().String(), |
| 418 | )) |
| 419 | a.hostRequired = []string{"deapexer", "debugfs"} |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | type systemExtContext struct { |
| 424 | android.ModuleContext |
| 425 | } |
| 426 | |
| 427 | func (*systemExtContext) SystemExtSpecific() bool { |
| 428 | return true |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | func (a *ApexSet) AndroidMkEntries() []android.AndroidMkEntries { |
| 432 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jooyung Han | 2963716 | 2020-06-30 06:34:23 +0900 | [diff] [blame] | 433 | Class: "ETC", |
| 434 | OutputFile: android.OptionalPathForPath(a.outputApex), |
| 435 | Include: "$(BUILD_PREBUILT)", |
| 436 | Host_required: a.hostRequired, |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 437 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 438 | func(entries *android.AndroidMkEntries) { |
| 439 | entries.SetString("LOCAL_MODULE_PATH", a.installDir.ToMakePath().String()) |
| 440 | entries.SetString("LOCAL_MODULE_STEM", a.installFilename) |
| 441 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !a.installable()) |
| 442 | entries.AddStrings("LOCAL_OVERRIDES_MODULES", a.properties.Overrides...) |
Jooyung Han | 2963716 | 2020-06-30 06:34:23 +0900 | [diff] [blame] | 443 | postInstallCommands := append([]string{}, a.postInstallCommands...) |
| 444 | postInstallCommands = append(postInstallCommands, a.compatSymlinks...) |
| 445 | if len(postInstallCommands) > 0 { |
| 446 | entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && ")) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 447 | } |
| 448 | }, |
| 449 | }, |
| 450 | }} |
| 451 | } |