blob: 6ea3819d55c3c1786bfbfb3f1923ce1335c07e8d [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{
Paul Duffine95b53a2021-04-23 20:41:23 +010035 PropertyName: "bootclasspath_fragments",
36 SupportsSdk: true,
37 TransitiveSdkMembers: true,
Paul Duffin4b64ba02021-03-29 11:02:53 +010038 },
39 })
Paul Duffin3451e162021-01-20 15:16:56 +000040}
41
Paul Duffin7771eba2021-04-23 14:25:28 +010042func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +010043 ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory)
44 ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory)
Paul Duffin3451e162021-01-20 15:16:56 +000045}
46
Paul Duffin65898052021-04-20 22:47:03 +010047type bootclasspathFragmentContentDependencyTag struct {
Paul Duffinc7ef9892021-03-23 23:21:59 +000048 blueprint.BaseDependencyTag
49}
50
Paul Duffin7771eba2021-04-23 14:25:28 +010051// Avoid having to make bootclasspath_fragment content visible to the bootclasspath_fragment.
Paul Duffinc7ef9892021-03-23 23:21:59 +000052//
Paul Duffin7771eba2021-04-23 14:25:28 +010053// This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules
54// with proper dependencies.
Paul Duffinc7ef9892021-03-23 23:21:59 +000055// TODO(b/177892522): Remove this and add needed visibility.
Paul Duffin65898052021-04-20 22:47:03 +010056func (b bootclasspathFragmentContentDependencyTag) ExcludeFromVisibilityEnforcement() {
57}
58
59// The bootclasspath_fragment contents must never depend on prebuilts.
60func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
61 return false
Paul Duffinc7ef9892021-03-23 23:21:59 +000062}
63
Paul Duffine95b53a2021-04-23 20:41:23 +010064// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
65// they were specified using java_boot_libs.
Paul Duffineee466e2021-04-27 23:17:56 +010066func (b bootclasspathFragmentContentDependencyTag) SdkMemberType(_ android.Module) android.SdkMemberType {
Paul Duffine95b53a2021-04-23 20:41:23 +010067 return javaBootLibsSdkMemberType
68}
69
70func (b bootclasspathFragmentContentDependencyTag) ExportMember() bool {
71 return true
72}
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 Duffine95b53a2021-04-23 20:41:23 +010079var _ android.SdkMemberTypeDependencyTag = bootclasspathFragmentContentDepTag
Paul Duffinc7ef9892021-03-23 23:21:59 +000080
Paul Duffin65898052021-04-20 22:47:03 +010081func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
82 return tag == bootclasspathFragmentContentDepTag
Paul Duffin4d101b62021-03-24 15:42:20 +000083}
84
Paul Duffinc7d16442021-04-23 13:55:49 +010085// Properties that can be different when coverage is enabled.
86type BootclasspathFragmentCoverageAffectedProperties struct {
87 // The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library.
88 //
89 // The order of this list matters as it is the order that is used in the bootclasspath.
90 Contents []string
Paul Duffin10931582021-04-25 10:13:54 +010091
92 // The properties for specifying the API stubs provided by this fragment.
93 BootclasspathAPIProperties
Paul Duffinc7d16442021-04-23 13:55:49 +010094}
95
Paul Duffin7771eba2021-04-23 14:25:28 +010096type bootclasspathFragmentProperties struct {
Paul Duffin3451e162021-01-20 15:16:56 +000097 // The name of the image this represents.
98 //
Paul Duffin82886d62021-03-24 01:34:57 +000099 // If specified then it must be one of "art" or "boot".
Paul Duffin64be7bb2021-03-23 23:06:38 +0000100 Image_name *string
Paul Duffinc7ef9892021-03-23 23:21:59 +0000101
Paul Duffinc7d16442021-04-23 13:55:49 +0100102 // Properties whose values need to differ with and without coverage.
103 BootclasspathFragmentCoverageAffectedProperties
104 Coverage BootclasspathFragmentCoverageAffectedProperties
Paul Duffin9b381ef2021-04-08 23:01:37 +0100105
106 Hidden_api HiddenAPIFlagFileProperties
Paul Duffin3451e162021-01-20 15:16:56 +0000107}
108
Paul Duffin7771eba2021-04-23 14:25:28 +0100109type BootclasspathFragmentModule struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000110 android.ModuleBase
Paul Duffina1d60252021-01-21 18:13:43 +0000111 android.ApexModuleBase
Paul Duffinf7f65da2021-03-10 15:00:46 +0000112 android.SdkBase
Paul Duffin7771eba2021-04-23 14:25:28 +0100113 properties bootclasspathFragmentProperties
Paul Duffin3451e162021-01-20 15:16:56 +0000114}
115
Paul Duffin7771eba2021-04-23 14:25:28 +0100116func bootclasspathFragmentFactory() android.Module {
117 m := &BootclasspathFragmentModule{}
Paul Duffin3451e162021-01-20 15:16:56 +0000118 m.AddProperties(&m.properties)
Paul Duffina1d60252021-01-21 18:13:43 +0000119 android.InitApexModule(m)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000120 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000121 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000122
Paul Duffinc7ef9892021-03-23 23:21:59 +0000123 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffinc7d16442021-04-23 13:55:49 +0100124 // If code coverage has been enabled for the framework then append the properties with
125 // coverage specific properties.
126 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
127 err := proptools.AppendProperties(&m.properties.BootclasspathFragmentCoverageAffectedProperties, &m.properties.Coverage, nil)
128 if err != nil {
129 ctx.PropertyErrorf("coverage", "error trying to append coverage specific properties: %s", err)
130 return
131 }
132 }
133
134 // Initialize the contents property from the image_name.
Paul Duffin7771eba2021-04-23 14:25:28 +0100135 bootclasspathFragmentInitContentsFromImage(ctx, m)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000136 })
Paul Duffin3451e162021-01-20 15:16:56 +0000137 return m
138}
139
Paul Duffin7771eba2021-04-23 14:25:28 +0100140// bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if
141// necessary.
142func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
Paul Duffin82886d62021-03-24 01:34:57 +0000143 contents := m.properties.Contents
144 if m.properties.Image_name == nil && len(contents) == 0 {
145 ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
146 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000147
148 if len(contents) != 0 {
149 // Nothing to do.
150 return
Paul Duffin82886d62021-03-24 01:34:57 +0000151 }
Paul Duffin023dba02021-04-22 01:45:29 +0100152
Paul Duffinc7ef9892021-03-23 23:21:59 +0000153 imageName := proptools.String(m.properties.Image_name)
154 if imageName == "art" {
Paul Duffin023dba02021-04-22 01:45:29 +0100155 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
Paul Duffin0c2e0832021-04-28 00:39:52 +0100156 if android.IsModuleInVersionedSdk(m) {
Paul Duffin023dba02021-04-22 01:45:29 +0100157 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
158 // 1. There is no way to use this at the moment so ignoring it is safe.
159 // 2. Attempting to initialize the contents property from the configuration will end up having
160 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
161 // as the unversioned prebuilt could end up with an APEX variant created for the source
162 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
163 // turn will prevent it from accessing the dex implementation jar from that which will
164 // break hidden API processing, amongst others.
165 return
166 }
167
Paul Duffinc7ef9892021-03-23 23:21:59 +0000168 // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
169 // too early in the Soong processing for that to work.
170 global := dexpreopt.GetGlobalConfig(ctx)
171 modules := global.ArtApexJars
172
173 // Make sure that the apex specified in the configuration is consistent and is one for which
174 // this boot image is available.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000175 commonApex := ""
176 for i := 0; i < modules.Len(); i++ {
177 apex := modules.Apex(i)
178 jar := modules.Jar(i)
179 if apex == "platform" {
180 ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar)
181 continue
182 }
183 if !m.AvailableFor(apex) {
184 ctx.ModuleErrorf("incompatible with ArtApexJars which expects this to be in apex %q but this is only in apexes %q",
185 apex, m.ApexAvailable())
186 continue
187 }
188 if commonApex == "" {
189 commonApex = apex
190 } else if commonApex != apex {
191 ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q",
192 commonApex, apex)
193 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000194 }
195
196 // Store the jars in the Contents property so that they can be used to add dependencies.
Paul Duffinba6afd02019-11-19 19:44:10 +0000197 m.properties.Contents = modules.CopyOfJars()
198 }
199}
200
201// bootclasspathImageNameContentsConsistencyCheck checks that the configuration that applies to this
202// module (if any) matches the contents.
203//
204// This should be a noop as if image_name="art" then the contents will be set from the ArtApexJars
205// config by bootclasspathFragmentInitContentsFromImage so it will be guaranteed to match. However,
206// in future this will not be the case.
207func (b *BootclasspathFragmentModule) bootclasspathImageNameContentsConsistencyCheck(ctx android.BaseModuleContext) {
208 imageName := proptools.String(b.properties.Image_name)
209 if imageName == "art" {
210 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
Paul Duffin0c2e0832021-04-28 00:39:52 +0100211 if android.IsModuleInVersionedSdk(b) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000212 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
213 // 1. There is no way to use this at the moment so ignoring it is safe.
214 // 2. Attempting to initialize the contents property from the configuration will end up having
215 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
216 // as the unversioned prebuilt could end up with an APEX variant created for the source
217 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
218 // turn will prevent it from accessing the dex implementation jar from that which will
219 // break hidden API processing, amongst others.
220 return
221 }
222
223 // Get the configuration for the art apex jars.
224 modules := b.getImageConfig(ctx).modules
225 configuredJars := modules.CopyOfJars()
226
227 // Skip the check if the configured jars list is empty as that is a common configuration when
228 // building targets that do not result in a system image.
229 if len(configuredJars) == 0 {
230 return
231 }
232
233 contents := b.properties.Contents
234 if !reflect.DeepEqual(configuredJars, contents) {
235 ctx.ModuleErrorf("inconsistency in specification of contents. ArtApexJars configuration specifies %#v, contents property specifies %#v",
236 configuredJars, contents)
237 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000238 }
239}
240
Paul Duffine946b322021-04-25 23:04:00 +0100241var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{})
Paul Duffin3451e162021-01-20 15:16:56 +0000242
Paul Duffine946b322021-04-25 23:04:00 +0100243// BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the
244// apex contents.
245type BootclasspathFragmentApexContentInfo struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000246 // The image config, internal to this module (and the dex_bootjars singleton).
Paul Duffina1d60252021-01-21 18:13:43 +0000247 //
Paul Duffine946b322021-04-25 23:04:00 +0100248 // Will be nil if the BootclasspathFragmentApexContentInfo has not been provided for a specific module. That can occur
Paul Duffina1d60252021-01-21 18:13:43 +0000249 // when SkipDexpreoptBootJars(ctx) returns true.
Paul Duffin3451e162021-01-20 15:16:56 +0000250 imageConfig *bootImageConfig
251}
252
Paul Duffine946b322021-04-25 23:04:00 +0100253func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList {
Paul Duffin3451e162021-01-20 15:16:56 +0000254 return i.imageConfig.modules
255}
256
Paul Duffina1d60252021-01-21 18:13:43 +0000257// Get a map from ArchType to the associated boot image's contents for Android.
258//
259// Extension boot images only return their own files, not the files of the boot images they extend.
Paul Duffine946b322021-04-25 23:04:00 +0100260func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths {
Paul Duffina1d60252021-01-21 18:13:43 +0000261 files := map[android.ArchType]android.OutputPaths{}
262 if i.imageConfig != nil {
263 for _, variant := range i.imageConfig.variants {
264 // We also generate boot images for host (for testing), but we don't need those in the apex.
265 // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
266 if variant.target.Os == android.Android {
267 files[variant.target.Arch.ArchType] = variant.imagesDeps
268 }
269 }
270 }
271 return files
272}
273
Paul Duffin190fdef2021-04-26 10:33:59 +0100274// DexBootJarPathForContentModule returns the path to the dex boot jar for specified module.
275//
276// The dex boot jar is one which has had hidden API encoding performed on it.
277func (i BootclasspathFragmentApexContentInfo) DexBootJarPathForContentModule(module android.Module) android.Path {
278 j := module.(UsesLibraryDependency)
279 dexJar := j.DexJarBuildPath()
280 return dexJar
281}
282
Paul Duffin7771eba2021-04-23 14:25:28 +0100283func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffina1d60252021-01-21 18:13:43 +0000284 tag := ctx.OtherModuleDependencyTag(dep)
Paul Duffin65898052021-04-20 22:47:03 +0100285 if IsBootclasspathFragmentContentDepTag(tag) {
Paul Duffin4d101b62021-03-24 15:42:20 +0000286 // Boot image contents are automatically added to apex.
287 return true
Paul Duffinc7ef9892021-03-23 23:21:59 +0000288 }
Bob Badour07065cd2021-02-05 19:59:11 -0800289 if android.IsMetaDependencyTag(tag) {
290 // Cross-cutting metadata dependencies are metadata.
291 return false
292 }
Paul Duffina1d60252021-01-21 18:13:43 +0000293 panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag)))
294}
295
Paul Duffin7771eba2021-04-23 14:25:28 +0100296func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Paul Duffina1d60252021-01-21 18:13:43 +0000297 return nil
298}
299
Paul Duffin65898052021-04-20 22:47:03 +0100300// ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a
301// corresponding source module are renamed. This means that adding a dependency using a name without
302// a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix
303// it will always resolve to a prebuilt module.
Paul Duffin7771eba2021-04-23 14:25:28 +0100304func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin65898052021-04-20 22:47:03 +0100305 module := ctx.Module()
Paul Duffin7771eba2021-04-23 14:25:28 +0100306 _, isSourceModule := module.(*BootclasspathFragmentModule)
Paul Duffin65898052021-04-20 22:47:03 +0100307
308 for _, name := range b.properties.Contents {
309 // A bootclasspath_fragment must depend only on other source modules, while the
310 // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules.
Paul Duffina9dd6fa2021-04-22 17:25:57 +0100311 //
312 // TODO(b/177892522) - avoid special handling of jacocoagent.
313 if !isSourceModule && name != "jacocoagent" {
Paul Duffin65898052021-04-20 22:47:03 +0100314 name = android.PrebuiltNameFromSource(name)
315 }
316 ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name)
317 }
318
319}
320
Paul Duffin7771eba2021-04-23 14:25:28 +0100321func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin10931582021-04-25 10:13:54 +0100322 // Add dependencies onto all the modules that provide the API stubs for classes on this
323 // bootclasspath fragment.
324 hiddenAPIAddStubLibDependencies(ctx, b.properties.sdkKindToStubLibs())
Paul Duffinc7ef9892021-03-23 23:21:59 +0000325
Paul Duffina1d60252021-01-21 18:13:43 +0000326 if SkipDexpreoptBootJars(ctx) {
327 return
328 }
329
330 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
331 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
332 dexpreopt.RegisterToolDeps(ctx)
333}
334
Paul Duffin7771eba2021-04-23 14:25:28 +0100335func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000336 // Only perform a consistency check if this module is the active module. That will prevent an
337 // unused prebuilt that was created without instrumentation from breaking an instrumentation
338 // build.
339 if isActiveModule(ctx.Module()) {
340 b.bootclasspathImageNameContentsConsistencyCheck(ctx)
341 }
342
Paul Duffin9b381ef2021-04-08 23:01:37 +0100343 // Perform hidden API processing.
344 b.generateHiddenAPIBuildActions(ctx)
345
Paul Duffin3451e162021-01-20 15:16:56 +0000346 // Nothing to do if skipping the dexpreopt of boot image jars.
347 if SkipDexpreoptBootJars(ctx) {
348 return
349 }
350
Paul Duffina1d60252021-01-21 18:13:43 +0000351 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
352 // GenerateSingletonBuildActions method as it cannot create it for itself.
353 dexpreopt.GetGlobalSoongConfig(ctx)
354
Paul Duffin64be7bb2021-03-23 23:06:38 +0000355 imageConfig := b.getImageConfig(ctx)
Paul Duffin3451e162021-01-20 15:16:56 +0000356 if imageConfig == nil {
Paul Duffin3451e162021-01-20 15:16:56 +0000357 return
358 }
359
360 // Construct the boot image info from the config.
Paul Duffine946b322021-04-25 23:04:00 +0100361 info := BootclasspathFragmentApexContentInfo{imageConfig: imageConfig}
Paul Duffin3451e162021-01-20 15:16:56 +0000362
363 // Make it available for other modules.
Paul Duffine946b322021-04-25 23:04:00 +0100364 ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
Paul Duffin3451e162021-01-20 15:16:56 +0000365}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000366
Paul Duffin7771eba2021-04-23 14:25:28 +0100367func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000368 // Get a map of the image configs that are supported.
369 imageConfigs := genBootImageConfigs(ctx)
370
371 // Retrieve the config for this image.
372 imageNamePtr := b.properties.Image_name
373 if imageNamePtr == nil {
374 return nil
375 }
376
377 imageName := *imageNamePtr
378 imageConfig := imageConfigs[imageName]
379 if imageConfig == nil {
380 ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", "))
381 return nil
382 }
383 return imageConfig
384}
385
Paul Duffin9b381ef2021-04-08 23:01:37 +0100386// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffin7771eba2021-04-23 14:25:28 +0100387func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100388 // Resolve the properties to paths.
389 flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx)
390
391 // Store the information for use by platform_bootclasspath.
392 ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo)
Paul Duffin10931582021-04-25 10:13:54 +0100393
394 // Convert the kind specific lists of modules into kind specific lists of jars.
395 stubJarsByKind := hiddenAPIGatherStubLibDexJarPaths(ctx)
396
397 // Store the information for use by other modules.
398 bootclasspathApiInfo := bootclasspathApiInfo{stubJarsByKind: stubJarsByKind}
399 ctx.SetProvider(bootclasspathApiInfoProvider, bootclasspathApiInfo)
Paul Duffin9b381ef2021-04-08 23:01:37 +0100400}
401
Paul Duffin7771eba2021-04-23 14:25:28 +0100402type bootclasspathFragmentMemberType struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000403 android.SdkMemberTypeBase
404}
405
Paul Duffin7771eba2021-04-23 14:25:28 +0100406func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000407 mctx.AddVariationDependencies(nil, dependencyTag, names...)
408}
409
Paul Duffin7771eba2021-04-23 14:25:28 +0100410func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {
411 _, ok := module.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000412 return ok
413}
414
Paul Duffin7771eba2021-04-23 14:25:28 +0100415func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
Paul Duffin4b64ba02021-03-29 11:02:53 +0100416 if b.PropertyName == "boot_images" {
417 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
418 } else {
419 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment")
420 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000421}
422
Paul Duffin7771eba2021-04-23 14:25:28 +0100423func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
424 return &bootclasspathFragmentSdkMemberProperties{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000425}
426
Paul Duffin7771eba2021-04-23 14:25:28 +0100427type bootclasspathFragmentSdkMemberProperties struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000428 android.SdkMemberPropertiesBase
429
Paul Duffina57835e2021-04-19 13:23:06 +0100430 // The image name
Paul Duffin64be7bb2021-03-23 23:06:38 +0000431 Image_name *string
Paul Duffina57835e2021-04-19 13:23:06 +0100432
433 // Contents of the bootclasspath fragment
434 Contents []string
Paul Duffin7c955552021-04-19 13:23:53 +0100435
436 // Flag files by *hiddenAPIFlagFileCategory
437 Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000438}
439
Paul Duffin7771eba2021-04-23 14:25:28 +0100440func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
441 module := variant.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000442
443 b.Image_name = module.properties.Image_name
Paul Duffin2dc665b2021-04-23 16:58:51 +0100444 b.Contents = module.properties.Contents
Paul Duffin7c955552021-04-19 13:23:53 +0100445
446 // Get the flag file information from the module.
447 mctx := ctx.SdkModuleContext()
448 flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
449 b.Flag_files_by_category = flagFileInfo.categoryToPaths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000450}
451
Paul Duffin7771eba2021-04-23 14:25:28 +0100452func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000453 if b.Image_name != nil {
454 propertySet.AddProperty("image_name", *b.Image_name)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000455 }
Paul Duffina57835e2021-04-19 13:23:06 +0100456
457 if len(b.Contents) > 0 {
458 propertySet.AddPropertyWithTag("contents", b.Contents, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(true))
459 }
Paul Duffin7c955552021-04-19 13:23:53 +0100460
461 builder := ctx.SnapshotBuilder()
462 if b.Flag_files_by_category != nil {
463 hiddenAPISet := propertySet.AddPropertySet("hidden_api")
464 for _, category := range hiddenAPIFlagFileCategories {
465 paths := b.Flag_files_by_category[category]
466 if len(paths) > 0 {
467 dests := []string{}
468 for _, p := range paths {
469 dest := filepath.Join("hiddenapi", p.Base())
470 builder.CopyToSnapshot(p, dest)
471 dests = append(dests, dest)
472 }
473 hiddenAPISet.AddProperty(category.propertyName, dests)
474 }
475 }
476 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000477}
478
Paul Duffin7771eba2021-04-23 14:25:28 +0100479var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000480
Paul Duffin7771eba2021-04-23 14:25:28 +0100481// A prebuilt version of the bootclasspath_fragment module.
Paul Duffinf7f65da2021-03-10 15:00:46 +0000482//
Paul Duffin7771eba2021-04-23 14:25:28 +0100483// At the moment this is basically just a bootclasspath_fragment module that can be used as a
484// prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module
485// type from the various singletons then this will diverge.
486type prebuiltBootclasspathFragmentModule struct {
487 BootclasspathFragmentModule
Paul Duffinf7f65da2021-03-10 15:00:46 +0000488 prebuilt android.Prebuilt
489}
490
Paul Duffin7771eba2021-04-23 14:25:28 +0100491func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000492 return &module.prebuilt
493}
494
Paul Duffin7771eba2021-04-23 14:25:28 +0100495func (module *prebuiltBootclasspathFragmentModule) Name() string {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000496 return module.prebuilt.Name(module.ModuleBase.Name())
497}
498
Paul Duffin7771eba2021-04-23 14:25:28 +0100499func prebuiltBootclasspathFragmentFactory() android.Module {
500 m := &prebuiltBootclasspathFragmentModule{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000501 m.AddProperties(&m.properties)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000502 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
503 // array.
504 android.InitPrebuiltModule(m, &[]string{"placeholder"})
505 android.InitApexModule(m)
506 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000507 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000508
Paul Duffin7771eba2021-04-23 14:25:28 +0100509 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000510 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100511 bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000512 })
Paul Duffinf7f65da2021-03-10 15:00:46 +0000513 return m
514}