2021-04-09 00:49:27 +08: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 (
|
|
|
|
"android/soong/android"
|
2021-04-09 06:01:37 +08:00
|
|
|
"github.com/google/blueprint"
|
2021-04-09 00:49:27 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Contains support for processing hiddenAPI in a modular fashion.
|
|
|
|
|
2021-04-14 22:01:56 +08:00
|
|
|
// HiddenAPIFlagFileProperties contains paths to the flag files that can be used to augment the
|
|
|
|
// information obtained from annotations within the source code in order to create the complete set
|
|
|
|
// of flags that should be applied to the dex implementation jars on the bootclasspath.
|
2021-04-09 00:49:27 +08:00
|
|
|
//
|
|
|
|
// Each property contains a list of paths. With the exception of the Unsupported_packages the paths
|
|
|
|
// of each property reference a plain text file that contains a java signature per line. The flags
|
|
|
|
// for each of those signatures will be updated in a property specific way.
|
|
|
|
//
|
|
|
|
// The Unsupported_packages property contains a list of paths, each of which is a plain text file
|
|
|
|
// with one Java package per line. All members of all classes within that package (but not nested
|
|
|
|
// packages) will be updated in a property specific way.
|
2021-04-14 22:01:56 +08:00
|
|
|
type HiddenAPIFlagFileProperties struct {
|
2021-04-09 00:49:27 +08:00
|
|
|
// Marks each signature in the referenced files as being unsupported.
|
2021-04-09 03:12:41 +08:00
|
|
|
Unsupported []string `android:"path"`
|
2021-04-09 00:49:27 +08:00
|
|
|
|
|
|
|
// Marks each signature in the referenced files as being unsupported because it has been removed.
|
|
|
|
// Any conflicts with other flags are ignored.
|
2021-04-09 03:12:41 +08:00
|
|
|
Removed []string `android:"path"`
|
2021-04-09 00:49:27 +08:00
|
|
|
|
|
|
|
// Marks each signature in the referenced files as being supported only for targetSdkVersion <= R
|
|
|
|
// and low priority.
|
2021-04-09 03:12:41 +08:00
|
|
|
Max_target_r_low_priority []string `android:"path"`
|
2021-04-09 00:49:27 +08:00
|
|
|
|
|
|
|
// Marks each signature in the referenced files as being supported only for targetSdkVersion <= Q.
|
2021-04-09 03:12:41 +08:00
|
|
|
Max_target_q []string `android:"path"`
|
2021-04-09 00:49:27 +08:00
|
|
|
|
|
|
|
// Marks each signature in the referenced files as being supported only for targetSdkVersion <= P.
|
2021-04-09 03:12:41 +08:00
|
|
|
Max_target_p []string `android:"path"`
|
2021-04-09 00:49:27 +08:00
|
|
|
|
|
|
|
// Marks each signature in the referenced files as being supported only for targetSdkVersion <= O
|
|
|
|
// and low priority. Any conflicts with other flags are ignored.
|
2021-04-09 03:12:41 +08:00
|
|
|
Max_target_o_low_priority []string `android:"path"`
|
2021-04-09 00:49:27 +08:00
|
|
|
|
|
|
|
// Marks each signature in the referenced files as being blocked.
|
2021-04-09 03:12:41 +08:00
|
|
|
Blocked []string `android:"path"`
|
2021-04-09 00:49:27 +08:00
|
|
|
|
|
|
|
// Marks each signature in every package in the referenced files as being unsupported.
|
2021-04-09 03:12:41 +08:00
|
|
|
Unsupported_packages []string `android:"path"`
|
|
|
|
}
|
|
|
|
|
2021-04-14 22:01:56 +08:00
|
|
|
func (p *HiddenAPIFlagFileProperties) hiddenAPIFlagFileInfo(ctx android.ModuleContext) hiddenAPIFlagFileInfo {
|
|
|
|
info := hiddenAPIFlagFileInfo{categoryToPaths: map[*hiddenAPIFlagFileCategory]android.Paths{}}
|
2021-04-14 16:50:43 +08:00
|
|
|
for _, category := range hiddenAPIFlagFileCategories {
|
2021-04-19 20:21:20 +08:00
|
|
|
paths := android.PathsForModuleSrc(ctx, category.propertyValueReader(p))
|
2021-04-14 16:50:43 +08:00
|
|
|
info.categoryToPaths[category] = paths
|
2021-04-09 03:12:41 +08:00
|
|
|
}
|
2021-04-14 16:50:43 +08:00
|
|
|
return info
|
2021-04-09 03:12:41 +08:00
|
|
|
}
|
|
|
|
|
2021-04-14 16:50:43 +08:00
|
|
|
type hiddenAPIFlagFileCategory struct {
|
|
|
|
// propertyName is the name of the property for this category.
|
|
|
|
propertyName string
|
2021-04-09 03:12:41 +08:00
|
|
|
|
2021-04-19 20:21:20 +08:00
|
|
|
// propertyValueReader retrieves the value of the property for this category from the set of
|
2021-04-14 16:50:43 +08:00
|
|
|
// properties.
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader func(properties *HiddenAPIFlagFileProperties) []string
|
2021-04-09 03:12:41 +08:00
|
|
|
|
2021-04-14 16:50:43 +08:00
|
|
|
// commandMutator adds the appropriate command line options for this category to the supplied
|
|
|
|
// command
|
|
|
|
commandMutator func(command *android.RuleBuilderCommand, path android.Path)
|
|
|
|
}
|
2021-04-09 03:12:41 +08:00
|
|
|
|
2021-04-14 16:50:43 +08:00
|
|
|
var hiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{
|
2021-04-14 22:01:56 +08:00
|
|
|
// See HiddenAPIFlagFileProperties.Unsupported
|
2021-04-14 16:50:43 +08:00
|
|
|
{
|
|
|
|
propertyName: "unsupported",
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string {
|
2021-04-14 16:50:43 +08:00
|
|
|
return properties.Unsupported
|
|
|
|
},
|
|
|
|
commandMutator: func(command *android.RuleBuilderCommand, path android.Path) {
|
|
|
|
command.FlagWithInput("--unsupported ", path)
|
|
|
|
},
|
|
|
|
},
|
2021-04-14 22:01:56 +08:00
|
|
|
// See HiddenAPIFlagFileProperties.Removed
|
2021-04-14 16:50:43 +08:00
|
|
|
{
|
|
|
|
propertyName: "removed",
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string {
|
2021-04-14 16:50:43 +08:00
|
|
|
return properties.Removed
|
|
|
|
},
|
|
|
|
commandMutator: func(command *android.RuleBuilderCommand, path android.Path) {
|
|
|
|
command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed")
|
|
|
|
},
|
|
|
|
},
|
2021-04-14 22:01:56 +08:00
|
|
|
// See HiddenAPIFlagFileProperties.Max_target_r_low_priority
|
2021-04-14 16:50:43 +08:00
|
|
|
{
|
|
|
|
propertyName: "max_target_r_low_priority",
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string {
|
2021-04-14 16:50:43 +08:00
|
|
|
return properties.Max_target_r_low_priority
|
|
|
|
},
|
|
|
|
commandMutator: func(command *android.RuleBuilderCommand, path android.Path) {
|
|
|
|
command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio")
|
|
|
|
},
|
|
|
|
},
|
2021-04-14 22:01:56 +08:00
|
|
|
// See HiddenAPIFlagFileProperties.Max_target_q
|
2021-04-14 16:50:43 +08:00
|
|
|
{
|
|
|
|
propertyName: "max_target_q",
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string {
|
2021-04-14 16:50:43 +08:00
|
|
|
return properties.Max_target_q
|
|
|
|
},
|
|
|
|
commandMutator: func(command *android.RuleBuilderCommand, path android.Path) {
|
|
|
|
command.FlagWithInput("--max-target-q ", path)
|
|
|
|
},
|
|
|
|
},
|
2021-04-14 22:01:56 +08:00
|
|
|
// See HiddenAPIFlagFileProperties.Max_target_p
|
2021-04-14 16:50:43 +08:00
|
|
|
{
|
|
|
|
propertyName: "max_target_p",
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string {
|
2021-04-14 16:50:43 +08:00
|
|
|
return properties.Max_target_p
|
|
|
|
},
|
|
|
|
commandMutator: func(command *android.RuleBuilderCommand, path android.Path) {
|
|
|
|
command.FlagWithInput("--max-target-p ", path)
|
|
|
|
},
|
|
|
|
},
|
2021-04-14 22:01:56 +08:00
|
|
|
// See HiddenAPIFlagFileProperties.Max_target_o_low_priority
|
2021-04-14 16:50:43 +08:00
|
|
|
{
|
|
|
|
propertyName: "max_target_o_low_priority",
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string {
|
2021-04-14 16:50:43 +08:00
|
|
|
return properties.Max_target_o_low_priority
|
|
|
|
},
|
|
|
|
commandMutator: func(command *android.RuleBuilderCommand, path android.Path) {
|
|
|
|
command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio")
|
|
|
|
},
|
|
|
|
},
|
2021-04-14 22:01:56 +08:00
|
|
|
// See HiddenAPIFlagFileProperties.Blocked
|
2021-04-14 16:50:43 +08:00
|
|
|
{
|
|
|
|
propertyName: "blocked",
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string {
|
2021-04-14 16:50:43 +08:00
|
|
|
return properties.Blocked
|
|
|
|
},
|
|
|
|
commandMutator: func(command *android.RuleBuilderCommand, path android.Path) {
|
|
|
|
command.FlagWithInput("--blocked ", path)
|
|
|
|
},
|
|
|
|
},
|
2021-04-14 22:01:56 +08:00
|
|
|
// See HiddenAPIFlagFileProperties.Unsupported_packages
|
2021-04-14 16:50:43 +08:00
|
|
|
{
|
|
|
|
propertyName: "unsupported_packages",
|
2021-04-19 20:21:20 +08:00
|
|
|
propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string {
|
2021-04-14 16:50:43 +08:00
|
|
|
return properties.Unsupported_packages
|
|
|
|
},
|
|
|
|
commandMutator: func(command *android.RuleBuilderCommand, path android.Path) {
|
|
|
|
command.FlagWithInput("--unsupported ", path).Flag("--packages ")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-14 22:01:56 +08:00
|
|
|
// hiddenAPIFlagFileInfo contains paths resolved from HiddenAPIFlagFileProperties
|
|
|
|
type hiddenAPIFlagFileInfo struct {
|
2021-04-14 16:50:43 +08:00
|
|
|
// categoryToPaths maps from the flag file category to the paths containing information for that
|
|
|
|
// category.
|
|
|
|
categoryToPaths map[*hiddenAPIFlagFileCategory]android.Paths
|
2021-04-09 00:49:27 +08:00
|
|
|
}
|
2021-04-09 03:12:41 +08:00
|
|
|
|
2021-04-09 06:01:37 +08:00
|
|
|
func (i *hiddenAPIFlagFileInfo) append(other hiddenAPIFlagFileInfo) {
|
|
|
|
for _, category := range hiddenAPIFlagFileCategories {
|
|
|
|
i.categoryToPaths[category] = append(i.categoryToPaths[category], other.categoryToPaths[category]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var hiddenAPIFlagFileInfoProvider = blueprint.NewProvider(hiddenAPIFlagFileInfo{})
|
|
|
|
|
2021-04-09 03:12:41 +08:00
|
|
|
// ruleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from the
|
|
|
|
// flags from all the modules, the stub flags, augmented with some additional configuration files.
|
|
|
|
//
|
|
|
|
// baseFlagsPath is the path to the flags file containing all the information from the stubs plus
|
|
|
|
// an entry for every single member in the dex implementation jars of the individual modules. Every
|
|
|
|
// signature in any of the other files MUST be included in this file.
|
|
|
|
//
|
|
|
|
// moduleSpecificFlagsPaths are the paths to the flags files generated by each module using
|
|
|
|
// information from the baseFlagsPath as well as from annotations within the source.
|
|
|
|
//
|
|
|
|
// augmentationInfo is a struct containing paths to files that augment the information provided by
|
|
|
|
// the moduleSpecificFlagsPaths.
|
|
|
|
// ruleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from the
|
|
|
|
// flags from all the modules, the stub flags, augmented with some additional configuration files.
|
|
|
|
//
|
|
|
|
// baseFlagsPath is the path to the flags file containing all the information from the stubs plus
|
|
|
|
// an entry for every single member in the dex implementation jars of the individual modules. Every
|
|
|
|
// signature in any of the other files MUST be included in this file.
|
|
|
|
//
|
|
|
|
// moduleSpecificFlagsPaths are the paths to the flags files generated by each module using
|
|
|
|
// information from the baseFlagsPath as well as from annotations within the source.
|
|
|
|
//
|
|
|
|
// augmentationInfo is a struct containing paths to files that augment the information provided by
|
|
|
|
// the moduleSpecificFlagsPaths.
|
2021-04-14 22:01:56 +08:00
|
|
|
func ruleToGenerateHiddenApiFlags(ctx android.BuilderContext, outputPath android.WritablePath, baseFlagsPath android.Path, moduleSpecificFlagsPaths android.Paths, augmentationInfo hiddenAPIFlagFileInfo) {
|
2021-04-09 03:12:41 +08:00
|
|
|
tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp")
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
|
|
|
command := rule.Command().
|
|
|
|
BuiltTool("generate_hiddenapi_lists").
|
|
|
|
FlagWithInput("--csv ", baseFlagsPath).
|
|
|
|
Inputs(moduleSpecificFlagsPaths).
|
|
|
|
FlagWithOutput("--output ", tempPath)
|
|
|
|
|
2021-04-14 16:50:43 +08:00
|
|
|
// Add the options for the different categories of flag files.
|
|
|
|
for _, category := range hiddenAPIFlagFileCategories {
|
|
|
|
paths := augmentationInfo.categoryToPaths[category]
|
|
|
|
for _, path := range paths {
|
|
|
|
category.commandMutator(command, path)
|
|
|
|
}
|
2021-04-09 03:12:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
commitChangeForRestat(rule, tempPath, outputPath)
|
|
|
|
|
|
|
|
rule.Build("hiddenAPIFlagsFile", "hiddenapi flags")
|
|
|
|
}
|