blob: 3149952050b614ba511476ccada8004fbecabfce [file] [log] [blame]
Jiyong Park09d77522019-11-18 11:16:27 +09001// 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
15package apex
16
17import (
18 "fmt"
Jaewoong Jungfa00c062020-05-14 14:15:24 -070019 "strconv"
Jiyong Park09d77522019-11-18 11:16:27 +090020 "strings"
21
22 "android/soong/android"
Jaewoong Jungfa00c062020-05-14 14:15:24 -070023 "android/soong/java"
Jiyong Park10e926b2020-07-16 21:38:56 +090024
Jaewoong Jungfa00c062020-05-14 14:15:24 -070025 "github.com/google/blueprint"
Jiyong Park09d77522019-11-18 11:16:27 +090026
27 "github.com/google/blueprint/proptools"
28)
29
Jaewoong Jungfa00c062020-05-14 14:15:24 -070030var (
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 Park10e926b2020-07-16 21:38:56 +090043type prebuilt interface {
44 isForceDisabled() bool
45 InstallFilename() string
46}
47
48type prebuiltCommon struct {
49 prebuilt android.Prebuilt
50 properties prebuiltCommonProperties
51}
52
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -070053type sanitizedPrebuilt interface {
54 hasSanitizedSource(sanitizer string) bool
55}
56
Jiyong Park10e926b2020-07-16 21:38:56 +090057type prebuiltCommonProperties struct {
58 ForceDisable bool `blueprint:"mutated"`
59}
60
61func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
62 return &p.prebuilt
63}
64
65func (p *prebuiltCommon) isForceDisabled() bool {
66 return p.properties.ForceDisable
67}
68
69func (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 Stepanov2080bfe2020-07-24 15:35:40 -070082 // 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 Park10e926b2020-07-16 21:38:56 +090086
87 if forceDisable && p.prebuilt.SourceExists() {
88 p.properties.ForceDisable = true
89 return true
90 }
91 return false
92}
93
Jiyong Park09d77522019-11-18 11:16:27 +090094type Prebuilt struct {
95 android.ModuleBase
Jiyong Park10e926b2020-07-16 21:38:56 +090096 prebuiltCommon
Jiyong Park09d77522019-11-18 11:16:27 +090097
98 properties PrebuiltProperties
99
100 inputApex android.Path
101 installDir android.InstallPath
102 installFilename string
103 outputApex android.WritablePath
Jooyung Han002ab682020-01-08 01:57:58 +0900104
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 Park09d77522019-11-18 11:16:27 +0900108}
109
Paul Duffin851f3992021-01-13 17:03:51 +0000110type ApexFileProperties struct {
Jiyong Park09d77522019-11-18 11:16:27 +0900111 // the path to the prebuilt .apex file to import.
Jiyong Park10e926b2020-07-16 21:38:56 +0900112 Source string `blueprint:"mutated"`
Jiyong Park09d77522019-11-18 11:16:27 +0900113
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 }
Paul Duffin851f3992021-01-13 17:03:51 +0000129}
130
131func (p *ApexFileProperties) selectSource(ctx android.BottomUpMutatorContext) error {
132 // This is called before prebuilt_select and prebuilt_postdeps mutators
133 // The mutators requires that src to be set correctly for each arch so that
134 // arch variants are disabled when src is not provided for the arch.
135 if len(ctx.MultiTargets()) != 1 {
136 return fmt.Errorf("compile_multilib shouldn't be \"both\" for prebuilt_apex")
137 }
138 var src string
139 switch ctx.MultiTargets()[0].Arch.ArchType {
140 case android.Arm:
141 src = String(p.Arch.Arm.Src)
142 case android.Arm64:
143 src = String(p.Arch.Arm64.Src)
144 case android.X86:
145 src = String(p.Arch.X86.Src)
146 case android.X86_64:
147 src = String(p.Arch.X86_64.Src)
148 default:
149 return fmt.Errorf("prebuilt_apex does not support %q", ctx.MultiTargets()[0].Arch.String())
150 }
151 if src == "" {
152 src = String(p.Src)
153 }
154 p.Source = src
155
156 return nil
157}
158
159type PrebuiltProperties struct {
160 ApexFileProperties
Paul Duffin064b70c2020-11-02 17:32:38 +0000161 DeapexerProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900162
163 Installable *bool
164 // Optional name for the installed apex. If unspecified, name of the
165 // module is used as the file name
166 Filename *string
167
168 // Names of modules to be overridden. Listed modules can only be other binaries
169 // (in Make or Soong).
170 // This does not completely prevent installation of the overridden binaries, but if both
171 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
172 // from PRODUCT_PACKAGES.
173 Overrides []string
174}
175
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700176func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool {
177 return false
178}
179
Jiyong Park09d77522019-11-18 11:16:27 +0900180func (p *Prebuilt) installable() bool {
181 return p.properties.Installable == nil || proptools.Bool(p.properties.Installable)
182}
183
Jiyong Park09d77522019-11-18 11:16:27 +0900184func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
185 switch tag {
186 case "":
187 return android.Paths{p.outputApex}, nil
188 default:
189 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
190 }
191}
192
193func (p *Prebuilt) InstallFilename() string {
194 return proptools.StringDefault(p.properties.Filename, p.BaseModuleName()+imageApexSuffix)
195}
196
Jiyong Park09d77522019-11-18 11:16:27 +0900197func (p *Prebuilt) Name() string {
Jiyong Park10e926b2020-07-16 21:38:56 +0900198 return p.prebuiltCommon.prebuilt.Name(p.ModuleBase.Name())
Jiyong Park09d77522019-11-18 11:16:27 +0900199}
200
201// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
Paul Duffin064b70c2020-11-02 17:32:38 +0000202//
203// If this needs to make files from within a `.apex` file available for use by other Soong modules,
204// e.g. make dex implementation jars available for java_import modules isted in exported_java_libs,
205// it does so as follows:
206//
207// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and
208// makes them available for use by other modules, at both Soong and ninja levels.
209//
210// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what
211// an `apex` module does. That ensures that code which looks for specific apex variant, e.g.
212// dexpreopt, will work the same way from source and prebuilt.
213//
214// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto
215// itself so that they can retrieve the file paths to those files.
216//
Jiyong Park09d77522019-11-18 11:16:27 +0900217func PrebuiltFactory() android.Module {
218 module := &Prebuilt{}
219 module.AddProperties(&module.properties)
220 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Source")
221 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
Paul Duffin064b70c2020-11-02 17:32:38 +0000222
223 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
224 props := struct {
225 Name *string
226 }{
227 Name: proptools.StringPtr(module.BaseModuleName() + ".deapexer"),
228 }
229 ctx.CreateModule(privateDeapexerFactory,
230 &props,
231 &module.properties.ApexFileProperties,
232 &module.properties.DeapexerProperties,
233 )
234 })
235
Jiyong Park09d77522019-11-18 11:16:27 +0900236 return module
237}
238
Paul Duffin064b70c2020-11-02 17:32:38 +0000239func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string {
240 // The prebuilt_apex should be depending on prebuilt modules but as this runs after
241 // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So,
242 // check to see if the prefixed name is in use first, if it is then use that, otherwise assume
243 // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module
244 // and not a renamed prebuilt module then that will be detected and reported as an error when
245 // processing the dependency in ApexInfoMutator().
246 prebuiltName := "prebuilt_" + name
247 if ctx.OtherModuleExists(prebuiltName) {
248 name = prebuiltName
249 }
250 return name
251}
252
Liz Kammer356f7d42021-01-26 09:18:53 -0500253func prebuiltSelectSourceMutator(ctx android.BottomUpMutatorContext) {
254 p, ok := ctx.Module().(*Prebuilt)
255 if !ok {
Jiyong Park09d77522019-11-18 11:16:27 +0900256 return
257 }
Liz Kammer356f7d42021-01-26 09:18:53 -0500258 if err := p.properties.selectSource(ctx); err != nil {
259 ctx.ModuleErrorf("%s", err)
260 }
261}
Paul Duffin064b70c2020-11-02 17:32:38 +0000262
Liz Kammer356f7d42021-01-26 09:18:53 -0500263func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin064b70c2020-11-02 17:32:38 +0000264 // Add dependencies onto the java modules that represent the java libraries that are provided by
265 // and exported from this prebuilt apex.
266 for _, lib := range p.properties.Exported_java_libs {
267 dep := prebuiltApexExportedModuleName(ctx, lib)
268 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), javaLibTag, dep)
269 }
270}
271
272var _ ApexInfoMutator = (*Prebuilt)(nil)
273
274// ApexInfoMutator marks any modules for which this apex exports a file as requiring an apex
275// specific variant and checks that they are supported.
276//
277// The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are
278// associated with the apex specific variant using the ApexInfoProvider for later retrieval.
279//
280// Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants
281// across prebuilt_apex modules. That is because there is no way to determine whether two
282// prebuilt_apex modules that export files for the same module are compatible. e.g. they could have
283// been built from different source at different times or they could have been built with different
284// build options that affect the libraries.
285//
286// While it may be possible to provide sufficient information to determine whether two prebuilt_apex
287// modules were compatible it would be a lot of work and would not provide much benefit for a couple
288// of reasons:
289// * The number of prebuilt_apex modules that will be exporting files for the same module will be
290// low as the prebuilt_apex only exports files for the direct dependencies that require it and
291// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a
292// few com.android.art* apex files that contain the same contents and could export files for the
293// same modules but only one of them needs to do so. Contrast that with source apex modules which
294// need apex specific variants for every module that contributes code to the apex, whether direct
295// or indirect.
296// * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some
297// extra copying of files. Contrast that with source apex modules that has to build each variant
298// from source.
299func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) {
300
301 // Collect direct dependencies into contents.
302 contents := make(map[string]android.ApexMembership)
303
304 // Collect the list of dependencies.
305 var dependencies []android.ApexModule
306 mctx.VisitDirectDeps(func(m android.Module) {
307 tag := mctx.OtherModuleDependencyTag(m)
308 if tag == javaLibTag {
309 depName := mctx.OtherModuleName(m)
310
311 // It is an error if the other module is not a prebuilt.
312 if _, ok := m.(android.PrebuiltInterface); !ok {
313 mctx.PropertyErrorf("exported_java_libs", "%q is not a prebuilt module", depName)
314 return
315 }
316
317 // It is an error if the other module is not an ApexModule.
318 if _, ok := m.(android.ApexModule); !ok {
319 mctx.PropertyErrorf("exported_java_libs", "%q is not usable within an apex", depName)
320 return
321 }
322
323 // Strip off the prebuilt_ prefix if present before storing content to ensure consistent
324 // behavior whether there is a corresponding source module present or not.
325 depName = android.RemoveOptionalPrebuiltPrefix(depName)
326
327 // Remember that this module was added as a direct dependency.
328 contents[depName] = contents[depName].Add(true)
329
330 // Add the module to the list of dependencies that need to have an APEX variant.
331 dependencies = append(dependencies, m.(android.ApexModule))
332 }
333 })
334
335 // Create contents for the prebuilt_apex and store it away for later use.
336 apexContents := android.NewApexContents(contents)
337 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
338 Contents: apexContents,
339 })
340
341 // Create an ApexInfo for the prebuilt_apex.
342 apexInfo := android.ApexInfo{
343 ApexVariationName: mctx.ModuleName(),
344 InApexes: []string{mctx.ModuleName()},
345 ApexContents: []*android.ApexContents{apexContents},
346 ForPrebuiltApex: true,
347 }
348
349 // Mark the dependencies of this module as requiring a variant for this module.
350 for _, am := range dependencies {
351 am.BuildForApex(apexInfo)
352 }
Jiyong Park09d77522019-11-18 11:16:27 +0900353}
354
355func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park09d77522019-11-18 11:16:27 +0900356 // TODO(jungjw): Check the key validity.
357 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
358 p.installDir = android.PathForModuleInstall(ctx, "apex")
359 p.installFilename = p.InstallFilename()
360 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
361 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
362 }
363 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
364 ctx.Build(pctx, android.BuildParams{
365 Rule: android.Cp,
366 Input: p.inputApex,
367 Output: p.outputApex,
368 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900369
370 if p.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800371 p.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900372 return
373 }
374
Jiyong Park09d77522019-11-18 11:16:27 +0900375 if p.installable() {
376 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
377 }
378
Jooyung Han002ab682020-01-08 01:57:58 +0900379 // in case that prebuilt_apex replaces source apex (using prefer: prop)
380 p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx)
381 // or that prebuilt_apex overrides other apexes (using overrides: prop)
382 for _, overridden := range p.properties.Overrides {
383 p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
384 }
Jiyong Park09d77522019-11-18 11:16:27 +0900385}
386
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900387func (p *Prebuilt) AndroidMkEntries() []android.AndroidMkEntries {
388 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jiyong Park09d77522019-11-18 11:16:27 +0900389 Class: "ETC",
390 OutputFile: android.OptionalPathForPath(p.inputApex),
391 Include: "$(BUILD_PREBUILT)",
392 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
393 func(entries *android.AndroidMkEntries) {
394 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
395 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
396 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
397 entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.properties.Overrides...)
Jooyung Han002ab682020-01-08 01:57:58 +0900398 if len(p.compatSymlinks) > 0 {
399 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(p.compatSymlinks, " && "))
400 }
Jiyong Park09d77522019-11-18 11:16:27 +0900401 },
402 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900403 }}
Jiyong Park09d77522019-11-18 11:16:27 +0900404}
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700405
406type ApexSet struct {
407 android.ModuleBase
Jiyong Park10e926b2020-07-16 21:38:56 +0900408 prebuiltCommon
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700409
410 properties ApexSetProperties
411
412 installDir android.InstallPath
413 installFilename string
414 outputApex android.WritablePath
415
416 // list of commands to create symlinks for backward compatibility.
417 // these commands will be attached as LOCAL_POST_INSTALL_CMD
418 compatSymlinks []string
Jooyung Han29637162020-06-30 06:34:23 +0900419
420 hostRequired []string
421 postInstallCommands []string
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700422}
423
424type ApexSetProperties struct {
425 // the .apks file path that contains prebuilt apex files to be extracted.
426 Set *string
427
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700428 Sanitized struct {
429 None struct {
430 Set *string
431 }
432 Address struct {
433 Set *string
434 }
435 Hwaddress struct {
436 Set *string
437 }
438 }
439
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700440 // whether the extracted apex file installable.
441 Installable *bool
442
443 // optional name for the installed apex. If unspecified, name of the
444 // module is used as the file name
445 Filename *string
446
447 // names of modules to be overridden. Listed modules can only be other binaries
448 // (in Make or Soong).
449 // This does not completely prevent installation of the overridden binaries, but if both
450 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
451 // from PRODUCT_PACKAGES.
452 Overrides []string
453
454 // apexes in this set use prerelease SDK version
455 Prerelease *bool
456}
457
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700458func (a *ApexSet) prebuiltSrcs(ctx android.BaseModuleContext) []string {
459 var srcs []string
460 if a.properties.Set != nil {
461 srcs = append(srcs, *a.properties.Set)
462 }
463
464 var sanitizers []string
465 if ctx.Host() {
466 sanitizers = ctx.Config().SanitizeHost()
467 } else {
468 sanitizers = ctx.Config().SanitizeDevice()
469 }
470
471 if android.InList("address", sanitizers) && a.properties.Sanitized.Address.Set != nil {
472 srcs = append(srcs, *a.properties.Sanitized.Address.Set)
473 } else if android.InList("hwaddress", sanitizers) && a.properties.Sanitized.Hwaddress.Set != nil {
474 srcs = append(srcs, *a.properties.Sanitized.Hwaddress.Set)
475 } else if a.properties.Sanitized.None.Set != nil {
476 srcs = append(srcs, *a.properties.Sanitized.None.Set)
477 }
478
479 return srcs
480}
481
482func (a *ApexSet) hasSanitizedSource(sanitizer string) bool {
483 if sanitizer == "address" {
484 return a.properties.Sanitized.Address.Set != nil
485 }
486 if sanitizer == "hwaddress" {
487 return a.properties.Sanitized.Hwaddress.Set != nil
488 }
489
490 return false
491}
492
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700493func (a *ApexSet) installable() bool {
494 return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
495}
496
497func (a *ApexSet) InstallFilename() string {
498 return proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+imageApexSuffix)
499}
500
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700501func (a *ApexSet) Name() string {
Jiyong Park10e926b2020-07-16 21:38:56 +0900502 return a.prebuiltCommon.prebuilt.Name(a.ModuleBase.Name())
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700503}
504
Jiyong Park8d6c51e2020-06-12 17:26:31 +0900505func (a *ApexSet) Overrides() []string {
506 return a.properties.Overrides
507}
508
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700509// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
510func apexSetFactory() android.Module {
511 module := &ApexSet{}
512 module.AddProperties(&module.properties)
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700513
514 srcsSupplier := func(ctx android.BaseModuleContext) []string {
515 return module.prebuiltSrcs(ctx)
516 }
517
518 android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "set")
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700519 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
520 return module
521}
522
523func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
524 a.installFilename = a.InstallFilename()
525 if !strings.HasSuffix(a.installFilename, imageApexSuffix) {
526 ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
527 }
528
Jiyong Park10e926b2020-07-16 21:38:56 +0900529 apexSet := a.prebuiltCommon.prebuilt.SingleSourcePath(ctx)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700530 a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
531 ctx.Build(pctx,
532 android.BuildParams{
533 Rule: extractMatchingApex,
534 Description: "Extract an apex from an apex set",
535 Inputs: android.Paths{apexSet},
536 Output: a.outputApex,
537 Args: map[string]string{
538 "abis": strings.Join(java.SupportedAbis(ctx), ","),
539 "allow-prereleased": strconv.FormatBool(proptools.Bool(a.properties.Prerelease)),
Dan Albert4f378d72020-07-23 17:32:15 -0700540 "sdk-version": ctx.Config().PlatformSdkVersion().String(),
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700541 },
542 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900543
544 if a.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800545 a.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900546 return
547 }
548
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700549 a.installDir = android.PathForModuleInstall(ctx, "apex")
550 if a.installable() {
551 ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
552 }
553
554 // in case that apex_set replaces source apex (using prefer: prop)
555 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
556 // or that apex_set overrides other apexes (using overrides: prop)
557 for _, overridden := range a.properties.Overrides {
558 a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
559 }
Jooyung Han29637162020-06-30 06:34:23 +0900560
561 if ctx.Config().InstallExtraFlattenedApexes() {
562 // flattened apex should be in /system_ext/apex
563 flattenedApexDir := android.PathForModuleInstall(&systemExtContext{ctx}, "apex", a.BaseModuleName())
564 a.postInstallCommands = append(a.postInstallCommands,
565 fmt.Sprintf("$(HOST_OUT_EXECUTABLES)/deapexer --debugfs_path $(HOST_OUT_EXECUTABLES)/debugfs extract %s %s",
566 a.outputApex.String(),
567 flattenedApexDir.ToMakePath().String(),
568 ))
569 a.hostRequired = []string{"deapexer", "debugfs"}
570 }
571}
572
573type systemExtContext struct {
574 android.ModuleContext
575}
576
577func (*systemExtContext) SystemExtSpecific() bool {
578 return true
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700579}
580
581func (a *ApexSet) AndroidMkEntries() []android.AndroidMkEntries {
582 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han29637162020-06-30 06:34:23 +0900583 Class: "ETC",
584 OutputFile: android.OptionalPathForPath(a.outputApex),
585 Include: "$(BUILD_PREBUILT)",
586 Host_required: a.hostRequired,
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700587 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
588 func(entries *android.AndroidMkEntries) {
589 entries.SetString("LOCAL_MODULE_PATH", a.installDir.ToMakePath().String())
590 entries.SetString("LOCAL_MODULE_STEM", a.installFilename)
591 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !a.installable())
592 entries.AddStrings("LOCAL_OVERRIDES_MODULES", a.properties.Overrides...)
Jooyung Han29637162020-06-30 06:34:23 +0900593 postInstallCommands := append([]string{}, a.postInstallCommands...)
594 postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
595 if len(postInstallCommands) > 0 {
596 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && "))
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700597 }
598 },
599 },
600 }}
601}