blob: 9504b079761ee91e1a1f55e9bbe124dd3463d03f [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 Duffinc30aea22021-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"
25 "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 {
Paul Duffinef6b6952021-06-15 11:34:01 +010049 android.ModuleBase
Paul Duffinbb0dc132021-05-05 16:58:08 +010050 prebuilt android.Prebuilt
Paul Duffindfd33262021-04-06 17:02:08 +010051
Paul Duffinbb0dc132021-05-05 16:58:08 +010052 // Properties common to both prebuilt_apex and apex_set.
Paul Duffinef6b6952021-06-15 11:34:01 +010053 prebuiltCommonProperties *PrebuiltCommonProperties
54
55 installDir android.InstallPath
56 installFilename string
57 outputApex android.WritablePath
58
Paul Duffinc30aea22021-06-15 19:10:11 +010059 // A list of apexFile objects created in prebuiltCommon.initApexFilesForAndroidMk which are used
60 // to create make modules in prebuiltCommon.AndroidMkEntries.
61 apexFilesForAndroidMk []apexFile
62
Paul Duffinef6b6952021-06-15 11:34:01 +010063 // list of commands to create symlinks for backward compatibility.
64 // these commands will be attached as LOCAL_POST_INSTALL_CMD
65 compatSymlinks []string
66
67 hostRequired []string
68 postInstallCommands []string
Jiyong Park10e926b2020-07-16 21:38:56 +090069}
70
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -070071type sanitizedPrebuilt interface {
72 hasSanitizedSource(sanitizer string) bool
73}
74
Paul Duffinef6b6952021-06-15 11:34:01 +010075type PrebuiltCommonProperties struct {
Paul Duffinbb0dc132021-05-05 16:58:08 +010076 SelectedApexProperties
77
Jiyong Park10e926b2020-07-16 21:38:56 +090078 ForceDisable bool `blueprint:"mutated"`
Paul Duffin3bae0682021-05-05 18:03:47 +010079
Paul Duffinef6b6952021-06-15 11:34:01 +010080 // whether the extracted apex file is installable.
81 Installable *bool
82
83 // optional name for the installed apex. If unspecified, name of the
84 // module is used as the file name
85 Filename *string
86
87 // names of modules to be overridden. Listed modules can only be other binaries
88 // (in Make or Soong).
89 // This does not completely prevent installation of the overridden binaries, but if both
90 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
91 // from PRODUCT_PACKAGES.
92 Overrides []string
93
Paul Duffin3bae0682021-05-05 18:03:47 +010094 // List of java libraries that are embedded inside this prebuilt APEX bundle and for which this
95 // APEX bundle will create an APEX variant and provide dex implementation jars for use by
96 // dexpreopt and boot jars package check.
97 Exported_java_libs []string
98
99 // List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX
100 // bundle will create an APEX variant.
101 Exported_bootclasspath_fragments []string
Jiyong Park10e926b2020-07-16 21:38:56 +0900102}
103
Paul Duffinef6b6952021-06-15 11:34:01 +0100104// initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the
105// module that is common to Prebuilt and ApexSet.
106func (p *prebuiltCommon) initPrebuiltCommon(module android.Module, properties *PrebuiltCommonProperties) {
107 p.prebuiltCommonProperties = properties
108 android.InitSingleSourcePrebuiltModule(module.(android.PrebuiltInterface), properties, "Selected_apex")
109 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
110}
111
Jiyong Park10e926b2020-07-16 21:38:56 +0900112func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
113 return &p.prebuilt
114}
115
116func (p *prebuiltCommon) isForceDisabled() bool {
Paul Duffinbb0dc132021-05-05 16:58:08 +0100117 return p.prebuiltCommonProperties.ForceDisable
Jiyong Park10e926b2020-07-16 21:38:56 +0900118}
119
120func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool {
121 // If the device is configured to use flattened APEX, force disable the prebuilt because
122 // the prebuilt is a non-flattened one.
123 forceDisable := ctx.Config().FlattenApex()
124
125 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
126 // to build the prebuilts themselves.
127 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
128
129 // Force disable the prebuilts when coverage is enabled.
130 forceDisable = forceDisable || ctx.DeviceConfig().NativeCoverageEnabled()
131 forceDisable = forceDisable || ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
132
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700133 // b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source
134 sanitized := ctx.Module().(sanitizedPrebuilt)
135 forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address"))
136 forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress"))
Jiyong Park10e926b2020-07-16 21:38:56 +0900137
138 if forceDisable && p.prebuilt.SourceExists() {
Paul Duffinbb0dc132021-05-05 16:58:08 +0100139 p.prebuiltCommonProperties.ForceDisable = true
Jiyong Park10e926b2020-07-16 21:38:56 +0900140 return true
141 }
142 return false
143}
144
Paul Duffinef6b6952021-06-15 11:34:01 +0100145func (p *prebuiltCommon) InstallFilename() string {
146 return proptools.StringDefault(p.prebuiltCommonProperties.Filename, p.BaseModuleName()+imageApexSuffix)
147}
148
149func (p *prebuiltCommon) Name() string {
150 return p.prebuilt.Name(p.ModuleBase.Name())
151}
152
153func (p *prebuiltCommon) Overrides() []string {
154 return p.prebuiltCommonProperties.Overrides
155}
156
157func (p *prebuiltCommon) installable() bool {
158 return proptools.BoolDefault(p.prebuiltCommonProperties.Installable, true)
159}
160
Paul Duffinc30aea22021-06-15 19:10:11 +0100161// initApexFilesForAndroidMk initializes the prebuiltCommon.apexFilesForAndroidMk field from the
162// modules that this depends upon.
163func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) {
164 // Walk the dependencies of this module looking for the java modules that it exports.
165 ctx.WalkDeps(func(child, parent android.Module) bool {
166 tag := ctx.OtherModuleDependencyTag(child)
167
168 name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
169 if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
170 // If the exported java module provides a dex jar path then add it to the list of apexFiles.
171 path := child.(interface{ DexJarBuildPath() android.Path }).DexJarBuildPath()
172 if path != nil {
173 p.apexFilesForAndroidMk = append(p.apexFilesForAndroidMk, apexFile{
174 module: child,
175 moduleDir: ctx.OtherModuleDir(child),
176 androidMkModuleName: name,
177 builtFile: path,
178 class: javaSharedLib,
179 })
180 }
181 } else if tag == exportedBootclasspathFragmentTag {
182 // Visit the children of the bootclasspath_fragment.
183 return true
184 }
185
186 return false
187 })
188}
189
Paul Duffinef6b6952021-06-15 11:34:01 +0100190func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffinc30aea22021-06-15 19:10:11 +0100191 entriesList := []android.AndroidMkEntries{
Paul Duffinef6b6952021-06-15 11:34:01 +0100192 {
193 Class: "ETC",
194 OutputFile: android.OptionalPathForPath(p.outputApex),
195 Include: "$(BUILD_PREBUILT)",
196 Host_required: p.hostRequired,
197 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
198 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
199 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
200 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
201 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
202 entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.prebuiltCommonProperties.Overrides...)
203 postInstallCommands := append([]string{}, p.postInstallCommands...)
204 postInstallCommands = append(postInstallCommands, p.compatSymlinks...)
205 if len(postInstallCommands) > 0 {
206 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && "))
207 }
208 },
209 },
210 },
211 }
Paul Duffinc30aea22021-06-15 19:10:11 +0100212
213 // Iterate over the apexFilesForAndroidMk list and create an AndroidMkEntries struct for each
214 // file. This provides similar behavior to that provided in apexBundle.AndroidMk() as it makes the
215 // apex specific variants of the exported java modules available for use from within make.
216 apexName := p.BaseModuleName()
217 for _, fi := range p.apexFilesForAndroidMk {
Paul Duffin9dc8c542021-06-17 13:33:09 +0100218 entries := p.createEntriesForApexFile(fi, apexName)
Paul Duffinc30aea22021-06-15 19:10:11 +0100219 entriesList = append(entriesList, entries)
220 }
221
222 return entriesList
Paul Duffinef6b6952021-06-15 11:34:01 +0100223}
224
Paul Duffin9dc8c542021-06-17 13:33:09 +0100225// createEntriesForApexFile creates an AndroidMkEntries for the supplied apexFile
226func (p *prebuiltCommon) createEntriesForApexFile(fi apexFile, apexName string) android.AndroidMkEntries {
227 moduleName := fi.androidMkModuleName + "." + apexName
228 entries := android.AndroidMkEntries{
229 Class: fi.class.nameInMake(),
230 OverrideName: moduleName,
231 OutputFile: android.OptionalPathForPath(fi.builtFile),
232 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
233 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
234 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
235 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
236
237 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
238 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
239 // we will have foo.jar.jar
240 entries.SetString("LOCAL_MODULE_STEM", strings.TrimSuffix(fi.stem(), ".jar"))
241 var classesJar android.Path
242 var headerJar android.Path
243 if javaModule, ok := fi.module.(java.ApexDependency); ok {
244 classesJar = javaModule.ImplementationAndResourcesJars()[0]
245 headerJar = javaModule.HeaderJars()[0]
246 } else {
247 classesJar = fi.builtFile
248 headerJar = fi.builtFile
249 }
250 entries.SetString("LOCAL_SOONG_CLASSES_JAR", classesJar.String())
251 entries.SetString("LOCAL_SOONG_HEADER_JAR", headerJar.String())
252 entries.SetString("LOCAL_SOONG_DEX_JAR", fi.builtFile.String())
253 entries.SetString("LOCAL_DEX_PREOPT", "false")
254 },
255 },
256 ExtraFooters: []android.AndroidMkExtraFootersFunc{
257 func(w io.Writer, name, prefix, moduleDir string) {
258 // m <module_name> will build <module_name>.<apex_name> as well.
259 if fi.androidMkModuleName != moduleName {
260 fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
261 fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
262 }
263 },
264 },
265 }
266 return entries
267}
268
Paul Duffin5dda3e32021-05-05 14:13:27 +0100269// prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and
270// apex_set in order to create the modules needed to provide access to the prebuilt .apex file.
271type prebuiltApexModuleCreator interface {
272 createPrebuiltApexModules(ctx android.TopDownMutatorContext)
273}
274
275// prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the
276// prebuiltApexModuleCreator's createPrebuiltApexModules method.
277//
278// It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it
279// will need to access dependencies added by that (exported modules) but must run before the
280// DepsMutator so that the deapexer module it creates can add dependencies onto itself from the
281// exported modules.
282func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) {
283 module := ctx.Module()
284 if creator, ok := module.(prebuiltApexModuleCreator); ok {
285 creator.createPrebuiltApexModules(ctx)
286 }
287}
288
Paul Duffin57f83592021-05-05 15:09:44 +0100289// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
290func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
291 module := ctx.Module()
Paul Duffindfd33262021-04-06 17:02:08 +0100292 // Add dependencies onto the java modules that represent the java libraries that are provided by
293 // and exported from this prebuilt apex.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100294 for _, exported := range p.prebuiltCommonProperties.Exported_java_libs {
Paul Duffin57f83592021-05-05 15:09:44 +0100295 dep := android.PrebuiltNameFromSource(exported)
296 ctx.AddDependency(module, exportedJavaLibTag, dep)
Paul Duffindfd33262021-04-06 17:02:08 +0100297 }
Paul Duffin023dba02021-04-22 01:45:29 +0100298
299 // Add dependencies onto the bootclasspath fragment modules that are exported from this prebuilt
300 // apex.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100301 for _, exported := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
Paul Duffin57f83592021-05-05 15:09:44 +0100302 dep := android.PrebuiltNameFromSource(exported)
303 ctx.AddDependency(module, exportedBootclasspathFragmentTag, dep)
Paul Duffin023dba02021-04-22 01:45:29 +0100304 }
Paul Duffindfd33262021-04-06 17:02:08 +0100305}
306
Paul Duffinb17d0442021-05-05 12:07:00 +0100307// Implements android.DepInInSameApex
308func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
309 tag := ctx.OtherModuleDependencyTag(dep)
310 _, ok := tag.(exportedDependencyTag)
311 return ok
312}
313
Paul Duffindfd33262021-04-06 17:02:08 +0100314// apexInfoMutator marks any modules for which this apex exports a file as requiring an apex
315// specific variant and checks that they are supported.
316//
317// The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are
318// associated with the apex specific variant using the ApexInfoProvider for later retrieval.
319//
320// Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants
321// across prebuilt_apex modules. That is because there is no way to determine whether two
322// prebuilt_apex modules that export files for the same module are compatible. e.g. they could have
323// been built from different source at different times or they could have been built with different
324// build options that affect the libraries.
325//
326// While it may be possible to provide sufficient information to determine whether two prebuilt_apex
327// modules were compatible it would be a lot of work and would not provide much benefit for a couple
328// of reasons:
329// * The number of prebuilt_apex modules that will be exporting files for the same module will be
330// low as the prebuilt_apex only exports files for the direct dependencies that require it and
331// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a
332// few com.android.art* apex files that contain the same contents and could export files for the
333// same modules but only one of them needs to do so. Contrast that with source apex modules which
334// need apex specific variants for every module that contributes code to the apex, whether direct
335// or indirect.
336// * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some
337// extra copying of files. Contrast that with source apex modules that has to build each variant
338// from source.
339func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) {
340
341 // Collect direct dependencies into contents.
342 contents := make(map[string]android.ApexMembership)
343
344 // Collect the list of dependencies.
345 var dependencies []android.ApexModule
Paul Duffinb17d0442021-05-05 12:07:00 +0100346 mctx.WalkDeps(func(child, parent android.Module) bool {
347 // If the child is not in the same apex as the parent then exit immediately and do not visit
348 // any of the child's dependencies.
349 if !android.IsDepInSameApex(mctx, parent, child) {
350 return false
351 }
352
353 tag := mctx.OtherModuleDependencyTag(child)
354 depName := mctx.OtherModuleName(child)
Paul Duffin023dba02021-04-22 01:45:29 +0100355 if exportedTag, ok := tag.(exportedDependencyTag); ok {
356 propertyName := exportedTag.name
Paul Duffindfd33262021-04-06 17:02:08 +0100357
358 // It is an error if the other module is not a prebuilt.
Paul Duffinb17d0442021-05-05 12:07:00 +0100359 if !android.IsModulePrebuilt(child) {
Paul Duffin023dba02021-04-22 01:45:29 +0100360 mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName)
Paul Duffinb17d0442021-05-05 12:07:00 +0100361 return false
Paul Duffindfd33262021-04-06 17:02:08 +0100362 }
363
364 // It is an error if the other module is not an ApexModule.
Paul Duffinb17d0442021-05-05 12:07:00 +0100365 if _, ok := child.(android.ApexModule); !ok {
Paul Duffin023dba02021-04-22 01:45:29 +0100366 mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName)
Paul Duffinb17d0442021-05-05 12:07:00 +0100367 return false
Paul Duffindfd33262021-04-06 17:02:08 +0100368 }
Paul Duffindfd33262021-04-06 17:02:08 +0100369 }
Paul Duffinb17d0442021-05-05 12:07:00 +0100370
371 // Strip off the prebuilt_ prefix if present before storing content to ensure consistent
372 // behavior whether there is a corresponding source module present or not.
373 depName = android.RemoveOptionalPrebuiltPrefix(depName)
374
375 // Remember if this module was added as a direct dependency.
376 direct := parent == mctx.Module()
377 contents[depName] = contents[depName].Add(direct)
378
379 // Add the module to the list of dependencies that need to have an APEX variant.
380 dependencies = append(dependencies, child.(android.ApexModule))
381
382 return true
Paul Duffindfd33262021-04-06 17:02:08 +0100383 })
384
385 // Create contents for the prebuilt_apex and store it away for later use.
386 apexContents := android.NewApexContents(contents)
387 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
388 Contents: apexContents,
389 })
390
391 // Create an ApexInfo for the prebuilt_apex.
Martin Stjernholmc4f4ced2021-05-27 11:17:00 +0000392 apexVariationName := android.RemoveOptionalPrebuiltPrefix(mctx.ModuleName())
Paul Duffindfd33262021-04-06 17:02:08 +0100393 apexInfo := android.ApexInfo{
Martin Stjernholmc4f4ced2021-05-27 11:17:00 +0000394 ApexVariationName: apexVariationName,
395 InApexVariants: []string{apexVariationName},
396 InApexModules: []string{apexVariationName},
Paul Duffindfd33262021-04-06 17:02:08 +0100397 ApexContents: []*android.ApexContents{apexContents},
398 ForPrebuiltApex: true,
399 }
400
401 // Mark the dependencies of this module as requiring a variant for this module.
402 for _, am := range dependencies {
403 am.BuildForApex(apexInfo)
404 }
405}
406
Paul Duffin11216db2021-03-01 14:14:52 +0000407// prebuiltApexSelectorModule is a private module type that is only created by the prebuilt_apex
408// module. It selects the apex to use and makes it available for use by prebuilt_apex and the
409// deapexer.
410type prebuiltApexSelectorModule struct {
411 android.ModuleBase
412
413 apexFileProperties ApexFileProperties
414
415 inputApex android.Path
416}
417
418func privateApexSelectorModuleFactory() android.Module {
419 module := &prebuiltApexSelectorModule{}
420 module.AddProperties(
421 &module.apexFileProperties,
422 )
423 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
424 return module
425}
426
427func (p *prebuiltApexSelectorModule) Srcs() android.Paths {
428 return android.Paths{p.inputApex}
429}
430
431func (p *prebuiltApexSelectorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
432 p.inputApex = android.SingleSourcePathFromSupplier(ctx, p.apexFileProperties.prebuiltApexSelector, "src")
433}
434
Jiyong Park09d77522019-11-18 11:16:27 +0900435type Prebuilt struct {
Jiyong Park10e926b2020-07-16 21:38:56 +0900436 prebuiltCommon
Jiyong Park09d77522019-11-18 11:16:27 +0900437
Paul Duffinbb0dc132021-05-05 16:58:08 +0100438 properties PrebuiltProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900439
Paul Duffinef6b6952021-06-15 11:34:01 +0100440 inputApex android.Path
Jiyong Park09d77522019-11-18 11:16:27 +0900441}
442
Paul Duffin851f3992021-01-13 17:03:51 +0000443type ApexFileProperties struct {
Jiyong Park09d77522019-11-18 11:16:27 +0900444 // the path to the prebuilt .apex file to import.
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000445 //
446 // This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated
447 // for android_common. That is so that it will have the same arch variant as, and so be compatible
448 // with, the source `apex` module type that it replaces.
Paul Duffin11216db2021-03-01 14:14:52 +0000449 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900450 Arch struct {
451 Arm struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000452 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900453 }
454 Arm64 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000455 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900456 }
457 X86 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000458 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900459 }
460 X86_64 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000461 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900462 }
463 }
Paul Duffin851f3992021-01-13 17:03:51 +0000464}
465
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000466// prebuiltApexSelector selects the correct prebuilt APEX file for the build target.
467//
468// The ctx parameter can be for any module not just the prebuilt module so care must be taken not
469// to use methods on it that are specific to the current module.
470//
471// See the ApexFileProperties.Src property.
472func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) []string {
473 multiTargets := prebuilt.MultiTargets()
474 if len(multiTargets) != 1 {
475 ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex")
476 return nil
Paul Duffin851f3992021-01-13 17:03:51 +0000477 }
478 var src string
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000479 switch multiTargets[0].Arch.ArchType {
Paul Duffin851f3992021-01-13 17:03:51 +0000480 case android.Arm:
481 src = String(p.Arch.Arm.Src)
482 case android.Arm64:
483 src = String(p.Arch.Arm64.Src)
484 case android.X86:
485 src = String(p.Arch.X86.Src)
486 case android.X86_64:
487 src = String(p.Arch.X86_64.Src)
Paul Duffin851f3992021-01-13 17:03:51 +0000488 }
489 if src == "" {
490 src = String(p.Src)
491 }
Paul Duffin851f3992021-01-13 17:03:51 +0000492
Paul Duffinc0609c62021-03-01 17:27:16 +0000493 if src == "" {
494 ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String())
495 // Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt
496 // logic from reporting a more general, less useful message.
497 }
498
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000499 return []string{src}
Paul Duffin851f3992021-01-13 17:03:51 +0000500}
501
502type PrebuiltProperties struct {
503 ApexFileProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900504
Paul Duffinef6b6952021-06-15 11:34:01 +0100505 PrebuiltCommonProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900506}
507
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700508func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool {
509 return false
510}
511
Jiyong Park09d77522019-11-18 11:16:27 +0900512func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
513 switch tag {
514 case "":
515 return android.Paths{p.outputApex}, nil
516 default:
517 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
518 }
519}
520
Jiyong Park09d77522019-11-18 11:16:27 +0900521// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
522func PrebuiltFactory() android.Module {
523 module := &Prebuilt{}
Paul Duffinef6b6952021-06-15 11:34:01 +0100524 module.AddProperties(&module.properties)
525 module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
Paul Duffin064b70c2020-11-02 17:32:38 +0000526
Jiyong Park09d77522019-11-18 11:16:27 +0900527 return module
528}
529
Paul Duffin5dda3e32021-05-05 14:13:27 +0100530func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, apexFileProperties *ApexFileProperties) {
Paul Duffin11216db2021-03-01 14:14:52 +0000531 props := struct {
532 Name *string
533 }{
534 Name: proptools.StringPtr(name),
535 }
536
537 ctx.CreateModule(privateApexSelectorModuleFactory,
538 &props,
539 apexFileProperties,
540 )
541}
542
Paul Duffin5dda3e32021-05-05 14:13:27 +0100543// createDeapexerModuleIfNeeded will create a deapexer module if it is needed.
544//
Paul Duffin57f83592021-05-05 15:09:44 +0100545// A deapexer module is only needed when the prebuilt apex specifies one or more modules in either
546// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that
547// the listed modules need access to files from within the prebuilt .apex file.
Paul Duffinef6b6952021-06-15 11:34:01 +0100548func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string, properties *PrebuiltCommonProperties) {
Paul Duffin5dda3e32021-05-05 14:13:27 +0100549 // Only create the deapexer module if it is needed.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100550 if len(properties.Exported_java_libs)+len(properties.Exported_bootclasspath_fragments) == 0 {
Paul Duffin5dda3e32021-05-05 14:13:27 +0100551 return
552 }
553
Paul Duffin57f83592021-05-05 15:09:44 +0100554 // Compute the deapexer properties from the transitive dependencies of this module.
Paul Duffinb5084052021-06-07 10:25:31 +0100555 commonModules := []string{}
Paul Duffin034196d2021-06-17 15:59:07 +0100556 exportedFiles := []string{}
Paul Duffin57f83592021-05-05 15:09:44 +0100557 ctx.WalkDeps(func(child, parent android.Module) bool {
558 tag := ctx.OtherModuleDependencyTag(child)
559
Paul Duffin7db57e02021-06-17 14:56:05 +0100560 // If the child is not in the same apex as the parent then ignore it and all its children.
561 if !android.IsDepInSameApex(ctx, parent, child) {
562 return false
563 }
564
Paul Duffin57f83592021-05-05 15:09:44 +0100565 name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
Paul Duffin7db57e02021-06-17 14:56:05 +0100566 if _, ok := tag.(android.RequiresFilesFromPrebuiltApexTag); ok {
Paul Duffinb5084052021-06-07 10:25:31 +0100567 commonModules = append(commonModules, name)
568
569 requiredFiles := child.(android.RequiredFilesFromPrebuiltApex).RequiredFilesFromPrebuiltApex(ctx)
Paul Duffin034196d2021-06-17 15:59:07 +0100570 exportedFiles = append(exportedFiles, requiredFiles...)
Paul Duffinb5084052021-06-07 10:25:31 +0100571
Paul Duffin7db57e02021-06-17 14:56:05 +0100572 // Visit the dependencies of this module just in case they also require files from the
573 // prebuilt apex.
Paul Duffin57f83592021-05-05 15:09:44 +0100574 return true
575 }
576
577 return false
578 })
579
Paul Duffin3bae0682021-05-05 18:03:47 +0100580 // Create properties for deapexer module.
581 deapexerProperties := &DeapexerProperties{
Paul Duffinb5084052021-06-07 10:25:31 +0100582 // Remove any duplicates from the common modules lists as a module may be included via a direct
Paul Duffin3bae0682021-05-05 18:03:47 +0100583 // dependency as well as transitive ones.
Paul Duffinb5084052021-06-07 10:25:31 +0100584 CommonModules: android.SortedUniqueStrings(commonModules),
Paul Duffin3bae0682021-05-05 18:03:47 +0100585 }
586
587 // Populate the exported files property in a fixed order.
Paul Duffin034196d2021-06-17 15:59:07 +0100588 deapexerProperties.ExportedFiles = android.SortedUniqueStrings(exportedFiles)
Paul Duffin57f83592021-05-05 15:09:44 +0100589
Paul Duffin11216db2021-03-01 14:14:52 +0000590 props := struct {
591 Name *string
592 Selected_apex *string
593 }{
594 Name: proptools.StringPtr(deapexerName),
595 Selected_apex: proptools.StringPtr(apexFileSource),
596 }
597 ctx.CreateModule(privateDeapexerFactory,
598 &props,
599 deapexerProperties,
600 )
601}
602
603func deapexerModuleName(baseModuleName string) string {
604 return baseModuleName + ".deapexer"
605}
606
607func apexSelectorModuleName(baseModuleName string) string {
608 return baseModuleName + ".apex.selector"
609}
610
Paul Duffin064b70c2020-11-02 17:32:38 +0000611func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string {
612 // The prebuilt_apex should be depending on prebuilt modules but as this runs after
613 // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So,
614 // check to see if the prefixed name is in use first, if it is then use that, otherwise assume
615 // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module
616 // and not a renamed prebuilt module then that will be detected and reported as an error when
617 // processing the dependency in ApexInfoMutator().
Paul Duffin864116c2021-04-02 10:24:13 +0100618 prebuiltName := android.PrebuiltNameFromSource(name)
Paul Duffin064b70c2020-11-02 17:32:38 +0000619 if ctx.OtherModuleExists(prebuiltName) {
620 name = prebuiltName
621 }
622 return name
623}
624
Paul Duffina7139422021-02-08 11:01:58 +0000625type exportedDependencyTag struct {
626 blueprint.BaseDependencyTag
627 name string
628}
629
630// Mark this tag so dependencies that use it are excluded from visibility enforcement.
631//
632// This does allow any prebuilt_apex to reference any module which does open up a small window for
633// restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so
634// avoids opening up a much bigger window by widening the visibility of modules that need files
635// provided by the prebuilt_apex to include all the possible locations they may be defined, which
636// could include everything below vendor/.
637//
638// A prebuilt_apex that references a module via this tag will have to contain the appropriate files
639// corresponding to that module, otherwise it will fail when attempting to retrieve the files from
640// the .apex file. It will also have to be included in the module's apex_available property too.
641// That makes it highly unlikely that a prebuilt_apex would reference a restricted module
642// incorrectly.
643func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {}
644
Paul Duffin7db57e02021-06-17 14:56:05 +0100645func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {}
646
647var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{}
648
Paul Duffina7139422021-02-08 11:01:58 +0000649var (
Paul Duffin023dba02021-04-22 01:45:29 +0100650 exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
651 exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
Paul Duffina7139422021-02-08 11:01:58 +0000652)
653
Paul Duffin5dda3e32021-05-05 14:13:27 +0100654var _ prebuiltApexModuleCreator = (*Prebuilt)(nil)
655
656// createPrebuiltApexModules creates modules necessary to export files from the prebuilt apex to the
657// build.
658//
659// If this needs to make files from within a `.apex` file available for use by other Soong modules,
660// e.g. make dex implementation jars available for java_import modules listed in exported_java_libs,
661// it does so as follows:
662//
663// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and
664// makes them available for use by other modules, at both Soong and ninja levels.
665//
666// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what
667// an `apex` module does. That ensures that code which looks for specific apex variant, e.g.
668// dexpreopt, will work the same way from source and prebuilt.
669//
670// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto
671// itself so that they can retrieve the file paths to those files.
672//
673// It also creates a child module `selector` that is responsible for selecting the appropriate
674// input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons:
675// 1. To dedup the selection logic so it only runs in one module.
676// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an
677// `apex_set`.
678//
679// prebuilt_apex
680// / | \
681// / | \
682// V V V
683// selector <--- deapexer <--- exported java lib
684//
685func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
686 baseModuleName := p.BaseModuleName()
687
688 apexSelectorModuleName := apexSelectorModuleName(baseModuleName)
689 createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties)
690
691 apexFileSource := ":" + apexSelectorModuleName
Paul Duffinef6b6952021-06-15 11:34:01 +0100692 createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, p.prebuiltCommonProperties)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100693
694 // Add a source reference to retrieve the selected apex from the selector module.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100695 p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100696}
697
Paul Duffin57f83592021-05-05 15:09:44 +0100698func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
699 p.prebuiltApexContentsDeps(ctx)
Paul Duffin064b70c2020-11-02 17:32:38 +0000700}
701
702var _ ApexInfoMutator = (*Prebuilt)(nil)
703
Paul Duffin064b70c2020-11-02 17:32:38 +0000704func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Paul Duffindfd33262021-04-06 17:02:08 +0100705 p.apexInfoMutator(mctx)
Jiyong Park09d77522019-11-18 11:16:27 +0900706}
707
708func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park09d77522019-11-18 11:16:27 +0900709 // TODO(jungjw): Check the key validity.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100710 p.inputApex = android.OptionalPathForModuleSrc(ctx, p.prebuiltCommonProperties.Selected_apex).Path()
Jiyong Park09d77522019-11-18 11:16:27 +0900711 p.installDir = android.PathForModuleInstall(ctx, "apex")
712 p.installFilename = p.InstallFilename()
713 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
714 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
715 }
716 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
717 ctx.Build(pctx, android.BuildParams{
718 Rule: android.Cp,
719 Input: p.inputApex,
720 Output: p.outputApex,
721 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900722
723 if p.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800724 p.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900725 return
726 }
727
Paul Duffinc30aea22021-06-15 19:10:11 +0100728 // Save the files that need to be made available to Make.
729 p.initApexFilesForAndroidMk(ctx)
730
Jiyong Park09d77522019-11-18 11:16:27 +0900731 if p.installable() {
732 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
733 }
734
Jooyung Han002ab682020-01-08 01:57:58 +0900735 // in case that prebuilt_apex replaces source apex (using prefer: prop)
736 p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx)
737 // or that prebuilt_apex overrides other apexes (using overrides: prop)
Paul Duffinef6b6952021-06-15 11:34:01 +0100738 for _, overridden := range p.prebuiltCommonProperties.Overrides {
Jooyung Han002ab682020-01-08 01:57:58 +0900739 p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
740 }
Jiyong Park09d77522019-11-18 11:16:27 +0900741}
742
Paul Duffin24704672021-04-06 16:09:30 +0100743// prebuiltApexExtractorModule is a private module type that is only created by the prebuilt_apex
744// module. It extracts the correct apex to use and makes it available for use by apex_set.
745type prebuiltApexExtractorModule struct {
746 android.ModuleBase
747
748 properties ApexExtractorProperties
749
750 extractedApex android.WritablePath
751}
752
753func privateApexExtractorModuleFactory() android.Module {
754 module := &prebuiltApexExtractorModule{}
755 module.AddProperties(
756 &module.properties,
757 )
758 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
759 return module
760}
761
762func (p *prebuiltApexExtractorModule) Srcs() android.Paths {
763 return android.Paths{p.extractedApex}
764}
765
766func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
767 srcsSupplier := func(ctx android.BaseModuleContext, prebuilt android.Module) []string {
768 return p.properties.prebuiltSrcs(ctx)
769 }
770 apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set")
771 p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base())
772 ctx.Build(pctx,
773 android.BuildParams{
774 Rule: extractMatchingApex,
775 Description: "Extract an apex from an apex set",
776 Inputs: android.Paths{apexSet},
777 Output: p.extractedApex,
778 Args: map[string]string{
779 "abis": strings.Join(java.SupportedAbis(ctx), ","),
780 "allow-prereleased": strconv.FormatBool(proptools.Bool(p.properties.Prerelease)),
781 "sdk-version": ctx.Config().PlatformSdkVersion().String(),
782 },
783 })
784}
785
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700786type ApexSet struct {
Jiyong Park10e926b2020-07-16 21:38:56 +0900787 prebuiltCommon
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700788
789 properties ApexSetProperties
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700790}
791
Paul Duffin24704672021-04-06 16:09:30 +0100792type ApexExtractorProperties struct {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700793 // the .apks file path that contains prebuilt apex files to be extracted.
794 Set *string
795
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700796 Sanitized struct {
797 None struct {
798 Set *string
799 }
800 Address struct {
801 Set *string
802 }
803 Hwaddress struct {
804 Set *string
805 }
806 }
807
Paul Duffin24704672021-04-06 16:09:30 +0100808 // apexes in this set use prerelease SDK version
809 Prerelease *bool
810}
811
812func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string {
813 var srcs []string
814 if e.Set != nil {
815 srcs = append(srcs, *e.Set)
816 }
817
818 var sanitizers []string
819 if ctx.Host() {
820 sanitizers = ctx.Config().SanitizeHost()
821 } else {
822 sanitizers = ctx.Config().SanitizeDevice()
823 }
824
825 if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil {
826 srcs = append(srcs, *e.Sanitized.Address.Set)
827 } else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil {
828 srcs = append(srcs, *e.Sanitized.Hwaddress.Set)
829 } else if e.Sanitized.None.Set != nil {
830 srcs = append(srcs, *e.Sanitized.None.Set)
831 }
832
833 return srcs
834}
835
836type ApexSetProperties struct {
837 ApexExtractorProperties
838
Paul Duffinef6b6952021-06-15 11:34:01 +0100839 PrebuiltCommonProperties
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700840}
841
842func (a *ApexSet) hasSanitizedSource(sanitizer string) bool {
843 if sanitizer == "address" {
844 return a.properties.Sanitized.Address.Set != nil
845 }
846 if sanitizer == "hwaddress" {
847 return a.properties.Sanitized.Hwaddress.Set != nil
848 }
849
850 return false
851}
852
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700853// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
854func apexSetFactory() android.Module {
855 module := &ApexSet{}
Paul Duffinef6b6952021-06-15 11:34:01 +0100856 module.AddProperties(&module.properties)
857 module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
Paul Duffin24704672021-04-06 16:09:30 +0100858
Paul Duffin24704672021-04-06 16:09:30 +0100859 return module
860}
861
Paul Duffin5dda3e32021-05-05 14:13:27 +0100862func createApexExtractorModule(ctx android.TopDownMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) {
Paul Duffin24704672021-04-06 16:09:30 +0100863 props := struct {
864 Name *string
865 }{
866 Name: proptools.StringPtr(name),
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700867 }
868
Paul Duffin24704672021-04-06 16:09:30 +0100869 ctx.CreateModule(privateApexExtractorModuleFactory,
870 &props,
871 apexExtractorProperties,
872 )
873}
874
875func apexExtractorModuleName(baseModuleName string) string {
876 return baseModuleName + ".apex.extractor"
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700877}
878
Paul Duffin5dda3e32021-05-05 14:13:27 +0100879var _ prebuiltApexModuleCreator = (*ApexSet)(nil)
880
881// createPrebuiltApexModules creates modules necessary to export files from the apex set to other
882// modules.
883//
884// This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a
885// prebuilt_apex except that instead of creating a selector module which selects one .apex file
886// from those provided this creates an extractor module which extracts the appropriate .apex file
887// from the zip file containing them.
888func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
889 baseModuleName := a.BaseModuleName()
890
891 apexExtractorModuleName := apexExtractorModuleName(baseModuleName)
892 createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties)
893
894 apexFileSource := ":" + apexExtractorModuleName
Paul Duffinef6b6952021-06-15 11:34:01 +0100895 createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, a.prebuiltCommonProperties)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100896
897 // After passing the arch specific src properties to the creating the apex selector module
Paul Duffinbb0dc132021-05-05 16:58:08 +0100898 a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100899}
900
Paul Duffin57f83592021-05-05 15:09:44 +0100901func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
902 a.prebuiltApexContentsDeps(ctx)
Paul Duffinf58fd9a2021-04-06 16:00:22 +0100903}
904
905var _ ApexInfoMutator = (*ApexSet)(nil)
906
907func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) {
908 a.apexInfoMutator(mctx)
909}
910
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700911func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
912 a.installFilename = a.InstallFilename()
913 if !strings.HasSuffix(a.installFilename, imageApexSuffix) {
914 ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
915 }
916
Paul Duffinbb0dc132021-05-05 16:58:08 +0100917 inputApex := android.OptionalPathForModuleSrc(ctx, a.prebuiltCommonProperties.Selected_apex).Path()
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700918 a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
Paul Duffin24704672021-04-06 16:09:30 +0100919 ctx.Build(pctx, android.BuildParams{
920 Rule: android.Cp,
921 Input: inputApex,
922 Output: a.outputApex,
923 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900924
925 if a.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800926 a.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900927 return
928 }
929
Paul Duffinc30aea22021-06-15 19:10:11 +0100930 // Save the files that need to be made available to Make.
931 a.initApexFilesForAndroidMk(ctx)
932
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700933 a.installDir = android.PathForModuleInstall(ctx, "apex")
934 if a.installable() {
935 ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
936 }
937
938 // in case that apex_set replaces source apex (using prefer: prop)
939 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
940 // or that apex_set overrides other apexes (using overrides: prop)
Paul Duffinef6b6952021-06-15 11:34:01 +0100941 for _, overridden := range a.prebuiltCommonProperties.Overrides {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700942 a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
943 }
944}
945
Paul Duffinef6b6952021-06-15 11:34:01 +0100946type systemExtContext struct {
947 android.ModuleContext
948}
949
950func (*systemExtContext) SystemExtSpecific() bool {
951 return true
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700952}