blob: fa9bd56a51a6550dd9dc7ca56e5d19a554eb75a6 [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 Duffin3451e162021-01-20 15:16:56 +000020 "strings"
21
22 "android/soong/android"
Paul Duffina1d60252021-01-21 18:13:43 +000023 "android/soong/dexpreopt"
Paul Duffinc7ef9892021-03-23 23:21:59 +000024 "github.com/google/blueprint/proptools"
Martin Stjernholmb79c7f12021-03-17 00:26:25 +000025
Paul Duffin3451e162021-01-20 15:16:56 +000026 "github.com/google/blueprint"
27)
28
29func init() {
Paul Duffin7771eba2021-04-23 14:25:28 +010030 registerBootclasspathFragmentBuildComponents(android.InitRegistrationContext)
Paul Duffinf7f65da2021-03-10 15:00:46 +000031
Paul Duffin4b64ba02021-03-29 11:02:53 +010032 // TODO(b/177892522): Remove after has been replaced by bootclasspath_fragments
Paul Duffin7771eba2021-04-23 14:25:28 +010033 android.RegisterSdkMemberType(&bootclasspathFragmentMemberType{
Paul Duffinf7f65da2021-03-10 15:00:46 +000034 SdkMemberTypeBase: android.SdkMemberTypeBase{
35 PropertyName: "boot_images",
36 SupportsSdk: true,
37 },
38 })
Paul Duffin4b64ba02021-03-29 11:02:53 +010039
Paul Duffin7771eba2021-04-23 14:25:28 +010040 android.RegisterSdkMemberType(&bootclasspathFragmentMemberType{
Paul Duffin4b64ba02021-03-29 11:02:53 +010041 SdkMemberTypeBase: android.SdkMemberTypeBase{
42 PropertyName: "bootclasspath_fragments",
43 SupportsSdk: true,
44 },
45 })
Paul Duffin3451e162021-01-20 15:16:56 +000046}
47
Paul Duffin7771eba2021-04-23 14:25:28 +010048func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) {
Paul Duffin4b64ba02021-03-29 11:02:53 +010049 // TODO(b/177892522): Remove after has been replaced by bootclasspath_fragment
Paul Duffin7771eba2021-04-23 14:25:28 +010050 ctx.RegisterModuleType("boot_image", bootclasspathFragmentFactory)
51 ctx.RegisterModuleType("prebuilt_boot_image", prebuiltBootclasspathFragmentFactory)
Paul Duffin4b64ba02021-03-29 11:02:53 +010052
Paul Duffin7771eba2021-04-23 14:25:28 +010053 ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory)
54 ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory)
Paul Duffin3451e162021-01-20 15:16:56 +000055}
56
Paul Duffin65898052021-04-20 22:47:03 +010057type bootclasspathFragmentContentDependencyTag struct {
Paul Duffinc7ef9892021-03-23 23:21:59 +000058 blueprint.BaseDependencyTag
59}
60
Paul Duffin7771eba2021-04-23 14:25:28 +010061// Avoid having to make bootclasspath_fragment content visible to the bootclasspath_fragment.
Paul Duffinc7ef9892021-03-23 23:21:59 +000062//
Paul Duffin7771eba2021-04-23 14:25:28 +010063// This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules
64// with proper dependencies.
Paul Duffinc7ef9892021-03-23 23:21:59 +000065// TODO(b/177892522): Remove this and add needed visibility.
Paul Duffin65898052021-04-20 22:47:03 +010066func (b bootclasspathFragmentContentDependencyTag) ExcludeFromVisibilityEnforcement() {
67}
68
69// The bootclasspath_fragment contents must never depend on prebuilts.
70func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
71 return false
Paul Duffinc7ef9892021-03-23 23:21:59 +000072}
73
Paul Duffin7771eba2021-04-23 14:25:28 +010074// The tag used for the dependency between the bootclasspath_fragment module and its contents.
Paul Duffin65898052021-04-20 22:47:03 +010075var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{}
Paul Duffinc7ef9892021-03-23 23:21:59 +000076
Paul Duffin65898052021-04-20 22:47:03 +010077var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag
78var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag
Paul Duffinc7ef9892021-03-23 23:21:59 +000079
Paul Duffin65898052021-04-20 22:47:03 +010080func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
81 return tag == bootclasspathFragmentContentDepTag
Paul Duffin4d101b62021-03-24 15:42:20 +000082}
83
Paul Duffin7771eba2021-04-23 14:25:28 +010084type bootclasspathFragmentProperties struct {
Paul Duffin3451e162021-01-20 15:16:56 +000085 // The name of the image this represents.
86 //
Paul Duffin82886d62021-03-24 01:34:57 +000087 // If specified then it must be one of "art" or "boot".
Paul Duffin64be7bb2021-03-23 23:06:38 +000088 Image_name *string
Paul Duffinc7ef9892021-03-23 23:21:59 +000089
Paul Duffin7771eba2021-04-23 14:25:28 +010090 // The contents of this bootclasspath_fragment, could be either java_library, java_sdk_library, or boot_image.
Paul Duffinc7ef9892021-03-23 23:21:59 +000091 //
92 // The order of this list matters as it is the order that is used in the bootclasspath.
Paul Duffin82886d62021-03-24 01:34:57 +000093 Contents []string
Paul Duffin9b381ef2021-04-08 23:01:37 +010094
95 Hidden_api HiddenAPIFlagFileProperties
Paul Duffin3451e162021-01-20 15:16:56 +000096}
97
Paul Duffin7771eba2021-04-23 14:25:28 +010098type BootclasspathFragmentModule struct {
Paul Duffin3451e162021-01-20 15:16:56 +000099 android.ModuleBase
Paul Duffina1d60252021-01-21 18:13:43 +0000100 android.ApexModuleBase
Paul Duffinf7f65da2021-03-10 15:00:46 +0000101 android.SdkBase
Paul Duffin7771eba2021-04-23 14:25:28 +0100102 properties bootclasspathFragmentProperties
Paul Duffin3451e162021-01-20 15:16:56 +0000103}
104
Paul Duffin7771eba2021-04-23 14:25:28 +0100105func bootclasspathFragmentFactory() android.Module {
106 m := &BootclasspathFragmentModule{}
Paul Duffin3451e162021-01-20 15:16:56 +0000107 m.AddProperties(&m.properties)
Paul Duffina1d60252021-01-21 18:13:43 +0000108 android.InitApexModule(m)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000109 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000110 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000111
Paul Duffin7771eba2021-04-23 14:25:28 +0100112 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000113 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100114 bootclasspathFragmentInitContentsFromImage(ctx, m)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000115 })
Paul Duffin3451e162021-01-20 15:16:56 +0000116 return m
117}
118
Paul Duffin7771eba2021-04-23 14:25:28 +0100119// bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if
120// necessary.
121func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
Paul Duffin82886d62021-03-24 01:34:57 +0000122 contents := m.properties.Contents
123 if m.properties.Image_name == nil && len(contents) == 0 {
124 ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
125 }
126 if m.properties.Image_name != nil && len(contents) != 0 {
127 ctx.ModuleErrorf(`both of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
128 }
Paul Duffin023dba02021-04-22 01:45:29 +0100129
Paul Duffinc7ef9892021-03-23 23:21:59 +0000130 imageName := proptools.String(m.properties.Image_name)
131 if imageName == "art" {
Paul Duffin023dba02021-04-22 01:45:29 +0100132 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
133 if m.MemberName() != "" {
134 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
135 // 1. There is no way to use this at the moment so ignoring it is safe.
136 // 2. Attempting to initialize the contents property from the configuration will end up having
137 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
138 // as the unversioned prebuilt could end up with an APEX variant created for the source
139 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
140 // turn will prevent it from accessing the dex implementation jar from that which will
141 // break hidden API processing, amongst others.
142 return
143 }
144
Paul Duffinc7ef9892021-03-23 23:21:59 +0000145 // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
146 // too early in the Soong processing for that to work.
147 global := dexpreopt.GetGlobalConfig(ctx)
148 modules := global.ArtApexJars
149
150 // Make sure that the apex specified in the configuration is consistent and is one for which
151 // this boot image is available.
152 jars := []string{}
153 commonApex := ""
154 for i := 0; i < modules.Len(); i++ {
155 apex := modules.Apex(i)
156 jar := modules.Jar(i)
157 if apex == "platform" {
158 ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar)
159 continue
160 }
161 if !m.AvailableFor(apex) {
162 ctx.ModuleErrorf("incompatible with ArtApexJars which expects this to be in apex %q but this is only in apexes %q",
163 apex, m.ApexAvailable())
164 continue
165 }
166 if commonApex == "" {
167 commonApex = apex
168 } else if commonApex != apex {
169 ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q",
170 commonApex, apex)
171 }
172 jars = append(jars, jar)
173 }
174
175 // Store the jars in the Contents property so that they can be used to add dependencies.
176 m.properties.Contents = jars
177 }
178}
179
Paul Duffin3451e162021-01-20 15:16:56 +0000180var BootImageInfoProvider = blueprint.NewProvider(BootImageInfo{})
181
182type BootImageInfo struct {
183 // The image config, internal to this module (and the dex_bootjars singleton).
Paul Duffina1d60252021-01-21 18:13:43 +0000184 //
185 // Will be nil if the BootImageInfo has not been provided for a specific module. That can occur
186 // when SkipDexpreoptBootJars(ctx) returns true.
Paul Duffin3451e162021-01-20 15:16:56 +0000187 imageConfig *bootImageConfig
188}
189
190func (i BootImageInfo) Modules() android.ConfiguredJarList {
191 return i.imageConfig.modules
192}
193
Paul Duffina1d60252021-01-21 18:13:43 +0000194// Get a map from ArchType to the associated boot image's contents for Android.
195//
196// Extension boot images only return their own files, not the files of the boot images they extend.
197func (i BootImageInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths {
198 files := map[android.ArchType]android.OutputPaths{}
199 if i.imageConfig != nil {
200 for _, variant := range i.imageConfig.variants {
201 // We also generate boot images for host (for testing), but we don't need those in the apex.
202 // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
203 if variant.target.Os == android.Android {
204 files[variant.target.Arch.ArchType] = variant.imagesDeps
205 }
206 }
207 }
208 return files
209}
210
Paul Duffin7771eba2021-04-23 14:25:28 +0100211func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffina1d60252021-01-21 18:13:43 +0000212 tag := ctx.OtherModuleDependencyTag(dep)
Paul Duffin65898052021-04-20 22:47:03 +0100213 if IsBootclasspathFragmentContentDepTag(tag) {
Paul Duffin4d101b62021-03-24 15:42:20 +0000214 // Boot image contents are automatically added to apex.
215 return true
Paul Duffinc7ef9892021-03-23 23:21:59 +0000216 }
Bob Badour07065cd2021-02-05 19:59:11 -0800217 if android.IsMetaDependencyTag(tag) {
218 // Cross-cutting metadata dependencies are metadata.
219 return false
220 }
Paul Duffina1d60252021-01-21 18:13:43 +0000221 panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag)))
222}
223
Paul Duffin7771eba2021-04-23 14:25:28 +0100224func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Paul Duffina1d60252021-01-21 18:13:43 +0000225 return nil
226}
227
Paul Duffin65898052021-04-20 22:47:03 +0100228// ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a
229// corresponding source module are renamed. This means that adding a dependency using a name without
230// a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix
231// it will always resolve to a prebuilt module.
Paul Duffin7771eba2021-04-23 14:25:28 +0100232func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin65898052021-04-20 22:47:03 +0100233 module := ctx.Module()
Paul Duffin7771eba2021-04-23 14:25:28 +0100234 _, isSourceModule := module.(*BootclasspathFragmentModule)
Paul Duffin65898052021-04-20 22:47:03 +0100235
236 for _, name := range b.properties.Contents {
237 // A bootclasspath_fragment must depend only on other source modules, while the
238 // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules.
Paul Duffina9dd6fa2021-04-22 17:25:57 +0100239 //
240 // TODO(b/177892522) - avoid special handling of jacocoagent.
241 if !isSourceModule && name != "jacocoagent" {
Paul Duffin65898052021-04-20 22:47:03 +0100242 name = android.PrebuiltNameFromSource(name)
243 }
244 ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name)
245 }
246
247}
248
Paul Duffin7771eba2021-04-23 14:25:28 +0100249func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffinc7ef9892021-03-23 23:21:59 +0000250
Paul Duffina1d60252021-01-21 18:13:43 +0000251 if SkipDexpreoptBootJars(ctx) {
252 return
253 }
254
255 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
256 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
257 dexpreopt.RegisterToolDeps(ctx)
258}
259
Paul Duffin7771eba2021-04-23 14:25:28 +0100260func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100261 // Perform hidden API processing.
262 b.generateHiddenAPIBuildActions(ctx)
263
Paul Duffin3451e162021-01-20 15:16:56 +0000264 // Nothing to do if skipping the dexpreopt of boot image jars.
265 if SkipDexpreoptBootJars(ctx) {
266 return
267 }
268
Paul Duffina1d60252021-01-21 18:13:43 +0000269 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
270 // GenerateSingletonBuildActions method as it cannot create it for itself.
271 dexpreopt.GetGlobalSoongConfig(ctx)
272
Paul Duffin64be7bb2021-03-23 23:06:38 +0000273 imageConfig := b.getImageConfig(ctx)
Paul Duffin3451e162021-01-20 15:16:56 +0000274 if imageConfig == nil {
Paul Duffin3451e162021-01-20 15:16:56 +0000275 return
276 }
277
278 // Construct the boot image info from the config.
279 info := BootImageInfo{imageConfig: imageConfig}
280
281 // Make it available for other modules.
282 ctx.SetProvider(BootImageInfoProvider, info)
283}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000284
Paul Duffin7771eba2021-04-23 14:25:28 +0100285func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000286 // Get a map of the image configs that are supported.
287 imageConfigs := genBootImageConfigs(ctx)
288
289 // Retrieve the config for this image.
290 imageNamePtr := b.properties.Image_name
291 if imageNamePtr == nil {
292 return nil
293 }
294
295 imageName := *imageNamePtr
296 imageConfig := imageConfigs[imageName]
297 if imageConfig == nil {
298 ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", "))
299 return nil
300 }
301 return imageConfig
302}
303
Paul Duffin9b381ef2021-04-08 23:01:37 +0100304// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffin7771eba2021-04-23 14:25:28 +0100305func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100306 // Resolve the properties to paths.
307 flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx)
308
309 // Store the information for use by platform_bootclasspath.
310 ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo)
311}
312
Paul Duffin7771eba2021-04-23 14:25:28 +0100313type bootclasspathFragmentMemberType struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000314 android.SdkMemberTypeBase
315}
316
Paul Duffin7771eba2021-04-23 14:25:28 +0100317func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000318 mctx.AddVariationDependencies(nil, dependencyTag, names...)
319}
320
Paul Duffin7771eba2021-04-23 14:25:28 +0100321func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {
322 _, ok := module.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000323 return ok
324}
325
Paul Duffin7771eba2021-04-23 14:25:28 +0100326func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
Paul Duffin4b64ba02021-03-29 11:02:53 +0100327 if b.PropertyName == "boot_images" {
328 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
329 } else {
330 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment")
331 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000332}
333
Paul Duffin7771eba2021-04-23 14:25:28 +0100334func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
335 return &bootclasspathFragmentSdkMemberProperties{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000336}
337
Paul Duffin7771eba2021-04-23 14:25:28 +0100338type bootclasspathFragmentSdkMemberProperties struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000339 android.SdkMemberPropertiesBase
340
Paul Duffina57835e2021-04-19 13:23:06 +0100341 // The image name
Paul Duffin64be7bb2021-03-23 23:06:38 +0000342 Image_name *string
Paul Duffina57835e2021-04-19 13:23:06 +0100343
344 // Contents of the bootclasspath fragment
345 Contents []string
Paul Duffin7c955552021-04-19 13:23:53 +0100346
347 // Flag files by *hiddenAPIFlagFileCategory
348 Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000349}
350
Paul Duffin7771eba2021-04-23 14:25:28 +0100351func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
352 module := variant.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000353
354 b.Image_name = module.properties.Image_name
Paul Duffina57835e2021-04-19 13:23:06 +0100355 if b.Image_name == nil {
356 // Only one of image_name or contents can be specified. However, if image_name is set then the
357 // contents property is updated to match the configuration used to create the corresponding
358 // boot image. Therefore, contents property is only copied if the image name is not specified.
359 b.Contents = module.properties.Contents
360 }
Paul Duffin7c955552021-04-19 13:23:53 +0100361
362 // Get the flag file information from the module.
363 mctx := ctx.SdkModuleContext()
364 flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
365 b.Flag_files_by_category = flagFileInfo.categoryToPaths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000366}
367
Paul Duffin7771eba2021-04-23 14:25:28 +0100368func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000369 if b.Image_name != nil {
370 propertySet.AddProperty("image_name", *b.Image_name)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000371 }
Paul Duffina57835e2021-04-19 13:23:06 +0100372
373 if len(b.Contents) > 0 {
374 propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true))
375 }
Paul Duffin7c955552021-04-19 13:23:53 +0100376
377 builder := ctx.SnapshotBuilder()
378 if b.Flag_files_by_category != nil {
379 hiddenAPISet := propertySet.AddPropertySet("hidden_api")
380 for _, category := range hiddenAPIFlagFileCategories {
381 paths := b.Flag_files_by_category[category]
382 if len(paths) > 0 {
383 dests := []string{}
384 for _, p := range paths {
385 dest := filepath.Join("hiddenapi", p.Base())
386 builder.CopyToSnapshot(p, dest)
387 dests = append(dests, dest)
388 }
389 hiddenAPISet.AddProperty(category.propertyName, dests)
390 }
391 }
392 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000393}
394
Paul Duffin7771eba2021-04-23 14:25:28 +0100395var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000396
Paul Duffin7771eba2021-04-23 14:25:28 +0100397// A prebuilt version of the bootclasspath_fragment module.
Paul Duffinf7f65da2021-03-10 15:00:46 +0000398//
Paul Duffin7771eba2021-04-23 14:25:28 +0100399// At the moment this is basically just a bootclasspath_fragment module that can be used as a
400// prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module
401// type from the various singletons then this will diverge.
402type prebuiltBootclasspathFragmentModule struct {
403 BootclasspathFragmentModule
Paul Duffinf7f65da2021-03-10 15:00:46 +0000404 prebuilt android.Prebuilt
405}
406
Paul Duffin7771eba2021-04-23 14:25:28 +0100407func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000408 return &module.prebuilt
409}
410
Paul Duffin7771eba2021-04-23 14:25:28 +0100411func (module *prebuiltBootclasspathFragmentModule) Name() string {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000412 return module.prebuilt.Name(module.ModuleBase.Name())
413}
414
Paul Duffin7771eba2021-04-23 14:25:28 +0100415func prebuiltBootclasspathFragmentFactory() android.Module {
416 m := &prebuiltBootclasspathFragmentModule{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000417 m.AddProperties(&m.properties)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000418 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
419 // array.
420 android.InitPrebuiltModule(m, &[]string{"placeholder"})
421 android.InitApexModule(m)
422 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000423 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000424
Paul Duffin7771eba2021-04-23 14:25:28 +0100425 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000426 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100427 bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000428 })
Paul Duffinf7f65da2021-03-10 15:00:46 +0000429 return m
430}