blob: 8bb5cb18e8ffc846f15d20bc4eabec9f1ff0226e [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 Duffinc7d16442021-04-23 13:55:49 +010072// Properties that can be different when coverage is enabled.
73type BootclasspathFragmentCoverageAffectedProperties struct {
74 // The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library.
75 //
76 // The order of this list matters as it is the order that is used in the bootclasspath.
77 Contents []string
78}
79
Paul Duffin7771eba2021-04-23 14:25:28 +010080type bootclasspathFragmentProperties struct {
Paul Duffin3451e162021-01-20 15:16:56 +000081 // The name of the image this represents.
82 //
Paul Duffin82886d62021-03-24 01:34:57 +000083 // If specified then it must be one of "art" or "boot".
Paul Duffin64be7bb2021-03-23 23:06:38 +000084 Image_name *string
Paul Duffinc7ef9892021-03-23 23:21:59 +000085
Paul Duffinc7d16442021-04-23 13:55:49 +010086 // Properties whose values need to differ with and without coverage.
87 BootclasspathFragmentCoverageAffectedProperties
88 Coverage BootclasspathFragmentCoverageAffectedProperties
Paul Duffin9b381ef2021-04-08 23:01:37 +010089
90 Hidden_api HiddenAPIFlagFileProperties
Paul Duffin3451e162021-01-20 15:16:56 +000091}
92
Paul Duffin7771eba2021-04-23 14:25:28 +010093type BootclasspathFragmentModule struct {
Paul Duffin3451e162021-01-20 15:16:56 +000094 android.ModuleBase
Paul Duffina1d60252021-01-21 18:13:43 +000095 android.ApexModuleBase
Paul Duffinf7f65da2021-03-10 15:00:46 +000096 android.SdkBase
Paul Duffin7771eba2021-04-23 14:25:28 +010097 properties bootclasspathFragmentProperties
Paul Duffin3451e162021-01-20 15:16:56 +000098}
99
Paul Duffin7771eba2021-04-23 14:25:28 +0100100func bootclasspathFragmentFactory() android.Module {
101 m := &BootclasspathFragmentModule{}
Paul Duffin3451e162021-01-20 15:16:56 +0000102 m.AddProperties(&m.properties)
Paul Duffina1d60252021-01-21 18:13:43 +0000103 android.InitApexModule(m)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000104 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000105 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000106
Paul Duffinc7ef9892021-03-23 23:21:59 +0000107 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffinc7d16442021-04-23 13:55:49 +0100108 // If code coverage has been enabled for the framework then append the properties with
109 // coverage specific properties.
110 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
111 err := proptools.AppendProperties(&m.properties.BootclasspathFragmentCoverageAffectedProperties, &m.properties.Coverage, nil)
112 if err != nil {
113 ctx.PropertyErrorf("coverage", "error trying to append coverage specific properties: %s", err)
114 return
115 }
116 }
117
118 // Initialize the contents property from the image_name.
Paul Duffin7771eba2021-04-23 14:25:28 +0100119 bootclasspathFragmentInitContentsFromImage(ctx, m)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000120 })
Paul Duffin3451e162021-01-20 15:16:56 +0000121 return m
122}
123
Paul Duffin7771eba2021-04-23 14:25:28 +0100124// bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if
125// necessary.
126func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
Paul Duffin82886d62021-03-24 01:34:57 +0000127 contents := m.properties.Contents
128 if m.properties.Image_name == nil && len(contents) == 0 {
129 ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
130 }
131 if m.properties.Image_name != nil && len(contents) != 0 {
132 ctx.ModuleErrorf(`both of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
133 }
Paul Duffin023dba02021-04-22 01:45:29 +0100134
Paul Duffinc7ef9892021-03-23 23:21:59 +0000135 imageName := proptools.String(m.properties.Image_name)
136 if imageName == "art" {
Paul Duffin023dba02021-04-22 01:45:29 +0100137 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
138 if m.MemberName() != "" {
139 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
140 // 1. There is no way to use this at the moment so ignoring it is safe.
141 // 2. Attempting to initialize the contents property from the configuration will end up having
142 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
143 // as the unversioned prebuilt could end up with an APEX variant created for the source
144 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
145 // turn will prevent it from accessing the dex implementation jar from that which will
146 // break hidden API processing, amongst others.
147 return
148 }
149
Paul Duffinc7ef9892021-03-23 23:21:59 +0000150 // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
151 // too early in the Soong processing for that to work.
152 global := dexpreopt.GetGlobalConfig(ctx)
153 modules := global.ArtApexJars
154
155 // Make sure that the apex specified in the configuration is consistent and is one for which
156 // this boot image is available.
157 jars := []string{}
158 commonApex := ""
159 for i := 0; i < modules.Len(); i++ {
160 apex := modules.Apex(i)
161 jar := modules.Jar(i)
162 if apex == "platform" {
163 ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar)
164 continue
165 }
166 if !m.AvailableFor(apex) {
167 ctx.ModuleErrorf("incompatible with ArtApexJars which expects this to be in apex %q but this is only in apexes %q",
168 apex, m.ApexAvailable())
169 continue
170 }
171 if commonApex == "" {
172 commonApex = apex
173 } else if commonApex != apex {
174 ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q",
175 commonApex, apex)
176 }
177 jars = append(jars, jar)
178 }
179
180 // Store the jars in the Contents property so that they can be used to add dependencies.
181 m.properties.Contents = jars
182 }
183}
184
Paul Duffine946b322021-04-25 23:04:00 +0100185var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{})
Paul Duffin3451e162021-01-20 15:16:56 +0000186
Paul Duffine946b322021-04-25 23:04:00 +0100187// BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the
188// apex contents.
189type BootclasspathFragmentApexContentInfo struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000190 // The image config, internal to this module (and the dex_bootjars singleton).
Paul Duffina1d60252021-01-21 18:13:43 +0000191 //
Paul Duffine946b322021-04-25 23:04:00 +0100192 // Will be nil if the BootclasspathFragmentApexContentInfo has not been provided for a specific module. That can occur
Paul Duffina1d60252021-01-21 18:13:43 +0000193 // when SkipDexpreoptBootJars(ctx) returns true.
Paul Duffin3451e162021-01-20 15:16:56 +0000194 imageConfig *bootImageConfig
195}
196
Paul Duffine946b322021-04-25 23:04:00 +0100197func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList {
Paul Duffin3451e162021-01-20 15:16:56 +0000198 return i.imageConfig.modules
199}
200
Paul Duffina1d60252021-01-21 18:13:43 +0000201// Get a map from ArchType to the associated boot image's contents for Android.
202//
203// Extension boot images only return their own files, not the files of the boot images they extend.
Paul Duffine946b322021-04-25 23:04:00 +0100204func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths {
Paul Duffina1d60252021-01-21 18:13:43 +0000205 files := map[android.ArchType]android.OutputPaths{}
206 if i.imageConfig != nil {
207 for _, variant := range i.imageConfig.variants {
208 // We also generate boot images for host (for testing), but we don't need those in the apex.
209 // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
210 if variant.target.Os == android.Android {
211 files[variant.target.Arch.ArchType] = variant.imagesDeps
212 }
213 }
214 }
215 return files
216}
217
Paul Duffin190fdef2021-04-26 10:33:59 +0100218// DexBootJarPathForContentModule returns the path to the dex boot jar for specified module.
219//
220// The dex boot jar is one which has had hidden API encoding performed on it.
221func (i BootclasspathFragmentApexContentInfo) DexBootJarPathForContentModule(module android.Module) android.Path {
222 j := module.(UsesLibraryDependency)
223 dexJar := j.DexJarBuildPath()
224 return dexJar
225}
226
Paul Duffin7771eba2021-04-23 14:25:28 +0100227func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffina1d60252021-01-21 18:13:43 +0000228 tag := ctx.OtherModuleDependencyTag(dep)
Paul Duffin65898052021-04-20 22:47:03 +0100229 if IsBootclasspathFragmentContentDepTag(tag) {
Paul Duffin4d101b62021-03-24 15:42:20 +0000230 // Boot image contents are automatically added to apex.
231 return true
Paul Duffinc7ef9892021-03-23 23:21:59 +0000232 }
Bob Badour07065cd2021-02-05 19:59:11 -0800233 if android.IsMetaDependencyTag(tag) {
234 // Cross-cutting metadata dependencies are metadata.
235 return false
236 }
Paul Duffina1d60252021-01-21 18:13:43 +0000237 panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag)))
238}
239
Paul Duffin7771eba2021-04-23 14:25:28 +0100240func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Paul Duffina1d60252021-01-21 18:13:43 +0000241 return nil
242}
243
Paul Duffin65898052021-04-20 22:47:03 +0100244// ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a
245// corresponding source module are renamed. This means that adding a dependency using a name without
246// a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix
247// it will always resolve to a prebuilt module.
Paul Duffin7771eba2021-04-23 14:25:28 +0100248func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin65898052021-04-20 22:47:03 +0100249 module := ctx.Module()
Paul Duffin7771eba2021-04-23 14:25:28 +0100250 _, isSourceModule := module.(*BootclasspathFragmentModule)
Paul Duffin65898052021-04-20 22:47:03 +0100251
252 for _, name := range b.properties.Contents {
253 // A bootclasspath_fragment must depend only on other source modules, while the
254 // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules.
Paul Duffina9dd6fa2021-04-22 17:25:57 +0100255 //
256 // TODO(b/177892522) - avoid special handling of jacocoagent.
257 if !isSourceModule && name != "jacocoagent" {
Paul Duffin65898052021-04-20 22:47:03 +0100258 name = android.PrebuiltNameFromSource(name)
259 }
260 ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name)
261 }
262
263}
264
Paul Duffin7771eba2021-04-23 14:25:28 +0100265func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffinc7ef9892021-03-23 23:21:59 +0000266
Paul Duffina1d60252021-01-21 18:13:43 +0000267 if SkipDexpreoptBootJars(ctx) {
268 return
269 }
270
271 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
272 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
273 dexpreopt.RegisterToolDeps(ctx)
274}
275
Paul Duffin7771eba2021-04-23 14:25:28 +0100276func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100277 // Perform hidden API processing.
278 b.generateHiddenAPIBuildActions(ctx)
279
Paul Duffin3451e162021-01-20 15:16:56 +0000280 // Nothing to do if skipping the dexpreopt of boot image jars.
281 if SkipDexpreoptBootJars(ctx) {
282 return
283 }
284
Paul Duffina1d60252021-01-21 18:13:43 +0000285 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
286 // GenerateSingletonBuildActions method as it cannot create it for itself.
287 dexpreopt.GetGlobalSoongConfig(ctx)
288
Paul Duffin64be7bb2021-03-23 23:06:38 +0000289 imageConfig := b.getImageConfig(ctx)
Paul Duffin3451e162021-01-20 15:16:56 +0000290 if imageConfig == nil {
Paul Duffin3451e162021-01-20 15:16:56 +0000291 return
292 }
293
294 // Construct the boot image info from the config.
Paul Duffine946b322021-04-25 23:04:00 +0100295 info := BootclasspathFragmentApexContentInfo{imageConfig: imageConfig}
Paul Duffin3451e162021-01-20 15:16:56 +0000296
297 // Make it available for other modules.
Paul Duffine946b322021-04-25 23:04:00 +0100298 ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
Paul Duffin3451e162021-01-20 15:16:56 +0000299}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000300
Paul Duffin7771eba2021-04-23 14:25:28 +0100301func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000302 // Get a map of the image configs that are supported.
303 imageConfigs := genBootImageConfigs(ctx)
304
305 // Retrieve the config for this image.
306 imageNamePtr := b.properties.Image_name
307 if imageNamePtr == nil {
308 return nil
309 }
310
311 imageName := *imageNamePtr
312 imageConfig := imageConfigs[imageName]
313 if imageConfig == nil {
314 ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", "))
315 return nil
316 }
317 return imageConfig
318}
319
Paul Duffin9b381ef2021-04-08 23:01:37 +0100320// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffin7771eba2021-04-23 14:25:28 +0100321func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100322 // Resolve the properties to paths.
323 flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx)
324
325 // Store the information for use by platform_bootclasspath.
326 ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo)
327}
328
Paul Duffin7771eba2021-04-23 14:25:28 +0100329type bootclasspathFragmentMemberType struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000330 android.SdkMemberTypeBase
331}
332
Paul Duffin7771eba2021-04-23 14:25:28 +0100333func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000334 mctx.AddVariationDependencies(nil, dependencyTag, names...)
335}
336
Paul Duffin7771eba2021-04-23 14:25:28 +0100337func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {
338 _, ok := module.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000339 return ok
340}
341
Paul Duffin7771eba2021-04-23 14:25:28 +0100342func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
Paul Duffin4b64ba02021-03-29 11:02:53 +0100343 if b.PropertyName == "boot_images" {
344 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
345 } else {
346 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment")
347 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000348}
349
Paul Duffin7771eba2021-04-23 14:25:28 +0100350func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
351 return &bootclasspathFragmentSdkMemberProperties{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000352}
353
Paul Duffin7771eba2021-04-23 14:25:28 +0100354type bootclasspathFragmentSdkMemberProperties struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000355 android.SdkMemberPropertiesBase
356
Paul Duffina57835e2021-04-19 13:23:06 +0100357 // The image name
Paul Duffin64be7bb2021-03-23 23:06:38 +0000358 Image_name *string
Paul Duffina57835e2021-04-19 13:23:06 +0100359
360 // Contents of the bootclasspath fragment
361 Contents []string
Paul Duffin7c955552021-04-19 13:23:53 +0100362
363 // Flag files by *hiddenAPIFlagFileCategory
364 Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000365}
366
Paul Duffin7771eba2021-04-23 14:25:28 +0100367func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
368 module := variant.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000369
370 b.Image_name = module.properties.Image_name
Paul Duffina57835e2021-04-19 13:23:06 +0100371 if b.Image_name == nil {
372 // Only one of image_name or contents can be specified. However, if image_name is set then the
373 // contents property is updated to match the configuration used to create the corresponding
374 // boot image. Therefore, contents property is only copied if the image name is not specified.
375 b.Contents = module.properties.Contents
376 }
Paul Duffin7c955552021-04-19 13:23:53 +0100377
378 // Get the flag file information from the module.
379 mctx := ctx.SdkModuleContext()
380 flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
381 b.Flag_files_by_category = flagFileInfo.categoryToPaths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000382}
383
Paul Duffin7771eba2021-04-23 14:25:28 +0100384func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000385 if b.Image_name != nil {
386 propertySet.AddProperty("image_name", *b.Image_name)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000387 }
Paul Duffina57835e2021-04-19 13:23:06 +0100388
389 if len(b.Contents) > 0 {
390 propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true))
391 }
Paul Duffin7c955552021-04-19 13:23:53 +0100392
393 builder := ctx.SnapshotBuilder()
394 if b.Flag_files_by_category != nil {
395 hiddenAPISet := propertySet.AddPropertySet("hidden_api")
396 for _, category := range hiddenAPIFlagFileCategories {
397 paths := b.Flag_files_by_category[category]
398 if len(paths) > 0 {
399 dests := []string{}
400 for _, p := range paths {
401 dest := filepath.Join("hiddenapi", p.Base())
402 builder.CopyToSnapshot(p, dest)
403 dests = append(dests, dest)
404 }
405 hiddenAPISet.AddProperty(category.propertyName, dests)
406 }
407 }
408 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000409}
410
Paul Duffin7771eba2021-04-23 14:25:28 +0100411var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000412
Paul Duffin7771eba2021-04-23 14:25:28 +0100413// A prebuilt version of the bootclasspath_fragment module.
Paul Duffinf7f65da2021-03-10 15:00:46 +0000414//
Paul Duffin7771eba2021-04-23 14:25:28 +0100415// At the moment this is basically just a bootclasspath_fragment module that can be used as a
416// prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module
417// type from the various singletons then this will diverge.
418type prebuiltBootclasspathFragmentModule struct {
419 BootclasspathFragmentModule
Paul Duffinf7f65da2021-03-10 15:00:46 +0000420 prebuilt android.Prebuilt
421}
422
Paul Duffin7771eba2021-04-23 14:25:28 +0100423func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000424 return &module.prebuilt
425}
426
Paul Duffin7771eba2021-04-23 14:25:28 +0100427func (module *prebuiltBootclasspathFragmentModule) Name() string {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000428 return module.prebuilt.Name(module.ModuleBase.Name())
429}
430
Paul Duffin7771eba2021-04-23 14:25:28 +0100431func prebuiltBootclasspathFragmentFactory() android.Module {
432 m := &prebuiltBootclasspathFragmentModule{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000433 m.AddProperties(&m.properties)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000434 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
435 // array.
436 android.InitPrebuiltModule(m, &[]string{"placeholder"})
437 android.InitApexModule(m)
438 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000439 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000440
Paul Duffin7771eba2021-04-23 14:25:28 +0100441 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000442 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100443 bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000444 })
Paul Duffinf7f65da2021-03-10 15:00:46 +0000445 return m
446}