2021-01-20 16:16:56 +01:00
|
|
|
// Copyright (C) 2021 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2021-01-21 19:13:43 +01:00
|
|
|
"fmt"
|
2021-04-19 14:23:53 +02:00
|
|
|
"path/filepath"
|
2019-11-19 20:44:10 +01:00
|
|
|
"reflect"
|
2021-01-20 16:16:56 +01:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2021-01-21 19:13:43 +01:00
|
|
|
"android/soong/dexpreopt"
|
2021-03-24 00:21:59 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
2021-03-17 01:26:25 +01:00
|
|
|
|
2021-01-20 16:16:56 +01:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-04-23 15:25:28 +02:00
|
|
|
registerBootclasspathFragmentBuildComponents(android.InitRegistrationContext)
|
2021-03-10 16:00:46 +01:00
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
android.RegisterSdkMemberType(&bootclasspathFragmentMemberType{
|
2021-03-29 12:02:53 +02:00
|
|
|
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
2021-05-06 13:02:27 +02:00
|
|
|
PropertyName: "bootclasspath_fragments",
|
|
|
|
SupportsSdk: true,
|
2021-03-29 12:02:53 +02:00
|
|
|
},
|
|
|
|
})
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func registerBootclasspathFragmentBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("bootclasspath_fragment", bootclasspathFragmentFactory)
|
|
|
|
ctx.RegisterModuleType("prebuilt_bootclasspath_fragment", prebuiltBootclasspathFragmentFactory)
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
2021-04-20 23:47:03 +02:00
|
|
|
type bootclasspathFragmentContentDependencyTag struct {
|
2021-03-24 00:21:59 +01:00
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// Avoid having to make bootclasspath_fragment content visible to the bootclasspath_fragment.
|
2021-03-24 00:21:59 +01:00
|
|
|
//
|
2021-04-23 15:25:28 +02:00
|
|
|
// This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules
|
|
|
|
// with proper dependencies.
|
2021-03-24 00:21:59 +01:00
|
|
|
// TODO(b/177892522): Remove this and add needed visibility.
|
2021-04-20 23:47:03 +02:00
|
|
|
func (b bootclasspathFragmentContentDependencyTag) ExcludeFromVisibilityEnforcement() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// The bootclasspath_fragment contents must never depend on prebuilts.
|
|
|
|
func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
|
|
|
|
return false
|
2021-03-24 00:21:59 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 21:41:23 +02:00
|
|
|
// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
|
2021-05-12 14:46:54 +02:00
|
|
|
// they were specified using java_boot_libs or java_sdk_libs.
|
|
|
|
func (b bootclasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
|
|
|
|
// If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
|
|
|
|
// property, otherwise treat if it was specified in the java_boot_libs property.
|
|
|
|
if javaSdkLibrarySdkMemberType.IsInstance(child) {
|
|
|
|
return javaSdkLibrarySdkMemberType
|
|
|
|
}
|
|
|
|
|
2021-04-23 21:41:23 +02:00
|
|
|
return javaBootLibsSdkMemberType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b bootclasspathFragmentContentDependencyTag) ExportMember() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// The tag used for the dependency between the bootclasspath_fragment module and its contents.
|
2021-04-20 23:47:03 +02:00
|
|
|
var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{}
|
2021-03-24 00:21:59 +01:00
|
|
|
|
2021-04-20 23:47:03 +02:00
|
|
|
var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag
|
|
|
|
var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag
|
2021-04-23 21:41:23 +02:00
|
|
|
var _ android.SdkMemberTypeDependencyTag = bootclasspathFragmentContentDepTag
|
2021-03-24 00:21:59 +01:00
|
|
|
|
2021-04-20 23:47:03 +02:00
|
|
|
func IsBootclasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
|
|
|
|
return tag == bootclasspathFragmentContentDepTag
|
2021-03-24 16:42:20 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 14:55:49 +02:00
|
|
|
// Properties that can be different when coverage is enabled.
|
|
|
|
type BootclasspathFragmentCoverageAffectedProperties struct {
|
|
|
|
// The contents of this bootclasspath_fragment, could be either java_library, or java_sdk_library.
|
|
|
|
//
|
2021-05-13 22:25:05 +02:00
|
|
|
// A java_sdk_library specified here will also be treated as if it was specified on the stub_libs
|
|
|
|
// property.
|
|
|
|
//
|
2021-04-23 14:55:49 +02:00
|
|
|
// The order of this list matters as it is the order that is used in the bootclasspath.
|
|
|
|
Contents []string
|
2021-04-25 11:13:54 +02:00
|
|
|
|
|
|
|
// The properties for specifying the API stubs provided by this fragment.
|
|
|
|
BootclasspathAPIProperties
|
2021-04-23 14:55:49 +02:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
type bootclasspathFragmentProperties struct {
|
2021-01-20 16:16:56 +01:00
|
|
|
// The name of the image this represents.
|
|
|
|
//
|
2021-03-24 02:34:57 +01:00
|
|
|
// If specified then it must be one of "art" or "boot".
|
2021-03-24 00:06:38 +01:00
|
|
|
Image_name *string
|
2021-03-24 00:21:59 +01:00
|
|
|
|
2021-04-23 14:55:49 +02:00
|
|
|
// Properties whose values need to differ with and without coverage.
|
|
|
|
BootclasspathFragmentCoverageAffectedProperties
|
|
|
|
Coverage BootclasspathFragmentCoverageAffectedProperties
|
2021-04-09 00:01:37 +02:00
|
|
|
|
|
|
|
Hidden_api HiddenAPIFlagFileProperties
|
2021-05-15 10:10:42 +02:00
|
|
|
|
|
|
|
// Properties that allow a fragment to depend on other fragments. This is needed for hidden API
|
|
|
|
// processing as it needs access to all the classes used by a fragment including those provided
|
|
|
|
// by other fragments.
|
|
|
|
BootclasspathFragmentsDepsProperties
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
type BootclasspathFragmentModule struct {
|
2021-01-20 16:16:56 +01:00
|
|
|
android.ModuleBase
|
2021-01-21 19:13:43 +01:00
|
|
|
android.ApexModuleBase
|
2021-03-10 16:00:46 +01:00
|
|
|
android.SdkBase
|
2021-05-07 00:59:58 +02:00
|
|
|
ClasspathFragmentBase
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
properties bootclasspathFragmentProperties
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 14:32:00 +02:00
|
|
|
// commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt
|
|
|
|
// bootclasspath fragment modules.
|
|
|
|
type commonBootclasspathFragment interface {
|
|
|
|
// produceHiddenAPIAllFlagsFile produces the all-flags.csv and intermediate files.
|
|
|
|
//
|
2021-05-21 23:18:49 +02:00
|
|
|
// Updates the supplied hiddenAPIInfo with the paths to the generated files set.
|
|
|
|
produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, input HiddenAPIFlagInput) *HiddenAPIFlagOutput
|
2021-04-15 14:32:00 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 17:15:31 +02:00
|
|
|
var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil)
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func bootclasspathFragmentFactory() android.Module {
|
|
|
|
m := &BootclasspathFragmentModule{}
|
2021-01-20 16:16:56 +01:00
|
|
|
m.AddProperties(&m.properties)
|
2021-01-21 19:13:43 +01:00
|
|
|
android.InitApexModule(m)
|
2021-03-10 16:00:46 +01:00
|
|
|
android.InitSdkAwareModule(m)
|
2021-05-07 00:59:58 +02:00
|
|
|
initClasspathFragment(m, BOOTCLASSPATH)
|
2021-03-17 01:26:25 +01:00
|
|
|
android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
|
2021-03-24 00:21:59 +01:00
|
|
|
|
|
|
|
android.AddLoadHook(m, func(ctx android.LoadHookContext) {
|
2021-04-23 14:55:49 +02:00
|
|
|
// If code coverage has been enabled for the framework then append the properties with
|
|
|
|
// coverage specific properties.
|
|
|
|
if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
|
|
|
|
err := proptools.AppendProperties(&m.properties.BootclasspathFragmentCoverageAffectedProperties, &m.properties.Coverage, nil)
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("coverage", "error trying to append coverage specific properties: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the contents property from the image_name.
|
2021-04-23 15:25:28 +02:00
|
|
|
bootclasspathFragmentInitContentsFromImage(ctx, m)
|
2021-03-24 00:21:59 +01:00
|
|
|
})
|
2021-01-20 16:16:56 +01:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// bootclasspathFragmentInitContentsFromImage will initialize the contents property from the image_name if
|
|
|
|
// necessary.
|
|
|
|
func bootclasspathFragmentInitContentsFromImage(ctx android.EarlyModuleContext, m *BootclasspathFragmentModule) {
|
2021-03-24 02:34:57 +01:00
|
|
|
contents := m.properties.Contents
|
|
|
|
if m.properties.Image_name == nil && len(contents) == 0 {
|
|
|
|
ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
|
|
|
|
}
|
2019-11-19 20:44:10 +01:00
|
|
|
|
2021-03-24 00:21:59 +01:00
|
|
|
imageName := proptools.String(m.properties.Image_name)
|
|
|
|
if imageName == "art" {
|
2021-04-22 02:45:29 +02:00
|
|
|
// TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
|
2021-04-28 01:39:52 +02:00
|
|
|
if android.IsModuleInVersionedSdk(m) {
|
2021-04-22 02:45:29 +02:00
|
|
|
// The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
|
|
|
|
// 1. There is no way to use this at the moment so ignoring it is safe.
|
|
|
|
// 2. Attempting to initialize the contents property from the configuration will end up having
|
|
|
|
// the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
|
|
|
|
// as the unversioned prebuilt could end up with an APEX variant created for the source
|
|
|
|
// APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
|
|
|
|
// turn will prevent it from accessing the dex implementation jar from that which will
|
|
|
|
// break hidden API processing, amongst others.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-24 00:21:59 +01:00
|
|
|
// Get the configuration for the art apex jars. Do not use getImageConfig(ctx) here as this is
|
|
|
|
// too early in the Soong processing for that to work.
|
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
|
|
|
modules := global.ArtApexJars
|
|
|
|
|
|
|
|
// Make sure that the apex specified in the configuration is consistent and is one for which
|
|
|
|
// this boot image is available.
|
|
|
|
commonApex := ""
|
|
|
|
for i := 0; i < modules.Len(); i++ {
|
|
|
|
apex := modules.Apex(i)
|
|
|
|
jar := modules.Jar(i)
|
|
|
|
if apex == "platform" {
|
|
|
|
ctx.ModuleErrorf("ArtApexJars is invalid as it requests a platform variant of %q", jar)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !m.AvailableFor(apex) {
|
2021-04-27 13:42:20 +02:00
|
|
|
ctx.ModuleErrorf("ArtApexJars configuration incompatible with this module, ArtApexJars expects this to be in apex %q but this is only in apexes %q",
|
2021-03-24 00:21:59 +01:00
|
|
|
apex, m.ApexAvailable())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if commonApex == "" {
|
|
|
|
commonApex = apex
|
|
|
|
} else if commonApex != apex {
|
|
|
|
ctx.ModuleErrorf("ArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex %q and %q",
|
|
|
|
commonApex, apex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 13:42:20 +02:00
|
|
|
if len(contents) != 0 {
|
|
|
|
// Nothing to do.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-24 00:21:59 +01:00
|
|
|
// Store the jars in the Contents property so that they can be used to add dependencies.
|
2019-11-19 20:44:10 +01:00
|
|
|
m.properties.Contents = modules.CopyOfJars()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bootclasspathImageNameContentsConsistencyCheck checks that the configuration that applies to this
|
|
|
|
// module (if any) matches the contents.
|
|
|
|
//
|
|
|
|
// This should be a noop as if image_name="art" then the contents will be set from the ArtApexJars
|
|
|
|
// config by bootclasspathFragmentInitContentsFromImage so it will be guaranteed to match. However,
|
|
|
|
// in future this will not be the case.
|
|
|
|
func (b *BootclasspathFragmentModule) bootclasspathImageNameContentsConsistencyCheck(ctx android.BaseModuleContext) {
|
|
|
|
imageName := proptools.String(b.properties.Image_name)
|
|
|
|
if imageName == "art" {
|
|
|
|
// TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
|
2021-04-28 01:39:52 +02:00
|
|
|
if android.IsModuleInVersionedSdk(b) {
|
2019-11-19 20:44:10 +01:00
|
|
|
// The module is a versioned prebuilt so ignore it. This is done for a couple of reasons:
|
|
|
|
// 1. There is no way to use this at the moment so ignoring it is safe.
|
|
|
|
// 2. Attempting to initialize the contents property from the configuration will end up having
|
|
|
|
// the versioned prebuilt depending on the unversioned prebuilt. That will cause problems
|
|
|
|
// as the unversioned prebuilt could end up with an APEX variant created for the source
|
|
|
|
// APEX which will prevent it from having an APEX variant for the prebuilt APEX which in
|
|
|
|
// turn will prevent it from accessing the dex implementation jar from that which will
|
|
|
|
// break hidden API processing, amongst others.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the configuration for the art apex jars.
|
|
|
|
modules := b.getImageConfig(ctx).modules
|
|
|
|
configuredJars := modules.CopyOfJars()
|
|
|
|
|
|
|
|
// Skip the check if the configured jars list is empty as that is a common configuration when
|
|
|
|
// building targets that do not result in a system image.
|
|
|
|
if len(configuredJars) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
contents := b.properties.Contents
|
|
|
|
if !reflect.DeepEqual(configuredJars, contents) {
|
|
|
|
ctx.ModuleErrorf("inconsistency in specification of contents. ArtApexJars configuration specifies %#v, contents property specifies %#v",
|
|
|
|
configuredJars, contents)
|
|
|
|
}
|
2021-03-24 00:21:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 00:04:00 +02:00
|
|
|
var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{})
|
2021-01-20 16:16:56 +01:00
|
|
|
|
2021-04-26 00:04:00 +02:00
|
|
|
// BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the
|
|
|
|
// apex contents.
|
|
|
|
type BootclasspathFragmentApexContentInfo struct {
|
2021-01-20 16:16:56 +01:00
|
|
|
// The image config, internal to this module (and the dex_bootjars singleton).
|
2021-01-21 19:13:43 +01:00
|
|
|
//
|
2021-04-26 00:04:00 +02:00
|
|
|
// Will be nil if the BootclasspathFragmentApexContentInfo has not been provided for a specific module. That can occur
|
2021-01-21 19:13:43 +01:00
|
|
|
// when SkipDexpreoptBootJars(ctx) returns true.
|
2021-01-20 16:16:56 +01:00
|
|
|
imageConfig *bootImageConfig
|
2021-05-15 13:39:23 +02:00
|
|
|
|
|
|
|
// Map from the name of the context module (as returned by Name()) to the hidden API encoded dex
|
|
|
|
// jar path.
|
|
|
|
contentModuleDexJarPaths map[string]android.Path
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
2021-04-26 00:04:00 +02:00
|
|
|
func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList {
|
2021-01-20 16:16:56 +01:00
|
|
|
return i.imageConfig.modules
|
|
|
|
}
|
|
|
|
|
2021-01-21 19:13:43 +01:00
|
|
|
// Get a map from ArchType to the associated boot image's contents for Android.
|
|
|
|
//
|
|
|
|
// Extension boot images only return their own files, not the files of the boot images they extend.
|
2021-04-26 00:04:00 +02:00
|
|
|
func (i BootclasspathFragmentApexContentInfo) AndroidBootImageFilesByArchType() map[android.ArchType]android.OutputPaths {
|
2021-01-21 19:13:43 +01:00
|
|
|
files := map[android.ArchType]android.OutputPaths{}
|
|
|
|
if i.imageConfig != nil {
|
|
|
|
for _, variant := range i.imageConfig.variants {
|
|
|
|
// We also generate boot images for host (for testing), but we don't need those in the apex.
|
|
|
|
// TODO(b/177892522) - consider changing this to check Os.OsClass = android.Device
|
|
|
|
if variant.target.Os == android.Android {
|
|
|
|
files[variant.target.Arch.ArchType] = variant.imagesDeps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return files
|
|
|
|
}
|
|
|
|
|
2021-04-26 11:33:59 +02:00
|
|
|
// DexBootJarPathForContentModule returns the path to the dex boot jar for specified module.
|
|
|
|
//
|
|
|
|
// The dex boot jar is one which has had hidden API encoding performed on it.
|
2021-05-15 13:39:23 +02:00
|
|
|
func (i BootclasspathFragmentApexContentInfo) DexBootJarPathForContentModule(module android.Module) (android.Path, error) {
|
|
|
|
name := module.Name()
|
|
|
|
if dexJar, ok := i.contentModuleDexJarPaths[name]; ok {
|
|
|
|
return dexJar, nil
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("unknown bootclasspath_fragment content module %s, expected one of %s",
|
|
|
|
name, strings.Join(android.SortedStringKeys(i.contentModuleDexJarPaths), ", "))
|
|
|
|
}
|
2021-04-26 11:33:59 +02:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
|
2021-01-21 19:13:43 +01:00
|
|
|
tag := ctx.OtherModuleDependencyTag(dep)
|
2021-04-20 23:47:03 +02:00
|
|
|
if IsBootclasspathFragmentContentDepTag(tag) {
|
2021-03-24 16:42:20 +01:00
|
|
|
// Boot image contents are automatically added to apex.
|
|
|
|
return true
|
2021-03-24 00:21:59 +01:00
|
|
|
}
|
2021-02-06 04:59:11 +01:00
|
|
|
if android.IsMetaDependencyTag(tag) {
|
|
|
|
// Cross-cutting metadata dependencies are metadata.
|
|
|
|
return false
|
|
|
|
}
|
2021-01-21 19:13:43 +01:00
|
|
|
panic(fmt.Errorf("boot_image module %q should not have a dependency on %q via tag %s", b, dep, android.PrettyPrintTag(tag)))
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *BootclasspathFragmentModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
|
2021-01-21 19:13:43 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-20 23:47:03 +02:00
|
|
|
// ComponentDepsMutator adds dependencies onto modules before any prebuilt modules without a
|
|
|
|
// corresponding source module are renamed. This means that adding a dependency using a name without
|
|
|
|
// a prebuilt_ prefix will always resolve to a source module and when using a name with that prefix
|
|
|
|
// it will always resolve to a prebuilt module.
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *BootclasspathFragmentModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
|
2021-04-20 23:47:03 +02:00
|
|
|
module := ctx.Module()
|
2021-04-23 15:25:28 +02:00
|
|
|
_, isSourceModule := module.(*BootclasspathFragmentModule)
|
2021-04-20 23:47:03 +02:00
|
|
|
|
|
|
|
for _, name := range b.properties.Contents {
|
|
|
|
// A bootclasspath_fragment must depend only on other source modules, while the
|
|
|
|
// prebuilt_bootclasspath_fragment must only depend on other prebuilt modules.
|
2021-04-22 18:25:57 +02:00
|
|
|
//
|
|
|
|
// TODO(b/177892522) - avoid special handling of jacocoagent.
|
|
|
|
if !isSourceModule && name != "jacocoagent" {
|
2021-04-20 23:47:03 +02:00
|
|
|
name = android.PrebuiltNameFromSource(name)
|
|
|
|
}
|
|
|
|
ctx.AddDependency(module, bootclasspathFragmentContentDepTag, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *BootclasspathFragmentModule) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2021-04-25 11:13:54 +02:00
|
|
|
// Add dependencies onto all the modules that provide the API stubs for classes on this
|
|
|
|
// bootclasspath fragment.
|
|
|
|
hiddenAPIAddStubLibDependencies(ctx, b.properties.sdkKindToStubLibs())
|
2021-03-24 00:21:59 +01:00
|
|
|
|
2021-01-21 19:13:43 +01:00
|
|
|
if SkipDexpreoptBootJars(ctx) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
|
|
|
|
// path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
|
|
|
|
dexpreopt.RegisterToolDeps(ctx)
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-11-19 20:44:10 +01:00
|
|
|
// Only perform a consistency check if this module is the active module. That will prevent an
|
|
|
|
// unused prebuilt that was created without instrumentation from breaking an instrumentation
|
|
|
|
// build.
|
|
|
|
if isActiveModule(ctx.Module()) {
|
|
|
|
b.bootclasspathImageNameContentsConsistencyCheck(ctx)
|
|
|
|
}
|
|
|
|
|
2021-05-07 00:59:58 +02:00
|
|
|
// Generate classpaths.proto config
|
|
|
|
b.generateClasspathProtoBuildActions(ctx)
|
|
|
|
|
2021-04-27 20:36:57 +02:00
|
|
|
// Gather the bootclasspath fragment's contents.
|
|
|
|
var contents []android.Module
|
|
|
|
ctx.VisitDirectDeps(func(module android.Module) {
|
|
|
|
tag := ctx.OtherModuleDependencyTag(module)
|
|
|
|
if IsBootclasspathFragmentContentDepTag(tag) {
|
2021-05-14 17:14:17 +02:00
|
|
|
contents = append(contents, module)
|
2021-04-27 20:36:57 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-04-09 00:01:37 +02:00
|
|
|
// Perform hidden API processing.
|
2021-05-21 17:15:31 +02:00
|
|
|
hiddenAPIFlagOutput := b.generateHiddenAPIBuildActions(ctx, contents)
|
2021-04-09 00:01:37 +02:00
|
|
|
|
2021-05-15 13:39:23 +02:00
|
|
|
// Verify that the image_name specified on a bootclasspath_fragment is valid even if this is a
|
|
|
|
// prebuilt which will not use the image config.
|
|
|
|
imageConfig := b.getImageConfig(ctx)
|
|
|
|
|
|
|
|
// A prebuilt fragment cannot contribute to the apex.
|
|
|
|
if !android.IsModulePrebuilt(ctx.Module()) {
|
|
|
|
// Provide the apex content info.
|
2021-05-21 17:15:31 +02:00
|
|
|
b.provideApexContentInfo(ctx, imageConfig, contents, hiddenAPIFlagOutput)
|
2021-05-15 13:39:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// provideApexContentInfo creates, initializes and stores the apex content info for use by other
|
|
|
|
// modules.
|
2021-05-21 17:15:31 +02:00
|
|
|
func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleContext, imageConfig *bootImageConfig, contents []android.Module, hiddenAPIFlagOutput *HiddenAPIFlagOutput) {
|
2021-05-15 13:39:23 +02:00
|
|
|
// Construct the apex content info from the config.
|
|
|
|
info := BootclasspathFragmentApexContentInfo{
|
|
|
|
imageConfig: imageConfig,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate the apex content info with paths to the dex jars.
|
2021-05-21 17:15:31 +02:00
|
|
|
b.populateApexContentInfoDexJars(ctx, &info, contents, hiddenAPIFlagOutput)
|
2021-05-15 13:39:23 +02:00
|
|
|
|
2021-05-07 00:59:58 +02:00
|
|
|
if !SkipDexpreoptBootJars(ctx) {
|
|
|
|
// Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
|
|
|
|
// GenerateSingletonBuildActions method as it cannot create it for itself.
|
|
|
|
dexpreopt.GetGlobalSoongConfig(ctx)
|
2021-04-27 20:36:57 +02:00
|
|
|
|
|
|
|
// Only generate the boot image if the configuration does not skip it.
|
|
|
|
b.generateBootImageBuildActions(ctx, contents)
|
2021-05-15 13:39:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make the apex content info available for other modules.
|
|
|
|
ctx.SetProvider(BootclasspathFragmentApexContentInfoProvider, info)
|
|
|
|
}
|
2021-01-20 16:16:56 +01:00
|
|
|
|
2021-05-15 13:39:23 +02:00
|
|
|
// populateApexContentInfoDexJars adds paths to the dex jars provided by this fragment to the
|
|
|
|
// apex content info.
|
2021-05-21 17:15:31 +02:00
|
|
|
func (b *BootclasspathFragmentModule) populateApexContentInfoDexJars(ctx android.ModuleContext, info *BootclasspathFragmentApexContentInfo, contents []android.Module, hiddenAPIFlagOutput *HiddenAPIFlagOutput) {
|
2021-05-15 09:54:30 +02:00
|
|
|
|
2021-05-15 13:39:23 +02:00
|
|
|
info.contentModuleDexJarPaths = map[string]android.Path{}
|
2021-05-21 17:15:31 +02:00
|
|
|
if hiddenAPIFlagOutput != nil {
|
2021-05-15 09:54:30 +02:00
|
|
|
// Hidden API encoding has been performed.
|
2021-05-21 17:15:31 +02:00
|
|
|
flags := hiddenAPIFlagOutput.AllFlagsPath
|
2021-05-15 09:54:30 +02:00
|
|
|
for _, m := range contents {
|
|
|
|
h := m.(hiddenAPIModule)
|
|
|
|
unencodedDex := h.bootDexJar()
|
|
|
|
if unencodedDex == nil {
|
|
|
|
// This is an error. Sometimes Soong will report the error directly, other times it will
|
|
|
|
// defer the error reporting to happen only when trying to use the missing file in ninja.
|
|
|
|
// Either way it is handled by extractBootDexJarsFromHiddenAPIModules which must have been
|
|
|
|
// called before this as it generates the flags that are used to encode these files.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
outputDir := android.PathForModuleOut(ctx, "hiddenapi-modular/encoded").OutputPath
|
|
|
|
encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, flags, *h.uncompressDex(), outputDir)
|
|
|
|
info.contentModuleDexJarPaths[m.Name()] = encodedDex
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, m := range contents {
|
|
|
|
j := m.(UsesLibraryDependency)
|
|
|
|
dexJar := j.DexJarBuildPath()
|
|
|
|
info.contentModuleDexJarPaths[m.Name()] = dexJar
|
|
|
|
}
|
2021-05-17 22:03:07 +02:00
|
|
|
}
|
2021-01-20 16:16:56 +01:00
|
|
|
}
|
2021-03-10 16:00:46 +01:00
|
|
|
|
2021-05-07 00:59:58 +02:00
|
|
|
// generateClasspathProtoBuildActions generates all required build actions for classpath.proto config
|
|
|
|
func (b *BootclasspathFragmentModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) {
|
|
|
|
var classpathJars []classpathJar
|
|
|
|
if "art" == proptools.String(b.properties.Image_name) {
|
|
|
|
// ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH
|
|
|
|
classpathJars = configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), BOOTCLASSPATH, DEX2OATBOOTCLASSPATH)
|
|
|
|
} else {
|
|
|
|
classpathJars = configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), b.classpathType)
|
|
|
|
}
|
|
|
|
b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BootclasspathFragmentModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList {
|
2021-05-07 01:10:33 +02:00
|
|
|
if "art" == proptools.String(b.properties.Image_name) {
|
|
|
|
return b.getImageConfig(ctx).modules
|
|
|
|
}
|
|
|
|
|
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
|
|
|
|
|
|
|
// Only create configs for updatable boot jars. Non-updatable boot jars must be part of the
|
|
|
|
// platform_bootclasspath's classpath proto config to guarantee that they come before any
|
|
|
|
// updatable jars at runtime.
|
|
|
|
return global.UpdatableBootJars.Filter(b.properties.Contents)
|
2021-05-07 00:59:58 +02:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
|
2021-03-24 00:06:38 +01:00
|
|
|
// Get a map of the image configs that are supported.
|
|
|
|
imageConfigs := genBootImageConfigs(ctx)
|
|
|
|
|
|
|
|
// Retrieve the config for this image.
|
|
|
|
imageNamePtr := b.properties.Image_name
|
|
|
|
if imageNamePtr == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
imageName := *imageNamePtr
|
|
|
|
imageConfig := imageConfigs[imageName]
|
|
|
|
if imageConfig == nil {
|
|
|
|
ctx.PropertyErrorf("image_name", "Unknown image name %q, expected one of %s", imageName, strings.Join(android.SortedStringKeys(imageConfigs), ", "))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return imageConfig
|
|
|
|
}
|
|
|
|
|
2021-04-09 00:01:37 +02:00
|
|
|
// generateHiddenAPIBuildActions generates all the hidden API related build rules.
|
2021-05-21 17:15:31 +02:00
|
|
|
func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, contents []android.Module) *HiddenAPIFlagOutput {
|
2021-04-25 11:13:54 +02:00
|
|
|
|
2021-05-21 23:18:49 +02:00
|
|
|
// Create hidden API input structure.
|
|
|
|
input := b.createHiddenAPIFlagInput(ctx, contents)
|
2021-04-25 11:13:54 +02:00
|
|
|
|
2021-05-23 17:55:37 +02:00
|
|
|
var output *HiddenAPIFlagOutput
|
|
|
|
|
|
|
|
// Hidden API processing is conditional as a temporary workaround as not all
|
|
|
|
// bootclasspath_fragments provide the appropriate information needed for hidden API processing
|
|
|
|
// which leads to breakages of the build.
|
|
|
|
// TODO(b/179354495): Stop hidden API processing being conditional once all bootclasspath_fragment
|
|
|
|
// modules have been updated to support it.
|
|
|
|
if input.canPerformHiddenAPIProcessing(ctx, b.properties) {
|
|
|
|
// Get the content modules that contribute to the hidden API processing.
|
|
|
|
hiddenAPIModules := gatherHiddenAPIModuleFromContents(ctx, contents)
|
2021-05-14 11:38:00 +02:00
|
|
|
|
2021-05-23 17:55:37 +02:00
|
|
|
// Delegate the production of the hidden API all-flags.csv file to a module type specific method.
|
|
|
|
common := ctx.Module().(commonBootclasspathFragment)
|
|
|
|
output = common.produceHiddenAPIAllFlagsFile(ctx, hiddenAPIModules, input)
|
|
|
|
}
|
2021-05-21 17:15:31 +02:00
|
|
|
|
2021-05-23 17:55:37 +02:00
|
|
|
// Initialize a HiddenAPIInfo structure.
|
2021-05-21 23:18:56 +02:00
|
|
|
hiddenAPIInfo := HiddenAPIInfo{
|
2021-05-23 17:55:37 +02:00
|
|
|
// The monolithic hidden API processing needs access to the flag files that override the default
|
|
|
|
// flags from all the fragments whether or not they actually perform their own hidden API flag
|
|
|
|
// generation. That is because the monolithic hidden API processing uses those flag files to
|
|
|
|
// perform its own flag generation.
|
2021-05-21 23:18:49 +02:00
|
|
|
FlagFilesByCategory: input.FlagFilesByCategory,
|
2021-05-21 23:46:59 +02:00
|
|
|
|
|
|
|
// Make these available for tests.
|
|
|
|
StubDexJarsByKind: input.StubDexJarsByKind,
|
2021-05-23 17:55:37 +02:00
|
|
|
}
|
2021-04-15 14:32:00 +02:00
|
|
|
|
2021-05-23 17:55:37 +02:00
|
|
|
if output != nil {
|
2021-05-21 23:18:49 +02:00
|
|
|
// The monolithic hidden API processing also needs access to all the output files produced by
|
|
|
|
// hidden API processing of this fragment.
|
2021-05-23 17:55:37 +02:00
|
|
|
hiddenAPIInfo.HiddenAPIFlagOutput = *output
|
2021-05-21 23:18:49 +02:00
|
|
|
}
|
2021-05-23 17:55:37 +02:00
|
|
|
|
|
|
|
// Provide it for use by other modules.
|
2021-05-21 23:18:56 +02:00
|
|
|
ctx.SetProvider(HiddenAPIInfoProvider, hiddenAPIInfo)
|
2021-05-15 09:54:30 +02:00
|
|
|
|
2021-05-21 17:15:31 +02:00
|
|
|
return output
|
2021-04-15 14:32:00 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 23:18:49 +02:00
|
|
|
// createHiddenAPIFlagInput creates a HiddenAPIFlagInput struct and initializes it with information derived
|
|
|
|
// from the properties on this module and its dependencies.
|
|
|
|
func (b *BootclasspathFragmentModule) createHiddenAPIFlagInput(ctx android.ModuleContext, contents []android.Module) HiddenAPIFlagInput {
|
|
|
|
input := newHiddenAPIFlagInput()
|
|
|
|
|
|
|
|
// Update the input structure with information obtained from the stub libraries.
|
|
|
|
input.gatherStubLibInfo(ctx, contents)
|
|
|
|
|
|
|
|
// Populate with flag file paths from the properties.
|
|
|
|
input.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api)
|
|
|
|
|
|
|
|
return input
|
|
|
|
}
|
|
|
|
|
2021-04-15 14:32:00 +02:00
|
|
|
// produceHiddenAPIAllFlagsFile produces the hidden API all-flags.csv file (and supporting files)
|
|
|
|
// for the fragment.
|
2021-05-21 23:18:49 +02:00
|
|
|
func (b *BootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, input HiddenAPIFlagInput) *HiddenAPIFlagOutput {
|
|
|
|
// Generate the rules to create the hidden API flags and update the supplied hiddenAPIInfo with the
|
2021-04-15 14:32:00 +02:00
|
|
|
// paths to the created files.
|
2021-05-21 23:18:49 +02:00
|
|
|
return hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx, contents, input)
|
2021-04-09 00:01:37 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 20:36:57 +02:00
|
|
|
// generateBootImageBuildActions generates ninja rules to create the boot image if required for this
|
|
|
|
// module.
|
|
|
|
func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, contents []android.Module) {
|
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
|
|
|
if !shouldBuildBootImages(ctx.Config(), global) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bootclasspath fragment modules that are not preferred do not produce a boot image.
|
|
|
|
if !isActiveModule(ctx.Module()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bootclasspath fragment modules that have no image_name property do not produce a boot image.
|
|
|
|
imageConfig := b.getImageConfig(ctx)
|
|
|
|
if imageConfig == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bootclasspath fragment modules that are for the platform do not produce a boot image.
|
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
if apexInfo.IsForPlatform() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bootclasspath fragment modules that are versioned do not produce a boot image.
|
|
|
|
if android.IsModuleInVersionedSdk(ctx.Module()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the dex jars of this fragment's content modules to their predefined locations.
|
|
|
|
copyBootJarsToPredefinedLocations(ctx, contents, imageConfig.modules, imageConfig.dexPaths)
|
2021-04-30 00:36:12 +02:00
|
|
|
|
|
|
|
// Build a profile for the image config and then use that to build the boot image.
|
|
|
|
profile := bootImageProfileRule(ctx, imageConfig)
|
|
|
|
buildBootImage(ctx, imageConfig, profile)
|
2021-04-27 20:36:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
type bootclasspathFragmentMemberType struct {
|
2021-03-10 16:00:46 +01:00
|
|
|
android.SdkMemberTypeBase
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
|
2021-03-10 16:00:46 +01:00
|
|
|
mctx.AddVariationDependencies(nil, dependencyTag, names...)
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {
|
|
|
|
_, ok := module.(*BootclasspathFragmentModule)
|
2021-03-10 16:00:46 +01:00
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *bootclasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
|
2021-03-29 12:02:53 +02:00
|
|
|
if b.PropertyName == "boot_images" {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_boot_image")
|
|
|
|
} else {
|
|
|
|
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_bootclasspath_fragment")
|
|
|
|
}
|
2021-03-10 16:00:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *bootclasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
|
|
|
|
return &bootclasspathFragmentSdkMemberProperties{}
|
2021-03-10 16:00:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
type bootclasspathFragmentSdkMemberProperties struct {
|
2021-03-10 16:00:46 +01:00
|
|
|
android.SdkMemberPropertiesBase
|
|
|
|
|
2021-04-19 14:23:06 +02:00
|
|
|
// The image name
|
2021-03-24 00:06:38 +01:00
|
|
|
Image_name *string
|
2021-04-19 14:23:06 +02:00
|
|
|
|
|
|
|
// Contents of the bootclasspath fragment
|
|
|
|
Contents []string
|
2021-04-19 14:23:53 +02:00
|
|
|
|
2021-04-25 14:40:15 +02:00
|
|
|
// Stub_libs properties.
|
|
|
|
Stub_libs []string
|
|
|
|
Core_platform_stub_libs []string
|
|
|
|
|
2021-04-19 14:23:53 +02:00
|
|
|
// Flag files by *hiddenAPIFlagFileCategory
|
2021-05-21 17:58:23 +02:00
|
|
|
Flag_files_by_category FlagFilesByCategory
|
2021-04-15 14:32:00 +02:00
|
|
|
|
|
|
|
// The path to the generated stub-flags.csv file.
|
|
|
|
Stub_flags_path android.OptionalPath
|
|
|
|
|
|
|
|
// The path to the generated annotation-flags.csv file.
|
|
|
|
Annotation_flags_path android.OptionalPath
|
|
|
|
|
|
|
|
// The path to the generated metadata.csv file.
|
|
|
|
Metadata_path android.OptionalPath
|
|
|
|
|
|
|
|
// The path to the generated index.csv file.
|
|
|
|
Index_path android.OptionalPath
|
|
|
|
|
|
|
|
// The path to the generated all-flags.csv file.
|
|
|
|
All_flags_path android.OptionalPath
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *bootclasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
|
|
|
module := variant.(*BootclasspathFragmentModule)
|
2021-03-10 16:00:46 +01:00
|
|
|
|
|
|
|
b.Image_name = module.properties.Image_name
|
2021-04-23 17:58:51 +02:00
|
|
|
b.Contents = module.properties.Contents
|
2021-04-19 14:23:53 +02:00
|
|
|
|
2021-05-21 23:18:56 +02:00
|
|
|
// Get the hidden API information from the module.
|
2021-04-19 14:23:53 +02:00
|
|
|
mctx := ctx.SdkModuleContext()
|
2021-05-21 23:18:56 +02:00
|
|
|
hiddenAPIInfo := mctx.OtherModuleProvider(module, HiddenAPIInfoProvider).(HiddenAPIInfo)
|
|
|
|
b.Flag_files_by_category = hiddenAPIInfo.FlagFilesByCategory
|
2021-04-25 14:40:15 +02:00
|
|
|
|
2021-04-15 14:32:00 +02:00
|
|
|
// Copy all the generated file paths.
|
2021-05-21 23:18:56 +02:00
|
|
|
b.Stub_flags_path = android.OptionalPathForPath(hiddenAPIInfo.StubFlagsPath)
|
|
|
|
b.Annotation_flags_path = android.OptionalPathForPath(hiddenAPIInfo.AnnotationFlagsPath)
|
|
|
|
b.Metadata_path = android.OptionalPathForPath(hiddenAPIInfo.MetadataPath)
|
|
|
|
b.Index_path = android.OptionalPathForPath(hiddenAPIInfo.IndexPath)
|
|
|
|
b.All_flags_path = android.OptionalPathForPath(hiddenAPIInfo.AllFlagsPath)
|
2021-04-15 14:32:00 +02:00
|
|
|
|
2021-04-25 14:40:15 +02:00
|
|
|
// Copy stub_libs properties.
|
|
|
|
b.Stub_libs = module.properties.Api.Stub_libs
|
|
|
|
b.Core_platform_stub_libs = module.properties.Core_platform_api.Stub_libs
|
2021-03-10 16:00:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
|
2021-03-24 00:06:38 +01:00
|
|
|
if b.Image_name != nil {
|
|
|
|
propertySet.AddProperty("image_name", *b.Image_name)
|
2021-03-10 16:00:46 +01:00
|
|
|
}
|
2021-04-19 14:23:06 +02:00
|
|
|
|
2021-04-25 14:40:15 +02:00
|
|
|
builder := ctx.SnapshotBuilder()
|
|
|
|
requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
|
|
|
|
|
2021-04-19 14:23:06 +02:00
|
|
|
if len(b.Contents) > 0 {
|
2021-04-25 14:40:15 +02:00
|
|
|
propertySet.AddPropertyWithTag("contents", b.Contents, requiredMemberDependency)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(b.Stub_libs) > 0 {
|
|
|
|
apiPropertySet := propertySet.AddPropertySet("api")
|
|
|
|
apiPropertySet.AddPropertyWithTag("stub_libs", b.Stub_libs, requiredMemberDependency)
|
|
|
|
}
|
|
|
|
if len(b.Core_platform_stub_libs) > 0 {
|
|
|
|
corePlatformApiPropertySet := propertySet.AddPropertySet("core_platform_api")
|
|
|
|
corePlatformApiPropertySet.AddPropertyWithTag("stub_libs", b.Core_platform_stub_libs, requiredMemberDependency)
|
2021-04-19 14:23:06 +02:00
|
|
|
}
|
2021-04-19 14:23:53 +02:00
|
|
|
|
2021-04-15 14:32:00 +02:00
|
|
|
hiddenAPISet := propertySet.AddPropertySet("hidden_api")
|
|
|
|
hiddenAPIDir := "hiddenapi"
|
|
|
|
|
|
|
|
// Copy manually curated flag files specified on the bootclasspath_fragment.
|
2021-04-19 14:23:53 +02:00
|
|
|
if b.Flag_files_by_category != nil {
|
|
|
|
for _, category := range hiddenAPIFlagFileCategories {
|
|
|
|
paths := b.Flag_files_by_category[category]
|
|
|
|
if len(paths) > 0 {
|
|
|
|
dests := []string{}
|
|
|
|
for _, p := range paths {
|
2021-04-15 14:32:00 +02:00
|
|
|
dest := filepath.Join(hiddenAPIDir, p.Base())
|
2021-04-19 14:23:53 +02:00
|
|
|
builder.CopyToSnapshot(p, dest)
|
|
|
|
dests = append(dests, dest)
|
|
|
|
}
|
|
|
|
hiddenAPISet.AddProperty(category.propertyName, dests)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-15 14:32:00 +02:00
|
|
|
|
|
|
|
copyOptionalPath := func(path android.OptionalPath, property string) {
|
|
|
|
if path.Valid() {
|
|
|
|
p := path.Path()
|
|
|
|
dest := filepath.Join(hiddenAPIDir, p.Base())
|
|
|
|
builder.CopyToSnapshot(p, dest)
|
|
|
|
hiddenAPISet.AddProperty(property, dest)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy all the generated files, if available.
|
|
|
|
copyOptionalPath(b.Stub_flags_path, "stub_flags")
|
|
|
|
copyOptionalPath(b.Annotation_flags_path, "annotation_flags")
|
|
|
|
copyOptionalPath(b.Metadata_path, "metadata")
|
|
|
|
copyOptionalPath(b.Index_path, "index")
|
|
|
|
copyOptionalPath(b.All_flags_path, "all_flags")
|
2021-03-10 16:00:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
var _ android.SdkMemberType = (*bootclasspathFragmentMemberType)(nil)
|
2021-03-10 16:00:46 +01:00
|
|
|
|
2021-04-15 14:32:00 +02:00
|
|
|
// prebuiltBootclasspathFragmentProperties contains additional prebuilt_bootclasspath_fragment
|
|
|
|
// specific properties.
|
|
|
|
type prebuiltBootclasspathFragmentProperties struct {
|
|
|
|
Hidden_api struct {
|
|
|
|
// The path to the stub-flags.csv file created by the bootclasspath_fragment.
|
|
|
|
Stub_flags *string `android:"path"`
|
|
|
|
|
|
|
|
// The path to the annotation-flags.csv file created by the bootclasspath_fragment.
|
|
|
|
Annotation_flags *string `android:"path"`
|
|
|
|
|
|
|
|
// The path to the metadata.csv file created by the bootclasspath_fragment.
|
|
|
|
Metadata *string `android:"path"`
|
|
|
|
|
|
|
|
// The path to the index.csv file created by the bootclasspath_fragment.
|
|
|
|
Index *string `android:"path"`
|
|
|
|
|
|
|
|
// The path to the all-flags.csv file created by the bootclasspath_fragment.
|
|
|
|
All_flags *string `android:"path"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// A prebuilt version of the bootclasspath_fragment module.
|
2021-03-10 16:00:46 +01:00
|
|
|
//
|
2021-04-23 15:25:28 +02:00
|
|
|
// At the moment this is basically just a bootclasspath_fragment module that can be used as a
|
|
|
|
// prebuilt. Eventually as more functionality is migrated into the bootclasspath_fragment module
|
|
|
|
// type from the various singletons then this will diverge.
|
|
|
|
type prebuiltBootclasspathFragmentModule struct {
|
|
|
|
BootclasspathFragmentModule
|
2021-03-10 16:00:46 +01:00
|
|
|
prebuilt android.Prebuilt
|
2021-04-15 14:32:00 +02:00
|
|
|
|
|
|
|
// Additional prebuilt specific properties.
|
|
|
|
prebuiltProperties prebuiltBootclasspathFragmentProperties
|
2021-03-10 16:00:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (module *prebuiltBootclasspathFragmentModule) Prebuilt() *android.Prebuilt {
|
2021-03-10 16:00:46 +01:00
|
|
|
return &module.prebuilt
|
|
|
|
}
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func (module *prebuiltBootclasspathFragmentModule) Name() string {
|
2021-03-10 16:00:46 +01:00
|
|
|
return module.prebuilt.Name(module.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2021-04-15 14:32:00 +02:00
|
|
|
// produceHiddenAPIAllFlagsFile returns a path to the prebuilt all-flags.csv or nil if none is
|
|
|
|
// specified.
|
2021-05-21 23:18:49 +02:00
|
|
|
func (module *prebuiltBootclasspathFragmentModule) produceHiddenAPIAllFlagsFile(ctx android.ModuleContext, contents []hiddenAPIModule, _ HiddenAPIFlagInput) *HiddenAPIFlagOutput {
|
2021-05-21 17:15:31 +02:00
|
|
|
pathForOptionalSrc := func(src *string) android.Path {
|
2021-04-15 14:32:00 +02:00
|
|
|
if src == nil {
|
|
|
|
// TODO(b/179354495): Fail if this is not provided once prebuilts have been updated.
|
|
|
|
return nil
|
|
|
|
}
|
2021-05-21 17:15:31 +02:00
|
|
|
return android.PathForModuleSrc(ctx, *src)
|
|
|
|
}
|
|
|
|
|
|
|
|
output := HiddenAPIFlagOutput{
|
|
|
|
StubFlagsPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Stub_flags),
|
|
|
|
AnnotationFlagsPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Annotation_flags),
|
|
|
|
MetadataPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Metadata),
|
|
|
|
IndexPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.Index),
|
|
|
|
AllFlagsPath: pathForOptionalSrc(module.prebuiltProperties.Hidden_api.All_flags),
|
2021-04-15 14:32:00 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 17:15:31 +02:00
|
|
|
return &output
|
2021-04-15 14:32:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ commonBootclasspathFragment = (*prebuiltBootclasspathFragmentModule)(nil)
|
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
func prebuiltBootclasspathFragmentFactory() android.Module {
|
|
|
|
m := &prebuiltBootclasspathFragmentModule{}
|
2021-04-15 14:32:00 +02:00
|
|
|
m.AddProperties(&m.properties, &m.prebuiltProperties)
|
2021-03-10 16:00:46 +01:00
|
|
|
// This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
|
|
|
|
// array.
|
|
|
|
android.InitPrebuiltModule(m, &[]string{"placeholder"})
|
|
|
|
android.InitApexModule(m)
|
|
|
|
android.InitSdkAwareModule(m)
|
2021-03-17 01:26:25 +01:00
|
|
|
android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon)
|
2021-03-24 00:21:59 +01:00
|
|
|
|
2021-04-23 15:25:28 +02:00
|
|
|
// Initialize the contents property from the image_name.
|
2021-03-24 00:21:59 +01:00
|
|
|
android.AddLoadHook(m, func(ctx android.LoadHookContext) {
|
2021-04-23 15:25:28 +02:00
|
|
|
bootclasspathFragmentInitContentsFromImage(ctx, &m.BootclasspathFragmentModule)
|
2021-03-24 00:21:59 +01:00
|
|
|
})
|
2021-03-10 16:00:46 +01:00
|
|
|
return m
|
|
|
|
}
|