blob: fa51b13f64154de8808580b47364bae326740c67 [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
Paul Duffina10bd3c2021-05-12 13:46:54 +010064// they were specified using java_boot_libs or java_sdk_libs.
65func (b bootclasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
66 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
67 // property, otherwise treat if it was specified in the java_boot_libs property.
68 if javaSdkLibrarySdkMemberType.IsInstance(child) {
69 return javaSdkLibrarySdkMemberType
70 }
71
Paul Duffine95b53a2021-04-23 20:41:23 +010072 return javaBootLibsSdkMemberType
73}
74
75func (b bootclasspathFragmentContentDependencyTag) ExportMember() bool {
76 return true
77}
78
Paul Duffin7771eba2021-04-23 14:25:28 +010079// The tag used for the dependency between the bootclasspath_fragment module and its contents.
Paul Duffin65898052021-04-20 22:47:03 +010080var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{}
Paul Duffinc7ef9892021-03-23 23:21:59 +000081
Paul Duffin65898052021-04-20 22:47:03 +010082var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag
83var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag
Paul Duffine95b53a2021-04-23 20:41:23 +010084var _ android.SdkMemberTypeDependencyTag = bootclasspathFragmentContentDepTag
Paul Duffinc7ef9892021-03-23 23:21:59 +000085
Paul Duffin65898052021-04-20 22:47:03 +010086func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
87 return tag == bootclasspathFragmentContentDepTag
Paul Duffin4d101b62021-03-24 15:42:20 +000088}
89
Paul Duffinc7d16442021-04-23 13:55:49 +010090// Properties that can be different when coverage is enabled.
91type BootclasspathFragmentCoverageAffectedProperties struct {
92 // The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library.
93 //
Paul Duffin34827d42021-05-13 21:25:05 +010094 // A java_sdk_library specified here will also be treated as if it was specified on the stub_libs
95 // property.
96 //
Paul Duffinc7d16442021-04-23 13:55:49 +010097 // The order of this list matters as it is the order that is used in the bootclasspath.
98 Contents []string
Paul Duffin10931582021-04-25 10:13:54 +010099
100 // The properties for specifying the API stubs provided by this fragment.
101 BootclasspathAPIProperties
Paul Duffinc7d16442021-04-23 13:55:49 +0100102}
103
Paul Duffin7771eba2021-04-23 14:25:28 +0100104type bootclasspathFragmentProperties struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000105 // The name of the image this represents.
106 //
Paul Duffin82886d62021-03-24 01:34:57 +0000107 // If specified then it must be one of "art" or "boot".
Paul Duffin64be7bb2021-03-23 23:06:38 +0000108 Image_name *string
Paul Duffinc7ef9892021-03-23 23:21:59 +0000109
Paul Duffinc7d16442021-04-23 13:55:49 +0100110 // Properties whose values need to differ with and without coverage.
111 BootclasspathFragmentCoverageAffectedProperties
112 Coverage BootclasspathFragmentCoverageAffectedProperties
Paul Duffin9b381ef2021-04-08 23:01:37 +0100113
114 Hidden_api HiddenAPIFlagFileProperties
Paul Duffin70cfdff2021-05-15 09:10:42 +0100115
116 // Properties that allow a fragment to depend on other fragments. This is needed for hidden API
117 // processing as it needs access to all the classes used by a fragment including those provided
118 // by other fragments.
119 BootclasspathFragmentsDepsProperties
Paul Duffin3451e162021-01-20 15:16:56 +0000120}
121
Paul Duffin7771eba2021-04-23 14:25:28 +0100122type BootclasspathFragmentModule struct {
Paul Duffin3451e162021-01-20 15:16:56 +0000123 android.ModuleBase
Paul Duffina1d60252021-01-21 18:13:43 +0000124 android.ApexModuleBase
Paul Duffinf7f65da2021-03-10 15:00:46 +0000125 android.SdkBase
satayev3db35472021-05-06 23:59:58 +0100126 ClasspathFragmentBase
127
Paul Duffin7771eba2021-04-23 14:25:28 +0100128 properties bootclasspathFragmentProperties
Paul Duffin3451e162021-01-20 15:16:56 +0000129}
130
Paul Duffin2fef1362021-04-15 13:32:00 +0100131// commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt
132// bootclasspath fragment modules.
133type commonBootclasspathFragment interface {
134 // produceHiddenAPIAllFlagsFile produces the all-flags.csv and intermediate files.
135 //
Paul Duffin1352f7c2021-05-21 22:18:49 +0100136 // Updates the supplied hiddenAPIInfo with the paths to the generated files set.
137 produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, input HiddenAPIFlagInput) *HiddenAPIFlagOutput
Paul Duffin2fef1362021-04-15 13:32:00 +0100138}
139
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100140var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil)
141
Paul Duffin7771eba2021-04-23 14:25:28 +0100142func bootclasspathFragmentFactory() android.Module {
143 m := &BootclasspathFragmentModule{}
Paul Duffin3451e162021-01-20 15:16:56 +0000144 m.AddProperties(&m.properties)
Paul Duffina1d60252021-01-21 18:13:43 +0000145 android.InitApexModule(m)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000146 android.InitSdkAwareModule(m)
satayev3db35472021-05-06 23:59:58 +0100147 initClasspathFragment(m, BOOTCLASSPATH)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000148 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000149
Paul Duffinc7ef9892021-03-23 23:21:59 +0000150 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffinc7d16442021-04-23 13:55:49 +0100151 // If code coverage has been enabled for the framework then append the properties with
152 // coverage specific properties.
153 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
154 err := proptools.AppendProperties(&m.properties.BootclasspathFragmentCoverageAffectedProperties, &m.properties.Coverage, nil)
155 if err != nil {
156 ctx.PropertyErrorf("coverage", "error trying to append coverage specific properties: %s", err)
157 return
158 }
159 }
160
161 // Initialize the contents property from the image_name.
Paul Duffin7771eba2021-04-23 14:25:28 +0100162 bootclasspathFragmentInitContentsFromImage(ctx, m)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000163 })
Paul Duffin3451e162021-01-20 15:16:56 +0000164 return m
165}
166
Paul Duffin7771eba2021-04-23 14:25:28 +0100167// bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if
168// necessary.
169func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
Paul Duffin82886d62021-03-24 01:34:57 +0000170 contents := m.properties.Contents
171 if m.properties.Image_name == nil && len(contents) == 0 {
172 ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
173 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000174
Paul Duffinc7ef9892021-03-23 23:21:59 +0000175 imageName := proptools.String(m.properties.Image_name)
176 if imageName == "art" {
Paul Duffin023dba02021-04-22 01:45:29 +0100177 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
Paul Duffin0c2e0832021-04-28 00:39:52 +0100178 if android.IsModuleInVersionedSdk(m) {
Paul Duffin023dba02021-04-22 01:45:29 +0100179 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
180 // 1. There is no way to use this at the moment so ignoring it is safe.
181 // 2. Attempting to initialize the contents property from the configuration will end up having
182 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
183 // as the unversioned prebuilt could end up with an APEX variant created for the source
184 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
185 // turn will prevent it from accessing the dex implementation jar from that which will
186 // break hidden API processing, amongst others.
187 return
188 }
189
Paul Duffinc7ef9892021-03-23 23:21:59 +0000190 // Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
191 // too early in the Soong processing for that to work.
192 global := dexpreopt.GetGlobalConfig(ctx)
193 modules := global.ArtApexJars
194
195 // Make sure that the apex specified in the configuration is consistent and is one for which
196 // this boot image is available.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000197 commonApex := ""
198 for i := 0; i < modules.Len(); i++ {
199 apex := modules.Apex(i)
200 jar := modules.Jar(i)
201 if apex == "platform" {
202 ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar)
203 continue
204 }
205 if !m.AvailableFor(apex) {
Paul Duffinf23bc472021-04-27 12:42:20 +0100206 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 +0000207 apex, m.ApexAvailable())
208 continue
209 }
210 if commonApex == "" {
211 commonApex = apex
212 } else if commonApex != apex {
213 ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q",
214 commonApex, apex)
215 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000216 }
217
Paul Duffinf23bc472021-04-27 12:42:20 +0100218 if len(contents) != 0 {
219 // Nothing to do.
220 return
221 }
222
Paul Duffinc7ef9892021-03-23 23:21:59 +0000223 // Store the jars in the Contents property so that they can be used to add dependencies.
Paul Duffinba6afd02019-11-19 19:44:10 +0000224 m.properties.Contents = modules.CopyOfJars()
225 }
226}
227
228// bootclasspathImageNameContentsConsistencyCheck checks that the configuration that applies to this
229// module (if any) matches the contents.
230//
231// This should be a noop as if image_name="art" then the contents will be set from the ArtApexJars
232// config by bootclasspathFragmentInitContentsFromImage so it will be guaranteed to match. However,
233// in future this will not be the case.
234func (b *BootclasspathFragmentModule) bootclasspathImageNameContentsConsistencyCheck(ctx android.BaseModuleContext) {
235 imageName := proptools.String(b.properties.Image_name)
236 if imageName == "art" {
237 // TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
Paul Duffin0c2e0832021-04-28 00:39:52 +0100238 if android.IsModuleInVersionedSdk(b) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000239 // The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
240 // 1. There is no way to use this at the moment so ignoring it is safe.
241 // 2. Attempting to initialize the contents property from the configuration will end up having
242 // the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
243 // as the unversioned prebuilt could end up with an APEX variant created for the source
244 // APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
245 // turn will prevent it from accessing the dex implementation jar from that which will
246 // break hidden API processing, amongst others.
247 return
248 }
249
250 // Get the configuration for the art apex jars.
251 modules := b.getImageConfig(ctx).modules
252 configuredJars := modules.CopyOfJars()
253
254 // Skip the check if the configured jars list is empty as that is a common configuration when
255 // building targets that do not result in a system image.
256 if len(configuredJars) == 0 {
257 return
258 }
259
260 contents := b.properties.Contents
261 if !reflect.DeepEqual(configuredJars, contents) {
262 ctx.ModuleErrorf("inconsistency in specification of contents. ArtApexJars configuration specifies %#v, contents property specifies %#v",
263 configuredJars, contents)
264 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000265 }
266}
267
Paul Duffine946b322021-04-25 23:04:00 +0100268var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{})
Paul Duffin3451e162021-01-20 15:16:56 +0000269
Paul Duffine946b322021-04-25 23:04:00 +0100270// BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the
271// apex contents.
272type BootclasspathFragmentApexContentInfo struct {
Paul Duffin58e0e762021-05-21 19:27:58 +0100273 // The configured modules, will be empty if this is from a bootclasspath_fragment that does not
274 // set image_name: "art".
275 modules android.ConfiguredJarList
276
277 // Map from arch type to the boot image files.
278 bootImageFilesByArch map[android.ArchType]android.OutputPaths
Paul Duffin1a8010a2021-05-15 12:39:23 +0100279
280 // Map from the name of the context module (as returned by Name()) to the hidden API encoded dex
281 // jar path.
282 contentModuleDexJarPaths map[string]android.Path
Paul Duffin3451e162021-01-20 15:16:56 +0000283}
284
Paul Duffine946b322021-04-25 23:04:00 +0100285func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList {
Paul Duffin58e0e762021-05-21 19:27:58 +0100286 return i.modules
Paul Duffin3451e162021-01-20 15:16:56 +0000287}
288
Paul Duffina1d60252021-01-21 18:13:43 +0000289// Get a map from ArchType to the associated boot image's contents for Android.
290//
291// Extension boot images only return their own files, not the files of the boot images they extend.
Paul Duffine946b322021-04-25 23:04:00 +0100292func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths {
Paul Duffin58e0e762021-05-21 19:27:58 +0100293 return i.bootImageFilesByArch
Paul Duffina1d60252021-01-21 18:13:43 +0000294}
295
Paul Duffin190fdef2021-04-26 10:33:59 +0100296// DexBootJarPathForContentModule returns the path to the dex boot jar for specified module.
297//
298// The dex boot jar is one which has had hidden API encoding performed on it.
Paul Duffin1a8010a2021-05-15 12:39:23 +0100299func (i BootclasspathFragmentApexContentInfo) DexBootJarPathForContentModule(module android.Module) (android.Path, error) {
300 name := module.Name()
301 if dexJar, ok := i.contentModuleDexJarPaths[name]; ok {
302 return dexJar, nil
303 } else {
304 return nil, fmt.Errorf("unknown bootclasspath_fragment content module %s, expected one of %s",
305 name, strings.Join(android.SortedStringKeys(i.contentModuleDexJarPaths), ", "))
306 }
Paul Duffin190fdef2021-04-26 10:33:59 +0100307}
308
Paul Duffin7771eba2021-04-23 14:25:28 +0100309func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffina1d60252021-01-21 18:13:43 +0000310 tag := ctx.OtherModuleDependencyTag(dep)
Paul Duffin65898052021-04-20 22:47:03 +0100311 if IsBootclasspathFragmentContentDepTag(tag) {
Paul Duffin4d101b62021-03-24 15:42:20 +0000312 // Boot image contents are automatically added to apex.
313 return true
Paul Duffinc7ef9892021-03-23 23:21:59 +0000314 }
Bob Badour07065cd2021-02-05 19:59:11 -0800315 if android.IsMetaDependencyTag(tag) {
316 // Cross-cutting metadata dependencies are metadata.
317 return false
318 }
Paul Duffina1d60252021-01-21 18:13:43 +0000319 panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag)))
320}
321
Paul Duffin7771eba2021-04-23 14:25:28 +0100322func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Paul Duffina1d60252021-01-21 18:13:43 +0000323 return nil
324}
325
Paul Duffin65898052021-04-20 22:47:03 +0100326// ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a
327// corresponding source module are renamed. This means that adding a dependency using a name without
328// a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix
329// it will always resolve to a prebuilt module.
Paul Duffin7771eba2021-04-23 14:25:28 +0100330func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin65898052021-04-20 22:47:03 +0100331 module := ctx.Module()
Paul Duffin7771eba2021-04-23 14:25:28 +0100332 _, isSourceModule := module.(*BootclasspathFragmentModule)
Paul Duffin65898052021-04-20 22:47:03 +0100333
334 for _, name := range b.properties.Contents {
335 // A bootclasspath_fragment must depend only on other source modules, while the
336 // prebuilt_bootclasspath_fragment must only depend on other prebuilt modules.
Paul Duffina9dd6fa2021-04-22 17:25:57 +0100337 //
338 // TODO(b/177892522) - avoid special handling of jacocoagent.
339 if !isSourceModule && name != "jacocoagent" {
Paul Duffin65898052021-04-20 22:47:03 +0100340 name = android.PrebuiltNameFromSource(name)
341 }
342 ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name)
343 }
344
345}
346
Paul Duffin7771eba2021-04-23 14:25:28 +0100347func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
Paul Duffin10931582021-04-25 10:13:54 +0100348 // Add dependencies onto all the modules that provide the API stubs for classes on this
349 // bootclasspath fragment.
350 hiddenAPIAddStubLibDependencies(ctx, b.properties.sdkKindToStubLibs())
Paul Duffinc7ef9892021-03-23 23:21:59 +0000351
Paul Duffina1d60252021-01-21 18:13:43 +0000352 if SkipDexpreoptBootJars(ctx) {
353 return
354 }
355
356 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
357 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
358 dexpreopt.RegisterToolDeps(ctx)
359}
360
Paul Duffinf1b358c2021-05-17 07:38:47 +0100361func (b *BootclasspathFragmentModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) {
362 // Add dependencies on all the fragments.
363 b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
364}
365
Paul Duffin7771eba2021-04-23 14:25:28 +0100366func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000367 // Only perform a consistency check if this module is the active module. That will prevent an
368 // unused prebuilt that was created without instrumentation from breaking an instrumentation
369 // build.
370 if isActiveModule(ctx.Module()) {
371 b.bootclasspathImageNameContentsConsistencyCheck(ctx)
372 }
373
satayev3db35472021-05-06 23:59:58 +0100374 // Generate classpaths.proto config
375 b.generateClasspathProtoBuildActions(ctx)
376
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100377 // Gather the bootclasspath fragment's contents.
378 var contents []android.Module
379 ctx.VisitDirectDeps(func(module android.Module) {
380 tag := ctx.OtherModuleDependencyTag(module)
381 if IsBootclasspathFragmentContentDepTag(tag) {
Paul Duffin79fd3d72021-05-14 16:14:17 +0100382 contents = append(contents, module)
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100383 }
384 })
385
Paul Duffinf1b358c2021-05-17 07:38:47 +0100386 fragments := gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
387
Paul Duffin9b381ef2021-04-08 23:01:37 +0100388 // Perform hidden API processing.
Paul Duffinf1b358c2021-05-17 07:38:47 +0100389 hiddenAPIFlagOutput := b.generateHiddenAPIBuildActions(ctx, contents, fragments)
Paul Duffin9b381ef2021-04-08 23:01:37 +0100390
Paul Duffin1a8010a2021-05-15 12:39:23 +0100391 // Verify that the image_name specified on a bootclasspath_fragment is valid even if this is a
392 // prebuilt which will not use the image config.
393 imageConfig := b.getImageConfig(ctx)
394
395 // A prebuilt fragment cannot contribute to the apex.
396 if !android.IsModulePrebuilt(ctx.Module()) {
397 // Provide the apex content info.
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100398 b.provideApexContentInfo(ctx, imageConfig, contents, hiddenAPIFlagOutput)
Paul Duffin1a8010a2021-05-15 12:39:23 +0100399 }
400}
401
402// provideApexContentInfo creates, initializes and stores the apex content info for use by other
403// modules.
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100404func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleContext, imageConfig *bootImageConfig, contents []android.Module, hiddenAPIFlagOutput *HiddenAPIFlagOutput) {
Paul Duffin1a8010a2021-05-15 12:39:23 +0100405 // Construct the apex content info from the config.
Paul Duffin58e0e762021-05-21 19:27:58 +0100406 info := BootclasspathFragmentApexContentInfo{}
Paul Duffin1a8010a2021-05-15 12:39:23 +0100407
408 // Populate the apex content info with paths to the dex jars.
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100409 b.populateApexContentInfoDexJars(ctx, &info, contents, hiddenAPIFlagOutput)
Paul Duffin1a8010a2021-05-15 12:39:23 +0100410
Paul Duffin58e0e762021-05-21 19:27:58 +0100411 if imageConfig != nil {
412 info.modules = imageConfig.modules
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100413
Paul Duffin58e0e762021-05-21 19:27:58 +0100414 if !SkipDexpreoptBootJars(ctx) {
415 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
416 // GenerateSingletonBuildActions method as it cannot create it for itself.
417 dexpreopt.GetGlobalSoongConfig(ctx)
418
419 // Only generate the boot image if the configuration does not skip it.
420 if b.generateBootImageBuildActions(ctx, contents, imageConfig) {
421 // Allow the apex to access the boot image files.
422 files := map[android.ArchType]android.OutputPaths{}
423 for _, variant := range imageConfig.variants {
424 // We also generate boot images for host (for testing), but we don't need those in the apex.
425 // TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
426 if variant.target.Os == android.Android {
427 files[variant.target.Arch.ArchType] = variant.imagesDeps
428 }
429 }
430 info.bootImageFilesByArch = files
431 }
432 }
Paul Duffin1a8010a2021-05-15 12:39:23 +0100433 }
Paul Duffin3451e162021-01-20 15:16:56 +0000434
Paul Duffin1a8010a2021-05-15 12:39:23 +0100435 // Make the apex content info available for other modules.
436 ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
437}
438
439// populateApexContentInfoDexJars adds paths to the dex jars provided by this fragment to the
440// apex content info.
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100441func (b *BootclasspathFragmentModule) populateApexContentInfoDexJars(ctx android.ModuleContext, info *BootclasspathFragmentApexContentInfo, contents []android.Module, hiddenAPIFlagOutput *HiddenAPIFlagOutput) {
Paul Duffin54c98f52021-05-15 08:54:30 +0100442
Paul Duffin1a8010a2021-05-15 12:39:23 +0100443 info.contentModuleDexJarPaths = map[string]android.Path{}
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100444 if hiddenAPIFlagOutput != nil {
Paul Duffin54c98f52021-05-15 08:54:30 +0100445 // Hidden API encoding has been performed.
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100446 flags := hiddenAPIFlagOutput.AllFlagsPath
Paul Duffin54c98f52021-05-15 08:54:30 +0100447 for _, m := range contents {
448 h := m.(hiddenAPIModule)
449 unencodedDex := h.bootDexJar()
450 if unencodedDex == nil {
451 // This is an error. Sometimes Soong will report the error directly, other times it will
452 // defer the error reporting to happen only when trying to use the missing file in ninja.
453 // Either way it is handled by extractBootDexJarsFromHiddenAPIModules which must have been
454 // called before this as it generates the flags that are used to encode these files.
455 continue
456 }
457
458 outputDir := android.PathForModuleOut(ctx, "hiddenapi-modular/encoded").OutputPath
459 encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, flags, *h.uncompressDex(), outputDir)
460 info.contentModuleDexJarPaths[m.Name()] = encodedDex
461 }
462 } else {
463 for _, m := range contents {
464 j := m.(UsesLibraryDependency)
465 dexJar := j.DexJarBuildPath()
466 info.contentModuleDexJarPaths[m.Name()] = dexJar
467 }
satayev14e49132021-05-17 21:03:07 +0100468 }
Paul Duffin3451e162021-01-20 15:16:56 +0000469}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000470
satayev3db35472021-05-06 23:59:58 +0100471// generateClasspathProtoBuildActions generates all required build actions for classpath.proto config
472func (b *BootclasspathFragmentModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) {
473 var classpathJars []classpathJar
474 if "art" == proptools.String(b.properties.Image_name) {
475 // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
476 classpathJars = configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), BOOTCLASSPATH, DEX2OATBOOTCLASSPATH)
477 } else {
478 classpathJars = configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), b.classpathType)
479 }
480 b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars)
481}
482
483func (b *BootclasspathFragmentModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
satayev8fab6f82021-05-07 00:10:33 +0100484 if "art" == proptools.String(b.properties.Image_name) {
485 return b.getImageConfig(ctx).modules
486 }
487
488 global := dexpreopt.GetGlobalConfig(ctx)
489
490 // Only create configs for updatable boot jars. Non-updatable boot jars must be part of the
491 // platform_bootclasspath's classpath proto config to guarantee that they come before any
492 // updatable jars at runtime.
493 return global.UpdatableBootJars.Filter(b.properties.Contents)
satayev3db35472021-05-06 23:59:58 +0100494}
495
Paul Duffin7771eba2021-04-23 14:25:28 +0100496func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000497 // Get a map of the image configs that are supported.
498 imageConfigs := genBootImageConfigs(ctx)
499
500 // Retrieve the config for this image.
501 imageNamePtr := b.properties.Image_name
502 if imageNamePtr == nil {
503 return nil
504 }
505
506 imageName := *imageNamePtr
507 imageConfig := imageConfigs[imageName]
508 if imageConfig == nil {
509 ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", "))
510 return nil
511 }
512 return imageConfig
513}
514
Paul Duffin9b381ef2021-04-08 23:01:37 +0100515// generateHiddenAPIBuildActions generates all the hidden API related build rules.
Paul Duffinf1b358c2021-05-17 07:38:47 +0100516func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, contents []android.Module, fragments []android.Module) *HiddenAPIFlagOutput {
Paul Duffin10931582021-04-25 10:13:54 +0100517
Paul Duffin1352f7c2021-05-21 22:18:49 +0100518 // Create hidden API input structure.
Paul Duffinf1b358c2021-05-17 07:38:47 +0100519 input := b.createHiddenAPIFlagInput(ctx, contents, fragments)
Paul Duffin10931582021-04-25 10:13:54 +0100520
Paul Duffin62370922021-05-23 16:55:37 +0100521 var output *HiddenAPIFlagOutput
Paul Duffin537ea3d2021-05-14 10:38:00 +0100522
Paul Duffin62370922021-05-23 16:55:37 +0100523 // Hidden API processing is conditional as a temporary workaround as not all
524 // bootclasspath_fragments provide the appropriate information needed for hidden API processing
525 // which leads to breakages of the build.
526 // TODO(b/179354495): Stop hidden API processing being conditional once all bootclasspath_fragment
527 // modules have been updated to support it.
528 if input.canPerformHiddenAPIProcessing(ctx, b.properties) {
529 // Get the content modules that contribute to the hidden API processing.
530 hiddenAPIModules := gatherHiddenAPIModuleFromContents(ctx, contents)
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100531
Paul Duffin62370922021-05-23 16:55:37 +0100532 // Delegate the production of the hidden API all-flags.csv file to a module type specific method.
533 common := ctx.Module().(commonBootclasspathFragment)
534 output = common.produceHiddenAPIAllFlagsFile(ctx, hiddenAPIModules, input)
535 }
536
537 // Initialize a HiddenAPIInfo structure.
Paul Duffinaf99afa2021-05-21 22:18:56 +0100538 hiddenAPIInfo := HiddenAPIInfo{
Paul Duffin62370922021-05-23 16:55:37 +0100539 // The monolithic hidden API processing needs access to the flag files that override the default
540 // flags from all the fragments whether or not they actually perform their own hidden API flag
541 // generation. That is because the monolithic hidden API processing uses those flag files to
542 // perform its own flag generation.
Paul Duffin1352f7c2021-05-21 22:18:49 +0100543 FlagFilesByCategory: input.FlagFilesByCategory,
Paul Duffin18cf1972021-05-21 22:46:59 +0100544
Paul Duffinf1b358c2021-05-17 07:38:47 +0100545 // Other bootclasspath_fragments that depend on this need the transitive set of stub dex jars
546 // from this to resolve any references from their code to classes provided by this fragment
547 // and the fragments this depends upon.
548 TransitiveStubDexJarsByKind: input.transitiveStubDexJarsByKind(),
Paul Duffin62370922021-05-23 16:55:37 +0100549 }
Paul Duffin2fef1362021-04-15 13:32:00 +0100550
Paul Duffin62370922021-05-23 16:55:37 +0100551 if output != nil {
Paul Duffin1352f7c2021-05-21 22:18:49 +0100552 // The monolithic hidden API processing also needs access to all the output files produced by
553 // hidden API processing of this fragment.
Paul Duffin62370922021-05-23 16:55:37 +0100554 hiddenAPIInfo.HiddenAPIFlagOutput = *output
Paul Duffin1352f7c2021-05-21 22:18:49 +0100555 }
Paul Duffin62370922021-05-23 16:55:37 +0100556
557 // Provide it for use by other modules.
Paul Duffinaf99afa2021-05-21 22:18:56 +0100558 ctx.SetProvider(HiddenAPIInfoProvider, hiddenAPIInfo)
Paul Duffin54c98f52021-05-15 08:54:30 +0100559
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100560 return output
Paul Duffin2fef1362021-04-15 13:32:00 +0100561}
562
Paul Duffin1352f7c2021-05-21 22:18:49 +0100563// createHiddenAPIFlagInput creates a HiddenAPIFlagInput struct and initializes it with information derived
564// from the properties on this module and its dependencies.
Paul Duffinf1b358c2021-05-17 07:38:47 +0100565func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.ModuleContext, contents []android.Module, fragments []android.Module) HiddenAPIFlagInput {
566
567 // Merge the HiddenAPIInfo from all the fragment dependencies.
568 dependencyHiddenApiInfo := newHiddenAPIInfo()
569 dependencyHiddenApiInfo.mergeFromFragmentDeps(ctx, fragments)
570
571 // Create hidden API flag input structure.
Paul Duffin1352f7c2021-05-21 22:18:49 +0100572 input := newHiddenAPIFlagInput()
573
574 // Update the input structure with information obtained from the stub libraries.
575 input.gatherStubLibInfo(ctx, contents)
576
577 // Populate with flag file paths from the properties.
578 input.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api)
579
Paul Duffinf1b358c2021-05-17 07:38:47 +0100580 // Store the stub dex jars from this module's fragment dependencies.
581 input.DependencyStubDexJarsByKind = dependencyHiddenApiInfo.TransitiveStubDexJarsByKind
582
Paul Duffin1352f7c2021-05-21 22:18:49 +0100583 return input
584}
585
Paul Duffin2fef1362021-04-15 13:32:00 +0100586// produceHiddenAPIAllFlagsFile produces the hidden API all-flags.csv file (and supporting files)
587// for the fragment.
Paul Duffin1352f7c2021-05-21 22:18:49 +0100588func (b *BootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, input HiddenAPIFlagInput) *HiddenAPIFlagOutput {
589 // Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the
Paul Duffin2fef1362021-04-15 13:32:00 +0100590 // paths to the created files.
Paul Duffin1352f7c2021-05-21 22:18:49 +0100591 return hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx, contents, input)
Paul Duffin9b381ef2021-04-08 23:01:37 +0100592}
593
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100594// generateBootImageBuildActions generates ninja rules to create the boot image if required for this
595// module.
Paul Duffin58e0e762021-05-21 19:27:58 +0100596//
597// Returns true if the boot image is created, false otherwise.
598func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, contents []android.Module, imageConfig *bootImageConfig) bool {
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100599 global := dexpreopt.GetGlobalConfig(ctx)
600 if !shouldBuildBootImages(ctx.Config(), global) {
Paul Duffin58e0e762021-05-21 19:27:58 +0100601 return false
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100602 }
603
604 // Bootclasspath fragment modules that are for the platform do not produce a boot image.
605 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
606 if apexInfo.IsForPlatform() {
Paul Duffin58e0e762021-05-21 19:27:58 +0100607 return false
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100608 }
609
610 // Bootclasspath fragment modules that are versioned do not produce a boot image.
611 if android.IsModuleInVersionedSdk(ctx.Module()) {
Paul Duffin58e0e762021-05-21 19:27:58 +0100612 return false
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100613 }
614
615 // Copy the dex jars of this fragment's content modules to their predefined locations.
616 copyBootJarsToPredefinedLocations(ctx, contents, imageConfig.modules, imageConfig.dexPaths)
Paul Duffin2fc82ad2021-04-29 23:36:12 +0100617
618 // Build a profile for the image config and then use that to build the boot image.
619 profile := bootImageProfileRule(ctx, imageConfig)
620 buildBootImage(ctx, imageConfig, profile)
Paul Duffin58e0e762021-05-21 19:27:58 +0100621
622 return true
Paul Duffin7ebebfd2021-04-27 19:36:57 +0100623}
624
Paul Duffin7771eba2021-04-23 14:25:28 +0100625type bootclasspathFragmentMemberType struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000626 android.SdkMemberTypeBase
627}
628
Paul Duffin7771eba2021-04-23 14:25:28 +0100629func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000630 mctx.AddVariationDependencies(nil, dependencyTag, names...)
631}
632
Paul Duffin7771eba2021-04-23 14:25:28 +0100633func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {
634 _, ok := module.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000635 return ok
636}
637
Paul Duffin7771eba2021-04-23 14:25:28 +0100638func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
Paul Duffin4b64ba02021-03-29 11:02:53 +0100639 if b.PropertyName == "boot_images" {
640 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
641 } else {
642 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment")
643 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000644}
645
Paul Duffin7771eba2021-04-23 14:25:28 +0100646func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
647 return &bootclasspathFragmentSdkMemberProperties{}
Paul Duffinf7f65da2021-03-10 15:00:46 +0000648}
649
Paul Duffin7771eba2021-04-23 14:25:28 +0100650type bootclasspathFragmentSdkMemberProperties struct {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000651 android.SdkMemberPropertiesBase
652
Paul Duffina57835e2021-04-19 13:23:06 +0100653 // The image name
Paul Duffin64be7bb2021-03-23 23:06:38 +0000654 Image_name *string
Paul Duffina57835e2021-04-19 13:23:06 +0100655
656 // Contents of the bootclasspath fragment
657 Contents []string
Paul Duffin7c955552021-04-19 13:23:53 +0100658
Paul Duffin895c7142021-04-25 13:40:15 +0100659 // Stub_libs properties.
660 Stub_libs []string
661 Core_platform_stub_libs []string
662
Paul Duffin7c955552021-04-19 13:23:53 +0100663 // Flag files by *hiddenAPIFlagFileCategory
Paul Duffin438eb572021-05-21 16:58:23 +0100664 Flag_files_by_category FlagFilesByCategory
Paul Duffin2fef1362021-04-15 13:32:00 +0100665
666 // The path to the generated stub-flags.csv file.
667 Stub_flags_path android.OptionalPath
668
669 // The path to the generated annotation-flags.csv file.
670 Annotation_flags_path android.OptionalPath
671
672 // The path to the generated metadata.csv file.
673 Metadata_path android.OptionalPath
674
675 // The path to the generated index.csv file.
676 Index_path android.OptionalPath
677
678 // The path to the generated all-flags.csv file.
679 All_flags_path android.OptionalPath
680}
681
Paul Duffin7771eba2021-04-23 14:25:28 +0100682func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
683 module := variant.(*BootclasspathFragmentModule)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000684
685 b.Image_name = module.properties.Image_name
Paul Duffin2dc665b2021-04-23 16:58:51 +0100686 b.Contents = module.properties.Contents
Paul Duffin7c955552021-04-19 13:23:53 +0100687
Paul Duffinaf99afa2021-05-21 22:18:56 +0100688 // Get the hidden API information from the module.
Paul Duffin7c955552021-04-19 13:23:53 +0100689 mctx := ctx.SdkModuleContext()
Paul Duffinaf99afa2021-05-21 22:18:56 +0100690 hiddenAPIInfo := mctx.OtherModuleProvider(module, HiddenAPIInfoProvider).(HiddenAPIInfo)
691 b.Flag_files_by_category = hiddenAPIInfo.FlagFilesByCategory
Paul Duffin895c7142021-04-25 13:40:15 +0100692
Paul Duffin2fef1362021-04-15 13:32:00 +0100693 // Copy all the generated file paths.
Paul Duffinaf99afa2021-05-21 22:18:56 +0100694 b.Stub_flags_path = android.OptionalPathForPath(hiddenAPIInfo.StubFlagsPath)
695 b.Annotation_flags_path = android.OptionalPathForPath(hiddenAPIInfo.AnnotationFlagsPath)
696 b.Metadata_path = android.OptionalPathForPath(hiddenAPIInfo.MetadataPath)
697 b.Index_path = android.OptionalPathForPath(hiddenAPIInfo.IndexPath)
698 b.All_flags_path = android.OptionalPathForPath(hiddenAPIInfo.AllFlagsPath)
Paul Duffin2fef1362021-04-15 13:32:00 +0100699
Paul Duffin895c7142021-04-25 13:40:15 +0100700 // Copy stub_libs properties.
701 b.Stub_libs = module.properties.Api.Stub_libs
702 b.Core_platform_stub_libs = module.properties.Core_platform_api.Stub_libs
Paul Duffinf7f65da2021-03-10 15:00:46 +0000703}
704
Paul Duffin7771eba2021-04-23 14:25:28 +0100705func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffin64be7bb2021-03-23 23:06:38 +0000706 if b.Image_name != nil {
707 propertySet.AddProperty("image_name", *b.Image_name)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000708 }
Paul Duffina57835e2021-04-19 13:23:06 +0100709
Paul Duffin895c7142021-04-25 13:40:15 +0100710 builder := ctx.SnapshotBuilder()
711 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
712
Paul Duffina57835e2021-04-19 13:23:06 +0100713 if len(b.Contents) > 0 {
Paul Duffin895c7142021-04-25 13:40:15 +0100714 propertySet.AddPropertyWithTag("contents", b.Contents, requiredMemberDependency)
Paul Duffina57835e2021-04-19 13:23:06 +0100715 }
Paul Duffin7c955552021-04-19 13:23:53 +0100716
Paul Duffin895c7142021-04-25 13:40:15 +0100717 if len(b.Stub_libs) > 0 {
718 apiPropertySet := propertySet.AddPropertySet("api")
719 apiPropertySet.AddPropertyWithTag("stub_libs", b.Stub_libs, requiredMemberDependency)
720 }
721 if len(b.Core_platform_stub_libs) > 0 {
722 corePlatformApiPropertySet := propertySet.AddPropertySet("core_platform_api")
723 corePlatformApiPropertySet.AddPropertyWithTag("stub_libs", b.Core_platform_stub_libs, requiredMemberDependency)
724 }
725
Paul Duffin2fef1362021-04-15 13:32:00 +0100726 hiddenAPISet := propertySet.AddPropertySet("hidden_api")
727 hiddenAPIDir := "hiddenapi"
728
729 // Copy manually curated flag files specified on the bootclasspath_fragment.
Paul Duffin7c955552021-04-19 13:23:53 +0100730 if b.Flag_files_by_category != nil {
Paul Duffin7c955552021-04-19 13:23:53 +0100731 for _, category := range hiddenAPIFlagFileCategories {
732 paths := b.Flag_files_by_category[category]
733 if len(paths) > 0 {
734 dests := []string{}
735 for _, p := range paths {
Paul Duffin2fef1362021-04-15 13:32:00 +0100736 dest := filepath.Join(hiddenAPIDir, p.Base())
Paul Duffin7c955552021-04-19 13:23:53 +0100737 builder.CopyToSnapshot(p, dest)
738 dests = append(dests, dest)
739 }
740 hiddenAPISet.AddProperty(category.propertyName, dests)
741 }
742 }
743 }
Paul Duffin2fef1362021-04-15 13:32:00 +0100744
745 copyOptionalPath := func(path android.OptionalPath, property string) {
746 if path.Valid() {
747 p := path.Path()
748 dest := filepath.Join(hiddenAPIDir, p.Base())
749 builder.CopyToSnapshot(p, dest)
750 hiddenAPISet.AddProperty(property, dest)
751 }
752 }
753
754 // Copy all the generated files, if available.
755 copyOptionalPath(b.Stub_flags_path, "stub_flags")
756 copyOptionalPath(b.Annotation_flags_path, "annotation_flags")
757 copyOptionalPath(b.Metadata_path, "metadata")
758 copyOptionalPath(b.Index_path, "index")
759 copyOptionalPath(b.All_flags_path, "all_flags")
Paul Duffinf7f65da2021-03-10 15:00:46 +0000760}
761
Paul Duffin7771eba2021-04-23 14:25:28 +0100762var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000763
Paul Duffin2fef1362021-04-15 13:32:00 +0100764// prebuiltBootclasspathFragmentProperties contains additional prebuilt_bootclasspath_fragment
765// specific properties.
766type prebuiltBootclasspathFragmentProperties struct {
767 Hidden_api struct {
768 // The path to the stub-flags.csv file created by the bootclasspath_fragment.
769 Stub_flags *string `android:"path"`
770
771 // The path to the annotation-flags.csv file created by the bootclasspath_fragment.
772 Annotation_flags *string `android:"path"`
773
774 // The path to the metadata.csv file created by the bootclasspath_fragment.
775 Metadata *string `android:"path"`
776
777 // The path to the index.csv file created by the bootclasspath_fragment.
778 Index *string `android:"path"`
779
780 // The path to the all-flags.csv file created by the bootclasspath_fragment.
781 All_flags *string `android:"path"`
782 }
783}
784
Paul Duffin7771eba2021-04-23 14:25:28 +0100785// A prebuilt version of the bootclasspath_fragment module.
Paul Duffinf7f65da2021-03-10 15:00:46 +0000786//
Paul Duffin7771eba2021-04-23 14:25:28 +0100787// At the moment this is basically just a bootclasspath_fragment module that can be used as a
788// prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module
789// type from the various singletons then this will diverge.
790type prebuiltBootclasspathFragmentModule struct {
791 BootclasspathFragmentModule
Paul Duffinf7f65da2021-03-10 15:00:46 +0000792 prebuilt android.Prebuilt
Paul Duffin2fef1362021-04-15 13:32:00 +0100793
794 // Additional prebuilt specific properties.
795 prebuiltProperties prebuiltBootclasspathFragmentProperties
Paul Duffinf7f65da2021-03-10 15:00:46 +0000796}
797
Paul Duffin7771eba2021-04-23 14:25:28 +0100798func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000799 return &module.prebuilt
800}
801
Paul Duffin7771eba2021-04-23 14:25:28 +0100802func (module *prebuiltBootclasspathFragmentModule) Name() string {
Paul Duffinf7f65da2021-03-10 15:00:46 +0000803 return module.prebuilt.Name(module.ModuleBase.Name())
804}
805
Paul Duffin2fef1362021-04-15 13:32:00 +0100806// produceHiddenAPIAllFlagsFile returns a path to the prebuilt all-flags.csv or nil if none is
807// specified.
Paul Duffin1352f7c2021-05-21 22:18:49 +0100808func (module *prebuiltBootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, _ HiddenAPIFlagInput) *HiddenAPIFlagOutput {
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100809 pathForOptionalSrc := func(src *string) android.Path {
Paul Duffin2fef1362021-04-15 13:32:00 +0100810 if src == nil {
811 // TODO(b/179354495): Fail if this is not provided once prebuilts have been updated.
812 return nil
813 }
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100814 return android.PathForModuleSrc(ctx, *src)
Paul Duffin2fef1362021-04-15 13:32:00 +0100815 }
816
Paul Duffin1e6f5c42021-05-21 16:15:31 +0100817 output := HiddenAPIFlagOutput{
818 StubFlagsPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Stub_flags),
819 AnnotationFlagsPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Annotation_flags),
820 MetadataPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Metadata),
821 IndexPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Index),
822 AllFlagsPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.All_flags),
823 }
824
825 return &output
Paul Duffin2fef1362021-04-15 13:32:00 +0100826}
827
828var _ commonBootclasspathFragment = (*prebuiltBootclasspathFragmentModule)(nil)
829
Paul Duffin7771eba2021-04-23 14:25:28 +0100830func prebuiltBootclasspathFragmentFactory() android.Module {
831 m := &prebuiltBootclasspathFragmentModule{}
Paul Duffin2fef1362021-04-15 13:32:00 +0100832 m.AddProperties(&m.properties, &m.prebuiltProperties)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000833 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
834 // array.
835 android.InitPrebuiltModule(m, &[]string{"placeholder"})
836 android.InitApexModule(m)
837 android.InitSdkAwareModule(m)
Martin Stjernholmb79c7f12021-03-17 00:26:25 +0000838 android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000839
Paul Duffin7771eba2021-04-23 14:25:28 +0100840 // Initialize the contents property from the image_name.
Paul Duffinc7ef9892021-03-23 23:21:59 +0000841 android.AddLoadHook(m, func(ctx android.LoadHookContext) {
Paul Duffin7771eba2021-04-23 14:25:28 +0100842 bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule)
Paul Duffinc7ef9892021-03-23 23:21:59 +0000843 })
Paul Duffinf7f65da2021-03-10 15:00:46 +0000844 return m
845}