blob: ea06d45cba4e8959a09f3ee7bd599b6b4a346ae5 [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"
Paul Duffina35f8db2021-06-15 19:10:11 +010019 "io"
Jaewoong Jungfa00c062020-05-14 14:15:24 -070020 "strconv"
Jiyong Park09d77522019-11-18 11:16:27 +090021 "strings"
22
23 "android/soong/android"
Jaewoong Jungfa00c062020-05-14 14:15:24 -070024 "android/soong/java"
Jiyong Park10e926b2020-07-16 21:38:56 +090025
Jaewoong Jungfa00c062020-05-14 14:15:24 -070026 "github.com/google/blueprint"
Jiyong Park09d77522019-11-18 11:16:27 +090027
28 "github.com/google/blueprint/proptools"
29)
30
Jaewoong Jungfa00c062020-05-14 14:15:24 -070031var (
32 extractMatchingApex = pctx.StaticRule(
33 "extractMatchingApex",
34 blueprint.RuleParams{
35 Command: `rm -rf "$out" && ` +
36 `${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` +
37 `-sdk-version=${sdk-version} -abis=${abis} -screen-densities=all -extract-single ` +
38 `${in}`,
39 CommandDeps: []string{"${extract_apks}"},
40 },
41 "abis", "allow-prereleased", "sdk-version")
42)
43
Jiyong Park10e926b2020-07-16 21:38:56 +090044type prebuilt interface {
45 isForceDisabled() bool
46 InstallFilename() string
47}
48
49type prebuiltCommon struct {
Paul Duffina9c81102021-06-15 11:34:01 +010050 android.ModuleBase
Paul Duffinbb0dc132021-05-05 16:58:08 +010051 prebuilt android.Prebuilt
Paul Duffindfd33262021-04-06 17:02:08 +010052
Paul Duffinbb0dc132021-05-05 16:58:08 +010053 // Properties common to both prebuilt_apex and apex_set.
Paul Duffina9c81102021-06-15 11:34:01 +010054 prebuiltCommonProperties *PrebuiltCommonProperties
55
56 installDir android.InstallPath
57 installFilename string
58 outputApex android.WritablePath
59
Paul Duffina35f8db2021-06-15 19:10:11 +010060 // A list of apexFile objects created in prebuiltCommon.initApexFilesForAndroidMk which are used
61 // to create make modules in prebuiltCommon.AndroidMkEntries.
62 apexFilesForAndroidMk []apexFile
63
Paul Duffina9c81102021-06-15 11:34:01 +010064 // list of commands to create symlinks for backward compatibility.
65 // these commands will be attached as LOCAL_POST_INSTALL_CMD
66 compatSymlinks []string
67
68 hostRequired []string
69 postInstallCommands []string
Jiyong Park10e926b2020-07-16 21:38:56 +090070}
71
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -070072type sanitizedPrebuilt interface {
73 hasSanitizedSource(sanitizer string) bool
74}
75
Paul Duffina9c81102021-06-15 11:34:01 +010076type PrebuiltCommonProperties struct {
Paul Duffinbb0dc132021-05-05 16:58:08 +010077 SelectedApexProperties
78
Jiyong Park10e926b2020-07-16 21:38:56 +090079 ForceDisable bool `blueprint:"mutated"`
Paul Duffin3bae0682021-05-05 18:03:47 +010080
Paul Duffina9c81102021-06-15 11:34:01 +010081 // whether the extracted apex file is installable.
82 Installable *bool
83
84 // optional name for the installed apex. If unspecified, name of the
85 // module is used as the file name
86 Filename *string
87
88 // names of modules to be overridden. Listed modules can only be other binaries
89 // (in Make or Soong).
90 // This does not completely prevent installation of the overridden binaries, but if both
91 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
92 // from PRODUCT_PACKAGES.
93 Overrides []string
94
Paul Duffin3bae0682021-05-05 18:03:47 +010095 // List of java libraries that are embedded inside this prebuilt APEX bundle and for which this
96 // APEX bundle will create an APEX variant and provide dex implementation jars for use by
97 // dexpreopt and boot jars package check.
98 Exported_java_libs []string
99
100 // List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX
101 // bundle will create an APEX variant.
102 Exported_bootclasspath_fragments []string
Jiyong Park10e926b2020-07-16 21:38:56 +0900103}
104
Paul Duffina9c81102021-06-15 11:34:01 +0100105// initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the
106// module that is common to Prebuilt and ApexSet.
107func (p *prebuiltCommon) initPrebuiltCommon(module android.Module, properties *PrebuiltCommonProperties) {
108 p.prebuiltCommonProperties = properties
109 android.InitSingleSourcePrebuiltModule(module.(android.PrebuiltInterface), properties, "Selected_apex")
110 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
111}
112
Jiyong Park10e926b2020-07-16 21:38:56 +0900113func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
114 return &p.prebuilt
115}
116
117func (p *prebuiltCommon) isForceDisabled() bool {
Paul Duffinbb0dc132021-05-05 16:58:08 +0100118 return p.prebuiltCommonProperties.ForceDisable
Jiyong Park10e926b2020-07-16 21:38:56 +0900119}
120
121func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool {
122 // If the device is configured to use flattened APEX, force disable the prebuilt because
123 // the prebuilt is a non-flattened one.
124 forceDisable := ctx.Config().FlattenApex()
125
126 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
127 // to build the prebuilts themselves.
128 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
129
130 // Force disable the prebuilts when coverage is enabled.
131 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
132 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
133
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700134 // b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source
135 sanitized := ctx.Module().(sanitizedPrebuilt)
136 forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address"))
137 forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress"))
Jiyong Park10e926b2020-07-16 21:38:56 +0900138
139 if forceDisable && p.prebuilt.SourceExists() {
Paul Duffinbb0dc132021-05-05 16:58:08 +0100140 p.prebuiltCommonProperties.ForceDisable = true
Jiyong Park10e926b2020-07-16 21:38:56 +0900141 return true
142 }
143 return false
144}
145
Paul Duffina9c81102021-06-15 11:34:01 +0100146func (p *prebuiltCommon) InstallFilename() string {
147 return proptools.StringDefault(p.prebuiltCommonProperties.Filename, p.BaseModuleName()+imageApexSuffix)
148}
149
150func (p *prebuiltCommon) Name() string {
151 return p.prebuilt.Name(p.ModuleBase.Name())
152}
153
154func (p *prebuiltCommon) Overrides() []string {
155 return p.prebuiltCommonProperties.Overrides
156}
157
158func (p *prebuiltCommon) installable() bool {
159 return proptools.BoolDefault(p.prebuiltCommonProperties.Installable, true)
160}
161
Paul Duffina35f8db2021-06-15 19:10:11 +0100162// initApexFilesForAndroidMk initializes the prebuiltCommon.apexFilesForAndroidMk field from the
163// modules that this depends upon.
164func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) {
165 // Walk the dependencies of this module looking for the java modules that it exports.
166 ctx.WalkDeps(func(child, parent android.Module) bool {
167 tag := ctx.OtherModuleDependencyTag(child)
168
169 name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
170 if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
171 // If the exported java module provides a dex jar path then add it to the list of apexFiles.
172 path := child.(interface{ DexJarBuildPath() android.Path }).DexJarBuildPath()
173 if path != nil {
174 p.apexFilesForAndroidMk = append(p.apexFilesForAndroidMk, apexFile{
175 module: child,
176 moduleDir: ctx.OtherModuleDir(child),
177 androidMkModuleName: name,
178 builtFile: path,
179 class: javaSharedLib,
180 })
181 }
182 } else if tag == exportedBootclasspathFragmentTag {
183 // Visit the children of the bootclasspath_fragment.
184 return true
185 }
186
187 return false
188 })
189}
190
Paul Duffina9c81102021-06-15 11:34:01 +0100191func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffina35f8db2021-06-15 19:10:11 +0100192 entriesList := []android.AndroidMkEntries{
Paul Duffina9c81102021-06-15 11:34:01 +0100193 {
194 Class: "ETC",
195 OutputFile: android.OptionalPathForPath(p.outputApex),
196 Include: "$(BUILD_PREBUILT)",
197 Host_required: p.hostRequired,
198 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
199 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
200 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
201 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
202 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
203 entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.prebuiltCommonProperties.Overrides...)
204 postInstallCommands := append([]string{}, p.postInstallCommands...)
205 postInstallCommands = append(postInstallCommands, p.compatSymlinks...)
206 if len(postInstallCommands) > 0 {
207 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && "))
208 }
209 },
210 },
211 },
212 }
Paul Duffina35f8db2021-06-15 19:10:11 +0100213
214 // Iterate over the apexFilesForAndroidMk list and create an AndroidMkEntries struct for each
215 // file. This provides similar behavior to that provided in apexBundle.AndroidMk() as it makes the
216 // apex specific variants of the exported java modules available for use from within make.
217 apexName := p.BaseModuleName()
218 for _, fi := range p.apexFilesForAndroidMk {
Paul Duffin155c1772021-06-17 13:33:09 +0100219 entries := p.createEntriesForApexFile(fi, apexName)
Paul Duffina35f8db2021-06-15 19:10:11 +0100220 entriesList = append(entriesList, entries)
221 }
222
223 return entriesList
Paul Duffina9c81102021-06-15 11:34:01 +0100224}
225
Paul Duffin155c1772021-06-17 13:33:09 +0100226// createEntriesForApexFile creates an AndroidMkEntries for the supplied apexFile
227func (p *prebuiltCommon) createEntriesForApexFile(fi apexFile, apexName string) android.AndroidMkEntries {
228 moduleName := fi.androidMkModuleName + "." + apexName
229 entries := android.AndroidMkEntries{
230 Class: fi.class.nameInMake(),
231 OverrideName: moduleName,
232 OutputFile: android.OptionalPathForPath(fi.builtFile),
233 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
234 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
235 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
236 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
237
238 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
239 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
240 // we will have foo.jar.jar
241 entries.SetString("LOCAL_MODULE_STEM", strings.TrimSuffix(fi.stem(), ".jar"))
242 var classesJar android.Path
243 var headerJar android.Path
244 if javaModule, ok := fi.module.(java.ApexDependency); ok {
245 classesJar = javaModule.ImplementationAndResourcesJars()[0]
246 headerJar = javaModule.HeaderJars()[0]
247 } else {
248 classesJar = fi.builtFile
249 headerJar = fi.builtFile
250 }
251 entries.SetString("LOCAL_SOONG_CLASSES_JAR", classesJar.String())
252 entries.SetString("LOCAL_SOONG_HEADER_JAR", headerJar.String())
253 entries.SetString("LOCAL_SOONG_DEX_JAR", fi.builtFile.String())
254 entries.SetString("LOCAL_DEX_PREOPT", "false")
255 },
256 },
257 ExtraFooters: []android.AndroidMkExtraFootersFunc{
258 func(w io.Writer, name, prefix, moduleDir string) {
259 // m <module_name> will build <module_name>.<apex_name> as well.
260 if fi.androidMkModuleName != moduleName {
261 fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
262 fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
263 }
264 },
265 },
266 }
267 return entries
268}
269
Paul Duffin5dda3e32021-05-05 14:13:27 +0100270// prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and
271// apex_set in order to create the modules needed to provide access to the prebuilt .apex file.
272type prebuiltApexModuleCreator interface {
273 createPrebuiltApexModules(ctx android.TopDownMutatorContext)
274}
275
276// prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the
277// prebuiltApexModuleCreator's createPrebuiltApexModules method.
278//
279// It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it
280// will need to access dependencies added by that (exported modules) but must run before the
281// DepsMutator so that the deapexer module it creates can add dependencies onto itself from the
282// exported modules.
283func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) {
284 module := ctx.Module()
285 if creator, ok := module.(prebuiltApexModuleCreator); ok {
286 creator.createPrebuiltApexModules(ctx)
287 }
288}
289
Paul Duffin57f83592021-05-05 15:09:44 +0100290// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
291func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
292 module := ctx.Module()
Paul Duffindfd33262021-04-06 17:02:08 +0100293 // Add dependencies onto the java modules that represent the java libraries that are provided by
294 // and exported from this prebuilt apex.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100295 for _, exported := range p.prebuiltCommonProperties.Exported_java_libs {
Paul Duffin57f83592021-05-05 15:09:44 +0100296 dep := android.PrebuiltNameFromSource(exported)
297 ctx.AddDependency(module, exportedJavaLibTag, dep)
Paul Duffindfd33262021-04-06 17:02:08 +0100298 }
Paul Duffin023dba02021-04-22 01:45:29 +0100299
300 // Add dependencies onto the bootclasspath fragment modules that are exported from this prebuilt
301 // apex.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100302 for _, exported := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
Paul Duffin57f83592021-05-05 15:09:44 +0100303 dep := android.PrebuiltNameFromSource(exported)
304 ctx.AddDependency(module, exportedBootclasspathFragmentTag, dep)
Paul Duffin023dba02021-04-22 01:45:29 +0100305 }
Paul Duffindfd33262021-04-06 17:02:08 +0100306}
307
Paul Duffinb17d0442021-05-05 12:07:00 +0100308// Implements android.DepInInSameApex
309func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
310 tag := ctx.OtherModuleDependencyTag(dep)
311 _, ok := tag.(exportedDependencyTag)
312 return ok
313}
314
Paul Duffindfd33262021-04-06 17:02:08 +0100315// apexInfoMutator marks any modules for which this apex exports a file as requiring an apex
316// specific variant and checks that they are supported.
317//
318// The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are
319// associated with the apex specific variant using the ApexInfoProvider for later retrieval.
320//
321// Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants
322// across prebuilt_apex modules. That is because there is no way to determine whether two
323// prebuilt_apex modules that export files for the same module are compatible. e.g. they could have
324// been built from different source at different times or they could have been built with different
325// build options that affect the libraries.
326//
327// While it may be possible to provide sufficient information to determine whether two prebuilt_apex
328// modules were compatible it would be a lot of work and would not provide much benefit for a couple
329// of reasons:
330// * The number of prebuilt_apex modules that will be exporting files for the same module will be
331// low as the prebuilt_apex only exports files for the direct dependencies that require it and
332// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a
333// few com.android.art* apex files that contain the same contents and could export files for the
334// same modules but only one of them needs to do so. Contrast that with source apex modules which
335// need apex specific variants for every module that contributes code to the apex, whether direct
336// or indirect.
337// * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some
338// extra copying of files. Contrast that with source apex modules that has to build each variant
339// from source.
340func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) {
341
342 // Collect direct dependencies into contents.
343 contents := make(map[string]android.ApexMembership)
344
345 // Collect the list of dependencies.
346 var dependencies []android.ApexModule
Paul Duffinb17d0442021-05-05 12:07:00 +0100347 mctx.WalkDeps(func(child, parent android.Module) bool {
348 // If the child is not in the same apex as the parent then exit immediately and do not visit
349 // any of the child's dependencies.
350 if !android.IsDepInSameApex(mctx, parent, child) {
351 return false
352 }
353
354 tag := mctx.OtherModuleDependencyTag(child)
355 depName := mctx.OtherModuleName(child)
Paul Duffin023dba02021-04-22 01:45:29 +0100356 if exportedTag, ok := tag.(exportedDependencyTag); ok {
357 propertyName := exportedTag.name
Paul Duffindfd33262021-04-06 17:02:08 +0100358
359 // It is an error if the other module is not a prebuilt.
Paul Duffinb17d0442021-05-05 12:07:00 +0100360 if !android.IsModulePrebuilt(child) {
Paul Duffin023dba02021-04-22 01:45:29 +0100361 mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName)
Paul Duffinb17d0442021-05-05 12:07:00 +0100362 return false
Paul Duffindfd33262021-04-06 17:02:08 +0100363 }
364
365 // It is an error if the other module is not an ApexModule.
Paul Duffinb17d0442021-05-05 12:07:00 +0100366 if _, ok := child.(android.ApexModule); !ok {
Paul Duffin023dba02021-04-22 01:45:29 +0100367 mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName)
Paul Duffinb17d0442021-05-05 12:07:00 +0100368 return false
Paul Duffindfd33262021-04-06 17:02:08 +0100369 }
Paul Duffindfd33262021-04-06 17:02:08 +0100370 }
Paul Duffinb17d0442021-05-05 12:07:00 +0100371
372 // Strip off the prebuilt_ prefix if present before storing content to ensure consistent
373 // behavior whether there is a corresponding source module present or not.
374 depName = android.RemoveOptionalPrebuiltPrefix(depName)
375
376 // Remember if this module was added as a direct dependency.
377 direct := parent == mctx.Module()
378 contents[depName] = contents[depName].Add(direct)
379
380 // Add the module to the list of dependencies that need to have an APEX variant.
381 dependencies = append(dependencies, child.(android.ApexModule))
382
383 return true
Paul Duffindfd33262021-04-06 17:02:08 +0100384 })
385
386 // Create contents for the prebuilt_apex and store it away for later use.
387 apexContents := android.NewApexContents(contents)
388 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
389 Contents: apexContents,
390 })
391
392 // Create an ApexInfo for the prebuilt_apex.
Martin Stjernholmbe105032021-05-26 16:57:39 +0100393 apexVariationName := android.RemoveOptionalPrebuiltPrefix(mctx.ModuleName())
Paul Duffindfd33262021-04-06 17:02:08 +0100394 apexInfo := android.ApexInfo{
Martin Stjernholmbe105032021-05-26 16:57:39 +0100395 ApexVariationName: apexVariationName,
396 InApexVariants: []string{apexVariationName},
397 InApexModules: []string{apexVariationName},
Paul Duffindfd33262021-04-06 17:02:08 +0100398 ApexContents: []*android.ApexContents{apexContents},
399 ForPrebuiltApex: true,
400 }
401
402 // Mark the dependencies of this module as requiring a variant for this module.
403 for _, am := range dependencies {
404 am.BuildForApex(apexInfo)
405 }
406}
407
Paul Duffin11216db2021-03-01 14:14:52 +0000408// prebuiltApexSelectorModule is a private module type that is only created by the prebuilt_apex
409// module. It selects the apex to use and makes it available for use by prebuilt_apex and the
410// deapexer.
411type prebuiltApexSelectorModule struct {
412 android.ModuleBase
413
414 apexFileProperties ApexFileProperties
415
416 inputApex android.Path
417}
418
419func privateApexSelectorModuleFactory() android.Module {
420 module := &prebuiltApexSelectorModule{}
421 module.AddProperties(
422 &module.apexFileProperties,
423 )
424 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
425 return module
426}
427
428func (p *prebuiltApexSelectorModule) Srcs() android.Paths {
429 return android.Paths{p.inputApex}
430}
431
432func (p *prebuiltApexSelectorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
433 p.inputApex = android.SingleSourcePathFromSupplier(ctx, p.apexFileProperties.prebuiltApexSelector, "src")
434}
435
Jiyong Park09d77522019-11-18 11:16:27 +0900436type Prebuilt struct {
Jiyong Park10e926b2020-07-16 21:38:56 +0900437 prebuiltCommon
Jiyong Park09d77522019-11-18 11:16:27 +0900438
Paul Duffinbb0dc132021-05-05 16:58:08 +0100439 properties PrebuiltProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900440
Paul Duffina9c81102021-06-15 11:34:01 +0100441 inputApex android.Path
Jiyong Park09d77522019-11-18 11:16:27 +0900442}
443
Paul Duffin851f3992021-01-13 17:03:51 +0000444type ApexFileProperties struct {
Jiyong Park09d77522019-11-18 11:16:27 +0900445 // the path to the prebuilt .apex file to import.
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000446 //
447 // This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated
448 // for android_common. That is so that it will have the same arch variant as, and so be compatible
449 // with, the source `apex` module type that it replaces.
Paul Duffin11216db2021-03-01 14:14:52 +0000450 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900451 Arch struct {
452 Arm struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000453 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900454 }
455 Arm64 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000456 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900457 }
458 X86 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000459 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900460 }
461 X86_64 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000462 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900463 }
464 }
Paul Duffin851f3992021-01-13 17:03:51 +0000465}
466
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000467// prebuiltApexSelector selects the correct prebuilt APEX file for the build target.
468//
469// The ctx parameter can be for any module not just the prebuilt module so care must be taken not
470// to use methods on it that are specific to the current module.
471//
472// See the ApexFileProperties.Src property.
473func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) []string {
474 multiTargets := prebuilt.MultiTargets()
475 if len(multiTargets) != 1 {
476 ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex")
477 return nil
Paul Duffin851f3992021-01-13 17:03:51 +0000478 }
479 var src string
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000480 switch multiTargets[0].Arch.ArchType {
Paul Duffin851f3992021-01-13 17:03:51 +0000481 case android.Arm:
482 src = String(p.Arch.Arm.Src)
483 case android.Arm64:
484 src = String(p.Arch.Arm64.Src)
485 case android.X86:
486 src = String(p.Arch.X86.Src)
487 case android.X86_64:
488 src = String(p.Arch.X86_64.Src)
Paul Duffin851f3992021-01-13 17:03:51 +0000489 }
490 if src == "" {
491 src = String(p.Src)
492 }
Paul Duffin851f3992021-01-13 17:03:51 +0000493
Paul Duffinc0609c62021-03-01 17:27:16 +0000494 if src == "" {
495 ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String())
496 // Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt
497 // logic from reporting a more general, less useful message.
498 }
499
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000500 return []string{src}
Paul Duffin851f3992021-01-13 17:03:51 +0000501}
502
503type PrebuiltProperties struct {
504 ApexFileProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900505
Paul Duffina9c81102021-06-15 11:34:01 +0100506 PrebuiltCommonProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900507}
508
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700509func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool {
510 return false
511}
512
Jiyong Park09d77522019-11-18 11:16:27 +0900513func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
514 switch tag {
515 case "":
516 return android.Paths{p.outputApex}, nil
517 default:
518 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
519 }
520}
521
Jiyong Park09d77522019-11-18 11:16:27 +0900522// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
523func PrebuiltFactory() android.Module {
524 module := &Prebuilt{}
Paul Duffina9c81102021-06-15 11:34:01 +0100525 module.AddProperties(&module.properties)
526 module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
Paul Duffin064b70c2020-11-02 17:32:38 +0000527
Jiyong Park09d77522019-11-18 11:16:27 +0900528 return module
529}
530
Paul Duffin5dda3e32021-05-05 14:13:27 +0100531func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, apexFileProperties *ApexFileProperties) {
Paul Duffin11216db2021-03-01 14:14:52 +0000532 props := struct {
533 Name *string
534 }{
535 Name: proptools.StringPtr(name),
536 }
537
538 ctx.CreateModule(privateApexSelectorModuleFactory,
539 &props,
540 apexFileProperties,
541 )
542}
543
Paul Duffin5dda3e32021-05-05 14:13:27 +0100544// createDeapexerModuleIfNeeded will create a deapexer module if it is needed.
545//
Paul Duffin57f83592021-05-05 15:09:44 +0100546// A deapexer module is only needed when the prebuilt apex specifies one or more modules in either
547// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that
548// the listed modules need access to files from within the prebuilt .apex file.
Paul Duffina9c81102021-06-15 11:34:01 +0100549func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string, properties *PrebuiltCommonProperties) {
Paul Duffin5dda3e32021-05-05 14:13:27 +0100550 // Only create the deapexer module if it is needed.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100551 if len(properties.Exported_java_libs)+len(properties.Exported_bootclasspath_fragments) == 0 {
Paul Duffin5dda3e32021-05-05 14:13:27 +0100552 return
553 }
554
Paul Duffin57f83592021-05-05 15:09:44 +0100555 // Compute the deapexer properties from the transitive dependencies of this module.
Paul Duffin5466a362021-06-07 10:25:31 +0100556 commonModules := []string{}
Paul Duffinb4bbf2c2021-06-17 15:59:07 +0100557 exportedFiles := []string{}
Paul Duffin57f83592021-05-05 15:09:44 +0100558 ctx.WalkDeps(func(child, parent android.Module) bool {
559 tag := ctx.OtherModuleDependencyTag(child)
560
Paul Duffinfef55002021-06-17 14:56:05 +0100561 // If the child is not in the same apex as the parent then ignore it and all its children.
562 if !android.IsDepInSameApex(ctx, parent, child) {
563 return false
564 }
565
Paul Duffin57f83592021-05-05 15:09:44 +0100566 name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
Paul Duffinfef55002021-06-17 14:56:05 +0100567 if _, ok := tag.(android.RequiresFilesFromPrebuiltApexTag); ok {
Paul Duffin5466a362021-06-07 10:25:31 +0100568 commonModules = append(commonModules, name)
569
570 requiredFiles := child.(android.RequiredFilesFromPrebuiltApex).RequiredFilesFromPrebuiltApex(ctx)
Paul Duffinb4bbf2c2021-06-17 15:59:07 +0100571 exportedFiles = append(exportedFiles, requiredFiles...)
Paul Duffin5466a362021-06-07 10:25:31 +0100572
Paul Duffinfef55002021-06-17 14:56:05 +0100573 // Visit the dependencies of this module just in case they also require files from the
574 // prebuilt apex.
Paul Duffin57f83592021-05-05 15:09:44 +0100575 return true
576 }
577
578 return false
579 })
580
Paul Duffin3bae0682021-05-05 18:03:47 +0100581 // Create properties for deapexer module.
582 deapexerProperties := &DeapexerProperties{
Paul Duffin5466a362021-06-07 10:25:31 +0100583 // Remove any duplicates from the common modules lists as a module may be included via a direct
Paul Duffin3bae0682021-05-05 18:03:47 +0100584 // dependency as well as transitive ones.
Paul Duffin5466a362021-06-07 10:25:31 +0100585 CommonModules: android.SortedUniqueStrings(commonModules),
Paul Duffin3bae0682021-05-05 18:03:47 +0100586 }
587
588 // Populate the exported files property in a fixed order.
Paul Duffinb4bbf2c2021-06-17 15:59:07 +0100589 deapexerProperties.ExportedFiles = android.SortedUniqueStrings(exportedFiles)
Paul Duffin57f83592021-05-05 15:09:44 +0100590
Paul Duffin11216db2021-03-01 14:14:52 +0000591 props := struct {
592 Name *string
593 Selected_apex *string
594 }{
595 Name: proptools.StringPtr(deapexerName),
596 Selected_apex: proptools.StringPtr(apexFileSource),
597 }
598 ctx.CreateModule(privateDeapexerFactory,
599 &props,
600 deapexerProperties,
601 )
602}
603
604func deapexerModuleName(baseModuleName string) string {
605 return baseModuleName + ".deapexer"
606}
607
608func apexSelectorModuleName(baseModuleName string) string {
609 return baseModuleName + ".apex.selector"
610}
611
Paul Duffin064b70c2020-11-02 17:32:38 +0000612func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string {
613 // The prebuilt_apex should be depending on prebuilt modules but as this runs after
614 // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So,
615 // check to see if the prefixed name is in use first, if it is then use that, otherwise assume
616 // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module
617 // and not a renamed prebuilt module then that will be detected and reported as an error when
618 // processing the dependency in ApexInfoMutator().
Paul Duffin864116c2021-04-02 10:24:13 +0100619 prebuiltName := android.PrebuiltNameFromSource(name)
Paul Duffin064b70c2020-11-02 17:32:38 +0000620 if ctx.OtherModuleExists(prebuiltName) {
621 name = prebuiltName
622 }
623 return name
624}
625
Paul Duffina7139422021-02-08 11:01:58 +0000626type exportedDependencyTag struct {
627 blueprint.BaseDependencyTag
628 name string
629}
630
631// Mark this tag so dependencies that use it are excluded from visibility enforcement.
632//
633// This does allow any prebuilt_apex to reference any module which does open up a small window for
634// restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so
635// avoids opening up a much bigger window by widening the visibility of modules that need files
636// provided by the prebuilt_apex to include all the possible locations they may be defined, which
637// could include everything below vendor/.
638//
639// A prebuilt_apex that references a module via this tag will have to contain the appropriate files
640// corresponding to that module, otherwise it will fail when attempting to retrieve the files from
641// the .apex file. It will also have to be included in the module's apex_available property too.
642// That makes it highly unlikely that a prebuilt_apex would reference a restricted module
643// incorrectly.
644func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {}
645
Paul Duffinfef55002021-06-17 14:56:05 +0100646func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {}
647
648var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{}
649
Paul Duffina7139422021-02-08 11:01:58 +0000650var (
Paul Duffin023dba02021-04-22 01:45:29 +0100651 exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
652 exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
Paul Duffina7139422021-02-08 11:01:58 +0000653)
654
Paul Duffin5dda3e32021-05-05 14:13:27 +0100655var _ prebuiltApexModuleCreator = (*Prebuilt)(nil)
656
657// createPrebuiltApexModules creates modules necessary to export files from the prebuilt apex to the
658// build.
659//
660// If this needs to make files from within a `.apex` file available for use by other Soong modules,
661// e.g. make dex implementation jars available for java_import modules listed in exported_java_libs,
662// it does so as follows:
663//
664// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and
665// makes them available for use by other modules, at both Soong and ninja levels.
666//
667// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what
668// an `apex` module does. That ensures that code which looks for specific apex variant, e.g.
669// dexpreopt, will work the same way from source and prebuilt.
670//
671// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto
672// itself so that they can retrieve the file paths to those files.
673//
674// It also creates a child module `selector` that is responsible for selecting the appropriate
675// input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons:
676// 1. To dedup the selection logic so it only runs in one module.
677// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an
678// `apex_set`.
679//
680// prebuilt_apex
681// / | \
682// / | \
683// V V V
684// selector <--- deapexer <--- exported java lib
685//
686func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
687 baseModuleName := p.BaseModuleName()
688
689 apexSelectorModuleName := apexSelectorModuleName(baseModuleName)
690 createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties)
691
692 apexFileSource := ":" + apexSelectorModuleName
Paul Duffina9c81102021-06-15 11:34:01 +0100693 createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, p.prebuiltCommonProperties)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100694
695 // Add a source reference to retrieve the selected apex from the selector module.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100696 p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100697}
698
Paul Duffin57f83592021-05-05 15:09:44 +0100699func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
700 p.prebuiltApexContentsDeps(ctx)
Paul Duffin064b70c2020-11-02 17:32:38 +0000701}
702
703var _ ApexInfoMutator = (*Prebuilt)(nil)
704
Paul Duffin064b70c2020-11-02 17:32:38 +0000705func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Paul Duffindfd33262021-04-06 17:02:08 +0100706 p.apexInfoMutator(mctx)
Jiyong Park09d77522019-11-18 11:16:27 +0900707}
708
709func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park09d77522019-11-18 11:16:27 +0900710 // TODO(jungjw): Check the key validity.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100711 p.inputApex = android.OptionalPathForModuleSrc(ctx, p.prebuiltCommonProperties.Selected_apex).Path()
Jiyong Park09d77522019-11-18 11:16:27 +0900712 p.installDir = android.PathForModuleInstall(ctx, "apex")
713 p.installFilename = p.InstallFilename()
714 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
715 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
716 }
717 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
718 ctx.Build(pctx, android.BuildParams{
719 Rule: android.Cp,
720 Input: p.inputApex,
721 Output: p.outputApex,
722 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900723
724 if p.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800725 p.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900726 return
727 }
728
Paul Duffina35f8db2021-06-15 19:10:11 +0100729 // Save the files that need to be made available to Make.
730 p.initApexFilesForAndroidMk(ctx)
731
Jiyong Park09d77522019-11-18 11:16:27 +0900732 if p.installable() {
733 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
734 }
735
Jooyung Han002ab682020-01-08 01:57:58 +0900736 // in case that prebuilt_apex replaces source apex (using prefer: prop)
737 p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx)
738 // or that prebuilt_apex overrides other apexes (using overrides: prop)
Paul Duffina9c81102021-06-15 11:34:01 +0100739 for _, overridden := range p.prebuiltCommonProperties.Overrides {
Jooyung Han002ab682020-01-08 01:57:58 +0900740 p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
741 }
Jiyong Park09d77522019-11-18 11:16:27 +0900742}
743
Paul Duffin24704672021-04-06 16:09:30 +0100744// prebuiltApexExtractorModule is a private module type that is only created by the prebuilt_apex
745// module. It extracts the correct apex to use and makes it available for use by apex_set.
746type prebuiltApexExtractorModule struct {
747 android.ModuleBase
748
749 properties ApexExtractorProperties
750
751 extractedApex android.WritablePath
752}
753
754func privateApexExtractorModuleFactory() android.Module {
755 module := &prebuiltApexExtractorModule{}
756 module.AddProperties(
757 &module.properties,
758 )
759 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
760 return module
761}
762
763func (p *prebuiltApexExtractorModule) Srcs() android.Paths {
764 return android.Paths{p.extractedApex}
765}
766
767func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
768 srcsSupplier := func(ctx android.BaseModuleContext, prebuilt android.Module) []string {
769 return p.properties.prebuiltSrcs(ctx)
770 }
771 apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set")
772 p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base())
773 ctx.Build(pctx,
774 android.BuildParams{
775 Rule: extractMatchingApex,
776 Description: "Extract an apex from an apex set",
777 Inputs: android.Paths{apexSet},
778 Output: p.extractedApex,
779 Args: map[string]string{
780 "abis": strings.Join(java.SupportedAbis(ctx), ","),
781 "allow-prereleased": strconv.FormatBool(proptools.Bool(p.properties.Prerelease)),
782 "sdk-version": ctx.Config().PlatformSdkVersion().String(),
783 },
784 })
785}
786
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700787type ApexSet struct {
Jiyong Park10e926b2020-07-16 21:38:56 +0900788 prebuiltCommon
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700789
790 properties ApexSetProperties
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700791}
792
Paul Duffin24704672021-04-06 16:09:30 +0100793type ApexExtractorProperties struct {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700794 // the .apks file path that contains prebuilt apex files to be extracted.
795 Set *string
796
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700797 Sanitized struct {
798 None struct {
799 Set *string
800 }
801 Address struct {
802 Set *string
803 }
804 Hwaddress struct {
805 Set *string
806 }
807 }
808
Paul Duffin24704672021-04-06 16:09:30 +0100809 // apexes in this set use prerelease SDK version
810 Prerelease *bool
811}
812
813func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string {
814 var srcs []string
815 if e.Set != nil {
816 srcs = append(srcs, *e.Set)
817 }
818
819 var sanitizers []string
820 if ctx.Host() {
821 sanitizers = ctx.Config().SanitizeHost()
822 } else {
823 sanitizers = ctx.Config().SanitizeDevice()
824 }
825
826 if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil {
827 srcs = append(srcs, *e.Sanitized.Address.Set)
828 } else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil {
829 srcs = append(srcs, *e.Sanitized.Hwaddress.Set)
830 } else if e.Sanitized.None.Set != nil {
831 srcs = append(srcs, *e.Sanitized.None.Set)
832 }
833
834 return srcs
835}
836
837type ApexSetProperties struct {
838 ApexExtractorProperties
839
Paul Duffina9c81102021-06-15 11:34:01 +0100840 PrebuiltCommonProperties
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700841}
842
843func (a *ApexSet) hasSanitizedSource(sanitizer string) bool {
844 if sanitizer == "address" {
845 return a.properties.Sanitized.Address.Set != nil
846 }
847 if sanitizer == "hwaddress" {
848 return a.properties.Sanitized.Hwaddress.Set != nil
849 }
850
851 return false
852}
853
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700854// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
855func apexSetFactory() android.Module {
856 module := &ApexSet{}
Paul Duffina9c81102021-06-15 11:34:01 +0100857 module.AddProperties(&module.properties)
858 module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
Paul Duffin24704672021-04-06 16:09:30 +0100859
Paul Duffin24704672021-04-06 16:09:30 +0100860 return module
861}
862
Paul Duffin5dda3e32021-05-05 14:13:27 +0100863func createApexExtractorModule(ctx android.TopDownMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) {
Paul Duffin24704672021-04-06 16:09:30 +0100864 props := struct {
865 Name *string
866 }{
867 Name: proptools.StringPtr(name),
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700868 }
869
Paul Duffin24704672021-04-06 16:09:30 +0100870 ctx.CreateModule(privateApexExtractorModuleFactory,
871 &props,
872 apexExtractorProperties,
873 )
874}
875
876func apexExtractorModuleName(baseModuleName string) string {
877 return baseModuleName + ".apex.extractor"
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700878}
879
Paul Duffin5dda3e32021-05-05 14:13:27 +0100880var _ prebuiltApexModuleCreator = (*ApexSet)(nil)
881
882// createPrebuiltApexModules creates modules necessary to export files from the apex set to other
883// modules.
884//
885// This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a
886// prebuilt_apex except that instead of creating a selector module which selects one .apex file
887// from those provided this creates an extractor module which extracts the appropriate .apex file
888// from the zip file containing them.
889func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
890 baseModuleName := a.BaseModuleName()
891
892 apexExtractorModuleName := apexExtractorModuleName(baseModuleName)
893 createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties)
894
895 apexFileSource := ":" + apexExtractorModuleName
Paul Duffina9c81102021-06-15 11:34:01 +0100896 createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, a.prebuiltCommonProperties)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100897
898 // After passing the arch specific src properties to the creating the apex selector module
Paul Duffinbb0dc132021-05-05 16:58:08 +0100899 a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100900}
901
Paul Duffin57f83592021-05-05 15:09:44 +0100902func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
903 a.prebuiltApexContentsDeps(ctx)
Paul Duffinf58fd9a2021-04-06 16:00:22 +0100904}
905
906var _ ApexInfoMutator = (*ApexSet)(nil)
907
908func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) {
909 a.apexInfoMutator(mctx)
910}
911
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700912func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
913 a.installFilename = a.InstallFilename()
914 if !strings.HasSuffix(a.installFilename, imageApexSuffix) {
915 ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
916 }
917
Paul Duffinbb0dc132021-05-05 16:58:08 +0100918 inputApex := android.OptionalPathForModuleSrc(ctx, a.prebuiltCommonProperties.Selected_apex).Path()
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700919 a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
Paul Duffin24704672021-04-06 16:09:30 +0100920 ctx.Build(pctx, android.BuildParams{
921 Rule: android.Cp,
922 Input: inputApex,
923 Output: a.outputApex,
924 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900925
926 if a.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800927 a.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900928 return
929 }
930
Paul Duffina35f8db2021-06-15 19:10:11 +0100931 // Save the files that need to be made available to Make.
932 a.initApexFilesForAndroidMk(ctx)
933
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700934 a.installDir = android.PathForModuleInstall(ctx, "apex")
935 if a.installable() {
936 ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
937 }
938
939 // in case that apex_set replaces source apex (using prefer: prop)
940 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
941 // or that apex_set overrides other apexes (using overrides: prop)
Paul Duffina9c81102021-06-15 11:34:01 +0100942 for _, overridden := range a.prebuiltCommonProperties.Overrides {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700943 a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
944 }
Jooyung Han29637162020-06-30 06:34:23 +0900945
946 if ctx.Config().InstallExtraFlattenedApexes() {
947 // flattened apex should be in /system_ext/apex
948 flattenedApexDir := android.PathForModuleInstall(&systemExtContext{ctx}, "apex", a.BaseModuleName())
949 a.postInstallCommands = append(a.postInstallCommands,
950 fmt.Sprintf("$(HOST_OUT_EXECUTABLES)/deapexer --debugfs_path $(HOST_OUT_EXECUTABLES)/debugfs extract %s %s",
951 a.outputApex.String(),
952 flattenedApexDir.ToMakePath().String(),
953 ))
954 a.hostRequired = []string{"deapexer", "debugfs"}
955 }
956}
957
958type systemExtContext struct {
959 android.ModuleContext
960}
961
962func (*systemExtContext) SystemExtSpecific() bool {
963 return true
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700964}