blob: c72a9ebfc83ff9786fb6c824023c92b758725f0d [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
Jiyong Park09d77522019-11-18 11:16:27 +0900253func (p *Prebuilt) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin851f3992021-01-13 17:03:51 +0000254 if err := p.properties.selectSource(ctx); err != nil {
255 ctx.ModuleErrorf("%s", err)
Jiyong Park09d77522019-11-18 11:16:27 +0900256 return
257 }
Paul Duffin064b70c2020-11-02 17:32:38 +0000258
259 // Add dependencies onto the java modules that represent the java libraries that are provided by
260 // and exported from this prebuilt apex.
261 for _, lib := range p.properties.Exported_java_libs {
262 dep := prebuiltApexExportedModuleName(ctx, lib)
263 ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), javaLibTag, dep)
264 }
265}
266
267var _ ApexInfoMutator = (*Prebuilt)(nil)
268
269// ApexInfoMutator marks any modules for which this apex exports a file as requiring an apex
270// specific variant and checks that they are supported.
271//
272// The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are
273// associated with the apex specific variant using the ApexInfoProvider for later retrieval.
274//
275// Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants
276// across prebuilt_apex modules. That is because there is no way to determine whether two
277// prebuilt_apex modules that export files for the same module are compatible. e.g. they could have
278// been built from different source at different times or they could have been built with different
279// build options that affect the libraries.
280//
281// While it may be possible to provide sufficient information to determine whether two prebuilt_apex
282// modules were compatible it would be a lot of work and would not provide much benefit for a couple
283// of reasons:
284// * The number of prebuilt_apex modules that will be exporting files for the same module will be
285// low as the prebuilt_apex only exports files for the direct dependencies that require it and
286// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a
287// few com.android.art* apex files that contain the same contents and could export files for the
288// same modules but only one of them needs to do so. Contrast that with source apex modules which
289// need apex specific variants for every module that contributes code to the apex, whether direct
290// or indirect.
291// * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some
292// extra copying of files. Contrast that with source apex modules that has to build each variant
293// from source.
294func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) {
295
296 // Collect direct dependencies into contents.
297 contents := make(map[string]android.ApexMembership)
298
299 // Collect the list of dependencies.
300 var dependencies []android.ApexModule
301 mctx.VisitDirectDeps(func(m android.Module) {
302 tag := mctx.OtherModuleDependencyTag(m)
303 if tag == javaLibTag {
304 depName := mctx.OtherModuleName(m)
305
306 // It is an error if the other module is not a prebuilt.
307 if _, ok := m.(android.PrebuiltInterface); !ok {
308 mctx.PropertyErrorf("exported_java_libs", "%q is not a prebuilt module", depName)
309 return
310 }
311
312 // It is an error if the other module is not an ApexModule.
313 if _, ok := m.(android.ApexModule); !ok {
314 mctx.PropertyErrorf("exported_java_libs", "%q is not usable within an apex", depName)
315 return
316 }
317
318 // Strip off the prebuilt_ prefix if present before storing content to ensure consistent
319 // behavior whether there is a corresponding source module present or not.
320 depName = android.RemoveOptionalPrebuiltPrefix(depName)
321
322 // Remember that this module was added as a direct dependency.
323 contents[depName] = contents[depName].Add(true)
324
325 // Add the module to the list of dependencies that need to have an APEX variant.
326 dependencies = append(dependencies, m.(android.ApexModule))
327 }
328 })
329
330 // Create contents for the prebuilt_apex and store it away for later use.
331 apexContents := android.NewApexContents(contents)
332 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
333 Contents: apexContents,
334 })
335
336 // Create an ApexInfo for the prebuilt_apex.
337 apexInfo := android.ApexInfo{
338 ApexVariationName: mctx.ModuleName(),
339 InApexes: []string{mctx.ModuleName()},
340 ApexContents: []*android.ApexContents{apexContents},
341 ForPrebuiltApex: true,
342 }
343
344 // Mark the dependencies of this module as requiring a variant for this module.
345 for _, am := range dependencies {
346 am.BuildForApex(apexInfo)
347 }
Jiyong Park09d77522019-11-18 11:16:27 +0900348}
349
350func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park09d77522019-11-18 11:16:27 +0900351 // TODO(jungjw): Check the key validity.
352 p.inputApex = p.Prebuilt().SingleSourcePath(ctx)
353 p.installDir = android.PathForModuleInstall(ctx, "apex")
354 p.installFilename = p.InstallFilename()
355 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
356 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
357 }
358 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
359 ctx.Build(pctx, android.BuildParams{
360 Rule: android.Cp,
361 Input: p.inputApex,
362 Output: p.outputApex,
363 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900364
365 if p.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800366 p.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900367 return
368 }
369
Jiyong Park09d77522019-11-18 11:16:27 +0900370 if p.installable() {
371 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
372 }
373
Jooyung Han002ab682020-01-08 01:57:58 +0900374 // in case that prebuilt_apex replaces source apex (using prefer: prop)
375 p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx)
376 // or that prebuilt_apex overrides other apexes (using overrides: prop)
377 for _, overridden := range p.properties.Overrides {
378 p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
379 }
Jiyong Park09d77522019-11-18 11:16:27 +0900380}
381
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900382func (p *Prebuilt) AndroidMkEntries() []android.AndroidMkEntries {
383 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jiyong Park09d77522019-11-18 11:16:27 +0900384 Class: "ETC",
385 OutputFile: android.OptionalPathForPath(p.inputApex),
386 Include: "$(BUILD_PREBUILT)",
387 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
388 func(entries *android.AndroidMkEntries) {
389 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
390 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
391 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
392 entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.properties.Overrides...)
Jooyung Han002ab682020-01-08 01:57:58 +0900393 if len(p.compatSymlinks) > 0 {
394 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(p.compatSymlinks, " && "))
395 }
Jiyong Park09d77522019-11-18 11:16:27 +0900396 },
397 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900398 }}
Jiyong Park09d77522019-11-18 11:16:27 +0900399}
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700400
401type ApexSet struct {
402 android.ModuleBase
Jiyong Park10e926b2020-07-16 21:38:56 +0900403 prebuiltCommon
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700404
405 properties ApexSetProperties
406
407 installDir android.InstallPath
408 installFilename string
409 outputApex android.WritablePath
410
411 // list of commands to create symlinks for backward compatibility.
412 // these commands will be attached as LOCAL_POST_INSTALL_CMD
413 compatSymlinks []string
Jooyung Han29637162020-06-30 06:34:23 +0900414
415 hostRequired []string
416 postInstallCommands []string
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700417}
418
419type ApexSetProperties struct {
420 // the .apks file path that contains prebuilt apex files to be extracted.
421 Set *string
422
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700423 Sanitized struct {
424 None struct {
425 Set *string
426 }
427 Address struct {
428 Set *string
429 }
430 Hwaddress struct {
431 Set *string
432 }
433 }
434
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700435 // whether the extracted apex file installable.
436 Installable *bool
437
438 // optional name for the installed apex. If unspecified, name of the
439 // module is used as the file name
440 Filename *string
441
442 // names of modules to be overridden. Listed modules can only be other binaries
443 // (in Make or Soong).
444 // This does not completely prevent installation of the overridden binaries, but if both
445 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
446 // from PRODUCT_PACKAGES.
447 Overrides []string
448
449 // apexes in this set use prerelease SDK version
450 Prerelease *bool
451}
452
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700453func (a *ApexSet) prebuiltSrcs(ctx android.BaseModuleContext) []string {
454 var srcs []string
455 if a.properties.Set != nil {
456 srcs = append(srcs, *a.properties.Set)
457 }
458
459 var sanitizers []string
460 if ctx.Host() {
461 sanitizers = ctx.Config().SanitizeHost()
462 } else {
463 sanitizers = ctx.Config().SanitizeDevice()
464 }
465
466 if android.InList("address", sanitizers) && a.properties.Sanitized.Address.Set != nil {
467 srcs = append(srcs, *a.properties.Sanitized.Address.Set)
468 } else if android.InList("hwaddress", sanitizers) && a.properties.Sanitized.Hwaddress.Set != nil {
469 srcs = append(srcs, *a.properties.Sanitized.Hwaddress.Set)
470 } else if a.properties.Sanitized.None.Set != nil {
471 srcs = append(srcs, *a.properties.Sanitized.None.Set)
472 }
473
474 return srcs
475}
476
477func (a *ApexSet) hasSanitizedSource(sanitizer string) bool {
478 if sanitizer == "address" {
479 return a.properties.Sanitized.Address.Set != nil
480 }
481 if sanitizer == "hwaddress" {
482 return a.properties.Sanitized.Hwaddress.Set != nil
483 }
484
485 return false
486}
487
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700488func (a *ApexSet) installable() bool {
489 return a.properties.Installable == nil || proptools.Bool(a.properties.Installable)
490}
491
492func (a *ApexSet) InstallFilename() string {
493 return proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+imageApexSuffix)
494}
495
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700496func (a *ApexSet) Name() string {
Jiyong Park10e926b2020-07-16 21:38:56 +0900497 return a.prebuiltCommon.prebuilt.Name(a.ModuleBase.Name())
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700498}
499
Jiyong Park8d6c51e2020-06-12 17:26:31 +0900500func (a *ApexSet) Overrides() []string {
501 return a.properties.Overrides
502}
503
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700504// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
505func apexSetFactory() android.Module {
506 module := &ApexSet{}
507 module.AddProperties(&module.properties)
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700508
509 srcsSupplier := func(ctx android.BaseModuleContext) []string {
510 return module.prebuiltSrcs(ctx)
511 }
512
513 android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "set")
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700514 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
515 return module
516}
517
518func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
519 a.installFilename = a.InstallFilename()
520 if !strings.HasSuffix(a.installFilename, imageApexSuffix) {
521 ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
522 }
523
Jiyong Park10e926b2020-07-16 21:38:56 +0900524 apexSet := a.prebuiltCommon.prebuilt.SingleSourcePath(ctx)
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700525 a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
526 ctx.Build(pctx,
527 android.BuildParams{
528 Rule: extractMatchingApex,
529 Description: "Extract an apex from an apex set",
530 Inputs: android.Paths{apexSet},
531 Output: a.outputApex,
532 Args: map[string]string{
533 "abis": strings.Join(java.SupportedAbis(ctx), ","),
534 "allow-prereleased": strconv.FormatBool(proptools.Bool(a.properties.Prerelease)),
Dan Albert4f378d72020-07-23 17:32:15 -0700535 "sdk-version": ctx.Config().PlatformSdkVersion().String(),
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700536 },
537 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900538
539 if a.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800540 a.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900541 return
542 }
543
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700544 a.installDir = android.PathForModuleInstall(ctx, "apex")
545 if a.installable() {
546 ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
547 }
548
549 // in case that apex_set replaces source apex (using prefer: prop)
550 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
551 // or that apex_set overrides other apexes (using overrides: prop)
552 for _, overridden := range a.properties.Overrides {
553 a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
554 }
Jooyung Han29637162020-06-30 06:34:23 +0900555
556 if ctx.Config().InstallExtraFlattenedApexes() {
557 // flattened apex should be in /system_ext/apex
558 flattenedApexDir := android.PathForModuleInstall(&systemExtContext{ctx}, "apex", a.BaseModuleName())
559 a.postInstallCommands = append(a.postInstallCommands,
560 fmt.Sprintf("$(HOST_OUT_EXECUTABLES)/deapexer --debugfs_path $(HOST_OUT_EXECUTABLES)/debugfs extract %s %s",
561 a.outputApex.String(),
562 flattenedApexDir.ToMakePath().String(),
563 ))
564 a.hostRequired = []string{"deapexer", "debugfs"}
565 }
566}
567
568type systemExtContext struct {
569 android.ModuleContext
570}
571
572func (*systemExtContext) SystemExtSpecific() bool {
573 return true
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700574}
575
576func (a *ApexSet) AndroidMkEntries() []android.AndroidMkEntries {
577 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jooyung Han29637162020-06-30 06:34:23 +0900578 Class: "ETC",
579 OutputFile: android.OptionalPathForPath(a.outputApex),
580 Include: "$(BUILD_PREBUILT)",
581 Host_required: a.hostRequired,
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700582 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
583 func(entries *android.AndroidMkEntries) {
584 entries.SetString("LOCAL_MODULE_PATH", a.installDir.ToMakePath().String())
585 entries.SetString("LOCAL_MODULE_STEM", a.installFilename)
586 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !a.installable())
587 entries.AddStrings("LOCAL_OVERRIDES_MODULES", a.properties.Overrides...)
Jooyung Han29637162020-06-30 06:34:23 +0900588 postInstallCommands := append([]string{}, a.postInstallCommands...)
589 postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
590 if len(postInstallCommands) > 0 {
591 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && "))
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700592 }
593 },
594 },
595 }}
596}