blob: c567fe01253fc8d03918beb4ae915127be6b53a8 [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 "github.com/google/blueprint/proptools"
27)
28
Jaewoong Jungfa00c062020-05-14 14:15:24 -070029var (
30 extractMatchingApex = pctx.StaticRule(
31 "extractMatchingApex",
32 blueprint.RuleParams{
33 Command: `rm -rf "$out" && ` +
34 `${extract_apks} -o "${out}" -allow-prereleased=${allow-prereleased} ` +
35 `-sdk-version=${sdk-version} -abis=${abis} -screen-densities=all -extract-single ` +
36 `${in}`,
37 CommandDeps: []string{"${extract_apks}"},
38 },
39 "abis", "allow-prereleased", "sdk-version")
40)
41
Jiyong Park10e926b2020-07-16 21:38:56 +090042type prebuilt interface {
43 isForceDisabled() bool
44 InstallFilename() string
45}
46
47type prebuiltCommon struct {
Paul Duffinef6b6952021-06-15 11:34:01 +010048 android.ModuleBase
Paul Duffinbb0dc132021-05-05 16:58:08 +010049 prebuilt android.Prebuilt
Paul Duffindfd33262021-04-06 17:02:08 +010050
Paul Duffinbb0dc132021-05-05 16:58:08 +010051 // Properties common to both prebuilt_apex and apex_set.
Paul Duffinef6b6952021-06-15 11:34:01 +010052 prebuiltCommonProperties *PrebuiltCommonProperties
53
54 installDir android.InstallPath
55 installFilename string
56 outputApex android.WritablePath
57
Paul Duffinc30aea22021-06-15 19:10:11 +010058 // A list of apexFile objects created in prebuiltCommon.initApexFilesForAndroidMk which are used
59 // to create make modules in prebuiltCommon.AndroidMkEntries.
60 apexFilesForAndroidMk []apexFile
61
Paul Duffinef6b6952021-06-15 11:34:01 +010062 // list of commands to create symlinks for backward compatibility.
63 // these commands will be attached as LOCAL_POST_INSTALL_CMD
64 compatSymlinks []string
65
66 hostRequired []string
67 postInstallCommands []string
Jiyong Park10e926b2020-07-16 21:38:56 +090068}
69
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -070070type sanitizedPrebuilt interface {
71 hasSanitizedSource(sanitizer string) bool
72}
73
Paul Duffinef6b6952021-06-15 11:34:01 +010074type PrebuiltCommonProperties struct {
Paul Duffinbb0dc132021-05-05 16:58:08 +010075 SelectedApexProperties
76
Martin Stjernholmd8da28e2021-06-24 14:37:13 +010077 // Canonical name of this APEX. Used to determine the path to the activated APEX on
78 // device (/apex/<apex_name>). If unspecified, follows the name property.
79 Apex_name *string
80
Jiyong Park10e926b2020-07-16 21:38:56 +090081 ForceDisable bool `blueprint:"mutated"`
Paul Duffin3bae0682021-05-05 18:03:47 +010082
Paul Duffinef6b6952021-06-15 11:34:01 +010083 // whether the extracted apex file is installable.
84 Installable *bool
85
86 // optional name for the installed apex. If unspecified, name of the
87 // module is used as the file name
88 Filename *string
89
90 // names of modules to be overridden. Listed modules can only be other binaries
91 // (in Make or Soong).
92 // This does not completely prevent installation of the overridden binaries, but if both
93 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
94 // from PRODUCT_PACKAGES.
95 Overrides []string
96
Paul Duffin3bae0682021-05-05 18:03:47 +010097 // List of java libraries that are embedded inside this prebuilt APEX bundle and for which this
98 // APEX bundle will create an APEX variant and provide dex implementation jars for use by
99 // dexpreopt and boot jars package check.
100 Exported_java_libs []string
101
102 // List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX
103 // bundle will create an APEX variant.
104 Exported_bootclasspath_fragments []string
Jiyong Park10e926b2020-07-16 21:38:56 +0900105}
106
Paul Duffinef6b6952021-06-15 11:34:01 +0100107// initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the
108// module that is common to Prebuilt and ApexSet.
109func (p *prebuiltCommon) initPrebuiltCommon(module android.Module, properties *PrebuiltCommonProperties) {
110 p.prebuiltCommonProperties = properties
111 android.InitSingleSourcePrebuiltModule(module.(android.PrebuiltInterface), properties, "Selected_apex")
112 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
113}
114
Martin Stjernholmd8da28e2021-06-24 14:37:13 +0100115func (p *prebuiltCommon) ApexVariationName() string {
116 return proptools.StringDefault(p.prebuiltCommonProperties.Apex_name, p.ModuleBase.BaseModuleName())
117}
118
Jiyong Park10e926b2020-07-16 21:38:56 +0900119func (p *prebuiltCommon) Prebuilt() *android.Prebuilt {
120 return &p.prebuilt
121}
122
123func (p *prebuiltCommon) isForceDisabled() bool {
Paul Duffinbb0dc132021-05-05 16:58:08 +0100124 return p.prebuiltCommonProperties.ForceDisable
Jiyong Park10e926b2020-07-16 21:38:56 +0900125}
126
127func (p *prebuiltCommon) checkForceDisable(ctx android.ModuleContext) bool {
128 // If the device is configured to use flattened APEX, force disable the prebuilt because
129 // the prebuilt is a non-flattened one.
130 forceDisable := ctx.Config().FlattenApex()
131
132 // Force disable the prebuilts when we are doing unbundled build. We do unbundled build
133 // to build the prebuilts themselves.
134 forceDisable = forceDisable || ctx.Config().UnbundledBuild()
135
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700136 // b/137216042 don't use prebuilts when address sanitizer is on, unless the prebuilt has a sanitized source
137 sanitized := ctx.Module().(sanitizedPrebuilt)
138 forceDisable = forceDisable || (android.InList("address", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("address"))
139 forceDisable = forceDisable || (android.InList("hwaddress", ctx.Config().SanitizeDevice()) && !sanitized.hasSanitizedSource("hwaddress"))
Jiyong Park10e926b2020-07-16 21:38:56 +0900140
141 if forceDisable && p.prebuilt.SourceExists() {
Paul Duffinbb0dc132021-05-05 16:58:08 +0100142 p.prebuiltCommonProperties.ForceDisable = true
Jiyong Park10e926b2020-07-16 21:38:56 +0900143 return true
144 }
145 return false
146}
147
Paul Duffinef6b6952021-06-15 11:34:01 +0100148func (p *prebuiltCommon) InstallFilename() string {
149 return proptools.StringDefault(p.prebuiltCommonProperties.Filename, p.BaseModuleName()+imageApexSuffix)
150}
151
152func (p *prebuiltCommon) Name() string {
153 return p.prebuilt.Name(p.ModuleBase.Name())
154}
155
156func (p *prebuiltCommon) Overrides() []string {
157 return p.prebuiltCommonProperties.Overrides
158}
159
160func (p *prebuiltCommon) installable() bool {
161 return proptools.BoolDefault(p.prebuiltCommonProperties.Installable, true)
162}
163
Paul Duffinc30aea22021-06-15 19:10:11 +0100164// initApexFilesForAndroidMk initializes the prebuiltCommon.apexFilesForAndroidMk field from the
165// modules that this depends upon.
166func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) {
167 // Walk the dependencies of this module looking for the java modules that it exports.
168 ctx.WalkDeps(func(child, parent android.Module) bool {
169 tag := ctx.OtherModuleDependencyTag(child)
170
171 name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
172 if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
173 // If the exported java module provides a dex jar path then add it to the list of apexFiles.
174 path := child.(interface{ DexJarBuildPath() android.Path }).DexJarBuildPath()
175 if path != nil {
176 p.apexFilesForAndroidMk = append(p.apexFilesForAndroidMk, apexFile{
177 module: child,
178 moduleDir: ctx.OtherModuleDir(child),
179 androidMkModuleName: name,
180 builtFile: path,
181 class: javaSharedLib,
182 })
183 }
184 } else if tag == exportedBootclasspathFragmentTag {
185 // Visit the children of the bootclasspath_fragment.
186 return true
187 }
188
189 return false
190 })
191}
192
Paul Duffinef6b6952021-06-15 11:34:01 +0100193func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries {
Paul Duffinc30aea22021-06-15 19:10:11 +0100194 entriesList := []android.AndroidMkEntries{
Paul Duffinef6b6952021-06-15 11:34:01 +0100195 {
196 Class: "ETC",
197 OutputFile: android.OptionalPathForPath(p.outputApex),
198 Include: "$(BUILD_PREBUILT)",
199 Host_required: p.hostRequired,
200 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
201 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
202 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
203 entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
204 entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
205 entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.prebuiltCommonProperties.Overrides...)
206 postInstallCommands := append([]string{}, p.postInstallCommands...)
207 postInstallCommands = append(postInstallCommands, p.compatSymlinks...)
208 if len(postInstallCommands) > 0 {
209 entries.SetString("LOCAL_POST_INSTALL_CMD", strings.Join(postInstallCommands, " && "))
210 }
211 },
212 },
213 },
214 }
Paul Duffinc30aea22021-06-15 19:10:11 +0100215
216 // Iterate over the apexFilesForAndroidMk list and create an AndroidMkEntries struct for each
217 // file. This provides similar behavior to that provided in apexBundle.AndroidMk() as it makes the
218 // apex specific variants of the exported java modules available for use from within make.
219 apexName := p.BaseModuleName()
220 for _, fi := range p.apexFilesForAndroidMk {
Paul Duffin9dc8c542021-06-17 13:33:09 +0100221 entries := p.createEntriesForApexFile(fi, apexName)
Paul Duffinc30aea22021-06-15 19:10:11 +0100222 entriesList = append(entriesList, entries)
223 }
224
225 return entriesList
Paul Duffinef6b6952021-06-15 11:34:01 +0100226}
227
Paul Duffin9dc8c542021-06-17 13:33:09 +0100228// createEntriesForApexFile creates an AndroidMkEntries for the supplied apexFile
229func (p *prebuiltCommon) createEntriesForApexFile(fi apexFile, apexName string) android.AndroidMkEntries {
230 moduleName := fi.androidMkModuleName + "." + apexName
231 entries := android.AndroidMkEntries{
232 Class: fi.class.nameInMake(),
233 OverrideName: moduleName,
234 OutputFile: android.OptionalPathForPath(fi.builtFile),
235 Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
236 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
237 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
238 entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String())
239
240 // soong_java_prebuilt.mk sets LOCAL_MODULE_SUFFIX := .jar Therefore
241 // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise
242 // we will have foo.jar.jar
243 entries.SetString("LOCAL_MODULE_STEM", strings.TrimSuffix(fi.stem(), ".jar"))
244 var classesJar android.Path
245 var headerJar android.Path
246 if javaModule, ok := fi.module.(java.ApexDependency); ok {
247 classesJar = javaModule.ImplementationAndResourcesJars()[0]
248 headerJar = javaModule.HeaderJars()[0]
249 } else {
250 classesJar = fi.builtFile
251 headerJar = fi.builtFile
252 }
253 entries.SetString("LOCAL_SOONG_CLASSES_JAR", classesJar.String())
254 entries.SetString("LOCAL_SOONG_HEADER_JAR", headerJar.String())
255 entries.SetString("LOCAL_SOONG_DEX_JAR", fi.builtFile.String())
256 entries.SetString("LOCAL_DEX_PREOPT", "false")
257 },
258 },
259 ExtraFooters: []android.AndroidMkExtraFootersFunc{
260 func(w io.Writer, name, prefix, moduleDir string) {
261 // m <module_name> will build <module_name>.<apex_name> as well.
262 if fi.androidMkModuleName != moduleName {
263 fmt.Fprintf(w, ".PHONY: %s\n", fi.androidMkModuleName)
264 fmt.Fprintf(w, "%s: %s\n", fi.androidMkModuleName, moduleName)
265 }
266 },
267 },
268 }
269 return entries
270}
271
Paul Duffin5dda3e32021-05-05 14:13:27 +0100272// prebuiltApexModuleCreator defines the methods that need to be implemented by prebuilt_apex and
273// apex_set in order to create the modules needed to provide access to the prebuilt .apex file.
274type prebuiltApexModuleCreator interface {
275 createPrebuiltApexModules(ctx android.TopDownMutatorContext)
276}
277
278// prebuiltApexModuleCreatorMutator is the mutator responsible for invoking the
279// prebuiltApexModuleCreator's createPrebuiltApexModules method.
280//
281// It is registered as a pre-arch mutator as it must run after the ComponentDepsMutator because it
282// will need to access dependencies added by that (exported modules) but must run before the
283// DepsMutator so that the deapexer module it creates can add dependencies onto itself from the
284// exported modules.
285func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) {
286 module := ctx.Module()
287 if creator, ok := module.(prebuiltApexModuleCreator); ok {
288 creator.createPrebuiltApexModules(ctx)
289 }
290}
291
Paul Duffin57f83592021-05-05 15:09:44 +0100292// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
293func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
294 module := ctx.Module()
Paul Duffindfd33262021-04-06 17:02:08 +0100295 // Add dependencies onto the java modules that represent the java libraries that are provided by
296 // and exported from this prebuilt apex.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100297 for _, exported := range p.prebuiltCommonProperties.Exported_java_libs {
Paul Duffin57f83592021-05-05 15:09:44 +0100298 dep := android.PrebuiltNameFromSource(exported)
299 ctx.AddDependency(module, exportedJavaLibTag, dep)
Paul Duffindfd33262021-04-06 17:02:08 +0100300 }
Paul Duffin023dba02021-04-22 01:45:29 +0100301
302 // Add dependencies onto the bootclasspath fragment modules that are exported from this prebuilt
303 // apex.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100304 for _, exported := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
Paul Duffin57f83592021-05-05 15:09:44 +0100305 dep := android.PrebuiltNameFromSource(exported)
306 ctx.AddDependency(module, exportedBootclasspathFragmentTag, dep)
Paul Duffin023dba02021-04-22 01:45:29 +0100307 }
Paul Duffindfd33262021-04-06 17:02:08 +0100308}
309
Paul Duffinb17d0442021-05-05 12:07:00 +0100310// Implements android.DepInInSameApex
311func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
312 tag := ctx.OtherModuleDependencyTag(dep)
313 _, ok := tag.(exportedDependencyTag)
314 return ok
315}
316
Paul Duffindfd33262021-04-06 17:02:08 +0100317// apexInfoMutator marks any modules for which this apex exports a file as requiring an apex
318// specific variant and checks that they are supported.
319//
320// The apexMutator will ensure that the ApexInfo objects passed to BuildForApex(ApexInfo) are
321// associated with the apex specific variant using the ApexInfoProvider for later retrieval.
322//
323// Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants
324// across prebuilt_apex modules. That is because there is no way to determine whether two
325// prebuilt_apex modules that export files for the same module are compatible. e.g. they could have
326// been built from different source at different times or they could have been built with different
327// build options that affect the libraries.
328//
329// While it may be possible to provide sufficient information to determine whether two prebuilt_apex
330// modules were compatible it would be a lot of work and would not provide much benefit for a couple
331// of reasons:
332// * The number of prebuilt_apex modules that will be exporting files for the same module will be
333// low as the prebuilt_apex only exports files for the direct dependencies that require it and
334// very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a
335// few com.android.art* apex files that contain the same contents and could export files for the
336// same modules but only one of them needs to do so. Contrast that with source apex modules which
337// need apex specific variants for every module that contributes code to the apex, whether direct
338// or indirect.
339// * The build cost of a prebuilt_apex variant is generally low as at worst it will involve some
340// extra copying of files. Contrast that with source apex modules that has to build each variant
341// from source.
342func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) {
343
344 // Collect direct dependencies into contents.
345 contents := make(map[string]android.ApexMembership)
346
347 // Collect the list of dependencies.
348 var dependencies []android.ApexModule
Paul Duffinb17d0442021-05-05 12:07:00 +0100349 mctx.WalkDeps(func(child, parent android.Module) bool {
350 // If the child is not in the same apex as the parent then exit immediately and do not visit
351 // any of the child's dependencies.
352 if !android.IsDepInSameApex(mctx, parent, child) {
353 return false
354 }
355
356 tag := mctx.OtherModuleDependencyTag(child)
357 depName := mctx.OtherModuleName(child)
Paul Duffin023dba02021-04-22 01:45:29 +0100358 if exportedTag, ok := tag.(exportedDependencyTag); ok {
359 propertyName := exportedTag.name
Paul Duffindfd33262021-04-06 17:02:08 +0100360
361 // It is an error if the other module is not a prebuilt.
Paul Duffinb17d0442021-05-05 12:07:00 +0100362 if !android.IsModulePrebuilt(child) {
Paul Duffin023dba02021-04-22 01:45:29 +0100363 mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName)
Paul Duffinb17d0442021-05-05 12:07:00 +0100364 return false
Paul Duffindfd33262021-04-06 17:02:08 +0100365 }
366
367 // It is an error if the other module is not an ApexModule.
Paul Duffinb17d0442021-05-05 12:07:00 +0100368 if _, ok := child.(android.ApexModule); !ok {
Paul Duffin023dba02021-04-22 01:45:29 +0100369 mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName)
Paul Duffinb17d0442021-05-05 12:07:00 +0100370 return false
Paul Duffindfd33262021-04-06 17:02:08 +0100371 }
Paul Duffindfd33262021-04-06 17:02:08 +0100372 }
Paul Duffinb17d0442021-05-05 12:07:00 +0100373
Paul Duffinfee8cf32021-06-29 18:38:38 +0100374 // Ignore any modules that do not implement ApexModule as they cannot have an APEX specific
375 // variant.
376 if _, ok := child.(android.ApexModule); !ok {
377 return false
378 }
379
Paul Duffinb17d0442021-05-05 12:07:00 +0100380 // Strip off the prebuilt_ prefix if present before storing content to ensure consistent
381 // behavior whether there is a corresponding source module present or not.
382 depName = android.RemoveOptionalPrebuiltPrefix(depName)
383
384 // Remember if this module was added as a direct dependency.
385 direct := parent == mctx.Module()
386 contents[depName] = contents[depName].Add(direct)
387
388 // Add the module to the list of dependencies that need to have an APEX variant.
389 dependencies = append(dependencies, child.(android.ApexModule))
390
391 return true
Paul Duffindfd33262021-04-06 17:02:08 +0100392 })
393
394 // Create contents for the prebuilt_apex and store it away for later use.
395 apexContents := android.NewApexContents(contents)
396 mctx.SetProvider(ApexBundleInfoProvider, ApexBundleInfo{
397 Contents: apexContents,
398 })
399
400 // Create an ApexInfo for the prebuilt_apex.
Martin Stjernholmd8da28e2021-06-24 14:37:13 +0100401 apexVariationName := p.ApexVariationName()
Paul Duffindfd33262021-04-06 17:02:08 +0100402 apexInfo := android.ApexInfo{
Martin Stjernholmc4f4ced2021-05-27 11:17:00 +0000403 ApexVariationName: apexVariationName,
404 InApexVariants: []string{apexVariationName},
Martin Stjernholmd8da28e2021-06-24 14:37:13 +0100405 InApexModules: []string{p.ModuleBase.BaseModuleName()}, // BaseModuleName() to avoid the prebuilt_ prefix.
Paul Duffindfd33262021-04-06 17:02:08 +0100406 ApexContents: []*android.ApexContents{apexContents},
407 ForPrebuiltApex: true,
408 }
409
410 // Mark the dependencies of this module as requiring a variant for this module.
411 for _, am := range dependencies {
412 am.BuildForApex(apexInfo)
413 }
414}
415
Paul Duffin11216db2021-03-01 14:14:52 +0000416// prebuiltApexSelectorModule is a private module type that is only created by the prebuilt_apex
417// module. It selects the apex to use and makes it available for use by prebuilt_apex and the
418// deapexer.
419type prebuiltApexSelectorModule struct {
420 android.ModuleBase
421
422 apexFileProperties ApexFileProperties
423
424 inputApex android.Path
425}
426
427func privateApexSelectorModuleFactory() android.Module {
428 module := &prebuiltApexSelectorModule{}
429 module.AddProperties(
430 &module.apexFileProperties,
431 )
432 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
433 return module
434}
435
436func (p *prebuiltApexSelectorModule) Srcs() android.Paths {
437 return android.Paths{p.inputApex}
438}
439
440func (p *prebuiltApexSelectorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
441 p.inputApex = android.SingleSourcePathFromSupplier(ctx, p.apexFileProperties.prebuiltApexSelector, "src")
442}
443
Jiyong Park09d77522019-11-18 11:16:27 +0900444type Prebuilt struct {
Jiyong Park10e926b2020-07-16 21:38:56 +0900445 prebuiltCommon
Jiyong Park09d77522019-11-18 11:16:27 +0900446
Paul Duffinbb0dc132021-05-05 16:58:08 +0100447 properties PrebuiltProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900448
Paul Duffinef6b6952021-06-15 11:34:01 +0100449 inputApex android.Path
Jiyong Park09d77522019-11-18 11:16:27 +0900450}
451
Paul Duffin851f3992021-01-13 17:03:51 +0000452type ApexFileProperties struct {
Jiyong Park09d77522019-11-18 11:16:27 +0900453 // the path to the prebuilt .apex file to import.
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000454 //
455 // This cannot be marked as `android:"arch_variant"` because the `prebuilt_apex` is only mutated
456 // for android_common. That is so that it will have the same arch variant as, and so be compatible
457 // with, the source `apex` module type that it replaces.
Paul Duffin11216db2021-03-01 14:14:52 +0000458 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900459 Arch struct {
460 Arm struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000461 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900462 }
463 Arm64 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000464 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900465 }
466 X86 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000467 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900468 }
469 X86_64 struct {
Paul Duffin11216db2021-03-01 14:14:52 +0000470 Src *string `android:"path"`
Jiyong Park09d77522019-11-18 11:16:27 +0900471 }
472 }
Paul Duffin851f3992021-01-13 17:03:51 +0000473}
474
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000475// prebuiltApexSelector selects the correct prebuilt APEX file for the build target.
476//
477// The ctx parameter can be for any module not just the prebuilt module so care must be taken not
478// to use methods on it that are specific to the current module.
479//
480// See the ApexFileProperties.Src property.
481func (p *ApexFileProperties) prebuiltApexSelector(ctx android.BaseModuleContext, prebuilt android.Module) []string {
482 multiTargets := prebuilt.MultiTargets()
483 if len(multiTargets) != 1 {
484 ctx.OtherModuleErrorf(prebuilt, "compile_multilib shouldn't be \"both\" for prebuilt_apex")
485 return nil
Paul Duffin851f3992021-01-13 17:03:51 +0000486 }
487 var src string
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000488 switch multiTargets[0].Arch.ArchType {
Paul Duffin851f3992021-01-13 17:03:51 +0000489 case android.Arm:
490 src = String(p.Arch.Arm.Src)
491 case android.Arm64:
492 src = String(p.Arch.Arm64.Src)
493 case android.X86:
494 src = String(p.Arch.X86.Src)
495 case android.X86_64:
496 src = String(p.Arch.X86_64.Src)
Paul Duffin851f3992021-01-13 17:03:51 +0000497 }
498 if src == "" {
499 src = String(p.Src)
500 }
Paul Duffin851f3992021-01-13 17:03:51 +0000501
Paul Duffinc0609c62021-03-01 17:27:16 +0000502 if src == "" {
503 ctx.OtherModuleErrorf(prebuilt, "prebuilt_apex does not support %q", multiTargets[0].Arch.String())
504 // Drop through to return an empty string as the src (instead of nil) to avoid the prebuilt
505 // logic from reporting a more general, less useful message.
506 }
507
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000508 return []string{src}
Paul Duffin851f3992021-01-13 17:03:51 +0000509}
510
511type PrebuiltProperties struct {
512 ApexFileProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900513
Paul Duffinef6b6952021-06-15 11:34:01 +0100514 PrebuiltCommonProperties
Jiyong Park09d77522019-11-18 11:16:27 +0900515}
516
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700517func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool {
518 return false
519}
520
Jiyong Park09d77522019-11-18 11:16:27 +0900521func (p *Prebuilt) OutputFiles(tag string) (android.Paths, error) {
522 switch tag {
523 case "":
524 return android.Paths{p.outputApex}, nil
525 default:
526 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
527 }
528}
529
Jiyong Park09d77522019-11-18 11:16:27 +0900530// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
531func PrebuiltFactory() android.Module {
532 module := &Prebuilt{}
Paul Duffinef6b6952021-06-15 11:34:01 +0100533 module.AddProperties(&module.properties)
534 module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
Paul Duffin064b70c2020-11-02 17:32:38 +0000535
Jiyong Park09d77522019-11-18 11:16:27 +0900536 return module
537}
538
Paul Duffin5dda3e32021-05-05 14:13:27 +0100539func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, apexFileProperties *ApexFileProperties) {
Paul Duffin11216db2021-03-01 14:14:52 +0000540 props := struct {
541 Name *string
542 }{
543 Name: proptools.StringPtr(name),
544 }
545
546 ctx.CreateModule(privateApexSelectorModuleFactory,
547 &props,
548 apexFileProperties,
549 )
550}
551
Paul Duffin5dda3e32021-05-05 14:13:27 +0100552// createDeapexerModuleIfNeeded will create a deapexer module if it is needed.
553//
Paul Duffin57f83592021-05-05 15:09:44 +0100554// A deapexer module is only needed when the prebuilt apex specifies one or more modules in either
555// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that
556// the listed modules need access to files from within the prebuilt .apex file.
Paul Duffinef6b6952021-06-15 11:34:01 +0100557func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string, properties *PrebuiltCommonProperties) {
Paul Duffin5dda3e32021-05-05 14:13:27 +0100558 // Only create the deapexer module if it is needed.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100559 if len(properties.Exported_java_libs)+len(properties.Exported_bootclasspath_fragments) == 0 {
Paul Duffin5dda3e32021-05-05 14:13:27 +0100560 return
561 }
562
Paul Duffin57f83592021-05-05 15:09:44 +0100563 // Compute the deapexer properties from the transitive dependencies of this module.
Paul Duffinb5084052021-06-07 10:25:31 +0100564 commonModules := []string{}
Paul Duffin034196d2021-06-17 15:59:07 +0100565 exportedFiles := []string{}
Paul Duffin57f83592021-05-05 15:09:44 +0100566 ctx.WalkDeps(func(child, parent android.Module) bool {
567 tag := ctx.OtherModuleDependencyTag(child)
568
Paul Duffin7db57e02021-06-17 14:56:05 +0100569 // If the child is not in the same apex as the parent then ignore it and all its children.
570 if !android.IsDepInSameApex(ctx, parent, child) {
571 return false
572 }
573
Paul Duffin57f83592021-05-05 15:09:44 +0100574 name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
Paul Duffin7db57e02021-06-17 14:56:05 +0100575 if _, ok := tag.(android.RequiresFilesFromPrebuiltApexTag); ok {
Paul Duffinb5084052021-06-07 10:25:31 +0100576 commonModules = append(commonModules, name)
577
578 requiredFiles := child.(android.RequiredFilesFromPrebuiltApex).RequiredFilesFromPrebuiltApex(ctx)
Paul Duffin034196d2021-06-17 15:59:07 +0100579 exportedFiles = append(exportedFiles, requiredFiles...)
Paul Duffinb5084052021-06-07 10:25:31 +0100580
Paul Duffin7db57e02021-06-17 14:56:05 +0100581 // Visit the dependencies of this module just in case they also require files from the
582 // prebuilt apex.
Paul Duffin57f83592021-05-05 15:09:44 +0100583 return true
584 }
585
586 return false
587 })
588
Paul Duffin3bae0682021-05-05 18:03:47 +0100589 // Create properties for deapexer module.
590 deapexerProperties := &DeapexerProperties{
Paul Duffinb5084052021-06-07 10:25:31 +0100591 // Remove any duplicates from the common modules lists as a module may be included via a direct
Paul Duffin3bae0682021-05-05 18:03:47 +0100592 // dependency as well as transitive ones.
Paul Duffinb5084052021-06-07 10:25:31 +0100593 CommonModules: android.SortedUniqueStrings(commonModules),
Paul Duffin3bae0682021-05-05 18:03:47 +0100594 }
595
596 // Populate the exported files property in a fixed order.
Paul Duffin034196d2021-06-17 15:59:07 +0100597 deapexerProperties.ExportedFiles = android.SortedUniqueStrings(exportedFiles)
Paul Duffin57f83592021-05-05 15:09:44 +0100598
Paul Duffin11216db2021-03-01 14:14:52 +0000599 props := struct {
600 Name *string
601 Selected_apex *string
602 }{
603 Name: proptools.StringPtr(deapexerName),
604 Selected_apex: proptools.StringPtr(apexFileSource),
605 }
606 ctx.CreateModule(privateDeapexerFactory,
607 &props,
608 deapexerProperties,
609 )
610}
611
612func deapexerModuleName(baseModuleName string) string {
613 return baseModuleName + ".deapexer"
614}
615
616func apexSelectorModuleName(baseModuleName string) string {
617 return baseModuleName + ".apex.selector"
618}
619
Paul Duffin064b70c2020-11-02 17:32:38 +0000620func prebuiltApexExportedModuleName(ctx android.BottomUpMutatorContext, name string) string {
621 // The prebuilt_apex should be depending on prebuilt modules but as this runs after
622 // prebuilt_rename the prebuilt module may or may not be using the prebuilt_ prefixed named. So,
623 // check to see if the prefixed name is in use first, if it is then use that, otherwise assume
624 // the unprefixed name is the one to use. If the unprefixed one turns out to be a source module
625 // and not a renamed prebuilt module then that will be detected and reported as an error when
626 // processing the dependency in ApexInfoMutator().
Paul Duffin864116c2021-04-02 10:24:13 +0100627 prebuiltName := android.PrebuiltNameFromSource(name)
Paul Duffin064b70c2020-11-02 17:32:38 +0000628 if ctx.OtherModuleExists(prebuiltName) {
629 name = prebuiltName
630 }
631 return name
632}
633
Paul Duffina7139422021-02-08 11:01:58 +0000634type exportedDependencyTag struct {
635 blueprint.BaseDependencyTag
636 name string
637}
638
639// Mark this tag so dependencies that use it are excluded from visibility enforcement.
640//
641// This does allow any prebuilt_apex to reference any module which does open up a small window for
642// restricted visibility modules to be referenced from the wrong prebuilt_apex. However, doing so
643// avoids opening up a much bigger window by widening the visibility of modules that need files
644// provided by the prebuilt_apex to include all the possible locations they may be defined, which
645// could include everything below vendor/.
646//
647// A prebuilt_apex that references a module via this tag will have to contain the appropriate files
648// corresponding to that module, otherwise it will fail when attempting to retrieve the files from
649// the .apex file. It will also have to be included in the module's apex_available property too.
650// That makes it highly unlikely that a prebuilt_apex would reference a restricted module
651// incorrectly.
652func (t exportedDependencyTag) ExcludeFromVisibilityEnforcement() {}
653
Paul Duffin7db57e02021-06-17 14:56:05 +0100654func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {}
655
656var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{}
657
Paul Duffina7139422021-02-08 11:01:58 +0000658var (
Paul Duffin023dba02021-04-22 01:45:29 +0100659 exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
660 exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
Paul Duffina7139422021-02-08 11:01:58 +0000661)
662
Paul Duffin5dda3e32021-05-05 14:13:27 +0100663var _ prebuiltApexModuleCreator = (*Prebuilt)(nil)
664
665// createPrebuiltApexModules creates modules necessary to export files from the prebuilt apex to the
666// build.
667//
668// If this needs to make files from within a `.apex` file available for use by other Soong modules,
669// e.g. make dex implementation jars available for java_import modules listed in exported_java_libs,
670// it does so as follows:
671//
672// 1. It creates a `deapexer` module that actually extracts the files from the `.apex` file and
673// makes them available for use by other modules, at both Soong and ninja levels.
674//
675// 2. It adds a dependency onto those modules and creates an apex specific variant similar to what
676// an `apex` module does. That ensures that code which looks for specific apex variant, e.g.
677// dexpreopt, will work the same way from source and prebuilt.
678//
679// 3. The `deapexer` module adds a dependency from the modules that require the exported files onto
680// itself so that they can retrieve the file paths to those files.
681//
682// It also creates a child module `selector` that is responsible for selecting the appropriate
683// input apex for both the prebuilt_apex and the deapexer. That is needed for a couple of reasons:
684// 1. To dedup the selection logic so it only runs in one module.
685// 2. To allow the deapexer to be wired up to a different source for the input apex, e.g. an
686// `apex_set`.
687//
688// prebuilt_apex
689// / | \
690// / | \
691// V V V
692// selector <--- deapexer <--- exported java lib
693//
694func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
695 baseModuleName := p.BaseModuleName()
696
697 apexSelectorModuleName := apexSelectorModuleName(baseModuleName)
698 createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties)
699
700 apexFileSource := ":" + apexSelectorModuleName
Paul Duffinef6b6952021-06-15 11:34:01 +0100701 createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, p.prebuiltCommonProperties)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100702
703 // Add a source reference to retrieve the selected apex from the selector module.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100704 p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100705}
706
Paul Duffin57f83592021-05-05 15:09:44 +0100707func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
708 p.prebuiltApexContentsDeps(ctx)
Paul Duffin064b70c2020-11-02 17:32:38 +0000709}
710
711var _ ApexInfoMutator = (*Prebuilt)(nil)
712
Paul Duffin064b70c2020-11-02 17:32:38 +0000713func (p *Prebuilt) ApexInfoMutator(mctx android.TopDownMutatorContext) {
Paul Duffindfd33262021-04-06 17:02:08 +0100714 p.apexInfoMutator(mctx)
Jiyong Park09d77522019-11-18 11:16:27 +0900715}
716
717func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park09d77522019-11-18 11:16:27 +0900718 // TODO(jungjw): Check the key validity.
Paul Duffinbb0dc132021-05-05 16:58:08 +0100719 p.inputApex = android.OptionalPathForModuleSrc(ctx, p.prebuiltCommonProperties.Selected_apex).Path()
Jiyong Park09d77522019-11-18 11:16:27 +0900720 p.installDir = android.PathForModuleInstall(ctx, "apex")
721 p.installFilename = p.InstallFilename()
722 if !strings.HasSuffix(p.installFilename, imageApexSuffix) {
723 ctx.ModuleErrorf("filename should end in %s for prebuilt_apex", imageApexSuffix)
724 }
725 p.outputApex = android.PathForModuleOut(ctx, p.installFilename)
726 ctx.Build(pctx, android.BuildParams{
727 Rule: android.Cp,
728 Input: p.inputApex,
729 Output: p.outputApex,
730 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900731
732 if p.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800733 p.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900734 return
735 }
736
Paul Duffinc30aea22021-06-15 19:10:11 +0100737 // Save the files that need to be made available to Make.
738 p.initApexFilesForAndroidMk(ctx)
739
Jiyong Park09d77522019-11-18 11:16:27 +0900740 if p.installable() {
741 ctx.InstallFile(p.installDir, p.installFilename, p.inputApex)
742 }
743
Jooyung Han002ab682020-01-08 01:57:58 +0900744 // in case that prebuilt_apex replaces source apex (using prefer: prop)
745 p.compatSymlinks = makeCompatSymlinks(p.BaseModuleName(), ctx)
746 // or that prebuilt_apex overrides other apexes (using overrides: prop)
Paul Duffinef6b6952021-06-15 11:34:01 +0100747 for _, overridden := range p.prebuiltCommonProperties.Overrides {
Jooyung Han002ab682020-01-08 01:57:58 +0900748 p.compatSymlinks = append(p.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
749 }
Jiyong Park09d77522019-11-18 11:16:27 +0900750}
751
Paul Duffin24704672021-04-06 16:09:30 +0100752// prebuiltApexExtractorModule is a private module type that is only created by the prebuilt_apex
753// module. It extracts the correct apex to use and makes it available for use by apex_set.
754type prebuiltApexExtractorModule struct {
755 android.ModuleBase
756
757 properties ApexExtractorProperties
758
759 extractedApex android.WritablePath
760}
761
762func privateApexExtractorModuleFactory() android.Module {
763 module := &prebuiltApexExtractorModule{}
764 module.AddProperties(
765 &module.properties,
766 )
767 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
768 return module
769}
770
771func (p *prebuiltApexExtractorModule) Srcs() android.Paths {
772 return android.Paths{p.extractedApex}
773}
774
775func (p *prebuiltApexExtractorModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
776 srcsSupplier := func(ctx android.BaseModuleContext, prebuilt android.Module) []string {
777 return p.properties.prebuiltSrcs(ctx)
778 }
779 apexSet := android.SingleSourcePathFromSupplier(ctx, srcsSupplier, "set")
780 p.extractedApex = android.PathForModuleOut(ctx, "extracted", apexSet.Base())
781 ctx.Build(pctx,
782 android.BuildParams{
783 Rule: extractMatchingApex,
784 Description: "Extract an apex from an apex set",
785 Inputs: android.Paths{apexSet},
786 Output: p.extractedApex,
787 Args: map[string]string{
788 "abis": strings.Join(java.SupportedAbis(ctx), ","),
789 "allow-prereleased": strconv.FormatBool(proptools.Bool(p.properties.Prerelease)),
790 "sdk-version": ctx.Config().PlatformSdkVersion().String(),
791 },
792 })
793}
794
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700795type ApexSet struct {
Jiyong Park10e926b2020-07-16 21:38:56 +0900796 prebuiltCommon
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700797
798 properties ApexSetProperties
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700799}
800
Paul Duffin24704672021-04-06 16:09:30 +0100801type ApexExtractorProperties struct {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700802 // the .apks file path that contains prebuilt apex files to be extracted.
803 Set *string
804
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700805 Sanitized struct {
806 None struct {
807 Set *string
808 }
809 Address struct {
810 Set *string
811 }
812 Hwaddress struct {
813 Set *string
814 }
815 }
816
Paul Duffin24704672021-04-06 16:09:30 +0100817 // apexes in this set use prerelease SDK version
818 Prerelease *bool
819}
820
821func (e *ApexExtractorProperties) prebuiltSrcs(ctx android.BaseModuleContext) []string {
822 var srcs []string
823 if e.Set != nil {
824 srcs = append(srcs, *e.Set)
825 }
826
827 var sanitizers []string
828 if ctx.Host() {
829 sanitizers = ctx.Config().SanitizeHost()
830 } else {
831 sanitizers = ctx.Config().SanitizeDevice()
832 }
833
834 if android.InList("address", sanitizers) && e.Sanitized.Address.Set != nil {
835 srcs = append(srcs, *e.Sanitized.Address.Set)
836 } else if android.InList("hwaddress", sanitizers) && e.Sanitized.Hwaddress.Set != nil {
837 srcs = append(srcs, *e.Sanitized.Hwaddress.Set)
838 } else if e.Sanitized.None.Set != nil {
839 srcs = append(srcs, *e.Sanitized.None.Set)
840 }
841
842 return srcs
843}
844
845type ApexSetProperties struct {
846 ApexExtractorProperties
847
Paul Duffinef6b6952021-06-15 11:34:01 +0100848 PrebuiltCommonProperties
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700849}
850
851func (a *ApexSet) hasSanitizedSource(sanitizer string) bool {
852 if sanitizer == "address" {
853 return a.properties.Sanitized.Address.Set != nil
854 }
855 if sanitizer == "hwaddress" {
856 return a.properties.Sanitized.Hwaddress.Set != nil
857 }
858
859 return false
860}
861
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700862// prebuilt_apex imports an `.apex` file into the build graph as if it was built with apex.
863func apexSetFactory() android.Module {
864 module := &ApexSet{}
Paul Duffinef6b6952021-06-15 11:34:01 +0100865 module.AddProperties(&module.properties)
866 module.initPrebuiltCommon(module, &module.properties.PrebuiltCommonProperties)
Paul Duffin24704672021-04-06 16:09:30 +0100867
Paul Duffin24704672021-04-06 16:09:30 +0100868 return module
869}
870
Paul Duffin5dda3e32021-05-05 14:13:27 +0100871func createApexExtractorModule(ctx android.TopDownMutatorContext, name string, apexExtractorProperties *ApexExtractorProperties) {
Paul Duffin24704672021-04-06 16:09:30 +0100872 props := struct {
873 Name *string
874 }{
875 Name: proptools.StringPtr(name),
Evgenii Stepanov2080bfe2020-07-24 15:35:40 -0700876 }
877
Paul Duffin24704672021-04-06 16:09:30 +0100878 ctx.CreateModule(privateApexExtractorModuleFactory,
879 &props,
880 apexExtractorProperties,
881 )
882}
883
884func apexExtractorModuleName(baseModuleName string) string {
885 return baseModuleName + ".apex.extractor"
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700886}
887
Paul Duffin5dda3e32021-05-05 14:13:27 +0100888var _ prebuiltApexModuleCreator = (*ApexSet)(nil)
889
890// createPrebuiltApexModules creates modules necessary to export files from the apex set to other
891// modules.
892//
893// This effectively does for apex_set what Prebuilt.createPrebuiltApexModules does for a
894// prebuilt_apex except that instead of creating a selector module which selects one .apex file
895// from those provided this creates an extractor module which extracts the appropriate .apex file
896// from the zip file containing them.
897func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
898 baseModuleName := a.BaseModuleName()
899
900 apexExtractorModuleName := apexExtractorModuleName(baseModuleName)
901 createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties)
902
903 apexFileSource := ":" + apexExtractorModuleName
Paul Duffinef6b6952021-06-15 11:34:01 +0100904 createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, a.prebuiltCommonProperties)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100905
906 // After passing the arch specific src properties to the creating the apex selector module
Paul Duffinbb0dc132021-05-05 16:58:08 +0100907 a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
Paul Duffin5dda3e32021-05-05 14:13:27 +0100908}
909
Paul Duffin57f83592021-05-05 15:09:44 +0100910func (a *ApexSet) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
911 a.prebuiltApexContentsDeps(ctx)
Paul Duffinf58fd9a2021-04-06 16:00:22 +0100912}
913
914var _ ApexInfoMutator = (*ApexSet)(nil)
915
916func (a *ApexSet) ApexInfoMutator(mctx android.TopDownMutatorContext) {
917 a.apexInfoMutator(mctx)
918}
919
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700920func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
921 a.installFilename = a.InstallFilename()
922 if !strings.HasSuffix(a.installFilename, imageApexSuffix) {
923 ctx.ModuleErrorf("filename should end in %s for apex_set", imageApexSuffix)
924 }
925
Paul Duffinbb0dc132021-05-05 16:58:08 +0100926 inputApex := android.OptionalPathForModuleSrc(ctx, a.prebuiltCommonProperties.Selected_apex).Path()
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700927 a.outputApex = android.PathForModuleOut(ctx, a.installFilename)
Paul Duffin24704672021-04-06 16:09:30 +0100928 ctx.Build(pctx, android.BuildParams{
929 Rule: android.Cp,
930 Input: inputApex,
931 Output: a.outputApex,
932 })
Jiyong Park10e926b2020-07-16 21:38:56 +0900933
934 if a.prebuiltCommon.checkForceDisable(ctx) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800935 a.HideFromMake()
Jiyong Park10e926b2020-07-16 21:38:56 +0900936 return
937 }
938
Paul Duffinc30aea22021-06-15 19:10:11 +0100939 // Save the files that need to be made available to Make.
940 a.initApexFilesForAndroidMk(ctx)
941
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700942 a.installDir = android.PathForModuleInstall(ctx, "apex")
943 if a.installable() {
944 ctx.InstallFile(a.installDir, a.installFilename, a.outputApex)
945 }
946
947 // in case that apex_set replaces source apex (using prefer: prop)
948 a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
949 // or that apex_set overrides other apexes (using overrides: prop)
Paul Duffinef6b6952021-06-15 11:34:01 +0100950 for _, overridden := range a.prebuiltCommonProperties.Overrides {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700951 a.compatSymlinks = append(a.compatSymlinks, makeCompatSymlinks(overridden, ctx)...)
952 }
953}
954
Paul Duffinef6b6952021-06-15 11:34:01 +0100955type systemExtContext struct {
956 android.ModuleContext
957}
958
959func (*systemExtContext) SystemExtSpecific() bool {
960 return true
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700961}