blob: 6270b5b3555fd8109e6e9e4c892b8675a75aa55e [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 Duffin2d3da312021-05-06 12:02:27 +010035 PropertyName: "bootclasspath_fragments",
36 SupportsSdk: true,
Paul Duffin4b64ba02021-03-29 11:02:53 +010037 },
38 })
Paul Duffin3451e162021-01-20 15:16:56 +000039}
40
Paul Duffin7771eba2021-04-23 14:25:28 +010041func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +010042 ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory)
43 ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory)
Paul Duffin3451e162021-01-20 15:16:56 +000044}
45
Paul Duffin65898052021-04-20 22:47:03 +010046type bootclasspathFragmentContentDependencyTag struct {
Paul Duffinc7ef9892021-03-23 23:21:59 +000047 blueprint.BaseDependencyTag
48}
49
Paul Duffin7771eba2021-04-23 14:25:28 +010050// Avoid having to make bootclasspath_fragment content visible to the bootclasspath_fragment.
Paul Duffinc7ef9892021-03-23 23:21:59 +000051//
Paul Duffin7771eba2021-04-23 14:25:28 +010052// This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules
53// with proper dependencies.
Paul Duffinc7ef9892021-03-23 23:21:59 +000054// TODO(b/177892522): Remove this and add needed visibility.
Paul Duffin65898052021-04-20 22:47:03 +010055func (b bootclasspathFragmentContentDependencyTag) ExcludeFromVisibilityEnforcement() {
56}
57
58// The bootclasspath_fragment contents must never depend on prebuilts.
59func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
60 return false
Paul Duffinc7ef9892021-03-23 23:21:59 +000061}
62
Paul Duffine95b53a2021-04-23 20:41:23 +010063// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
64// they were specified using java_boot_libs.
Paul Duffineee466e2021-04-27 23:17:56 +010065func (b bootclasspathFragmentContentDependencyTag) SdkMemberType(_ android.Module) android.SdkMemberType {
Paul Duffine95b53a2021-04-23 20:41:23 +010066 return javaBootLibsSdkMemberType
67}
68
69func (b bootclasspathFragmentContentDependencyTag) ExportMember() bool {
70 return true
71}
72
Paul Duffin7771eba2021-04-23 14:25:28 +010073// The tag used for the dependency between the bootclasspath_fragment module and its contents.
Paul Duffin65898052021-04-20 22:47:03 +010074var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{}
Paul Duffinc7ef9892021-03-23 23:21:59 +000075
Paul Duffin65898052021-04-20 22:47:03 +010076var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag
77var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag
Paul Duffine95b53a2021-04-23 20:41:23 +010078var _ android.SdkMemberTypeDependencyTag = 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 Duffinc7d16442021-04-23 13:55:49 +010084// Properties that can be different when coverage is enabled.
85type BootclasspathFragmentCoverageAffectedProperties struct {
86 // The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library.
87 //
88 // The order of this list matters as it is the order that is used in the bootclasspath.
89 Contents []string
Paul Duffin10931582021-04-25 10:13:54 +010090
91 // The properties for specifying the API stubs provided by this fragment.
92 BootclasspathAPIProperties
Paul Duffinc7d16442021-04-23 13:55:49 +010093}
94
Paul Duffin7771eba2021-04-23 14:25:28 +010095type bootclasspathFragmentProperties struct {
Paul Duffin3451e162021-01-20 15:16:56 +000096 // The name of the image this represents.
97 //
Paul Duffin82886d62021-03-24 01:34:57 +000098 // If specified then it must be one of "art" or "boot".
Paul Duffin64be7bb2021-03-23 23:06:38 +000099 Image_name *string
Paul Duffinc7ef9892021-03-23 23:21:59 +0000100
Paul Duffinc7d16442021-04-23 13:55:49 +0100101 // Properties whose values need to differ with and without coverage.
102 BootclasspathFragmentCoverageAffectedProperties
103 Coverage BootclasspathFragmentCoverageAffectedProperties
Paul Duffin9b381ef2021-04-08 23:01:37 +0100104
105 Hidden_api HiddenAPIFlagFileProperties
Paul Duffin3451e162021-01-20 15:16:56 +0000106}
107
Paul Duffin7771eba2021-04-23 14:25:28 +0100108type BootclasspathFragmentModule struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000109 android.ModuleBase
Paul Duffina1d60252021-01-21 18:13:43 +0000110 android.ApexModuleBase
Paul Duffinf7f65da2021-03-10 15:00:46 +0000111 android.SdkBase
Paul Duffin7771eba2021-04-23 14:25:28 +0100112 properties bootclasspathFragmentProperties
Paul Duffin3451e162021-01-20 15:16:56 +0000113}
114
Paul Duffin7771eba2021-04-23 14:25:28 +0100115func bootclasspathFragmentFactory() android.Module {
116 m := &BootclasspathFragmentModule{}
Paul Duffin3451e162021-01-20 15:16:56 +0000117 m.AddProperties(&m.properties)
Paul Duffina1d60252021-01-21 18:13:43 +0000118 android.InitApexModule(m)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000119 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000120 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000121
Paul Duffinc7ef9892021-03-23 23:21:59 +0000122 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffinc7d16442021-04-23 13:55:49 +0100123 // If code coverage has been enabled for the framework then append the properties with
124 // coverage specific properties.
125 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
126 err := proptools.AppendProperties(&m.properties.BootclasspathFragmentCoverageAffectedProperties, &m.properties.Coverage, nil)
127 if err != nil {
128 ctx.PropertyErrorf("coverage", "error trying to append coverage specific properties: %s", err)
129 return
130 }
131 }
132
133 // Initialize the contents property from the image_name.
Paul Duffin7771eba2021-04-23 14:25:28 +0100134 bootclasspathFragmentInitContentsFromImage(ctx, m)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000135 })
Paul Duffin3451e162021-01-20 15:16:56 +0000136 return m
137}
138
Paul Duffin7771eba2021-04-23 14:25:28 +0100139// bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if
140// necessary.
141func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
Paul Duffin82886d62021-03-24 01:34:57 +0000142 contents := m.properties.Contents
143 if m.properties.Image_name == nil && len(contents) == 0 {
144 ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
145 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000146
Paul Duffinc7ef9892021-03-23 23:21:59 +0000147 imageName := proptools.String(m.properties.Image_name)
148 if imageName == "art" {
Paul Duffin023dba02021-04-22 01:45:29 +0100149 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
Paul Duffin0c2e0832021-04-28 00:39:52 +0100150 if android.IsModuleInVersionedSdk(m) {
Paul Duffin023dba02021-04-22 01:45:29 +0100151 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
152 // 1. There is no way to use this at the moment so ignoring it is safe.
153 // 2. Attempting to initialize the contents property from the configuration will end up having
154 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
155 // as the unversioned prebuilt could end up with an APEX variant created for the source
156 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
157 // turn will prevent it from accessing the dex implementation jar from that which will
158 // break hidden API processing, amongst others.
159 return
160 }
161
Paul Duffinc7ef9892021-03-23 23:21:59 +0000162 // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
163 // too early in the Soong processing for that to work.
164 global := dexpreopt.GetGlobalConfig(ctx)
165 modules := global.ArtApexJars
166
167 // Make sure that the apex specified in the configuration is consistent and is one for which
168 // this boot image is available.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000169 commonApex := ""
170 for i := 0; i < modules.Len(); i++ {
171 apex := modules.Apex(i)
172 jar := modules.Jar(i)
173 if apex == "platform" {
174 ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar)
175 continue
176 }
177 if !m.AvailableFor(apex) {
Paul Duffinf23bc472021-04-27 12:42:20 +0100178 ctx.ModuleErrorf("ArtApexJars configuration incompatible with this module, ArtApexJars expects this to be in apex %q but this is only in apexes %q",
Paul Duffinc7ef9892021-03-23 23:21:59 +0000179 apex, m.ApexAvailable())
180 continue
181 }
182 if commonApex == "" {
183 commonApex = apex
184 } else if commonApex != apex {
185 ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q",
186 commonApex, apex)
187 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000188 }
189
Paul Duffinf23bc472021-04-27 12:42:20 +0100190 if len(contents) != 0 {
191 // Nothing to do.
192 return
193 }
194
Paul Duffinc7ef9892021-03-23 23:21:59 +0000195 // Store the jars in the Contents property so that they can be used to add dependencies.
Paul Duffinba6afd02019-11-19 19:44:10 +0000196 m.properties.Contents = modules.CopyOfJars()
197 }
198}
199
200// bootclasspathImageNameContentsConsistencyCheck checks that the configuration that applies to this
201// module (if any) matches the contents.
202//
203// This should be a noop as if image_name="art" then the contents will be set from the ArtApexJars
204// config by bootclasspathFragmentInitContentsFromImage so it will be guaranteed to match. However,
205// in future this will not be the case.
206func (b *BootclasspathFragmentModule) bootclasspathImageNameContentsConsistencyCheck(ctx android.BaseModuleContext) {
207 imageName := proptools.String(b.properties.Image_name)
208 if imageName == "art" {
209 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
Paul Duffin0c2e0832021-04-28 00:39:52 +0100210 if android.IsModuleInVersionedSdk(b) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000211 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
212 // 1. There is no way to use this at the moment so ignoring it is safe.
213 // 2. Attempting to initialize the contents property from the configuration will end up having
214 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
215 // as the unversioned prebuilt could end up with an APEX variant created for the source
216 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
217 // turn will prevent it from accessing the dex implementation jar from that which will
218 // break hidden API processing, amongst others.
219 return
220 }
221
222 // Get the configuration for the art apex jars.
223 modules := b.getImageConfig(ctx).modules
224 configuredJars := modules.CopyOfJars()
225
226 // Skip the check if the configured jars list is empty as that is a common configuration when
227 // building targets that do not result in a system image.
228 if len(configuredJars) == 0 {
229 return
230 }
231
232 contents := b.properties.Contents
233 if !reflect.DeepEqual(configuredJars, contents) {
234 ctx.ModuleErrorf("inconsistency in specification of contents. ArtApexJars configuration specifies %#v, contents property specifies %#v",
235 configuredJars, contents)
236 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000237 }
238}
239
Paul Duffine946b322021-04-25 23:04:00 +0100240var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{})
Paul Duffin3451e162021-01-20 15:16:56 +0000241
Paul Duffine946b322021-04-25 23:04:00 +0100242// BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the
243// apex contents.
244type BootclasspathFragmentApexContentInfo struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000245 // The image config, internal to this module (and the dex_bootjars singleton).
Paul Duffina1d60252021-01-21 18:13:43 +0000246 //
Paul Duffine946b322021-04-25 23:04:00 +0100247 // Will be nil if the BootclasspathFragmentApexContentInfo has not been provided for a specific module. That can occur
Paul Duffina1d60252021-01-21 18:13:43 +0000248 // when SkipDexpreoptBootJars(ctx) returns true.
Paul Duffin3451e162021-01-20 15:16:56 +0000249 imageConfig *bootImageConfig
250}
251
Paul Duffine946b322021-04-25 23:04:00 +0100252func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList {
Paul Duffin3451e162021-01-20 15:16:56 +0000253 return i.imageConfig.modules
254}
255
Paul Duffina1d60252021-01-21 18:13:43 +0000256// Get a map from ArchType to the associated boot image's contents for Android.
257//
258// Extension boot images only return their own files, not the files of the boot images they extend.
Paul Duffine946b322021-04-25 23:04:00 +0100259func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths {
Paul Duffina1d60252021-01-21 18:13:43 +0000260 files := map[android.ArchType]android.OutputPaths{}
261 if i.imageConfig != nil {
262 for _, variant := range i.imageConfig.variants {
263 // We also generate boot images for host (for testing), but we don't need those in the apex.
264 // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
265 if variant.target.Os == android.Android {
266 files[variant.target.Arch.ArchType] = variant.imagesDeps
267 }
268 }
269 }
270 return files
271}
272
Paul Duffin190fdef2021-04-26 10:33:59 +0100273// DexBootJarPathForContentModule returns the path to the dex boot jar for specified module.
274//
275// The dex boot jar is one which has had hidden API encoding performed on it.
276func (i BootclasspathFragmentApexContentInfo) DexBootJarPathForContentModule(module android.Module) android.Path {
277 j := module.(UsesLibraryDependency)
278 dexJar := j.DexJarBuildPath()
279 return dexJar
280}
281
Paul Duffin7771eba2021-04-23 14:25:28 +0100282func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffina1d60252021-01-21 18:13:43 +0000283 tag := ctx.OtherModuleDependencyTag(dep)
Paul Duffin65898052021-04-20 22:47:03 +0100284 if IsBootclasspathFragmentContentDepTag(tag) {
Paul Duffin4d101b62021-03-24 15:42:20 +0000285 // Boot image contents are automatically added to apex.
286 return true
Paul Duffinc7ef9892021-03-23 23:21:59 +0000287 }
Bob Badour07065cd2021-02-05 19:59:11 -0800288 if android.IsMetaDependencyTag(tag) {
289 // Cross-cutting metadata dependencies are metadata.
290 return false
291 }
Paul Duffina1d60252021-01-21 18:13:43 +0000292 panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag)))
293}
294
Paul Duffin7771eba2021-04-23 14:25:28 +0100295func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Paul Duffina1d60252021-01-21 18:13:43 +0000296 return nil
297}
298
Paul Duffin65898052021-04-20 22:47:03 +0100299// ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a
300// corresponding source module are renamed. This means that adding a dependency using a name without
301// a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix
302// it will always resolve to a prebuilt module.
Paul Duffin7771eba2021-04-23 14:25:28 +0100303func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin65898052021-04-20 22:47:03 +0100304 module := ctx.Module()
Paul Duffin7771eba2021-04-23 14:25:28 +0100305 _, isSourceModule := module.(*BootclasspathFragmentModule)
Paul Duffin65898052021-04-20 22:47:03 +0100306
307 for _, name := range b.properties.Contents {
308 // A bootclasspath_fragment must depend only on other source modules, while the
309 // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules.
Paul Duffina9dd6fa2021-04-22 17:25:57 +0100310 //
311 // TODO(b/177892522) - avoid special handling of jacocoagent.
312 if !isSourceModule && name != "jacocoagent" {
Paul Duffin65898052021-04-20 22:47:03 +0100313 name = android.PrebuiltNameFromSource(name)
314 }
315 ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name)
316 }
317
318}
319
Paul Duffin7771eba2021-04-23 14:25:28 +0100320func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin10931582021-04-25 10:13:54 +0100321 // Add dependencies onto all the modules that provide the API stubs for classes on this
322 // bootclasspath fragment.
323 hiddenAPIAddStubLibDependencies(ctx, b.properties.sdkKindToStubLibs())
Paul Duffinc7ef9892021-03-23 23:21:59 +0000324
Paul Duffina1d60252021-01-21 18:13:43 +0000325 if SkipDexpreoptBootJars(ctx) {
326 return
327 }
328
329 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
330 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
331 dexpreopt.RegisterToolDeps(ctx)
332}
333
Paul Duffin7771eba2021-04-23 14:25:28 +0100334func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000335 // Only perform a consistency check if this module is the active module. That will prevent an
336 // unused prebuilt that was created without instrumentation from breaking an instrumentation
337 // build.
338 if isActiveModule(ctx.Module()) {
339 b.bootclasspathImageNameContentsConsistencyCheck(ctx)
340 }
341
Paul Duffin9b381ef2021-04-08 23:01:37 +0100342 // Perform hidden API processing.
343 b.generateHiddenAPIBuildActions(ctx)
344
Paul Duffin3451e162021-01-20 15:16:56 +0000345 // Nothing to do if skipping the dexpreopt of boot image jars.
346 if SkipDexpreoptBootJars(ctx) {
347 return
348 }
349
Paul Duffina1d60252021-01-21 18:13:43 +0000350 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
351 // GenerateSingletonBuildActions method as it cannot create it for itself.
352 dexpreopt.GetGlobalSoongConfig(ctx)
353
Paul Duffin64be7bb2021-03-23 23:06:38 +0000354 imageConfig := b.getImageConfig(ctx)
Paul Duffin3451e162021-01-20 15:16:56 +0000355 if imageConfig == nil {
Paul Duffin3451e162021-01-20 15:16:56 +0000356 return
357 }
358
359 // Construct the boot image info from the config.
Paul Duffine946b322021-04-25 23:04:00 +0100360 info := BootclasspathFragmentApexContentInfo{imageConfig: imageConfig}
Paul Duffin3451e162021-01-20 15:16:56 +0000361
362 // Make it available for other modules.
Paul Duffine946b322021-04-25 23:04:00 +0100363 ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
Paul Duffin3451e162021-01-20 15:16:56 +0000364}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000365
Paul Duffin7771eba2021-04-23 14:25:28 +0100366func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000367 // Get a map of the image configs that are supported.
368 imageConfigs := genBootImageConfigs(ctx)
369
370 // Retrieve the config for this image.
371 imageNamePtr := b.properties.Image_name
372 if imageNamePtr == nil {
373 return nil
374 }
375
376 imageName := *imageNamePtr
377 imageConfig := imageConfigs[imageName]
378 if imageConfig == nil {
379 ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", "))
380 return nil
381 }
382 return imageConfig
383}
384
Paul Duffin9b381ef2021-04-08 23:01:37 +0100385// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffin7771eba2021-04-23 14:25:28 +0100386func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext) {
Paul Duffin9b381ef2021-04-08 23:01:37 +0100387 // Resolve the properties to paths.
388 flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx)
389
390 // Store the information for use by platform_bootclasspath.
391 ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo)
Paul Duffin10931582021-04-25 10:13:54 +0100392
393 // Convert the kind specific lists of modules into kind specific lists of jars.
394 stubJarsByKind := hiddenAPIGatherStubLibDexJarPaths(ctx)
395
396 // Store the information for use by other modules.
397 bootclasspathApiInfo := bootclasspathApiInfo{stubJarsByKind: stubJarsByKind}
398 ctx.SetProvider(bootclasspathApiInfoProvider, bootclasspathApiInfo)
Paul Duffin9b381ef2021-04-08 23:01:37 +0100399}
400
Paul Duffin7771eba2021-04-23 14:25:28 +0100401type bootclasspathFragmentMemberType struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000402 android.SdkMemberTypeBase
403}
404
Paul Duffin7771eba2021-04-23 14:25:28 +0100405func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000406 mctx.AddVariationDependencies(nil, dependencyTag, names...)
407}
408
Paul Duffin7771eba2021-04-23 14:25:28 +0100409func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {
410 _, ok := module.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000411 return ok
412}
413
Paul Duffin7771eba2021-04-23 14:25:28 +0100414func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
Paul Duffin4b64ba02021-03-29 11:02:53 +0100415 if b.PropertyName == "boot_images" {
416 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
417 } else {
418 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment")
419 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000420}
421
Paul Duffin7771eba2021-04-23 14:25:28 +0100422func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
423 return &bootclasspathFragmentSdkMemberProperties{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000424}
425
Paul Duffin7771eba2021-04-23 14:25:28 +0100426type bootclasspathFragmentSdkMemberProperties struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000427 android.SdkMemberPropertiesBase
428
Paul Duffina57835e2021-04-19 13:23:06 +0100429 // The image name
Paul Duffin64be7bb2021-03-23 23:06:38 +0000430 Image_name *string
Paul Duffina57835e2021-04-19 13:23:06 +0100431
432 // Contents of the bootclasspath fragment
433 Contents []string
Paul Duffin7c955552021-04-19 13:23:53 +0100434
Paul Duffin895c7142021-04-25 13:40:15 +0100435 // Stub_libs properties.
436 Stub_libs []string
437 Core_platform_stub_libs []string
438
Paul Duffin7c955552021-04-19 13:23:53 +0100439 // Flag files by *hiddenAPIFlagFileCategory
440 Flag_files_by_category map[*hiddenAPIFlagFileCategory]android.Paths
Paul Duffinf7f65da2021-03-10 15:00:46 +0000441}
442
Paul Duffin7771eba2021-04-23 14:25:28 +0100443func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
444 module := variant.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000445
446 b.Image_name = module.properties.Image_name
Paul Duffin2dc665b2021-04-23 16:58:51 +0100447 b.Contents = module.properties.Contents
Paul Duffin7c955552021-04-19 13:23:53 +0100448
449 // Get the flag file information from the module.
450 mctx := ctx.SdkModuleContext()
451 flagFileInfo := mctx.OtherModuleProvider(module, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
452 b.Flag_files_by_category = flagFileInfo.categoryToPaths
Paul Duffin895c7142021-04-25 13:40:15 +0100453
454 // Copy stub_libs properties.
455 b.Stub_libs = module.properties.Api.Stub_libs
456 b.Core_platform_stub_libs = module.properties.Core_platform_api.Stub_libs
Paul Duffinf7f65da2021-03-10 15:00:46 +0000457}
458
Paul Duffin7771eba2021-04-23 14:25:28 +0100459func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000460 if b.Image_name != nil {
461 propertySet.AddProperty("image_name", *b.Image_name)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000462 }
Paul Duffina57835e2021-04-19 13:23:06 +0100463
Paul Duffin895c7142021-04-25 13:40:15 +0100464 builder := ctx.SnapshotBuilder()
465 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
466
Paul Duffina57835e2021-04-19 13:23:06 +0100467 if len(b.Contents) > 0 {
Paul Duffin895c7142021-04-25 13:40:15 +0100468 propertySet.AddPropertyWithTag("contents", b.Contents, requiredMemberDependency)
Paul Duffina57835e2021-04-19 13:23:06 +0100469 }
Paul Duffin7c955552021-04-19 13:23:53 +0100470
Paul Duffin895c7142021-04-25 13:40:15 +0100471 if len(b.Stub_libs) > 0 {
472 apiPropertySet := propertySet.AddPropertySet("api")
473 apiPropertySet.AddPropertyWithTag("stub_libs", b.Stub_libs, requiredMemberDependency)
474 }
475 if len(b.Core_platform_stub_libs) > 0 {
476 corePlatformApiPropertySet := propertySet.AddPropertySet("core_platform_api")
477 corePlatformApiPropertySet.AddPropertyWithTag("stub_libs", b.Core_platform_stub_libs, requiredMemberDependency)
478 }
479
Paul Duffin7c955552021-04-19 13:23:53 +0100480 if b.Flag_files_by_category != nil {
481 hiddenAPISet := propertySet.AddPropertySet("hidden_api")
482 for _, category := range hiddenAPIFlagFileCategories {
483 paths := b.Flag_files_by_category[category]
484 if len(paths) > 0 {
485 dests := []string{}
486 for _, p := range paths {
487 dest := filepath.Join("hiddenapi", p.Base())
488 builder.CopyToSnapshot(p, dest)
489 dests = append(dests, dest)
490 }
491 hiddenAPISet.AddProperty(category.propertyName, dests)
492 }
493 }
494 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000495}
496
Paul Duffin7771eba2021-04-23 14:25:28 +0100497var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000498
Paul Duffin7771eba2021-04-23 14:25:28 +0100499// A prebuilt version of the bootclasspath_fragment module.
Paul Duffinf7f65da2021-03-10 15:00:46 +0000500//
Paul Duffin7771eba2021-04-23 14:25:28 +0100501// At the moment this is basically just a bootclasspath_fragment module that can be used as a
502// prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module
503// type from the various singletons then this will diverge.
504type prebuiltBootclasspathFragmentModule struct {
505 BootclasspathFragmentModule
Paul Duffinf7f65da2021-03-10 15:00:46 +0000506 prebuilt android.Prebuilt
507}
508
Paul Duffin7771eba2021-04-23 14:25:28 +0100509func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000510 return &module.prebuilt
511}
512
Paul Duffin7771eba2021-04-23 14:25:28 +0100513func (module *prebuiltBootclasspathFragmentModule) Name() string {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000514 return module.prebuilt.Name(module.ModuleBase.Name())
515}
516
Paul Duffin7771eba2021-04-23 14:25:28 +0100517func prebuiltBootclasspathFragmentFactory() android.Module {
518 m := &prebuiltBootclasspathFragmentModule{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000519 m.AddProperties(&m.properties)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000520 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
521 // array.
522 android.InitPrebuiltModule(m, &[]string{"placeholder"})
523 android.InitApexModule(m)
524 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000525 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000526
Paul Duffin7771eba2021-04-23 14:25:28 +0100527 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000528 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100529 bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000530 })
Paul Duffinf7f65da2021-03-10 15:00:46 +0000531 return m
532}