blob: 00d465992a0c6065c67371fb992d082854080595 [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 Duffin7771eba2021-04-23 14:25:28 +010032 android.RegisterSdkMemberType(&bootclasspathFragmentMemberType{
Paul Duffin4b64ba02021-03-29 11:02:53 +010033 SdkMemberTypeBase: android.SdkMemberTypeBase{
34 PropertyName: "bootclasspath_fragments",
35 SupportsSdk: true,
36 },
37 })
Paul Duffin3451e162021-01-20 15:16:56 +000038}
39
Paul Duffin7771eba2021-04-23 14:25:28 +010040func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +010041 ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory)
42 ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory)
Paul Duffin3451e162021-01-20 15:16:56 +000043}
44
Paul Duffin65898052021-04-20 22:47:03 +010045type bootclasspathFragmentContentDependencyTag struct {
Paul Duffinc7ef9892021-03-23 23:21:59 +000046 blueprint.BaseDependencyTag
47}
48
Paul Duffin7771eba2021-04-23 14:25:28 +010049// Avoid having to make bootclasspath_fragment content visible to the bootclasspath_fragment.
Paul Duffinc7ef9892021-03-23 23:21:59 +000050//
Paul Duffin7771eba2021-04-23 14:25:28 +010051// This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules
52// with proper dependencies.
Paul Duffinc7ef9892021-03-23 23:21:59 +000053// TODO(b/177892522): Remove this and add needed visibility.
Paul Duffin65898052021-04-20 22:47:03 +010054func (b bootclasspathFragmentContentDependencyTag) ExcludeFromVisibilityEnforcement() {
55}
56
57// The bootclasspath_fragment contents must never depend on prebuilts.
58func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
59 return false
Paul Duffinc7ef9892021-03-23 23:21:59 +000060}
61
Paul Duffin7771eba2021-04-23 14:25:28 +010062// The tag used for the dependency between the bootclasspath_fragment module and its contents.
Paul Duffin65898052021-04-20 22:47:03 +010063var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{}
Paul Duffinc7ef9892021-03-23 23:21:59 +000064
Paul Duffin65898052021-04-20 22:47:03 +010065var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag
66var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag
Paul Duffinc7ef9892021-03-23 23:21:59 +000067
Paul Duffin65898052021-04-20 22:47:03 +010068func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
69 return tag == bootclasspathFragmentContentDepTag
Paul Duffin4d101b62021-03-24 15:42:20 +000070}
71
Paul Duffin7771eba2021-04-23 14:25:28 +010072type bootclasspathFragmentProperties struct {
Paul Duffin3451e162021-01-20 15:16:56 +000073 // The name of the image this represents.
74 //
Paul Duffin82886d62021-03-24 01:34:57 +000075 // If specified then it must be one of "art" or "boot".
Paul Duffin64be7bb2021-03-23 23:06:38 +000076 Image_name *string
Paul Duffinc7ef9892021-03-23 23:21:59 +000077
Paul Duffin7771eba2021-04-23 14:25:28 +010078 // The contents of this bootclasspath_fragment, could be either java_library, java_sdk_library, or boot_image.
Paul Duffinc7ef9892021-03-23 23:21:59 +000079 //
80 // The order of this list matters as it is the order that is used in the bootclasspath.
Paul Duffin82886d62021-03-24 01:34:57 +000081 Contents []string
Paul Duffin9b381ef2021-04-08 23:01:37 +010082
83 Hidden_api HiddenAPIFlagFileProperties
Paul Duffin3451e162021-01-20 15:16:56 +000084}
85
Paul Duffin7771eba2021-04-23 14:25:28 +010086type BootclasspathFragmentModule struct {
Paul Duffin3451e162021-01-20 15:16:56 +000087 android.ModuleBase
Paul Duffina1d60252021-01-21 18:13:43 +000088 android.ApexModuleBase
Paul Duffinf7f65da2021-03-10 15:00:46 +000089 android.SdkBase
Paul Duffin7771eba2021-04-23 14:25:28 +010090 properties bootclasspathFragmentProperties
Paul Duffin3451e162021-01-20 15:16:56 +000091}
92
Paul Duffin7771eba2021-04-23 14:25:28 +010093func bootclasspathFragmentFactory() android.Module {
94 m := &BootclasspathFragmentModule{}
Paul Duffin3451e162021-01-20 15:16:56 +000095 m.AddProperties(&m.properties)
Paul Duffina1d60252021-01-21 18:13:43 +000096 android.InitApexModule(m)
Paul Duffinf7f65da2021-03-10 15:00:46 +000097 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +000098 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +000099
Paul Duffin7771eba2021-04-23 14:25:28 +0100100 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000101 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100102 bootclasspathFragmentInitContentsFromImage(ctx, m)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000103 })
Paul Duffin3451e162021-01-20 15:16:56 +0000104 return m
105}
106
Paul Duffin7771eba2021-04-23 14:25:28 +0100107// bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if
108// necessary.
109func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
Paul Duffin82886d62021-03-24 01:34:57 +0000110 contents := m.properties.Contents
111 if m.properties.Image_name == nil && len(contents) == 0 {
112 ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
113 }
114 if m.properties.Image_name != nil && len(contents) != 0 {
115 ctx.ModuleErrorf(`both of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
116 }
Paul Duffin023dba02021-04-22 01:45:29 +0100117
Paul Duffinc7ef9892021-03-23 23:21:59 +0000118 imageName := proptools.String(m.properties.Image_name)
119 if imageName == "art" {
Paul Duffin023dba02021-04-22 01:45:29 +0100120 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
121 if m.MemberName() != "" {
122 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
123 // 1. There is no way to use this at the moment so ignoring it is safe.
124 // 2. Attempting to initialize the contents property from the configuration will end up having
125 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
126 // as the unversioned prebuilt could end up with an APEX variant created for the source
127 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
128 // turn will prevent it from accessing the dex implementation jar from that which will
129 // break hidden API processing, amongst others.
130 return
131 }
132
Paul Duffinc7ef9892021-03-23 23:21:59 +0000133 // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
134 // too early in the Soong processing for that to work.
135 global := dexpreopt.GetGlobalConfig(ctx)
136 modules := global.ArtApexJars
137
138 // Make sure that the apex specified in the configuration is consistent and is one for which
139 // this boot image is available.
140 jars := []string{}
141 commonApex := ""
142 for i := 0; i < modules.Len(); i++ {
143 apex := modules.Apex(i)
144 jar := modules.Jar(i)
145 if apex == "platform" {
146 ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar)
147 continue
148 }
149 if !m.AvailableFor(apex) {
150 ctx.ModuleErrorf("incompatible with ArtApexJars which expects this to be in apex %q but this is only in apexes %q",
151 apex, m.ApexAvailable())
152 continue
153 }
154 if commonApex == "" {
155 commonApex = apex
156 } else if commonApex != apex {
157 ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q",
158 commonApex, apex)
159 }
160 jars = append(jars, jar)
161 }
162
163 // Store the jars in the Contents property so that they can be used to add dependencies.
164 m.properties.Contents = jars
165 }
166}
167
Paul Duffine946b322021-04-25 23:04:00 +0100168var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{})
Paul Duffin3451e162021-01-20 15:16:56 +0000169
Paul Duffine946b322021-04-25 23:04:00 +0100170// BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the
171// apex contents.
172type BootclasspathFragmentApexContentInfo struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000173 // The image config, internal to this module (and the dex_bootjars singleton).
Paul Duffina1d60252021-01-21 18:13:43 +0000174 //
Paul Duffine946b322021-04-25 23:04:00 +0100175 // Will be nil if the BootclasspathFragmentApexContentInfo has not been provided for a specific module. That can occur
Paul Duffina1d60252021-01-21 18:13:43 +0000176 // when SkipDexpreoptBootJars(ctx) returns true.
Paul Duffin3451e162021-01-20 15:16:56 +0000177 imageConfig *bootImageConfig
178}
179
Paul Duffine946b322021-04-25 23:04:00 +0100180func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList {
Paul Duffin3451e162021-01-20 15:16:56 +0000181 return i.imageConfig.modules
182}
183
Paul Duffina1d60252021-01-21 18:13:43 +0000184// Get a map from ArchType to the associated boot image's contents for Android.
185//
186// Extension boot images only return their own files, not the files of the boot images they extend.
Paul Duffine946b322021-04-25 23:04:00 +0100187func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths {
Paul Duffina1d60252021-01-21 18:13:43 +0000188 files := map[android.ArchType]android.OutputPaths{}
189 if i.imageConfig != nil {
190 for _, variant := range i.imageConfig.variants {
191 // We also generate boot images for host (for testing), but we don't need those in the apex.
192 // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
193 if variant.target.Os == android.Android {
194 files[variant.target.Arch.ArchType] = variant.imagesDeps
195 }
196 }
197 }
198 return files
199}
200
Paul Duffin7771eba2021-04-23 14:25:28 +0100201func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffina1d60252021-01-21 18:13:43 +0000202 tag := ctx.OtherModuleDependencyTag(dep)
Paul Duffin65898052021-04-20 22:47:03 +0100203 if IsBootclasspathFragmentContentDepTag(tag) {
Paul Duffin4d101b62021-03-24 15:42:20 +0000204 // Boot image contents are automatically added to apex.
205 return true
Paul Duffinc7ef9892021-03-23 23:21:59 +0000206 }
Bob Badour07065cd2021-02-05 19:59:11 -0800207 if android.IsMetaDependencyTag(tag) {
208 // Cross-cutting metadata dependencies are metadata.
209 return false
210 }
Paul Duffina1d60252021-01-21 18:13:43 +0000211 panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag)))
212}
213
Paul Duffin7771eba2021-04-23 14:25:28 +0100214func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Paul Duffina1d60252021-01-21 18:13:43 +0000215 return nil
216}
217
Paul Duffin65898052021-04-20 22:47:03 +0100218// ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a
219// corresponding source module are renamed. This means that adding a dependency using a name without
220// a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix
221// it will always resolve to a prebuilt module.
Paul Duffin7771eba2021-04-23 14:25:28 +0100222func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin65898052021-04-20 22:47:03 +0100223 module := ctx.Module()
Paul Duffin7771eba2021-04-23 14:25:28 +0100224 _, isSourceModule := module.(*BootclasspathFragmentModule)
Paul Duffin65898052021-04-20 22:47:03 +0100225
226 for _, name := range b.properties.Contents {
227 // A bootclasspath_fragment must depend only on other source modules, while the
228 // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules.
Paul Duffina9dd6fa2021-04-22 17:25:57 +0100229 //
230 // TODO(b/177892522) - avoid special handling of jacocoagent.
231 if !isSourceModule && name != "jacocoagent" {
Paul Duffin65898052021-04-20 22:47:03 +0100232 name = android.PrebuiltNameFromSource(name)
233 }
234 ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name)
235 }
236
237}
238
Paul Duffin7771eba2021-04-23 14:25:28 +0100239func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffinc7ef9892021-03-23 23:21:59 +0000240
Paul Duffina1d60252021-01-21 18:13:43 +0000241 if SkipDexpreoptBootJars(ctx) {
242 return
243 }
244
245 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
246 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
247 dexpreopt.RegisterToolDeps(ctx)
248}
249
Paul Duffin7771eba2021-04-23 14:25:28 +0100250func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100251 // Perform hidden API processing.
252 b.generateHiddenAPIBuildActions(ctx)
253
Paul Duffin3451e162021-01-20 15:16:56 +0000254 // Nothing to do if skipping the dexpreopt of boot image jars.
255 if SkipDexpreoptBootJars(ctx) {
256 return
257 }
258
Paul Duffina1d60252021-01-21 18:13:43 +0000259 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
260 // GenerateSingletonBuildActions method as it cannot create it for itself.
261 dexpreopt.GetGlobalSoongConfig(ctx)
262
Paul Duffin64be7bb2021-03-23 23:06:38 +0000263 imageConfig := b.getImageConfig(ctx)
Paul Duffin3451e162021-01-20 15:16:56 +0000264 if imageConfig == nil {
Paul Duffin3451e162021-01-20 15:16:56 +0000265 return
266 }
267
268 // Construct the boot image info from the config.
Paul Duffine946b322021-04-25 23:04:00 +0100269 info := BootclasspathFragmentApexContentInfo{imageConfig: imageConfig}
Paul Duffin3451e162021-01-20 15:16:56 +0000270
271 // Make it available for other modules.
Paul Duffine946b322021-04-25 23:04:00 +0100272 ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
Paul Duffin3451e162021-01-20 15:16:56 +0000273}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000274
Paul Duffin7771eba2021-04-23 14:25:28 +0100275func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000276 // Get a map of the image configs that are supported.
277 imageConfigs := genBootImageConfigs(ctx)
278
279 // Retrieve the config for this image.
280 imageNamePtr := b.properties.Image_name
281 if imageNamePtr == nil {
282 return nil
283 }
284
285 imageName := *imageNamePtr
286 imageConfig := imageConfigs[imageName]
287 if imageConfig == nil {
288 ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", "))
289 return nil
290 }
291 return imageConfig
292}
293
Paul Duffin9b381ef2021-04-08 23:01:37 +0100294// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffin7771eba2021-04-23 14:25:28 +0100295func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100296 // Resolve the properties to paths.
297 flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx)
298
299 // Store the information for use by platform_bootclasspath.
300 ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo)
301}
302
Paul Duffin7771eba2021-04-23 14:25:28 +0100303type bootclasspathFragmentMemberType struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000304 android.SdkMemberTypeBase
305}
306
Paul Duffin7771eba2021-04-23 14:25:28 +0100307func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000308 mctx.AddVariationDependencies(nil, dependencyTag, names...)
309}
310
Paul Duffin7771eba2021-04-23 14:25:28 +0100311func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {
312 _, ok := module.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000313 return ok
314}
315
Paul Duffin7771eba2021-04-23 14:25:28 +0100316func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
Paul Duffin4b64ba02021-03-29 11:02:53 +0100317 if b.PropertyName == "boot_images" {
318 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
319 } else {
320 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment")
321 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000322}
323
Paul Duffin7771eba2021-04-23 14:25:28 +0100324func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
325 return &bootclasspathFragmentSdkMemberProperties{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000326}
327
Paul Duffin7771eba2021-04-23 14:25:28 +0100328type bootclasspathFragmentSdkMemberProperties struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000329 android.SdkMemberPropertiesBase
330
Paul Duffina57835e2021-04-19 13:23:06 +0100331 // The image name
Paul Duffin64be7bb2021-03-23 23:06:38 +0000332 Image_name *string
Paul Duffina57835e2021-04-19 13:23:06 +0100333
334 // Contents of the bootclasspath fragment
335 Contents []string
Paul Duffin7c955552021-04-19 13:23:53 +0100336
337 // Flag files by *hiddenAPIFlagFileCategory
338 Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000339}
340
Paul Duffin7771eba2021-04-23 14:25:28 +0100341func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
342 module := variant.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000343
344 b.Image_name = module.properties.Image_name
Paul Duffina57835e2021-04-19 13:23:06 +0100345 if b.Image_name == nil {
346 // Only one of image_name or contents can be specified. However, if image_name is set then the
347 // contents property is updated to match the configuration used to create the corresponding
348 // boot image. Therefore, contents property is only copied if the image name is not specified.
349 b.Contents = module.properties.Contents
350 }
Paul Duffin7c955552021-04-19 13:23:53 +0100351
352 // Get the flag file information from the module.
353 mctx := ctx.SdkModuleContext()
354 flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
355 b.Flag_files_by_category = flagFileInfo.categoryToPaths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000356}
357
Paul Duffin7771eba2021-04-23 14:25:28 +0100358func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000359 if b.Image_name != nil {
360 propertySet.AddProperty("image_name", *b.Image_name)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000361 }
Paul Duffina57835e2021-04-19 13:23:06 +0100362
363 if len(b.Contents) > 0 {
364 propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true))
365 }
Paul Duffin7c955552021-04-19 13:23:53 +0100366
367 builder := ctx.SnapshotBuilder()
368 if b.Flag_files_by_category != nil {
369 hiddenAPISet := propertySet.AddPropertySet("hidden_api")
370 for _, category := range hiddenAPIFlagFileCategories {
371 paths := b.Flag_files_by_category[category]
372 if len(paths) > 0 {
373 dests := []string{}
374 for _, p := range paths {
375 dest := filepath.Join("hiddenapi", p.Base())
376 builder.CopyToSnapshot(p, dest)
377 dests = append(dests, dest)
378 }
379 hiddenAPISet.AddProperty(category.propertyName, dests)
380 }
381 }
382 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000383}
384
Paul Duffin7771eba2021-04-23 14:25:28 +0100385var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000386
Paul Duffin7771eba2021-04-23 14:25:28 +0100387// A prebuilt version of the bootclasspath_fragment module.
Paul Duffinf7f65da2021-03-10 15:00:46 +0000388//
Paul Duffin7771eba2021-04-23 14:25:28 +0100389// At the moment this is basically just a bootclasspath_fragment module that can be used as a
390// prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module
391// type from the various singletons then this will diverge.
392type prebuiltBootclasspathFragmentModule struct {
393 BootclasspathFragmentModule
Paul Duffinf7f65da2021-03-10 15:00:46 +0000394 prebuilt android.Prebuilt
395}
396
Paul Duffin7771eba2021-04-23 14:25:28 +0100397func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000398 return &module.prebuilt
399}
400
Paul Duffin7771eba2021-04-23 14:25:28 +0100401func (module *prebuiltBootclasspathFragmentModule) Name() string {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000402 return module.prebuilt.Name(module.ModuleBase.Name())
403}
404
Paul Duffin7771eba2021-04-23 14:25:28 +0100405func prebuiltBootclasspathFragmentFactory() android.Module {
406 m := &prebuiltBootclasspathFragmentModule{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000407 m.AddProperties(&m.properties)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000408 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
409 // array.
410 android.InitPrebuiltModule(m, &[]string{"placeholder"})
411 android.InitApexModule(m)
412 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000413 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000414
Paul Duffin7771eba2021-04-23 14:25:28 +0100415 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000416 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100417 bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000418 })
Paul Duffinf7f65da2021-03-10 15:00:46 +0000419 return m
420}