Add hidden API properties to java_sdk_library modules

Previously, hidden API properties were only allowed on
bootclasspath_fragment and platform_bootclasspath module types. This
change allows them to be specified on java_sdk_library modules too. It
involves the following changes:

1. Add the properties to the java.Module.
2. Populate and provide a HiddenAPIPropertyInfo struct from
   java_sdk_library modules.
3. Modify bootclasspath_fragment to merge information gathered from its
   content libraries as if it was specified on the fragment itself.

Bug: 240406019
Test: m nothing
      packages/modules/common/build/mainline_modules_sdks.sh
      # Ran the previous command with and without this change to make
      # sure that this change does not change the sdk snapshot
      # contents.
Change-Id: I64eb71c2039ddc14cf380689d0cec7ec221f5b88
(cherry picked from commit 3f1ae0b55a)
Merged-In: I64eb71c2039ddc14cf380689d0cec7ec221f5b88
This commit is contained in:
Paul Duffin
2022-07-27 16:27:42 +00:00
committed by Cherrypicker Worker
parent 067e12f46a
commit b5e3c9802a
6 changed files with 230 additions and 8 deletions

View File

@@ -15,6 +15,7 @@
package java
import (
"strings"
"testing"
"android/soong/android"
@@ -285,6 +286,119 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) {
android.AssertPathsRelativeToTopEquals(t, "widest dex stubs jar", expectedWidestPaths, info.TransitiveStubDexJarsByScope.StubDexJarsForWidestAPIScope())
}
func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForTestWithBootclasspathFragment,
PrepareForTestWithJavaSdkLibraryFiles,
FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"),
FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"),
android.MockFS{
"my-blocked.txt": nil,
"my-max-target-o-low-priority.txt": nil,
"my-max-target-p.txt": nil,
"my-max-target-q.txt": nil,
"my-max-target-r-low-priority.txt": nil,
"my-removed.txt": nil,
"my-unsupported-packages.txt": nil,
"my-unsupported.txt": nil,
"my-new-max-target-q.txt": nil,
}.AddToFixture(),
android.FixtureWithRootAndroidBp(`
bootclasspath_fragment {
name: "mybootclasspathfragment",
apex_available: ["myapex"],
contents: ["mybootlib", "mynewlibrary"],
hidden_api: {
unsupported: [
"my-unsupported.txt",
],
removed: [
"my-removed.txt",
],
max_target_r_low_priority: [
"my-max-target-r-low-priority.txt",
],
max_target_q: [
"my-max-target-q.txt",
],
max_target_p: [
"my-max-target-p.txt",
],
max_target_o_low_priority: [
"my-max-target-o-low-priority.txt",
],
blocked: [
"my-blocked.txt",
],
unsupported_packages: [
"my-unsupported-packages.txt",
],
split_packages: ["sdklibrary"],
package_prefixes: ["sdklibrary.all.mine"],
single_packages: ["sdklibrary.mine"],
},
}
java_library {
name: "mybootlib",
apex_available: ["myapex"],
srcs: ["Test.java"],
system_modules: "none",
sdk_version: "none",
min_sdk_version: "1",
compile_dex: true,
permitted_packages: ["mybootlib"],
}
java_sdk_library {
name: "mynewlibrary",
apex_available: ["myapex"],
srcs: ["Test.java"],
min_sdk_version: "10",
compile_dex: true,
public: {enabled: true},
permitted_packages: ["mysdklibrary"],
hidden_api: {
max_target_q: [
"my-new-max-target-q.txt",
],
split_packages: ["sdklibrary", "newlibrary"],
package_prefixes: ["newlibrary.all.mine"],
single_packages: ["newlibrary.mine"],
},
}
`),
).RunTest(t)
// Make sure that the library exports hidden API properties for use by the bootclasspath_fragment.
library := result.Module("mynewlibrary", "android_common")
info := result.ModuleProvider(library, hiddenAPIPropertyInfoProvider).(HiddenAPIPropertyInfo)
android.AssertArrayString(t, "split packages", []string{"sdklibrary", "newlibrary"}, info.SplitPackages)
android.AssertArrayString(t, "package prefixes", []string{"newlibrary.all.mine"}, info.PackagePrefixes)
android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages)
for _, c := range HiddenAPIFlagFileCategories {
expectedMaxTargetQPaths := []string(nil)
if c.PropertyName == "max_target_q" {
expectedMaxTargetQPaths = []string{"my-new-max-target-q.txt"}
}
android.AssertPathsRelativeToTopEquals(t, c.PropertyName, expectedMaxTargetQPaths, info.FlagFilesByCategory[c])
}
// Make sure that the signature-patterns.csv is passed all the appropriate package properties
// from the bootclasspath_fragment and its contents.
fragment := result.ModuleForTests("mybootclasspathfragment", "android_common")
rule := fragment.Output("modular-hiddenapi/signature-patterns.csv")
expectedCommand := strings.Join([]string{
"--split-package newlibrary",
"--split-package sdklibrary",
"--package-prefix newlibrary.all.mine",
"--package-prefix sdklibrary.all.mine",
"--single-package newlibrary.mine",
"--single-package sdklibrary",
}, " ")
android.AssertStringDoesContain(t, "signature patterns command", rule.RuleParams.Command, expectedCommand)
}
func TestBootclasspathFragment_Test(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForTestWithBootclasspathFragment,