Merge "Export monolithic hidden API files from platform_bootclasspath" am: db173510d3 am: 64e6f0ff5d

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1673266

Change-Id: I35021b0746a5aa9ac071ca488ae530f950634159
This commit is contained in:
Paul Duffin 2021-04-13 12:15:17 +00:00 committed by Automerger Merge Worker
commit 703509119f
3 changed files with 99 additions and 4 deletions

View File

@ -101,11 +101,15 @@ var hiddenAPISingletonPathsKey = android.NewOnceKey("hiddenAPISingletonPathsKey"
// yet been created. // yet been created.
func hiddenAPISingletonPaths(ctx android.PathContext) hiddenAPISingletonPathsStruct { func hiddenAPISingletonPaths(ctx android.PathContext) hiddenAPISingletonPathsStruct {
return ctx.Config().Once(hiddenAPISingletonPathsKey, func() interface{} { return ctx.Config().Once(hiddenAPISingletonPathsKey, func() interface{} {
// Make the paths relative to the out/soong/hiddenapi directory instead of to the out/soong/
// directory. This ensures that if they are used as java_resources they do not end up in a
// hiddenapi directory in the resulting APK.
hiddenapiDir := android.PathForOutput(ctx, "hiddenapi")
return hiddenAPISingletonPathsStruct{ return hiddenAPISingletonPathsStruct{
flags: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-flags.csv"), flags: hiddenapiDir.Join(ctx, "hiddenapi-flags.csv"),
index: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-index.csv"), index: hiddenapiDir.Join(ctx, "hiddenapi-index.csv"),
metadata: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-unsupported.csv"), metadata: hiddenapiDir.Join(ctx, "hiddenapi-unsupported.csv"),
stubFlags: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-stub-flags.txt"), stubFlags: hiddenapiDir.Join(ctx, "hiddenapi-stub-flags.txt"),
} }
}).(hiddenAPISingletonPathsStruct) }).(hiddenAPISingletonPathsStruct)
} }

View File

@ -15,6 +15,8 @@
package java package java
import ( import (
"fmt"
"android/soong/android" "android/soong/android"
"android/soong/dexpreopt" "android/soong/dexpreopt"
"github.com/google/blueprint" "github.com/google/blueprint"
@ -69,6 +71,15 @@ type platformBootclasspathModule struct {
// //
// Currently only for testing. // Currently only for testing.
fragments []android.Module fragments []android.Module
// Path to the monolithic hiddenapi-flags.csv file.
hiddenAPIFlagsCSV android.Path
// Path to the monolithic hiddenapi-index.csv file.
hiddenAPIIndexCSV android.Path
// Path to the monolithic hiddenapi-unsupported.csv file.
hiddenAPIMetadataCSV android.Path
} }
// ApexVariantReference specifies a particular apex variant of a module. // ApexVariantReference specifies a particular apex variant of a module.
@ -98,6 +109,34 @@ func platformBootclasspathFactory() android.Module {
return m return m
} }
var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil)
// A minimal AndroidMkEntries is needed in order to support the dists property.
func (b *platformBootclasspathModule) AndroidMkEntries() []android.AndroidMkEntries {
return []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)",
},
}
}
// 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)
}
func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) { func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
if SkipDexpreoptBootJars(ctx) { if SkipDexpreoptBootJars(ctx) {
return return
@ -222,6 +261,17 @@ func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleCont
// generateHiddenAPIBuildActions generates all the hidden API related build rules. // generateHiddenAPIBuildActions generates all the hidden API related build rules.
func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module) { func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module) {
// Save the paths to the monolithic files for retrieval via OutputFiles()
// Make the paths relative to the out/soong/hiddenapi directory instead of to the out/soong/
// directory. This ensures that if they are used as java_resources they do not end up in a
// hiddenapi directory in the resulting APK.
relToHiddenapiDir := func(path android.OutputPath) android.Path {
return path
}
b.hiddenAPIFlagsCSV = relToHiddenapiDir(hiddenAPISingletonPaths(ctx).flags)
b.hiddenAPIIndexCSV = relToHiddenapiDir(hiddenAPISingletonPaths(ctx).index)
b.hiddenAPIMetadataCSV = relToHiddenapiDir(hiddenAPISingletonPaths(ctx).metadata)
moduleSpecificFlagsPaths := android.Paths{} moduleSpecificFlagsPaths := android.Paths{}
for _, module := range modules { for _, module := range modules {
if h, ok := module.(hiddenAPIIntf); ok { if h, ok := module.(hiddenAPIIntf); ok {

View File

@ -131,3 +131,44 @@ func TestPlatformBootclasspath(t *testing.T) {
}) })
}) })
} }
func TestPlatformBootclasspath_Dist(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForTestWithPlatformBootclasspath,
dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar"),
android.PrepareForTestWithAndroidMk,
android.FixtureWithRootAndroidBp(`
platform_bootclasspath {
name: "platform-bootclasspath",
dists: [
{
targets: ["droidcore"],
tag: "hiddenapi-flags.csv",
},
],
}
java_library {
name: "bar",
srcs: ["a.java"],
system_modules: "none",
sdk_version: "none",
compile_dex: true,
}
java_library {
name: "foo",
srcs: ["a.java"],
system_modules: "none",
sdk_version: "none",
compile_dex: true,
}
`),
).RunTest(t)
platformBootclasspath := result.Module("platform-bootclasspath", "android_common").(*platformBootclasspathModule)
entries := android.AndroidMkEntriesForTest(t, result.TestContext, platformBootclasspath)
goals := entries[0].GetDistForGoals(platformBootclasspath)
android.AssertStringEquals(t, "platform dist goals phony", ".PHONY: droidcore\n", goals[0])
android.AssertStringEquals(t, "platform dist goals call", "$(call dist-for-goals,droidcore,out/soong/hiddenapi/hiddenapi-flags.csv:hiddenapi-flags.csv)\n", android.StringRelativeToTop(result.Config, goals[1]))
}