2019-02-01 06:12:44 +08:00
|
|
|
// Copyright 2019 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 (
|
2019-06-10 21:15:04 +08:00
|
|
|
"fmt"
|
|
|
|
|
2019-02-01 06:12:44 +08:00
|
|
|
"android/soong/android"
|
2020-10-06 19:04:34 +08:00
|
|
|
"android/soong/genrule"
|
2019-02-01 06:12:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory)
|
2020-02-20 00:39:59 +08:00
|
|
|
android.RegisterSingletonType("hiddenapi_index", hiddenAPIIndexSingletonFactory)
|
2019-06-10 21:15:04 +08:00
|
|
|
android.RegisterModuleType("hiddenapi_flags", hiddenAPIFlagsFactory)
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type hiddenAPISingletonPathsStruct struct {
|
|
|
|
flags android.OutputPath
|
2020-02-20 00:39:59 +08:00
|
|
|
index android.OutputPath
|
2019-02-01 06:12:44 +08:00
|
|
|
metadata android.OutputPath
|
2020-02-20 00:39:59 +08:00
|
|
|
stubFlags android.OutputPath
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var hiddenAPISingletonPathsKey = android.NewOnceKey("hiddenAPISingletonPathsKey")
|
|
|
|
|
|
|
|
// hiddenAPISingletonPaths creates all the paths for singleton files the first time it is called, which may be
|
|
|
|
// from a ModuleContext that needs to reference a file that will be created by a singleton rule that hasn't
|
|
|
|
// yet been created.
|
|
|
|
func hiddenAPISingletonPaths(ctx android.PathContext) hiddenAPISingletonPathsStruct {
|
|
|
|
return ctx.Config().Once(hiddenAPISingletonPathsKey, func() interface{} {
|
|
|
|
return hiddenAPISingletonPathsStruct{
|
|
|
|
flags: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-flags.csv"),
|
2020-02-20 00:39:59 +08:00
|
|
|
index: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-index.csv"),
|
2020-08-11 00:23:52 +08:00
|
|
|
metadata: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-unsupported.csv"),
|
2020-02-20 00:39:59 +08:00
|
|
|
stubFlags: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-stub-flags.txt"),
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
}).(hiddenAPISingletonPathsStruct)
|
|
|
|
}
|
|
|
|
|
|
|
|
func hiddenAPISingletonFactory() android.Singleton {
|
2019-02-20 04:38:45 +08:00
|
|
|
return &hiddenAPISingleton{}
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
|
2019-02-20 04:38:45 +08:00
|
|
|
type hiddenAPISingleton struct {
|
|
|
|
flags, metadata android.Path
|
|
|
|
}
|
2019-02-01 06:12:44 +08:00
|
|
|
|
|
|
|
// hiddenAPI singleton rules
|
2019-02-20 04:38:45 +08:00
|
|
|
func (h *hiddenAPISingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
2019-02-01 06:12:44 +08:00
|
|
|
// Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true
|
|
|
|
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
stubFlagsRule(ctx)
|
|
|
|
|
|
|
|
// These rules depend on files located in frameworks/base, skip them if running in a tree that doesn't have them.
|
2019-07-15 14:29:23 +08:00
|
|
|
if ctx.Config().FrameworksBaseDirExists(ctx) {
|
2019-02-20 04:38:45 +08:00
|
|
|
h.flags = flagsRule(ctx)
|
|
|
|
h.metadata = metadataRule(ctx)
|
2019-02-01 06:12:44 +08:00
|
|
|
} else {
|
2019-02-20 04:38:45 +08:00
|
|
|
h.flags = emptyFlagsRule(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export paths to Make. INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
|
|
|
|
// Both paths are used to call dist-for-goals.
|
|
|
|
func (h *hiddenAPISingleton) MakeVars(ctx android.MakeVarsContext) {
|
|
|
|
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", h.flags.String())
|
|
|
|
|
|
|
|
if h.metadata != nil {
|
|
|
|
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_GREYLIST_METADATA", h.metadata.String())
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// stubFlagsRule creates the rule to build hiddenapi-stub-flags.txt out of dex jars from stub modules and boot image
|
|
|
|
// modules.
|
|
|
|
func stubFlagsRule(ctx android.SingletonContext) {
|
2020-07-03 22:31:32 +08:00
|
|
|
var publicStubModules []string
|
|
|
|
var systemStubModules []string
|
|
|
|
var testStubModules []string
|
|
|
|
var corePlatformStubModules []string
|
|
|
|
|
|
|
|
if ctx.Config().AlwaysUsePrebuiltSdks() {
|
|
|
|
// Build configuration mandates using prebuilt stub modules
|
|
|
|
publicStubModules = append(publicStubModules, "sdk_public_current_android")
|
|
|
|
systemStubModules = append(systemStubModules, "sdk_system_current_android")
|
|
|
|
testStubModules = append(testStubModules, "sdk_test_current_android")
|
|
|
|
} else {
|
|
|
|
// Use stub modules built from source
|
|
|
|
publicStubModules = append(publicStubModules, "android_stubs_current")
|
|
|
|
systemStubModules = append(systemStubModules, "android_system_stubs_current")
|
|
|
|
testStubModules = append(testStubModules, "android_test_stubs_current")
|
2019-03-01 00:15:44 +08:00
|
|
|
}
|
2020-07-03 22:31:32 +08:00
|
|
|
// We do not have prebuilts of the core platform api yet
|
|
|
|
corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs")
|
2019-03-01 00:15:44 +08:00
|
|
|
|
|
|
|
// Add the android.test.base to the set of stubs only if the android.test.base module is on
|
|
|
|
// the boot jars list as the runtime will only enforce hiddenapi access against modules on
|
|
|
|
// that list.
|
2020-07-03 22:31:32 +08:00
|
|
|
if inList("android.test.base", ctx.Config().BootJars()) {
|
|
|
|
if ctx.Config().AlwaysUsePrebuiltSdks() {
|
|
|
|
publicStubModules = append(publicStubModules, "sdk_public_current_android.test.base")
|
|
|
|
} else {
|
|
|
|
publicStubModules = append(publicStubModules, "android.test.base.stubs")
|
|
|
|
}
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allow products to define their own stubs for custom product jars that apps can use.
|
|
|
|
publicStubModules = append(publicStubModules, ctx.Config().ProductHiddenAPIStubs()...)
|
|
|
|
systemStubModules = append(systemStubModules, ctx.Config().ProductHiddenAPIStubsSystem()...)
|
|
|
|
testStubModules = append(testStubModules, ctx.Config().ProductHiddenAPIStubsTest()...)
|
2019-02-26 08:37:42 +08:00
|
|
|
if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") {
|
|
|
|
publicStubModules = append(publicStubModules, "jacoco-stubs")
|
|
|
|
}
|
2019-02-01 06:12:44 +08:00
|
|
|
|
|
|
|
publicStubPaths := make(android.Paths, len(publicStubModules))
|
|
|
|
systemStubPaths := make(android.Paths, len(systemStubModules))
|
|
|
|
testStubPaths := make(android.Paths, len(testStubModules))
|
|
|
|
corePlatformStubPaths := make(android.Paths, len(corePlatformStubModules))
|
|
|
|
|
|
|
|
moduleListToPathList := map[*[]string]android.Paths{
|
|
|
|
&publicStubModules: publicStubPaths,
|
|
|
|
&systemStubModules: systemStubPaths,
|
|
|
|
&testStubModules: testStubPaths,
|
|
|
|
&corePlatformStubModules: corePlatformStubPaths,
|
|
|
|
}
|
|
|
|
|
|
|
|
var bootDexJars android.Paths
|
|
|
|
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
// Collect dex jar paths for the modules listed above.
|
|
|
|
if j, ok := module.(Dependency); ok {
|
|
|
|
name := ctx.ModuleName(module)
|
|
|
|
for moduleList, pathList := range moduleListToPathList {
|
|
|
|
if i := android.IndexList(name, *moduleList); i != -1 {
|
2020-06-04 22:08:17 +08:00
|
|
|
pathList[i] = j.DexJarBuildPath()
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect dex jar paths for modules that had hiddenapi encode called on them.
|
|
|
|
if h, ok := module.(hiddenAPIIntf); ok {
|
|
|
|
if jar := h.bootDexJar(); jar != nil {
|
2019-12-19 10:11:10 +08:00
|
|
|
// For a java lib included in an APEX, only take the one built for
|
|
|
|
// the platform variant, and skip the variants for APEXes.
|
|
|
|
// Otherwise, the hiddenapi tool will complain about duplicated classes
|
2020-09-16 09:30:11 +08:00
|
|
|
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
if !apexInfo.IsForPlatform() {
|
|
|
|
return
|
2019-07-25 21:02:35 +08:00
|
|
|
}
|
2020-08-06 06:40:41 +08:00
|
|
|
|
2019-02-01 06:12:44 +08:00
|
|
|
bootDexJars = append(bootDexJars, jar)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var missingDeps []string
|
|
|
|
// Ensure all modules were converted to paths
|
|
|
|
for moduleList, pathList := range moduleListToPathList {
|
|
|
|
for i := range pathList {
|
|
|
|
if pathList[i] == nil {
|
2019-04-03 04:03:46 +08:00
|
|
|
pathList[i] = android.PathForOutput(ctx, "missing")
|
2019-02-01 06:12:44 +08:00
|
|
|
if ctx.Config().AllowMissingDependencies() {
|
|
|
|
missingDeps = append(missingDeps, (*moduleList)[i])
|
|
|
|
} else {
|
|
|
|
ctx.Errorf("failed to find dex jar path for module %q",
|
|
|
|
(*moduleList)[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Singleton rule which applies hiddenapi on all boot class path dex files.
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
|
|
|
|
outputPath := hiddenAPISingletonPaths(ctx).stubFlags
|
|
|
|
tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp")
|
|
|
|
|
|
|
|
rule.MissingDeps(missingDeps)
|
|
|
|
|
|
|
|
rule.Command().
|
2019-12-10 05:47:14 +08:00
|
|
|
Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")).
|
2019-02-01 06:12:44 +08:00
|
|
|
Text("list").
|
2019-02-16 02:39:37 +08:00
|
|
|
FlagForEachInput("--boot-dex=", bootDexJars).
|
|
|
|
FlagWithInputList("--public-stub-classpath=", publicStubPaths, ":").
|
2019-03-02 01:44:13 +08:00
|
|
|
FlagWithInputList("--system-stub-classpath=", systemStubPaths, ":").
|
|
|
|
FlagWithInputList("--test-stub-classpath=", testStubPaths, ":").
|
2019-02-16 02:39:37 +08:00
|
|
|
FlagWithInputList("--core-platform-stub-classpath=", corePlatformStubPaths, ":").
|
|
|
|
FlagWithOutput("--out-api-flags=", tempPath)
|
2019-02-01 06:12:44 +08:00
|
|
|
|
|
|
|
commitChangeForRestat(rule, tempPath, outputPath)
|
|
|
|
|
|
|
|
rule.Build(pctx, ctx, "hiddenAPIStubFlagsFile", "hiddenapi stub flags")
|
|
|
|
}
|
|
|
|
|
|
|
|
// flagsRule creates a rule to build hiddenapi-flags.csv out of flags.csv files generated for boot image modules and
|
2020-07-28 21:44:24 +08:00
|
|
|
// the unsupported API.
|
2019-02-20 04:38:45 +08:00
|
|
|
func flagsRule(ctx android.SingletonContext) android.Path {
|
2019-02-01 06:12:44 +08:00
|
|
|
var flagsCSV android.Paths
|
2020-10-06 19:04:34 +08:00
|
|
|
var combinedRemovedApis android.Path
|
2019-02-01 06:12:44 +08:00
|
|
|
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
if h, ok := module.(hiddenAPIIntf); ok {
|
|
|
|
if csv := h.flagsCSV(); csv != nil {
|
|
|
|
flagsCSV = append(flagsCSV, csv)
|
|
|
|
}
|
2020-10-06 19:04:34 +08:00
|
|
|
} else if g, ok := module.(*genrule.Module); ok {
|
|
|
|
if ctx.ModuleName(module) == "combined-removed-dex" {
|
|
|
|
if len(g.GeneratedSourceFiles()) != 1 || combinedRemovedApis != nil {
|
|
|
|
ctx.Errorf("Expected 1 combined-removed-dex module that generates 1 output file.")
|
|
|
|
}
|
|
|
|
combinedRemovedApis = g.GeneratedSourceFiles()[0]
|
2020-03-26 00:48:49 +08:00
|
|
|
}
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-10-06 19:04:34 +08:00
|
|
|
if combinedRemovedApis == nil {
|
|
|
|
ctx.Errorf("Failed to find combined-removed-dex.")
|
|
|
|
}
|
2019-02-01 06:12:44 +08:00
|
|
|
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
|
|
|
|
outputPath := hiddenAPISingletonPaths(ctx).flags
|
|
|
|
tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp")
|
|
|
|
|
|
|
|
stubFlags := hiddenAPISingletonPaths(ctx).stubFlags
|
|
|
|
|
|
|
|
rule.Command().
|
2019-02-16 02:39:37 +08:00
|
|
|
Tool(android.PathForSource(ctx, "frameworks/base/tools/hiddenapi/generate_hiddenapi_lists.py")).
|
|
|
|
FlagWithInput("--csv ", stubFlags).
|
|
|
|
Inputs(flagsCSV).
|
2020-07-28 21:44:24 +08:00
|
|
|
FlagWithInput("--unsupported ",
|
2020-08-04 22:34:35 +08:00
|
|
|
android.PathForSource(ctx, "frameworks/base/config/hiddenapi-unsupported.txt")).
|
2020-10-20 22:23:04 +08:00
|
|
|
FlagWithInput("--unsupported ", combinedRemovedApis).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed").
|
2020-07-28 21:44:24 +08:00
|
|
|
FlagWithInput("--max-target-q ",
|
2020-08-04 22:34:35 +08:00
|
|
|
android.PathForSource(ctx, "frameworks/base/config/hiddenapi-max-target-q.txt")).
|
2020-07-28 21:44:24 +08:00
|
|
|
FlagWithInput("--max-target-p ",
|
2020-08-04 22:34:35 +08:00
|
|
|
android.PathForSource(ctx, "frameworks/base/config/hiddenapi-max-target-p.txt")).
|
2020-10-20 22:23:04 +08:00
|
|
|
FlagWithInput("--max-target-o ", android.PathForSource(
|
|
|
|
ctx, "frameworks/base/config/hiddenapi-max-target-o.txt")).Flag("--ignore-conflicts ").
|
2020-07-28 21:44:24 +08:00
|
|
|
FlagWithInput("--blocked ",
|
2020-08-04 22:34:35 +08:00
|
|
|
android.PathForSource(ctx, "frameworks/base/config/hiddenapi-force-blocked.txt")).
|
2020-11-04 18:13:34 +08:00
|
|
|
FlagWithInput("--blocked ",
|
|
|
|
android.PathForSource(ctx, "frameworks/base/config/hiddenapi-temp-blocklist.txt")).
|
2020-10-20 22:23:04 +08:00
|
|
|
FlagWithInput("--unsupported ", android.PathForSource(
|
|
|
|
ctx, "frameworks/base/config/hiddenapi-unsupported-packages.txt")).Flag("--packages ").
|
2019-02-16 02:39:37 +08:00
|
|
|
FlagWithOutput("--output ", tempPath)
|
2019-02-01 06:12:44 +08:00
|
|
|
|
|
|
|
commitChangeForRestat(rule, tempPath, outputPath)
|
|
|
|
|
|
|
|
rule.Build(pctx, ctx, "hiddenAPIFlagsFile", "hiddenapi flags")
|
2019-02-20 04:38:45 +08:00
|
|
|
|
|
|
|
return outputPath
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// emptyFlagsRule creates a rule to build an empty hiddenapi-flags.csv, which is needed by master-art-host builds that
|
|
|
|
// have a partial manifest without frameworks/base but still need to build a boot image.
|
2019-02-20 04:38:45 +08:00
|
|
|
func emptyFlagsRule(ctx android.SingletonContext) android.Path {
|
2019-02-01 06:12:44 +08:00
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
|
|
|
|
outputPath := hiddenAPISingletonPaths(ctx).flags
|
|
|
|
|
2019-02-16 02:39:37 +08:00
|
|
|
rule.Command().Text("rm").Flag("-f").Output(outputPath)
|
|
|
|
rule.Command().Text("touch").Output(outputPath)
|
2019-02-01 06:12:44 +08:00
|
|
|
|
|
|
|
rule.Build(pctx, ctx, "emptyHiddenAPIFlagsFile", "empty hiddenapi flags")
|
2019-02-20 04:38:45 +08:00
|
|
|
|
|
|
|
return outputPath
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
|
2020-08-11 00:23:52 +08:00
|
|
|
// metadataRule creates a rule to build hiddenapi-unsupported.csv out of the metadata.csv files generated for boot image
|
2019-02-01 06:12:44 +08:00
|
|
|
// modules.
|
2019-02-20 04:38:45 +08:00
|
|
|
func metadataRule(ctx android.SingletonContext) android.Path {
|
2019-02-01 06:12:44 +08:00
|
|
|
var metadataCSV android.Paths
|
|
|
|
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
if h, ok := module.(hiddenAPIIntf); ok {
|
|
|
|
if csv := h.metadataCSV(); csv != nil {
|
|
|
|
metadataCSV = append(metadataCSV, csv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
|
|
|
|
outputPath := hiddenAPISingletonPaths(ctx).metadata
|
|
|
|
|
|
|
|
rule.Command().
|
2020-01-21 01:53:31 +08:00
|
|
|
BuiltTool(ctx, "merge_csv").
|
2020-01-21 03:11:33 +08:00
|
|
|
FlagWithOutput("--output=", outputPath).
|
|
|
|
Inputs(metadataCSV)
|
2019-02-01 06:12:44 +08:00
|
|
|
|
|
|
|
rule.Build(pctx, ctx, "hiddenAPIGreylistMetadataFile", "hiddenapi greylist metadata")
|
2019-02-20 04:38:45 +08:00
|
|
|
|
|
|
|
return outputPath
|
2019-02-01 06:12:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// commitChangeForRestat adds a command to a rule that updates outputPath from tempPath if they are different. It
|
|
|
|
// also marks the rule as restat and marks the tempPath as a temporary file that should not be considered an output of
|
|
|
|
// the rule.
|
|
|
|
func commitChangeForRestat(rule *android.RuleBuilder, tempPath, outputPath android.WritablePath) {
|
|
|
|
rule.Restat()
|
2019-02-16 02:39:37 +08:00
|
|
|
rule.Temporary(tempPath)
|
2019-02-01 06:12:44 +08:00
|
|
|
rule.Command().
|
|
|
|
Text("(").
|
|
|
|
Text("if").
|
2019-02-16 02:39:37 +08:00
|
|
|
Text("cmp -s").Input(tempPath).Output(outputPath).Text(";").
|
2019-02-01 06:12:44 +08:00
|
|
|
Text("then").
|
2019-02-16 02:39:37 +08:00
|
|
|
Text("rm").Input(tempPath).Text(";").
|
2019-02-01 06:12:44 +08:00
|
|
|
Text("else").
|
2019-02-16 02:39:37 +08:00
|
|
|
Text("mv").Input(tempPath).Output(outputPath).Text(";").
|
2019-02-01 06:12:44 +08:00
|
|
|
Text("fi").
|
|
|
|
Text(")")
|
|
|
|
}
|
2019-06-10 21:15:04 +08:00
|
|
|
|
|
|
|
type hiddenAPIFlagsProperties struct {
|
|
|
|
// name of the file into which the flags will be copied.
|
|
|
|
Filename *string
|
|
|
|
}
|
|
|
|
|
|
|
|
type hiddenAPIFlags struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
properties hiddenAPIFlagsProperties
|
|
|
|
|
|
|
|
outputFilePath android.OutputPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *hiddenAPIFlags) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
filename := String(h.properties.Filename)
|
|
|
|
|
|
|
|
inputPath := hiddenAPISingletonPaths(ctx).flags
|
|
|
|
h.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
|
|
|
|
|
|
|
|
// This ensures that outputFilePath has the correct name for others to
|
|
|
|
// use, as the source file may have a different name.
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Output: h.outputFilePath,
|
|
|
|
Input: inputPath,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *hiddenAPIFlags) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "":
|
|
|
|
return android.Paths{h.outputFilePath}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// hiddenapi-flags provides access to the hiddenapi-flags.csv file generated during the build.
|
|
|
|
func hiddenAPIFlagsFactory() android.Module {
|
|
|
|
module := &hiddenAPIFlags{}
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
|
|
|
|
return module
|
|
|
|
}
|
2020-02-20 00:39:59 +08:00
|
|
|
|
|
|
|
func hiddenAPIIndexSingletonFactory() android.Singleton {
|
|
|
|
return &hiddenAPIIndexSingleton{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type hiddenAPIIndexSingleton struct {
|
|
|
|
index android.Path
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *hiddenAPIIndexSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
|
|
|
// Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true
|
|
|
|
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
indexes := android.Paths{}
|
|
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
|
|
if h, ok := module.(hiddenAPIIntf); ok {
|
|
|
|
if h.indexCSV() != nil {
|
|
|
|
indexes = append(indexes, h.indexCSV())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
rule.Command().
|
|
|
|
BuiltTool(ctx, "merge_csv").
|
|
|
|
FlagWithArg("--header=", "signature,file,startline,startcol,endline,endcol,properties").
|
|
|
|
FlagWithOutput("--output=", hiddenAPISingletonPaths(ctx).index).
|
|
|
|
Inputs(indexes)
|
|
|
|
rule.Build(pctx, ctx, "singleton-merged-hiddenapi-index", "Singleton merged Hidden API index")
|
|
|
|
|
|
|
|
h.index = hiddenAPISingletonPaths(ctx).index
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *hiddenAPIIndexSingleton) MakeVars(ctx android.MakeVarsContext) {
|
|
|
|
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_INDEX", h.index.String())
|
|
|
|
}
|