blob: d0570b4130cd7234e597c18724bead20f595e34e [file] [log] [blame]
Paul Duffin3451e162021-01-20 15:16:56 +00001// Copyright (C) 2021 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 java
16
17import (
Paul Duffina1d60252021-01-21 18:13:43 +000018 "fmt"
Paul Duffin7c955552021-04-19 13:23:53 +010019 "path/filepath"
Paul Duffinba6afd02019-11-19 19:44:10 +000020 "reflect"
Paul Duffin3451e162021-01-20 15:16:56 +000021 "strings"
22
23 "android/soong/android"
Paul Duffina1d60252021-01-21 18:13:43 +000024 "android/soong/dexpreopt"
Paul Duffinc7ef9892021-03-23 23:21:59 +000025 "github.com/google/blueprint/proptools"
Martin Stjernholmb79c7f12021-03-17 00:26:25 +000026
Paul Duffin3451e162021-01-20 15:16:56 +000027 "github.com/google/blueprint"
28)
29
30func init() {
Paul Duffin7771eba2021-04-23 14:25:28 +010031 registerBootclasspathFragmentBuildComponents(android.InitRegistrationContext)
Paul Duffinf7f65da2021-03-10 15:00:46 +000032
Paul Duffin7771eba2021-04-23 14:25:28 +010033 android.RegisterSdkMemberType(&bootclasspathFragmentMemberType{
Paul Duffin4b64ba02021-03-29 11:02:53 +010034 SdkMemberTypeBase: android.SdkMemberTypeBase{
35 PropertyName: "bootclasspath_fragments",
36 SupportsSdk: true,
37 },
38 })
Paul Duffin3451e162021-01-20 15:16:56 +000039}
40
Paul Duffin7771eba2021-04-23 14:25:28 +010041func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +010042 ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory)
43 ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory)
Paul Duffin3451e162021-01-20 15:16:56 +000044}
45
Paul Duffin65898052021-04-20 22:47:03 +010046type bootclasspathFragmentContentDependencyTag struct {
Paul Duffinc7ef9892021-03-23 23:21:59 +000047 blueprint.BaseDependencyTag
48}
49
Paul Duffin7771eba2021-04-23 14:25:28 +010050// Avoid having to make bootclasspath_fragment content visible to the bootclasspath_fragment.
Paul Duffinc7ef9892021-03-23 23:21:59 +000051//
Paul Duffin7771eba2021-04-23 14:25:28 +010052// This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules
53// with proper dependencies.
Paul Duffinc7ef9892021-03-23 23:21:59 +000054// TODO(b/177892522): Remove this and add needed visibility.
Paul Duffin65898052021-04-20 22:47:03 +010055func (b bootclasspathFragmentContentDependencyTag) ExcludeFromVisibilityEnforcement() {
56}
57
58// The bootclasspath_fragment contents must never depend on prebuilts.
59func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
60 return false
Paul Duffinc7ef9892021-03-23 23:21:59 +000061}
62
Paul Duffin7771eba2021-04-23 14:25:28 +010063// The tag used for the dependency between the bootclasspath_fragment module and its contents.
Paul Duffin65898052021-04-20 22:47:03 +010064var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{}
Paul Duffinc7ef9892021-03-23 23:21:59 +000065
Paul Duffin65898052021-04-20 22:47:03 +010066var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag
67var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag
Paul Duffinc7ef9892021-03-23 23:21:59 +000068
Paul Duffin65898052021-04-20 22:47:03 +010069func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
70 return tag == bootclasspathFragmentContentDepTag
Paul Duffin4d101b62021-03-24 15:42:20 +000071}
72
Paul Duffinc7d16442021-04-23 13:55:49 +010073// Properties that can be different when coverage is enabled.
74type BootclasspathFragmentCoverageAffectedProperties struct {
75 // The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library.
76 //
77 // The order of this list matters as it is the order that is used in the bootclasspath.
78 Contents []string
79}
80
Paul Duffin7771eba2021-04-23 14:25:28 +010081type bootclasspathFragmentProperties struct {
Paul Duffin3451e162021-01-20 15:16:56 +000082 // The name of the image this represents.
83 //
Paul Duffin82886d62021-03-24 01:34:57 +000084 // If specified then it must be one of "art" or "boot".
Paul Duffin64be7bb2021-03-23 23:06:38 +000085 Image_name *string
Paul Duffinc7ef9892021-03-23 23:21:59 +000086
Paul Duffinc7d16442021-04-23 13:55:49 +010087 // Properties whose values need to differ with and without coverage.
88 BootclasspathFragmentCoverageAffectedProperties
89 Coverage BootclasspathFragmentCoverageAffectedProperties
Paul Duffin9b381ef2021-04-08 23:01:37 +010090
91 Hidden_api HiddenAPIFlagFileProperties
Paul Duffin3451e162021-01-20 15:16:56 +000092}
93
Paul Duffin7771eba2021-04-23 14:25:28 +010094type BootclasspathFragmentModule struct {
Paul Duffin3451e162021-01-20 15:16:56 +000095 android.ModuleBase
Paul Duffina1d60252021-01-21 18:13:43 +000096 android.ApexModuleBase
Paul Duffinf7f65da2021-03-10 15:00:46 +000097 android.SdkBase
Paul Duffin7771eba2021-04-23 14:25:28 +010098 properties bootclasspathFragmentProperties
Paul Duffin3451e162021-01-20 15:16:56 +000099}
100
Paul Duffin7771eba2021-04-23 14:25:28 +0100101func bootclasspathFragmentFactory() android.Module {
102 m := &BootclasspathFragmentModule{}
Paul Duffin3451e162021-01-20 15:16:56 +0000103 m.AddProperties(&m.properties)
Paul Duffina1d60252021-01-21 18:13:43 +0000104 android.InitApexModule(m)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000105 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000106 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000107
Paul Duffinc7ef9892021-03-23 23:21:59 +0000108 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffinc7d16442021-04-23 13:55:49 +0100109 // If code coverage has been enabled for the framework then append the properties with
110 // coverage specific properties.
111 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
112 err := proptools.AppendProperties(&m.properties.BootclasspathFragmentCoverageAffectedProperties, &m.properties.Coverage, nil)
113 if err != nil {
114 ctx.PropertyErrorf("coverage", "error trying to append coverage specific properties: %s", err)
115 return
116 }
117 }
118
119 // Initialize the contents property from the image_name.
Paul Duffin7771eba2021-04-23 14:25:28 +0100120 bootclasspathFragmentInitContentsFromImage(ctx, m)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000121 })
Paul Duffin3451e162021-01-20 15:16:56 +0000122 return m
123}
124
Paul Duffin7771eba2021-04-23 14:25:28 +0100125// bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if
126// necessary.
127func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
Paul Duffin82886d62021-03-24 01:34:57 +0000128 contents := m.properties.Contents
129 if m.properties.Image_name == nil && len(contents) == 0 {
130 ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
131 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000132
133 if len(contents) != 0 {
134 // Nothing to do.
135 return
Paul Duffin82886d62021-03-24 01:34:57 +0000136 }
Paul Duffin023dba02021-04-22 01:45:29 +0100137
Paul Duffinc7ef9892021-03-23 23:21:59 +0000138 imageName := proptools.String(m.properties.Image_name)
139 if imageName == "art" {
Paul Duffin023dba02021-04-22 01:45:29 +0100140 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
141 if m.MemberName() != "" {
142 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
143 // 1. There is no way to use this at the moment so ignoring it is safe.
144 // 2. Attempting to initialize the contents property from the configuration will end up having
145 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
146 // as the unversioned prebuilt could end up with an APEX variant created for the source
147 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
148 // turn will prevent it from accessing the dex implementation jar from that which will
149 // break hidden API processing, amongst others.
150 return
151 }
152
Paul Duffinc7ef9892021-03-23 23:21:59 +0000153 // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
154 // too early in the Soong processing for that to work.
155 global := dexpreopt.GetGlobalConfig(ctx)
156 modules := global.ArtApexJars
157
158 // Make sure that the apex specified in the configuration is consistent and is one for which
159 // this boot image is available.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000160 commonApex := ""
161 for i := 0; i < modules.Len(); i++ {
162 apex := modules.Apex(i)
163 jar := modules.Jar(i)
164 if apex == "platform" {
165 ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar)
166 continue
167 }
168 if !m.AvailableFor(apex) {
169 ctx.ModuleErrorf("incompatible with ArtApexJars which expects this to be in apex %q but this is only in apexes %q",
170 apex, m.ApexAvailable())
171 continue
172 }
173 if commonApex == "" {
174 commonApex = apex
175 } else if commonApex != apex {
176 ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q",
177 commonApex, apex)
178 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000179 }
180
181 // Store the jars in the Contents property so that they can be used to add dependencies.
Paul Duffinba6afd02019-11-19 19:44:10 +0000182 m.properties.Contents = modules.CopyOfJars()
183 }
184}
185
186// bootclasspathImageNameContentsConsistencyCheck checks that the configuration that applies to this
187// module (if any) matches the contents.
188//
189// This should be a noop as if image_name="art" then the contents will be set from the ArtApexJars
190// config by bootclasspathFragmentInitContentsFromImage so it will be guaranteed to match. However,
191// in future this will not be the case.
192func (b *BootclasspathFragmentModule) bootclasspathImageNameContentsConsistencyCheck(ctx android.BaseModuleContext) {
193 imageName := proptools.String(b.properties.Image_name)
194 if imageName == "art" {
195 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
196 if b.MemberName() != "" {
197 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
198 // 1. There is no way to use this at the moment so ignoring it is safe.
199 // 2. Attempting to initialize the contents property from the configuration will end up having
200 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
201 // as the unversioned prebuilt could end up with an APEX variant created for the source
202 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
203 // turn will prevent it from accessing the dex implementation jar from that which will
204 // break hidden API processing, amongst others.
205 return
206 }
207
208 // Get the configuration for the art apex jars.
209 modules := b.getImageConfig(ctx).modules
210 configuredJars := modules.CopyOfJars()
211
212 // Skip the check if the configured jars list is empty as that is a common configuration when
213 // building targets that do not result in a system image.
214 if len(configuredJars) == 0 {
215 return
216 }
217
218 contents := b.properties.Contents
219 if !reflect.DeepEqual(configuredJars, contents) {
220 ctx.ModuleErrorf("inconsistency in specification of contents. ArtApexJars configuration specifies %#v, contents property specifies %#v",
221 configuredJars, contents)
222 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000223 }
224}
225
Paul Duffine946b322021-04-25 23:04:00 +0100226var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{})
Paul Duffin3451e162021-01-20 15:16:56 +0000227
Paul Duffine946b322021-04-25 23:04:00 +0100228// BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the
229// apex contents.
230type BootclasspathFragmentApexContentInfo struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000231 // The image config, internal to this module (and the dex_bootjars singleton).
Paul Duffina1d60252021-01-21 18:13:43 +0000232 //
Paul Duffine946b322021-04-25 23:04:00 +0100233 // Will be nil if the BootclasspathFragmentApexContentInfo has not been provided for a specific module. That can occur
Paul Duffina1d60252021-01-21 18:13:43 +0000234 // when SkipDexpreoptBootJars(ctx) returns true.
Paul Duffin3451e162021-01-20 15:16:56 +0000235 imageConfig *bootImageConfig
236}
237
Paul Duffine946b322021-04-25 23:04:00 +0100238func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList {
Paul Duffin3451e162021-01-20 15:16:56 +0000239 return i.imageConfig.modules
240}
241
Paul Duffina1d60252021-01-21 18:13:43 +0000242// Get a map from ArchType to the associated boot image's contents for Android.
243//
244// Extension boot images only return their own files, not the files of the boot images they extend.
Paul Duffine946b322021-04-25 23:04:00 +0100245func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths {
Paul Duffina1d60252021-01-21 18:13:43 +0000246 files := map[android.ArchType]android.OutputPaths{}
247 if i.imageConfig != nil {
248 for _, variant := range i.imageConfig.variants {
249 // We also generate boot images for host (for testing), but we don't need those in the apex.
250 // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
251 if variant.target.Os == android.Android {
252 files[variant.target.Arch.ArchType] = variant.imagesDeps
253 }
254 }
255 }
256 return files
257}
258
Paul Duffin190fdef2021-04-26 10:33:59 +0100259// DexBootJarPathForContentModule returns the path to the dex boot jar for specified module.
260//
261// The dex boot jar is one which has had hidden API encoding performed on it.
262func (i BootclasspathFragmentApexContentInfo) DexBootJarPathForContentModule(module android.Module) android.Path {
263 j := module.(UsesLibraryDependency)
264 dexJar := j.DexJarBuildPath()
265 return dexJar
266}
267
Paul Duffin7771eba2021-04-23 14:25:28 +0100268func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffina1d60252021-01-21 18:13:43 +0000269 tag := ctx.OtherModuleDependencyTag(dep)
Paul Duffin65898052021-04-20 22:47:03 +0100270 if IsBootclasspathFragmentContentDepTag(tag) {
Paul Duffin4d101b62021-03-24 15:42:20 +0000271 // Boot image contents are automatically added to apex.
272 return true
Paul Duffinc7ef9892021-03-23 23:21:59 +0000273 }
Bob Badour07065cd2021-02-05 19:59:11 -0800274 if android.IsMetaDependencyTag(tag) {
275 // Cross-cutting metadata dependencies are metadata.
276 return false
277 }
Paul Duffina1d60252021-01-21 18:13:43 +0000278 panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag)))
279}
280
Paul Duffin7771eba2021-04-23 14:25:28 +0100281func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Paul Duffina1d60252021-01-21 18:13:43 +0000282 return nil
283}
284
Paul Duffin65898052021-04-20 22:47:03 +0100285// ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a
286// corresponding source module are renamed. This means that adding a dependency using a name without
287// a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix
288// it will always resolve to a prebuilt module.
Paul Duffin7771eba2021-04-23 14:25:28 +0100289func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin65898052021-04-20 22:47:03 +0100290 module := ctx.Module()
Paul Duffin7771eba2021-04-23 14:25:28 +0100291 _, isSourceModule := module.(*BootclasspathFragmentModule)
Paul Duffin65898052021-04-20 22:47:03 +0100292
293 for _, name := range b.properties.Contents {
294 // A bootclasspath_fragment must depend only on other source modules, while the
295 // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules.
Paul Duffina9dd6fa2021-04-22 17:25:57 +0100296 //
297 // TODO(b/177892522) - avoid special handling of jacocoagent.
298 if !isSourceModule && name != "jacocoagent" {
Paul Duffin65898052021-04-20 22:47:03 +0100299 name = android.PrebuiltNameFromSource(name)
300 }
301 ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name)
302 }
303
304}
305
Paul Duffin7771eba2021-04-23 14:25:28 +0100306func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffinc7ef9892021-03-23 23:21:59 +0000307
Paul Duffina1d60252021-01-21 18:13:43 +0000308 if SkipDexpreoptBootJars(ctx) {
309 return
310 }
311
312 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
313 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
314 dexpreopt.RegisterToolDeps(ctx)
315}
316
Paul Duffin7771eba2021-04-23 14:25:28 +0100317func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000318 // Only perform a consistency check if this module is the active module. That will prevent an
319 // unused prebuilt that was created without instrumentation from breaking an instrumentation
320 // build.
321 if isActiveModule(ctx.Module()) {
322 b.bootclasspathImageNameContentsConsistencyCheck(ctx)
323 }
324
Paul Duffin9b381ef2021-04-08 23:01:37 +0100325 // Perform hidden API processing.
326 b.generateHiddenAPIBuildActions(ctx)
327
Paul Duffin3451e162021-01-20 15:16:56 +0000328 // Nothing to do if skipping the dexpreopt of boot image jars.
329 if SkipDexpreoptBootJars(ctx) {
330 return
331 }
332
Paul Duffina1d60252021-01-21 18:13:43 +0000333 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
334 // GenerateSingletonBuildActions method as it cannot create it for itself.
335 dexpreopt.GetGlobalSoongConfig(ctx)
336
Paul Duffin64be7bb2021-03-23 23:06:38 +0000337 imageConfig := b.getImageConfig(ctx)
Paul Duffin3451e162021-01-20 15:16:56 +0000338 if imageConfig == nil {
Paul Duffin3451e162021-01-20 15:16:56 +0000339 return
340 }
341
342 // Construct the boot image info from the config.
Paul Duffine946b322021-04-25 23:04:00 +0100343 info := BootclasspathFragmentApexContentInfo{imageConfig: imageConfig}
Paul Duffin3451e162021-01-20 15:16:56 +0000344
345 // Make it available for other modules.
Paul Duffine946b322021-04-25 23:04:00 +0100346 ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
Paul Duffin3451e162021-01-20 15:16:56 +0000347}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000348
Paul Duffin7771eba2021-04-23 14:25:28 +0100349func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000350 // Get a map of the image configs that are supported.
351 imageConfigs := genBootImageConfigs(ctx)
352
353 // Retrieve the config for this image.
354 imageNamePtr := b.properties.Image_name
355 if imageNamePtr == nil {
356 return nil
357 }
358
359 imageName := *imageNamePtr
360 imageConfig := imageConfigs[imageName]
361 if imageConfig == nil {
362 ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", "))
363 return nil
364 }
365 return imageConfig
366}
367
Paul Duffin9b381ef2021-04-08 23:01:37 +0100368// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffin7771eba2021-04-23 14:25:28 +0100369func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100370 // Resolve the properties to paths.
371 flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx)
372
373 // Store the information for use by platform_bootclasspath.
374 ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo)
375}
376
Paul Duffin7771eba2021-04-23 14:25:28 +0100377type bootclasspathFragmentMemberType struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000378 android.SdkMemberTypeBase
379}
380
Paul Duffin7771eba2021-04-23 14:25:28 +0100381func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000382 mctx.AddVariationDependencies(nil, dependencyTag, names...)
383}
384
Paul Duffin7771eba2021-04-23 14:25:28 +0100385func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {
386 _, ok := module.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000387 return ok
388}
389
Paul Duffin7771eba2021-04-23 14:25:28 +0100390func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
Paul Duffin4b64ba02021-03-29 11:02:53 +0100391 if b.PropertyName == "boot_images" {
392 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
393 } else {
394 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment")
395 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000396}
397
Paul Duffin7771eba2021-04-23 14:25:28 +0100398func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
399 return &bootclasspathFragmentSdkMemberProperties{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000400}
401
Paul Duffin7771eba2021-04-23 14:25:28 +0100402type bootclasspathFragmentSdkMemberProperties struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000403 android.SdkMemberPropertiesBase
404
Paul Duffina57835e2021-04-19 13:23:06 +0100405 // The image name
Paul Duffin64be7bb2021-03-23 23:06:38 +0000406 Image_name *string
Paul Duffina57835e2021-04-19 13:23:06 +0100407
408 // Contents of the bootclasspath fragment
409 Contents []string
Paul Duffin7c955552021-04-19 13:23:53 +0100410
411 // Flag files by *hiddenAPIFlagFileCategory
412 Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000413}
414
Paul Duffin7771eba2021-04-23 14:25:28 +0100415func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
416 module := variant.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000417
418 b.Image_name = module.properties.Image_name
Paul Duffina57835e2021-04-19 13:23:06 +0100419 if b.Image_name == nil {
420 // Only one of image_name or contents can be specified. However, if image_name is set then the
421 // contents property is updated to match the configuration used to create the corresponding
422 // boot image. Therefore, contents property is only copied if the image name is not specified.
423 b.Contents = module.properties.Contents
424 }
Paul Duffin7c955552021-04-19 13:23:53 +0100425
426 // Get the flag file information from the module.
427 mctx := ctx.SdkModuleContext()
428 flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
429 b.Flag_files_by_category = flagFileInfo.categoryToPaths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000430}
431
Paul Duffin7771eba2021-04-23 14:25:28 +0100432func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000433 if b.Image_name != nil {
434 propertySet.AddProperty("image_name", *b.Image_name)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000435 }
Paul Duffina57835e2021-04-19 13:23:06 +0100436
437 if len(b.Contents) > 0 {
438 propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true))
439 }
Paul Duffin7c955552021-04-19 13:23:53 +0100440
441 builder := ctx.SnapshotBuilder()
442 if b.Flag_files_by_category != nil {
443 hiddenAPISet := propertySet.AddPropertySet("hidden_api")
444 for _, category := range hiddenAPIFlagFileCategories {
445 paths := b.Flag_files_by_category[category]
446 if len(paths) > 0 {
447 dests := []string{}
448 for _, p := range paths {
449 dest := filepath.Join("hiddenapi", p.Base())
450 builder.CopyToSnapshot(p, dest)
451 dests = append(dests, dest)
452 }
453 hiddenAPISet.AddProperty(category.propertyName, dests)
454 }
455 }
456 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000457}
458
Paul Duffin7771eba2021-04-23 14:25:28 +0100459var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000460
Paul Duffin7771eba2021-04-23 14:25:28 +0100461// A prebuilt version of the bootclasspath_fragment module.
Paul Duffinf7f65da2021-03-10 15:00:46 +0000462//
Paul Duffin7771eba2021-04-23 14:25:28 +0100463// At the moment this is basically just a bootclasspath_fragment module that can be used as a
464// prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module
465// type from the various singletons then this will diverge.
466type prebuiltBootclasspathFragmentModule struct {
467 BootclasspathFragmentModule
Paul Duffinf7f65da2021-03-10 15:00:46 +0000468 prebuilt android.Prebuilt
469}
470
Paul Duffin7771eba2021-04-23 14:25:28 +0100471func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000472 return &module.prebuilt
473}
474
Paul Duffin7771eba2021-04-23 14:25:28 +0100475func (module *prebuiltBootclasspathFragmentModule) Name() string {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000476 return module.prebuilt.Name(module.ModuleBase.Name())
477}
478
Paul Duffin7771eba2021-04-23 14:25:28 +0100479func prebuiltBootclasspathFragmentFactory() android.Module {
480 m := &prebuiltBootclasspathFragmentModule{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000481 m.AddProperties(&m.properties)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000482 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
483 // array.
484 android.InitPrebuiltModule(m, &[]string{"placeholder"})
485 android.InitApexModule(m)
486 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000487 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000488
Paul Duffin7771eba2021-04-23 14:25:28 +0100489 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000490 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100491 bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000492 })
Paul Duffinf7f65da2021-03-10 15:00:46 +0000493 return m
494}