blob: f6539c80a2f47b914bb232cca0b0f78637ac33eb [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"
Paul Duffin3bae0682021-05-05 18:03:47 +010020 "path/filepath"
Jaewoong Jungfa00c062020-05-14 14:15:24 -070021 "strconv"
Jiyong Park09d77522019-11-18 11:16:27 +090022 "strings"
23
24 "android/soong/android"
Jaewoong Jungfa00c062020-05-14 14:15:24 -070025 "android/soong/java"
26 "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 Duffinef6b6952021-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 Duffinef6b6952021-06-15 11:34:01 +010054 prebuiltCommonProperties *PrebuiltCommonProperties
55
56 installDir android.InstallPath
57 installFilename string
58 outputApex android.WritablePath
59
Paul Duffinc30aea22021-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 Duffinef6b6952021-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 Duffinef6b6952021-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 Duffinef6b6952021-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 Duffinef6b6952021-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 Duffinef6b6952021-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 Duffinc30aea22021-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 Duffinef6b6952021-06-15 11:34:01 +0100191func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffinc30aea22021-06-15 19:10:11 +0100192 entriesList := []android.AndroidMkEntries{
Paul Duffinef6b6952021-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 Duffinc30aea22021-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 {
219 moduleName := fi.androidMkModuleName + "." + apexName
220 entries := android.AndroidMkEntries{
221 Class: fi.class.nameInMake(),
222 OverrideName: moduleName,
223 OutputFile: android.OptionalPathForPath(fi.builtFile),
224 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
225 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
226 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
227 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
228
229 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
230 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
231 // we will have foo.jar.jar
232 entries.SetString("LOCAL_MODULE_STEM", strings.TrimSuffix(fi.stem(), ".jar"))
Paul Duffinfd53e212021-06-17 20:31:40 +0100233 var classesJar android.Path
234 var headerJar android.Path
235 if javaModule, ok := fi.module.(java.ApexDependency); ok {
236 classesJar = javaModule.ImplementationAndResourcesJars()[0]
237 headerJar = javaModule.HeaderJars()[0]
238 } else {
239 classesJar = fi.builtFile
240 headerJar = fi.builtFile
241 }
242 entries.SetString("LOCAL_SOONG_CLASSES_JAR", classesJar.String())
243 entries.SetString("LOCAL_SOONG_HEADER_JAR", headerJar.String())
Paul Duffinc30aea22021-06-15 19:10:11 +0100244 entries.SetString("LOCAL_SOONG_DEX_JAR", fi.builtFile.String())
245 entries.SetString("LOCAL_DEX_PREOPT", "false")
246 },
247 },
248 ExtraFooters: []android.AndroidMkExtraFootersFunc{
249 func(w io.Writer, name, prefix, moduleDir string) {
250 // m <module_name> will build <module_name>.<apex_name> as well.
251 if fi.androidMkModuleName != moduleName {
252 fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
253 fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
254 }
255 },
256 },
257 }
258
259 entriesList = append(entriesList, entries)
260 }
261
262 return entriesList
Paul Duffinef6b6952021-06-15 11:34:01 +0100263}
264
Paul Duffin5dda3e32021-05-05 14:13:27 +0100265// prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and
266// apex_set in order to create the modules needed to provide access to the prebuilt .apex file.
267type prebuiltApexModuleCreator interface {
268 createPrebuiltApexModules(ctx android.TopDownMutatorContext)
269}
270
271// prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the
272// prebuiltApexModuleCreator's createPrebuiltApexModules method.
273//
274// It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it
275// will need to access dependencies added by that (exported modules) but must run before the
276// DepsMutator so that the deapexer module it creates can add dependencies onto itself from the
277// exported modules.
278func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) {
279 module := ctx.Module()
280 if creator, ok := module.(prebuiltApexModuleCreator); ok {
281 creator.createPrebuiltApexModules(ctx)
282 }
283}
284
Paul Duffin57f83592021-05-05 15:09:44 +0100285// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
286func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
287 module := ctx.Module()
Paul Duffindfd33262021-04-06 17:02:08 +0100288 // Add dependencies onto the java modules that represent the java libraries that are provided by
289 // and exported from this prebuilt apex.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100290 for _, exported := range p.prebuiltCommonProperties.Exported_java_libs {
Paul Duffin57f83592021-05-05 15:09:44 +0100291 dep := android.PrebuiltNameFromSource(exported)
292 ctx.AddDependency(module, exportedJavaLibTag, dep)
Paul Duffindfd33262021-04-06 17:02:08 +0100293 }
Paul Duffin023dba02021-04-22 01:45:29 +0100294
295 // Add dependencies onto the bootclasspath fragment modules that are exported from this prebuilt
296 // apex.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100297 for _, exported := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
Paul Duffin57f83592021-05-05 15:09:44 +0100298 dep := android.PrebuiltNameFromSource(exported)
299 ctx.AddDependency(module, exportedBootclasspathFragmentTag, dep)
Paul Duffin023dba02021-04-22 01:45:29 +0100300 }
Paul Duffindfd33262021-04-06 17:02:08 +0100301}
302
Paul Duffinb17d0442021-05-05 12:07:00 +0100303// Implements android.DepInInSameApex
304func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
305 tag := ctx.OtherModuleDependencyTag(dep)
306 _, ok := tag.(exportedDependencyTag)
307 return ok
308}
309
Paul Duffindfd33262021-04-06 17:02:08 +0100310// apexInfoMutator marks any modules for which this apex exports a file as requiring an apex
311// specific variant and checks that they are supported.
312//
313// The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are
314// associated with the apex specific variant using the ApexInfoProvider for later retrieval.
315//
316// Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants
317// across prebuilt_apex modules. That is because there is no way to determine whether two
318// prebuilt_apex modules that export files for the same module are compatible. e.g. they could have
319// been built from different source at different times or they could have been built with different
320// build options that affect the libraries.
321//
322// While it may be possible to provide sufficient information to determine whether two prebuilt_apex
323// modules were compatible it would be a lot of work and would not provide much benefit for a couple
324// of reasons:
325// * The number of prebuilt_apex modules that will be exporting files for the same module will be
326// low as the prebuilt_apex only exports files for the direct dependencies that require it and
327// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a
328// few com.android.art* apex files that contain the same contents and could export files for the
329// same modules but only one of them needs to do so. Contrast that with source apex modules which
330// need apex specific variants for every module that contributes code to the apex, whether direct
331// or indirect.
332// * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some
333// extra copying of files. Contrast that with source apex modules that has to build each variant
334// from source.
335func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) {
336
337 // Collect direct dependencies into contents.
338 contents := make(map[string]android.ApexMembership)
339
340 // Collect the list of dependencies.
341 var dependencies []android.ApexModule
Paul Duffinb17d0442021-05-05 12:07:00 +0100342 mctx.WalkDeps(func(child, parent android.Module) bool {
343 // If the child is not in the same apex as the parent then exit immediately and do not visit
344 // any of the child's dependencies.
345 if !android.IsDepInSameApex(mctx, parent, child) {
346 return false
347 }
348
349 tag := mctx.OtherModuleDependencyTag(child)
350 depName := mctx.OtherModuleName(child)
Paul Duffin023dba02021-04-22 01:45:29 +0100351 if exportedTag, ok := tag.(exportedDependencyTag); ok {
352 propertyName := exportedTag.name
Paul Duffindfd33262021-04-06 17:02:08 +0100353
354 // It is an error if the other module is not a prebuilt.
Paul Duffinb17d0442021-05-05 12:07:00 +0100355 if !android.IsModulePrebuilt(child) {
Paul Duffin023dba02021-04-22 01:45:29 +0100356 mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName)
Paul Duffinb17d0442021-05-05 12:07:00 +0100357 return false
Paul Duffindfd33262021-04-06 17:02:08 +0100358 }
359
360 // It is an error if the other module is not an ApexModule.
Paul Duffinb17d0442021-05-05 12:07:00 +0100361 if _, ok := child.(android.ApexModule); !ok {
Paul Duffin023dba02021-04-22 01:45:29 +0100362 mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName)
Paul Duffinb17d0442021-05-05 12:07:00 +0100363 return false
Paul Duffindfd33262021-04-06 17:02:08 +0100364 }
Paul Duffindfd33262021-04-06 17:02:08 +0100365 }
Paul Duffinb17d0442021-05-05 12:07:00 +0100366
367 // Strip off the prebuilt_ prefix if present before storing content to ensure consistent
368 // behavior whether there is a corresponding source module present or not.
369 depName = android.RemoveOptionalPrebuiltPrefix(depName)
370
371 // Remember if this module was added as a direct dependency.
372 direct := parent == mctx.Module()
373 contents[depName] = contents[depName].Add(direct)
374
375 // Add the module to the list of dependencies that need to have an APEX variant.
376 dependencies = append(dependencies, child.(android.ApexModule))
377
378 return true
Paul Duffindfd33262021-04-06 17:02:08 +0100379 })
380
381 // Create contents for the prebuilt_apex and store it away for later use.
382 apexContents := android.NewApexContents(contents)
383 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
384 Contents: apexContents,
385 })
386
387 // Create an ApexInfo for the prebuilt_apex.
Martin Stjernholmc4f4ced2021-05-27 11:17:00 +0000388 apexVariationName := android.RemoveOptionalPrebuiltPrefix(mctx.ModuleName())
Paul Duffindfd33262021-04-06 17:02:08 +0100389 apexInfo := android.ApexInfo{
Martin Stjernholmc4f4ced2021-05-27 11:17:00 +0000390 ApexVariationName: apexVariationName,
391 InApexVariants: []string{apexVariationName},
392 InApexModules: []string{apexVariationName},
Paul Duffindfd33262021-04-06 17:02:08 +0100393 ApexContents: []*android.ApexContents{apexContents},
394 ForPrebuiltApex: true,
395 }
396
397 // Mark the dependencies of this module as requiring a variant for this module.
398 for _, am := range dependencies {
399 am.BuildForApex(apexInfo)
400 }
401}
402
Paul Duffin11216db2021-03-01 14:14:52 +0000403// prebuiltApexSelectorModule is a private module type that is only created by the prebuilt_apex
404// module. It selects the apex to use and makes it available for use by prebuilt_apex and the
405// deapexer.
406type prebuiltApexSelectorModule struct {
407 android.ModuleBase
408
409 apexFileProperties ApexFileProperties
410
411 inputApex android.Path
412}
413
414func privateApexSelectorModuleFactory() android.Module {
415 module := &prebuiltApexSelectorModule{}
416 module.AddProperties(
417 &module.apexFileProperties,
418 )
419 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
420 return module
421}
422
423func (p *prebuiltApexSelectorModule) Srcs() android.Paths {
424 return android.Paths{p.inputApex}
425}
426
427func (p *prebuiltApexSelectorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
428 p.inputApex = android.SingleSourcePathFromSupplier(ctx, p.apexFileProperties.prebuiltApexSelector, "src")
429}
430
Jiyong Park09d77522019-11-18 11:16:27 +0900431type Prebuilt struct {
Jiyong Park10e926b2020-07-16 21:38:56 +0900432 prebuiltCommon
Jiyong Park09d77522019-11-18 11:16:27 +0900433
Paul Duffinbb0dc132021-05-05 16:58:08 +0100434 properties PrebuiltProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900435
Paul Duffinef6b6952021-06-15 11:34:01 +0100436 inputApex android.Path
Jiyong Park09d77522019-11-18 11:16:27 +0900437}
438
Paul Duffin851f3992021-01-13 17:03:51 +0000439type ApexFileProperties struct {
Jiyong Park09d77522019-11-18 11:16:27 +0900440 // the path to the prebuilt .apex file to import.
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000441 //
442 // This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated
443 // for android_common. That is so that it will have the same arch variant as, and so be compatible
444 // with, the source `apex` module type that it replaces.
Paul Duffin11216db2021-03-01 14:14:52 +0000445 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900446 Arch struct {
447 Arm struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000448 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900449 }
450 Arm64 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000451 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900452 }
453 X86 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000454 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900455 }
456 X86_64 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000457 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900458 }
459 }
Paul Duffin851f3992021-01-13 17:03:51 +0000460}
461
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000462// prebuiltApexSelector selects the correct prebuilt APEX file for the build target.
463//
464// The ctx parameter can be for any module not just the prebuilt module so care must be taken not
465// to use methods on it that are specific to the current module.
466//
467// See the ApexFileProperties.Src property.
468func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) []string {
469 multiTargets := prebuilt.MultiTargets()
470 if len(multiTargets) != 1 {
471 ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex")
472 return nil
Paul Duffin851f3992021-01-13 17:03:51 +0000473 }
474 var src string
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000475 switch multiTargets[0].Arch.ArchType {
Paul Duffin851f3992021-01-13 17:03:51 +0000476 case android.Arm:
477 src = String(p.Arch.Arm.Src)
478 case android.Arm64:
479 src = String(p.Arch.Arm64.Src)
480 case android.X86:
481 src = String(p.Arch.X86.Src)
482 case android.X86_64:
483 src = String(p.Arch.X86_64.Src)
Paul Duffin851f3992021-01-13 17:03:51 +0000484 }
485 if src == "" {
486 src = String(p.Src)
487 }
Paul Duffin851f3992021-01-13 17:03:51 +0000488
Paul Duffinc0609c62021-03-01 17:27:16 +0000489 if src == "" {
490 ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String())
491 // Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt
492 // logic from reporting a more general, less useful message.
493 }
494
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000495 return []string{src}
Paul Duffin851f3992021-01-13 17:03:51 +0000496}
497
498type PrebuiltProperties struct {
499 ApexFileProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900500
Paul Duffinef6b6952021-06-15 11:34:01 +0100501 PrebuiltCommonProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900502}
503
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700504func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool {
505 return false
506}
507
Jiyong Park09d77522019-11-18 11:16:27 +0900508func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
509 switch tag {
510 case "":
511 return android.Paths{p.outputApex}, nil
512 default:
513 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
514 }
515}
516
Jiyong Park09d77522019-11-18 11:16:27 +0900517// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
518func PrebuiltFactory() android.Module {
519 module := &Prebuilt{}
Paul Duffinef6b6952021-06-15 11:34:01 +0100520 module.AddProperties(&module.properties)
521 module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
Paul Duffin064b70c2020-11-02 17:32:38 +0000522
Jiyong Park09d77522019-11-18 11:16:27 +0900523 return module
524}
525
Paul Duffin5dda3e32021-05-05 14:13:27 +0100526func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, apexFileProperties *ApexFileProperties) {
Paul Duffin11216db2021-03-01 14:14:52 +0000527 props := struct {
528 Name *string
529 }{
530 Name: proptools.StringPtr(name),
531 }
532
533 ctx.CreateModule(privateApexSelectorModuleFactory,
534 &props,
535 apexFileProperties,
536 )
537}
538
Paul Duffin5dda3e32021-05-05 14:13:27 +0100539// createDeapexerModuleIfNeeded will create a deapexer module if it is needed.
540//
Paul Duffin57f83592021-05-05 15:09:44 +0100541// A deapexer module is only needed when the prebuilt apex specifies one or more modules in either
542// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that
543// the listed modules need access to files from within the prebuilt .apex file.
Paul Duffinef6b6952021-06-15 11:34:01 +0100544func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string, properties *PrebuiltCommonProperties) {
Paul Duffin5dda3e32021-05-05 14:13:27 +0100545 // Only create the deapexer module if it is needed.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100546 if len(properties.Exported_java_libs)+len(properties.Exported_bootclasspath_fragments) == 0 {
Paul Duffin5dda3e32021-05-05 14:13:27 +0100547 return
548 }
549
Paul Duffin57f83592021-05-05 15:09:44 +0100550 // Compute the deapexer properties from the transitive dependencies of this module.
Paul Duffin3bae0682021-05-05 18:03:47 +0100551 javaModules := []string{}
552 exportedFiles := map[string]string{}
Paul Duffin57f83592021-05-05 15:09:44 +0100553 ctx.WalkDeps(func(child, parent android.Module) bool {
554 tag := ctx.OtherModuleDependencyTag(child)
555
556 name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
557 if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
Paul Duffin3bae0682021-05-05 18:03:47 +0100558 javaModules = append(javaModules, name)
559
560 // Add the dex implementation jar to the set of exported files. The path here must match the
561 // path of the file in the APEX created by apexFileForJavaModule(...).
562 exportedFiles[name+"{.dexjar}"] = filepath.Join("javalib", name+".jar")
563
Paul Duffin57f83592021-05-05 15:09:44 +0100564 } else if tag == exportedBootclasspathFragmentTag {
Paul Duffin57f83592021-05-05 15:09:44 +0100565 // Only visit the children of the bootclasspath_fragment for now.
566 return true
567 }
568
569 return false
570 })
571
Paul Duffin3bae0682021-05-05 18:03:47 +0100572 // Create properties for deapexer module.
573 deapexerProperties := &DeapexerProperties{
574 // Remove any duplicates from the java modules lists as a module may be included via a direct
575 // dependency as well as transitive ones.
576 CommonModules: android.SortedUniqueStrings(javaModules),
577 }
578
579 // Populate the exported files property in a fixed order.
580 for _, tag := range android.SortedStringKeys(exportedFiles) {
581 deapexerProperties.ExportedFiles = append(deapexerProperties.ExportedFiles, DeapexerExportedFile{
582 Tag: tag,
583 Path: exportedFiles[tag],
584 })
585 }
Paul Duffin57f83592021-05-05 15:09:44 +0100586
Paul Duffin11216db2021-03-01 14:14:52 +0000587 props := struct {
588 Name *string
589 Selected_apex *string
590 }{
591 Name: proptools.StringPtr(deapexerName),
592 Selected_apex: proptools.StringPtr(apexFileSource),
593 }
594 ctx.CreateModule(privateDeapexerFactory,
595 &props,
596 deapexerProperties,
597 )
598}
599
600func deapexerModuleName(baseModuleName string) string {
601 return baseModuleName + ".deapexer"
602}
603
604func apexSelectorModuleName(baseModuleName string) string {
605 return baseModuleName + ".apex.selector"
606}
607
Paul Duffin064b70c2020-11-02 17:32:38 +0000608func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string {
609 // The prebuilt_apex should be depending on prebuilt modules but as this runs after
610 // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So,
611 // check to see if the prefixed name is in use first, if it is then use that, otherwise assume
612 // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module
613 // and not a renamed prebuilt module then that will be detected and reported as an error when
614 // processing the dependency in ApexInfoMutator().
Paul Duffin864116c2021-04-02 10:24:13 +0100615 prebuiltName := android.PrebuiltNameFromSource(name)
Paul Duffin064b70c2020-11-02 17:32:38 +0000616 if ctx.OtherModuleExists(prebuiltName) {
617 name = prebuiltName
618 }
619 return name
620}
621
Paul Duffina7139422021-02-08 11:01:58 +0000622type exportedDependencyTag struct {
623 blueprint.BaseDependencyTag
624 name string
625}
626
627// Mark this tag so dependencies that use it are excluded from visibility enforcement.
628//
629// This does allow any prebuilt_apex to reference any module which does open up a small window for
630// restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so
631// avoids opening up a much bigger window by widening the visibility of modules that need files
632// provided by the prebuilt_apex to include all the possible locations they may be defined, which
633// could include everything below vendor/.
634//
635// A prebuilt_apex that references a module via this tag will have to contain the appropriate files
636// corresponding to that module, otherwise it will fail when attempting to retrieve the files from
637// the .apex file. It will also have to be included in the module's apex_available property too.
638// That makes it highly unlikely that a prebuilt_apex would reference a restricted module
639// incorrectly.
640func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {}
641
642var (
Paul Duffin023dba02021-04-22 01:45:29 +0100643 exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
644 exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
Paul Duffina7139422021-02-08 11:01:58 +0000645)
646
Paul Duffin5dda3e32021-05-05 14:13:27 +0100647var _ prebuiltApexModuleCreator = (*Prebuilt)(nil)
648
649// createPrebuiltApexModules creates modules necessary to export files from the prebuilt apex to the
650// build.
651//
652// If this needs to make files from within a `.apex` file available for use by other Soong modules,
653// e.g. make dex implementation jars available for java_import modules listed in exported_java_libs,
654// it does so as follows:
655//
656// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and
657// makes them available for use by other modules, at both Soong and ninja levels.
658//
659// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what
660// an `apex` module does. That ensures that code which looks for specific apex variant, e.g.
661// dexpreopt, will work the same way from source and prebuilt.
662//
663// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto
664// itself so that they can retrieve the file paths to those files.
665//
666// It also creates a child module `selector` that is responsible for selecting the appropriate
667// input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons:
668// 1. To dedup the selection logic so it only runs in one module.
669// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an
670// `apex_set`.
671//
672// prebuilt_apex
673// / | \
674// / | \
675// V V V
676// selector <--- deapexer <--- exported java lib
677//
678func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
679 baseModuleName := p.BaseModuleName()
680
681 apexSelectorModuleName := apexSelectorModuleName(baseModuleName)
682 createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties)
683
684 apexFileSource := ":" + apexSelectorModuleName
Paul Duffinef6b6952021-06-15 11:34:01 +0100685 createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, p.prebuiltCommonProperties)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100686
687 // Add a source reference to retrieve the selected apex from the selector module.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100688 p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100689}
690
Paul Duffin57f83592021-05-05 15:09:44 +0100691func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
692 p.prebuiltApexContentsDeps(ctx)
Paul Duffin064b70c2020-11-02 17:32:38 +0000693}
694
695var _ ApexInfoMutator = (*Prebuilt)(nil)
696
Paul Duffin064b70c2020-11-02 17:32:38 +0000697func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Paul Duffindfd33262021-04-06 17:02:08 +0100698 p.apexInfoMutator(mctx)
Jiyong Park09d77522019-11-18 11:16:27 +0900699}
700
701func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park09d77522019-11-18 11:16:27 +0900702 // TODO(jungjw): Check the key validity.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100703 p.inputApex = android.OptionalPathForModuleSrc(ctx, p.prebuiltCommonProperties.Selected_apex).Path()
Jiyong Park09d77522019-11-18 11:16:27 +0900704 p.installDir = android.PathForModuleInstall(ctx, "apex")
705 p.installFilename = p.InstallFilename()
706 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
707 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
708 }
709 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
710 ctx.Build(pctx, android.BuildParams{
711 Rule: android.Cp,
712 Input: p.inputApex,
713 Output: p.outputApex,
714 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900715
716 if p.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800717 p.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900718 return
719 }
720
Paul Duffinc30aea22021-06-15 19:10:11 +0100721 // Save the files that need to be made available to Make.
722 p.initApexFilesForAndroidMk(ctx)
723
Jiyong Park09d77522019-11-18 11:16:27 +0900724 if p.installable() {
725 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
726 }
727
Jooyung Han002ab682020-01-08 01:57:58 +0900728 // in case that prebuilt_apex replaces source apex (using prefer: prop)
729 p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx)
730 // or that prebuilt_apex overrides other apexes (using overrides: prop)
Paul Duffinef6b6952021-06-15 11:34:01 +0100731 for _, overridden := range p.prebuiltCommonProperties.Overrides {
Jooyung Han002ab682020-01-08 01:57:58 +0900732 p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
733 }
Jiyong Park09d77522019-11-18 11:16:27 +0900734}
735
Paul Duffin24704672021-04-06 16:09:30 +0100736// prebuiltApexExtractorModule is a private module type that is only created by the prebuilt_apex
737// module. It extracts the correct apex to use and makes it available for use by apex_set.
738type prebuiltApexExtractorModule struct {
739 android.ModuleBase
740
741 properties ApexExtractorProperties
742
743 extractedApex android.WritablePath
744}
745
746func privateApexExtractorModuleFactory() android.Module {
747 module := &prebuiltApexExtractorModule{}
748 module.AddProperties(
749 &module.properties,
750 )
751 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
752 return module
753}
754
755func (p *prebuiltApexExtractorModule) Srcs() android.Paths {
756 return android.Paths{p.extractedApex}
757}
758
759func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
760 srcsSupplier := func(ctx android.BaseModuleContext, prebuilt android.Module) []string {
761 return p.properties.prebuiltSrcs(ctx)
762 }
763 apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set")
764 p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base())
765 ctx.Build(pctx,
766 android.BuildParams{
767 Rule: extractMatchingApex,
768 Description: "Extract an apex from an apex set",
769 Inputs: android.Paths{apexSet},
770 Output: p.extractedApex,
771 Args: map[string]string{
772 "abis": strings.Join(java.SupportedAbis(ctx), ","),
773 "allow-prereleased": strconv.FormatBool(proptools.Bool(p.properties.Prerelease)),
774 "sdk-version": ctx.Config().PlatformSdkVersion().String(),
775 },
776 })
777}
778
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700779type ApexSet struct {
Jiyong Park10e926b2020-07-16 21:38:56 +0900780 prebuiltCommon
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700781
782 properties ApexSetProperties
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700783}
784
Paul Duffin24704672021-04-06 16:09:30 +0100785type ApexExtractorProperties struct {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700786 // the .apks file path that contains prebuilt apex files to be extracted.
787 Set *string
788
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700789 Sanitized struct {
790 None struct {
791 Set *string
792 }
793 Address struct {
794 Set *string
795 }
796 Hwaddress struct {
797 Set *string
798 }
799 }
800
Paul Duffin24704672021-04-06 16:09:30 +0100801 // apexes in this set use prerelease SDK version
802 Prerelease *bool
803}
804
805func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string {
806 var srcs []string
807 if e.Set != nil {
808 srcs = append(srcs, *e.Set)
809 }
810
811 var sanitizers []string
812 if ctx.Host() {
813 sanitizers = ctx.Config().SanitizeHost()
814 } else {
815 sanitizers = ctx.Config().SanitizeDevice()
816 }
817
818 if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil {
819 srcs = append(srcs, *e.Sanitized.Address.Set)
820 } else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil {
821 srcs = append(srcs, *e.Sanitized.Hwaddress.Set)
822 } else if e.Sanitized.None.Set != nil {
823 srcs = append(srcs, *e.Sanitized.None.Set)
824 }
825
826 return srcs
827}
828
829type ApexSetProperties struct {
830 ApexExtractorProperties
831
Paul Duffinef6b6952021-06-15 11:34:01 +0100832 PrebuiltCommonProperties
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700833}
834
835func (a *ApexSet) hasSanitizedSource(sanitizer string) bool {
836 if sanitizer == "address" {
837 return a.properties.Sanitized.Address.Set != nil
838 }
839 if sanitizer == "hwaddress" {
840 return a.properties.Sanitized.Hwaddress.Set != nil
841 }
842
843 return false
844}
845
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700846// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
847func apexSetFactory() android.Module {
848 module := &ApexSet{}
Paul Duffinef6b6952021-06-15 11:34:01 +0100849 module.AddProperties(&module.properties)
850 module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
Paul Duffin24704672021-04-06 16:09:30 +0100851
Paul Duffin24704672021-04-06 16:09:30 +0100852 return module
853}
854
Paul Duffin5dda3e32021-05-05 14:13:27 +0100855func createApexExtractorModule(ctx android.TopDownMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) {
Paul Duffin24704672021-04-06 16:09:30 +0100856 props := struct {
857 Name *string
858 }{
859 Name: proptools.StringPtr(name),
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700860 }
861
Paul Duffin24704672021-04-06 16:09:30 +0100862 ctx.CreateModule(privateApexExtractorModuleFactory,
863 &props,
864 apexExtractorProperties,
865 )
866}
867
868func apexExtractorModuleName(baseModuleName string) string {
869 return baseModuleName + ".apex.extractor"
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700870}
871
Paul Duffin5dda3e32021-05-05 14:13:27 +0100872var _ prebuiltApexModuleCreator = (*ApexSet)(nil)
873
874// createPrebuiltApexModules creates modules necessary to export files from the apex set to other
875// modules.
876//
877// This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a
878// prebuilt_apex except that instead of creating a selector module which selects one .apex file
879// from those provided this creates an extractor module which extracts the appropriate .apex file
880// from the zip file containing them.
881func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
882 baseModuleName := a.BaseModuleName()
883
884 apexExtractorModuleName := apexExtractorModuleName(baseModuleName)
885 createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties)
886
887 apexFileSource := ":" + apexExtractorModuleName
Paul Duffinef6b6952021-06-15 11:34:01 +0100888 createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, a.prebuiltCommonProperties)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100889
890 // After passing the arch specific src properties to the creating the apex selector module
Paul Duffinbb0dc132021-05-05 16:58:08 +0100891 a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100892}
893
Paul Duffin57f83592021-05-05 15:09:44 +0100894func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
895 a.prebuiltApexContentsDeps(ctx)
Paul Duffinf58fd9a2021-04-06 16:00:22 +0100896}
897
898var _ ApexInfoMutator = (*ApexSet)(nil)
899
900func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) {
901 a.apexInfoMutator(mctx)
902}
903
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700904func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
905 a.installFilename = a.InstallFilename()
906 if !strings.HasSuffix(a.installFilename, imageApexSuffix) {
907 ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
908 }
909
Paul Duffinbb0dc132021-05-05 16:58:08 +0100910 inputApex := android.OptionalPathForModuleSrc(ctx, a.prebuiltCommonProperties.Selected_apex).Path()
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700911 a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
Paul Duffin24704672021-04-06 16:09:30 +0100912 ctx.Build(pctx, android.BuildParams{
913 Rule: android.Cp,
914 Input: inputApex,
915 Output: a.outputApex,
916 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900917
918 if a.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800919 a.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900920 return
921 }
922
Paul Duffinc30aea22021-06-15 19:10:11 +0100923 // Save the files that need to be made available to Make.
924 a.initApexFilesForAndroidMk(ctx)
925
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700926 a.installDir = android.PathForModuleInstall(ctx, "apex")
927 if a.installable() {
928 ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
929 }
930
931 // in case that apex_set replaces source apex (using prefer: prop)
932 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
933 // or that apex_set overrides other apexes (using overrides: prop)
Paul Duffinef6b6952021-06-15 11:34:01 +0100934 for _, overridden := range a.prebuiltCommonProperties.Overrides {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700935 a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
936 }
937}
938
Paul Duffinef6b6952021-06-15 11:34:01 +0100939type systemExtContext struct {
940 android.ModuleContext
941}
942
943func (*systemExtContext) SystemExtSpecific() bool {
944 return true
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700945}