2021-03-30 05:18:45 +08:00
|
|
|
// Copyright 2021 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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-04-12 21:15:22 +08:00
|
|
|
"fmt"
|
|
|
|
|
2021-03-30 05:18:45 +08:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/dexpreopt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
registerPlatformBootclasspathBuildComponents(android.InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("platform_bootclasspath", platformBootclasspathFactory)
|
2021-03-23 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 03:05:39 +08:00
|
|
|
// The tags used for the dependencies between the platform bootclasspath and any configured boot
|
|
|
|
// jars.
|
|
|
|
var (
|
|
|
|
platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag{name: "art-boot-jar"}
|
|
|
|
platformBootclasspathNonUpdatableBootJarDepTag = bootclasspathDependencyTag{name: "non-updatable-boot-jar"}
|
|
|
|
platformBootclasspathUpdatableBootJarDepTag = bootclasspathDependencyTag{name: "updatable-boot-jar"}
|
|
|
|
)
|
2021-03-23 06:09:42 +08:00
|
|
|
|
2021-03-30 05:18:45 +08:00
|
|
|
type platformBootclasspathModule struct {
|
|
|
|
android.ModuleBase
|
2021-04-07 22:17:14 +08:00
|
|
|
ClasspathFragmentBase
|
2021-03-23 06:09:42 +08:00
|
|
|
|
2021-04-08 03:35:11 +08:00
|
|
|
properties platformBootclasspathProperties
|
|
|
|
|
2021-03-23 06:09:42 +08:00
|
|
|
// The apex:module pairs obtained from the configured modules.
|
|
|
|
//
|
|
|
|
// Currently only for testing.
|
|
|
|
configuredModules []android.Module
|
2021-04-08 03:35:11 +08:00
|
|
|
|
|
|
|
// The apex:module pairs obtained from the fragments.
|
|
|
|
//
|
|
|
|
// Currently only for testing.
|
|
|
|
fragments []android.Module
|
2021-04-12 21:15:22 +08:00
|
|
|
|
|
|
|
// Path to the monolithic hiddenapi-flags.csv file.
|
2021-04-13 20:02:29 +08:00
|
|
|
hiddenAPIFlagsCSV android.OutputPath
|
2021-04-12 21:15:22 +08:00
|
|
|
|
|
|
|
// Path to the monolithic hiddenapi-index.csv file.
|
2021-04-13 20:02:29 +08:00
|
|
|
hiddenAPIIndexCSV android.OutputPath
|
2021-04-12 21:15:22 +08:00
|
|
|
|
|
|
|
// Path to the monolithic hiddenapi-unsupported.csv file.
|
2021-04-13 20:02:29 +08:00
|
|
|
hiddenAPIMetadataCSV android.OutputPath
|
2021-04-08 03:35:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type platformBootclasspathProperties struct {
|
2021-04-22 18:49:41 +08:00
|
|
|
BootclasspathFragmentsDepsProperties
|
2021-04-09 03:12:41 +08:00
|
|
|
|
2021-04-14 22:01:56 +08:00
|
|
|
Hidden_api HiddenAPIFlagFileProperties
|
2021-03-30 05:18:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func platformBootclasspathFactory() android.Module {
|
|
|
|
m := &platformBootclasspathModule{}
|
2021-04-08 03:35:11 +08:00
|
|
|
m.AddProperties(&m.properties)
|
2021-04-07 22:17:14 +08:00
|
|
|
// TODO(satayev): split systemserver and apex jars into separate configs.
|
|
|
|
initClasspathFragment(m)
|
2021-03-30 05:18:45 +08:00
|
|
|
android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:15:22 +08:00
|
|
|
var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil)
|
|
|
|
|
2021-04-07 22:17:14 +08:00
|
|
|
func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
|
|
|
|
entries = append(entries, android.AndroidMkEntries{
|
|
|
|
Class: "FAKE",
|
|
|
|
// Need at least one output file in order for this to take effect.
|
|
|
|
OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV),
|
|
|
|
Include: "$(BUILD_PHONY_PACKAGE)",
|
|
|
|
})
|
|
|
|
entries = append(entries, b.classpathFragmentBase().getAndroidMkEntries()...)
|
|
|
|
return
|
2021-04-12 21:15:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make the hidden API files available from the platform-bootclasspath module.
|
|
|
|
func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "hiddenapi-flags.csv":
|
|
|
|
return android.Paths{b.hiddenAPIFlagsCSV}, nil
|
|
|
|
case "hiddenapi-index.csv":
|
|
|
|
return android.Paths{b.hiddenAPIIndexCSV}, nil
|
|
|
|
case "hiddenapi-metadata.csv":
|
|
|
|
return android.Paths{b.hiddenAPIMetadataCSV}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknown tag %s", tag)
|
|
|
|
}
|
|
|
|
|
2021-03-30 05:18:45 +08:00
|
|
|
func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2021-04-21 21:10:42 +08:00
|
|
|
b.hiddenAPIDepsMutator(ctx)
|
|
|
|
|
2021-03-30 05:18:45 +08: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-21 21:10:42 +08:00
|
|
|
func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add dependencies onto the stub lib modules.
|
|
|
|
sdkKindToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config())
|
|
|
|
hiddenAPIAddStubLibDependencies(ctx, sdkKindToStubLibModules)
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:08:59 +08:00
|
|
|
func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
// Add dependencies on all the modules configured in the "art" boot image.
|
|
|
|
artImageConfig := genBootImageConfigs(ctx)[artBootImageName]
|
2021-04-27 03:05:39 +08:00
|
|
|
addDependenciesOntoBootImageModules(ctx, artImageConfig.modules, platformBootclasspathArtBootJarDepTag)
|
2021-03-23 06:09:42 +08:00
|
|
|
|
2021-04-27 03:05:39 +08:00
|
|
|
// Add dependencies on all the non-updatable module configured in the "boot" boot image. That does
|
|
|
|
// not include modules configured in the "art" boot image.
|
2021-04-22 19:08:59 +08:00
|
|
|
bootImageConfig := b.getImageConfig(ctx)
|
2021-04-27 03:05:39 +08:00
|
|
|
addDependenciesOntoBootImageModules(ctx, bootImageConfig.modules, platformBootclasspathNonUpdatableBootJarDepTag)
|
2021-03-23 06:09:42 +08:00
|
|
|
|
2021-04-22 19:08:59 +08:00
|
|
|
// Add dependencies on all the updatable modules.
|
|
|
|
updatableModules := dexpreopt.GetGlobalConfig(ctx).UpdatableBootJars
|
2021-04-27 03:05:39 +08:00
|
|
|
addDependenciesOntoBootImageModules(ctx, updatableModules, platformBootclasspathUpdatableBootJarDepTag)
|
2021-04-08 03:35:11 +08:00
|
|
|
|
2021-04-22 19:08:59 +08:00
|
|
|
// Add dependencies on all the fragments.
|
|
|
|
b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
|
2021-03-23 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 03:05:39 +08:00
|
|
|
func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) {
|
2021-03-23 06:09:42 +08:00
|
|
|
for i := 0; i < modules.Len(); i++ {
|
|
|
|
apex := modules.Apex(i)
|
|
|
|
name := modules.Jar(i)
|
|
|
|
|
2021-04-27 03:05:39 +08:00
|
|
|
addDependencyOntoApexModulePair(ctx, apex, name, tag)
|
2021-03-23 06:09:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 05:18:45 +08:00
|
|
|
func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-04-07 22:17:14 +08:00
|
|
|
b.classpathFragmentBase().generateAndroidBuildActions(ctx)
|
|
|
|
|
2021-04-27 03:05:39 +08:00
|
|
|
// Gather all the dependencies from the art, updatable and non-updatable boot jars.
|
|
|
|
artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag)
|
|
|
|
nonUpdatableModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathNonUpdatableBootJarDepTag)
|
|
|
|
updatableModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathUpdatableBootJarDepTag)
|
|
|
|
|
|
|
|
// Concatenate them all, in order as they would appear on the bootclasspath.
|
|
|
|
var allModules []android.Module
|
|
|
|
allModules = append(allModules, artModules...)
|
|
|
|
allModules = append(allModules, nonUpdatableModules...)
|
|
|
|
allModules = append(allModules, updatableModules...)
|
|
|
|
b.configuredModules = allModules
|
|
|
|
|
|
|
|
// Gather all the fragments dependencies.
|
2021-04-29 04:16:02 +08:00
|
|
|
b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
|
2021-03-23 06:09:42 +08:00
|
|
|
|
2021-04-09 06:01:37 +08:00
|
|
|
b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
|
2021-04-09 03:12:41 +08:00
|
|
|
|
2021-03-30 05:18:45 +08:00
|
|
|
// Nothing to do if skipping the dexpreopt of boot image jars.
|
|
|
|
if SkipDexpreoptBootJars(ctx) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-27 03:10:48 +08:00
|
|
|
b.generateBootImageBuildActions(ctx, updatableModules)
|
2021-03-30 05:18:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
|
|
|
|
return defaultBootImageConfig(ctx)
|
|
|
|
}
|
2021-04-09 03:12:41 +08:00
|
|
|
|
|
|
|
// generateHiddenAPIBuildActions generates all the hidden API related build rules.
|
2021-04-09 06:01:37 +08:00
|
|
|
func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) {
|
2021-04-09 03:12:41 +08:00
|
|
|
|
2021-04-13 19:25:01 +08:00
|
|
|
// Save the paths to the monolithic files for retrieval via OutputFiles().
|
|
|
|
b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags
|
|
|
|
b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index
|
|
|
|
b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata
|
2021-04-12 21:15:22 +08:00
|
|
|
|
2021-04-13 20:02:29 +08:00
|
|
|
// Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. This is a performance
|
|
|
|
// optimization that can be used to reduce the incremental build time but as its name suggests it
|
|
|
|
// can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
|
|
|
|
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
|
|
|
|
paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
|
|
|
|
for _, path := range paths {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Touch,
|
|
|
|
Output: path,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-13 06:26:14 +08:00
|
|
|
hiddenAPISupportingModules := []hiddenAPISupportingModule{}
|
2021-04-09 03:12:41 +08:00
|
|
|
for _, module := range modules {
|
2021-04-13 06:26:14 +08:00
|
|
|
if h, ok := module.(hiddenAPISupportingModule); ok {
|
|
|
|
if h.bootDexJar() == nil {
|
|
|
|
ctx.ModuleErrorf("module %s does not provide a bootDexJar file", module)
|
|
|
|
}
|
|
|
|
if h.flagsCSV() == nil {
|
|
|
|
ctx.ModuleErrorf("module %s does not provide a flagsCSV file", module)
|
|
|
|
}
|
|
|
|
if h.indexCSV() == nil {
|
|
|
|
ctx.ModuleErrorf("module %s does not provide an indexCSV file", module)
|
|
|
|
}
|
|
|
|
if h.metadataCSV() == nil {
|
|
|
|
ctx.ModuleErrorf("module %s does not provide a metadataCSV file", module)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Failed() {
|
|
|
|
continue
|
2021-04-09 03:12:41 +08:00
|
|
|
}
|
2021-04-13 06:26:14 +08:00
|
|
|
|
|
|
|
hiddenAPISupportingModules = append(hiddenAPISupportingModules, h)
|
2021-04-09 03:12:41 +08:00
|
|
|
} else {
|
2021-04-13 06:26:14 +08:00
|
|
|
ctx.ModuleErrorf("module %s of type %s does not support hidden API processing", module, ctx.OtherModuleType(module))
|
2021-04-09 03:12:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-13 06:26:14 +08:00
|
|
|
moduleSpecificFlagsPaths := android.Paths{}
|
|
|
|
for _, module := range hiddenAPISupportingModules {
|
|
|
|
moduleSpecificFlagsPaths = append(moduleSpecificFlagsPaths, module.flagsCSV())
|
|
|
|
}
|
|
|
|
|
2021-04-09 06:01:37 +08:00
|
|
|
flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx)
|
|
|
|
for _, fragment := range fragments {
|
|
|
|
if ctx.OtherModuleHasProvider(fragment, hiddenAPIFlagFileInfoProvider) {
|
|
|
|
info := ctx.OtherModuleProvider(fragment, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo)
|
|
|
|
flagFileInfo.append(info)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the information for testing.
|
|
|
|
ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo)
|
2021-04-09 03:12:41 +08:00
|
|
|
|
|
|
|
outputPath := hiddenAPISingletonPaths(ctx).flags
|
|
|
|
baseFlagsPath := hiddenAPISingletonPaths(ctx).stubFlags
|
2021-04-09 06:01:37 +08:00
|
|
|
ruleToGenerateHiddenApiFlags(ctx, outputPath, baseFlagsPath, moduleSpecificFlagsPaths, flagFileInfo)
|
2021-04-13 00:24:36 +08:00
|
|
|
|
2021-04-21 21:10:42 +08:00
|
|
|
b.generateHiddenAPIStubFlagsRules(ctx, hiddenAPISupportingModules)
|
2021-04-13 00:24:36 +08:00
|
|
|
b.generateHiddenAPIIndexRules(ctx, hiddenAPISupportingModules)
|
2021-04-13 07:14:38 +08:00
|
|
|
b.generatedHiddenAPIMetadataRules(ctx, hiddenAPISupportingModules)
|
2021-04-13 00:24:36 +08:00
|
|
|
}
|
|
|
|
|
2021-04-21 21:10:42 +08:00
|
|
|
func (b *platformBootclasspathModule) generateHiddenAPIStubFlagsRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) {
|
|
|
|
bootDexJars := android.Paths{}
|
|
|
|
for _, module := range modules {
|
|
|
|
bootDexJars = append(bootDexJars, module.bootDexJar())
|
|
|
|
}
|
|
|
|
|
|
|
|
sdkKindToStubPaths := hiddenAPIGatherStubLibDexJarPaths(ctx)
|
|
|
|
|
|
|
|
outputPath := hiddenAPISingletonPaths(ctx).stubFlags
|
|
|
|
rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, outputPath, bootDexJars, sdkKindToStubPaths)
|
|
|
|
rule.Build("platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags")
|
|
|
|
}
|
|
|
|
|
2021-04-13 00:24:36 +08:00
|
|
|
func (b *platformBootclasspathModule) generateHiddenAPIIndexRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) {
|
|
|
|
indexes := android.Paths{}
|
|
|
|
for _, module := range modules {
|
|
|
|
indexes = append(indexes, module.indexCSV())
|
|
|
|
}
|
|
|
|
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
rule.Command().
|
|
|
|
BuiltTool("merge_csv").
|
|
|
|
Flag("--key_field signature").
|
|
|
|
FlagWithArg("--header=", "signature,file,startline,startcol,endline,endcol,properties").
|
|
|
|
FlagWithOutput("--output=", hiddenAPISingletonPaths(ctx).index).
|
|
|
|
Inputs(indexes)
|
|
|
|
rule.Build("platform-bootclasspath-monolithic-hiddenapi-index", "monolithic hidden API index")
|
2021-04-09 03:12:41 +08:00
|
|
|
}
|
2021-04-13 07:14:38 +08:00
|
|
|
|
|
|
|
func (b *platformBootclasspathModule) generatedHiddenAPIMetadataRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) {
|
|
|
|
metadataCSVFiles := android.Paths{}
|
|
|
|
for _, module := range modules {
|
|
|
|
metadataCSVFiles = append(metadataCSVFiles, module.metadataCSV())
|
|
|
|
}
|
|
|
|
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
|
|
|
|
outputPath := hiddenAPISingletonPaths(ctx).metadata
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
BuiltTool("merge_csv").
|
|
|
|
Flag("--key_field signature").
|
|
|
|
FlagWithOutput("--output=", outputPath).
|
|
|
|
Inputs(metadataCSVFiles)
|
|
|
|
|
|
|
|
rule.Build("platform-bootclasspath-monolithic-hiddenapi-metadata", "monolithic hidden API metadata")
|
|
|
|
}
|
2021-04-26 23:44:00 +08:00
|
|
|
|
|
|
|
// generateBootImageBuildActions generates ninja rules related to the boot image creation.
|
2021-04-27 03:10:48 +08:00
|
|
|
func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext, updatableModules []android.Module) {
|
2021-04-26 23:44:00 +08:00
|
|
|
// 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)
|
|
|
|
|
|
|
|
imageConfig := b.getImageConfig(ctx)
|
|
|
|
if imageConfig == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
|
|
|
if !shouldBuildBootImages(ctx.Config(), global) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the framework profile rule
|
|
|
|
bootFrameworkProfileRule(ctx, imageConfig)
|
2021-04-27 03:10:48 +08:00
|
|
|
|
|
|
|
// Generate the updatable bootclasspath packages rule.
|
|
|
|
generateUpdatableBcpPackagesRule(ctx, imageConfig, updatableModules)
|
2021-04-26 23:44:00 +08:00
|
|
|
}
|