2021-03-22 23:09:42 +01: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 apex
|
|
|
|
|
|
|
|
import (
|
2021-06-09 15:32:53 +02:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
2021-03-22 23:09:42 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2023-05-11 17:39:27 +02:00
|
|
|
"android/soong/dexpreopt"
|
2021-03-22 23:09:42 +01:00
|
|
|
"android/soong/java"
|
2021-09-08 22:56:18 +02:00
|
|
|
|
2021-03-22 23:09:42 +01:00
|
|
|
"github.com/google/blueprint"
|
2021-05-19 10:36:09 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2021-03-22 23:09:42 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Contains tests for platform_bootclasspath logic from java/platform_bootclasspath.go that requires
|
|
|
|
// apexes.
|
|
|
|
|
|
|
|
var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers(
|
2023-05-11 17:39:27 +02:00
|
|
|
java.PrepareForTestWithJavaDefaultModules,
|
2021-03-22 23:09:42 +01:00
|
|
|
PrepareForTestWithApexBuildComponents,
|
|
|
|
)
|
|
|
|
|
2021-06-09 15:32:53 +02:00
|
|
|
func TestPlatformBootclasspath_Fragments(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithPlatformBootclasspath,
|
2021-06-09 16:31:05 +02:00
|
|
|
prepareForTestWithMyapex,
|
2021-06-09 15:32:53 +02:00
|
|
|
java.PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
java.FixtureWithLastReleaseApis("foo"),
|
2021-08-06 18:49:46 +02:00
|
|
|
java.FixtureConfigureApexBootJars("myapex:bar"),
|
2021-06-09 15:32:53 +02:00
|
|
|
android.FixtureWithRootAndroidBp(`
|
|
|
|
platform_bootclasspath {
|
|
|
|
name: "platform-bootclasspath",
|
|
|
|
fragments: [
|
2021-06-09 16:31:05 +02:00
|
|
|
{
|
|
|
|
apex: "myapex",
|
|
|
|
module:"bar-fragment",
|
|
|
|
},
|
2021-06-09 15:32:53 +02:00
|
|
|
],
|
|
|
|
hidden_api: {
|
|
|
|
unsupported: [
|
|
|
|
"unsupported.txt",
|
|
|
|
],
|
|
|
|
removed: [
|
|
|
|
"removed.txt",
|
|
|
|
],
|
|
|
|
max_target_r_low_priority: [
|
|
|
|
"max-target-r-low-priority.txt",
|
|
|
|
],
|
|
|
|
max_target_q: [
|
|
|
|
"max-target-q.txt",
|
|
|
|
],
|
|
|
|
max_target_p: [
|
|
|
|
"max-target-p.txt",
|
|
|
|
],
|
|
|
|
max_target_o_low_priority: [
|
|
|
|
"max-target-o-low-priority.txt",
|
|
|
|
],
|
|
|
|
blocked: [
|
|
|
|
"blocked.txt",
|
|
|
|
],
|
|
|
|
unsupported_packages: [
|
|
|
|
"unsupported-packages.txt",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-06-09 16:31:05 +02:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
bootclasspath_fragments: [
|
|
|
|
"bar-fragment",
|
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
2021-06-09 15:32:53 +02:00
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "bar-fragment",
|
|
|
|
contents: ["bar"],
|
2021-06-09 16:31:05 +02:00
|
|
|
apex_available: ["myapex"],
|
2021-06-09 15:32:53 +02:00
|
|
|
api: {
|
|
|
|
stub_libs: ["foo"],
|
|
|
|
},
|
|
|
|
hidden_api: {
|
|
|
|
unsupported: [
|
|
|
|
"bar-unsupported.txt",
|
|
|
|
],
|
|
|
|
removed: [
|
|
|
|
"bar-removed.txt",
|
|
|
|
],
|
|
|
|
max_target_r_low_priority: [
|
|
|
|
"bar-max-target-r-low-priority.txt",
|
|
|
|
],
|
|
|
|
max_target_q: [
|
|
|
|
"bar-max-target-q.txt",
|
|
|
|
],
|
|
|
|
max_target_p: [
|
|
|
|
"bar-max-target-p.txt",
|
|
|
|
],
|
|
|
|
max_target_o_low_priority: [
|
|
|
|
"bar-max-target-o-low-priority.txt",
|
|
|
|
],
|
|
|
|
blocked: [
|
|
|
|
"bar-blocked.txt",
|
|
|
|
],
|
|
|
|
unsupported_packages: [
|
|
|
|
"bar-unsupported-packages.txt",
|
|
|
|
],
|
2022-03-31 16:42:30 +02:00
|
|
|
split_packages: ["*"],
|
2021-06-09 15:32:53 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
2021-06-09 16:31:05 +02:00
|
|
|
apex_available: ["myapex"],
|
2021-06-09 15:32:53 +02:00
|
|
|
srcs: ["a.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
compile_dex: true,
|
2021-06-09 16:31:05 +02:00
|
|
|
permitted_packages: ["bar"],
|
2021-06-09 15:32:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
public: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
compile_dex: true,
|
|
|
|
}
|
|
|
|
`),
|
|
|
|
).RunTest(t)
|
|
|
|
|
|
|
|
pbcp := result.Module("platform-bootclasspath", "android_common")
|
2023-12-14 23:46:23 +01:00
|
|
|
info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider)
|
2021-06-09 15:32:53 +02:00
|
|
|
|
|
|
|
for _, category := range java.HiddenAPIFlagFileCategories {
|
|
|
|
name := category.PropertyName
|
|
|
|
message := fmt.Sprintf("category %s", name)
|
|
|
|
filename := strings.ReplaceAll(name, "_", "-")
|
|
|
|
expected := []string{fmt.Sprintf("%s.txt", filename), fmt.Sprintf("bar-%s.txt", filename)}
|
|
|
|
android.AssertPathsRelativeToTopEquals(t, message, expected, info.FlagsFilesByCategory[category])
|
|
|
|
}
|
|
|
|
|
2021-06-09 16:31:05 +02:00
|
|
|
android.AssertPathsRelativeToTopEquals(t, "annotation flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/annotation-flags.csv"}, info.AnnotationFlagsPaths)
|
|
|
|
android.AssertPathsRelativeToTopEquals(t, "metadata flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/metadata.csv"}, info.MetadataPaths)
|
|
|
|
android.AssertPathsRelativeToTopEquals(t, "index flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/index.csv"}, info.IndexPaths)
|
2021-07-21 18:38:47 +02:00
|
|
|
|
2021-07-20 19:03:53 +02:00
|
|
|
android.AssertArrayString(t, "stub flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/filtered-stub-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop())
|
|
|
|
android.AssertArrayString(t, "all flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/filtered-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop())
|
2021-06-09 15:32:53 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 17:14:16 +02:00
|
|
|
// TestPlatformBootclasspath_LegacyPrebuiltFragment verifies that the
|
|
|
|
// prebuilt_bootclasspath_fragment falls back to using the complete stub-flags/all-flags if the
|
|
|
|
// filtered files are not provided.
|
|
|
|
//
|
|
|
|
// TODO: Remove once all prebuilts use the filtered_... properties.
|
|
|
|
func TestPlatformBootclasspath_LegacyPrebuiltFragment(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithPlatformBootclasspath,
|
|
|
|
java.FixtureConfigureApexBootJars("myapex:foo"),
|
|
|
|
java.PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
).RunTestWithBp(t, `
|
|
|
|
prebuilt_apex {
|
|
|
|
name: "myapex",
|
|
|
|
src: "myapex.apex",
|
|
|
|
exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
|
|
|
|
}
|
|
|
|
|
|
|
|
// A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
|
|
|
|
// because AlwaysUsePrebuiltSdks() is true.
|
|
|
|
java_sdk_library_import {
|
|
|
|
name: "foo",
|
|
|
|
prefer: false,
|
|
|
|
shared_library: false,
|
|
|
|
permitted_packages: ["foo"],
|
|
|
|
public: {
|
|
|
|
jars: ["sdk_library/public/foo-stubs.jar"],
|
|
|
|
stub_srcs: ["sdk_library/public/foo_stub_sources"],
|
|
|
|
current_api: "sdk_library/public/foo.txt",
|
|
|
|
removed_api: "sdk_library/public/foo-removed.txt",
|
|
|
|
sdk_version: "current",
|
|
|
|
},
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt_bootclasspath_fragment {
|
|
|
|
name: "mybootclasspath-fragment",
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
contents: [
|
|
|
|
"foo",
|
|
|
|
],
|
|
|
|
hidden_api: {
|
|
|
|
stub_flags: "prebuilt-stub-flags.csv",
|
|
|
|
annotation_flags: "prebuilt-annotation-flags.csv",
|
|
|
|
metadata: "prebuilt-metadata.csv",
|
|
|
|
index: "prebuilt-index.csv",
|
|
|
|
all_flags: "prebuilt-all-flags.csv",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
platform_bootclasspath {
|
|
|
|
name: "myplatform-bootclasspath",
|
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
apex: "myapex",
|
|
|
|
module:"mybootclasspath-fragment",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
)
|
|
|
|
|
|
|
|
pbcp := result.Module("myplatform-bootclasspath", "android_common")
|
2023-12-14 23:46:23 +01:00
|
|
|
info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider)
|
2021-08-10 17:14:16 +02:00
|
|
|
|
|
|
|
android.AssertArrayString(t, "stub flags", []string{"prebuilt-stub-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop())
|
|
|
|
android.AssertArrayString(t, "all flags", []string{"prebuilt-all-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop())
|
|
|
|
}
|
|
|
|
|
2021-03-22 23:09:42 +01:00
|
|
|
func TestPlatformBootclasspathDependencies(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithPlatformBootclasspath,
|
|
|
|
prepareForTestWithArtApex,
|
|
|
|
prepareForTestWithMyapex,
|
|
|
|
// Configure some libraries in the art and framework boot images.
|
2021-04-12 21:02:36 +02:00
|
|
|
java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"),
|
2021-07-21 15:23:52 +02:00
|
|
|
java.FixtureConfigureApexBootJars("myapex:bar"),
|
2021-03-22 23:09:42 +01:00
|
|
|
java.PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
java.FixtureWithLastReleaseApis("foo"),
|
2023-05-11 17:39:27 +02:00
|
|
|
java.PrepareForTestWithDexpreopt,
|
|
|
|
dexpreopt.FixtureDisableDexpreoptBootImages(false),
|
2023-12-26 20:08:01 +01:00
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.BuildFlags = map[string]string{
|
|
|
|
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
|
|
|
|
}
|
|
|
|
}),
|
2021-03-22 23:09:42 +01:00
|
|
|
).RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "com.android.art",
|
|
|
|
key: "com.android.art.key",
|
|
|
|
bootclasspath_fragments: [
|
|
|
|
"art-bootclasspath-fragment",
|
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "com.android.art.key",
|
|
|
|
public_key: "com.android.art.avbpubkey",
|
|
|
|
private_key: "com.android.art.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "art-bootclasspath-fragment",
|
2021-08-06 18:49:46 +02:00
|
|
|
image_name: "art",
|
2021-03-22 23:09:42 +01:00
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
contents: [
|
|
|
|
"baz",
|
|
|
|
"quuz",
|
|
|
|
],
|
2022-03-31 16:42:30 +02:00
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
2021-03-22 23:09:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "baz",
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a java_import that is not preferred and so won't have an appropriate apex variant created
|
|
|
|
// for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it.
|
|
|
|
java_import {
|
|
|
|
name: "baz",
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
jars: ["b.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "quuz",
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art",
|
|
|
|
],
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2021-06-16 02:42:33 +02:00
|
|
|
bootclasspath_fragments: [
|
|
|
|
"my-bootclasspath-fragment",
|
2021-03-22 23:09:42 +01:00
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
2021-06-16 02:42:33 +02:00
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "my-bootclasspath-fragment",
|
|
|
|
contents: ["bar"],
|
|
|
|
apex_available: ["myapex"],
|
2022-03-31 16:42:30 +02:00
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
2021-06-16 02:42:33 +02:00
|
|
|
}
|
|
|
|
|
2021-03-22 23:09:42 +01:00
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
permitted_packages: ["bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
platform_bootclasspath {
|
|
|
|
name: "myplatform-bootclasspath",
|
2021-04-07 21:35:11 +02:00
|
|
|
|
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
apex: "com.android.art",
|
|
|
|
module: "art-bootclasspath-fragment",
|
|
|
|
},
|
2021-06-16 02:42:33 +02:00
|
|
|
{
|
|
|
|
apex: "myapex",
|
|
|
|
module: "my-bootclasspath-fragment",
|
|
|
|
},
|
2021-04-07 21:35:11 +02:00
|
|
|
],
|
2021-03-22 23:09:42 +01:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
)
|
|
|
|
|
2021-04-07 21:35:11 +02:00
|
|
|
java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
|
2021-04-21 15:10:42 +02:00
|
|
|
// The configured contents of BootJars.
|
2021-04-07 21:35:11 +02:00
|
|
|
"com.android.art:baz",
|
|
|
|
"com.android.art:quuz",
|
|
|
|
"platform:foo",
|
2021-04-21 15:10:42 +02:00
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
// The configured contents of ApexBootJars.
|
2021-04-07 21:35:11 +02:00
|
|
|
"myapex:bar",
|
|
|
|
})
|
|
|
|
|
|
|
|
java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{
|
2021-06-16 02:42:33 +02:00
|
|
|
"com.android.art:art-bootclasspath-fragment",
|
|
|
|
"myapex:my-bootclasspath-fragment",
|
2021-04-07 21:35:11 +02:00
|
|
|
})
|
|
|
|
|
2021-03-22 23:09:42 +01:00
|
|
|
// Make sure that the myplatform-bootclasspath has the correct dependencies.
|
|
|
|
CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
|
Use the correct bootjars for hiddneapi when multiple prebuilts exist
hiddenapi processing require boot jars from apexes to determine the full
set of methods available at runtime.
When building with prebuilts, this comes via
java_import/java_sdk_library_import, which acts as a hook for
prebuilt_apex/apex_set. If we have multiple apexes in the tree, this
hook becomes 1:many. This CL prepares platform_bootclasspath to select the right
deapexerd .jar files when mutliple prebuilts exist.
Implementation details
- Create a dependency edge from platform_bootclasspath to
all_apex_contributions (DepsMutator)
- For every boot jar, query all_apex_contributions to get the path to
dexjar file (GenerateAndroidBuildActions)
Some other important details
- This CL does not drop the old mechanism to get the dex file (i.e. by
creating a dep on java_library). Once all mainline
modules have been flagged using apex_contributions, the old mechanism
will be dropped
- This CL has a functional change when building with source apexes. At
ToT, the unecoded hiddenapi dex jar is used for package check and
generating the monolithic stub file. After this change, the hiddenapi
encoded file will be used for these operations.
This should be fine since the
package and dex signature do not change across the encoded and
unencoded dex file. In fact, we already have a split today. When
building with prebuilts, we use the encoded dex file. When building
with source, we use the unecoded dex file.
Test: Added a unit test
Test: Manual testing in internal described below
- lunch cf_x86_64_phone-next-userdebug
- flagged com.google.android.adservices using apex_contributions
- aninja -t commands out/soong/hiddenapi/hiddenapi-stubs-flags.txt # no
diff before and after
Bug: 308790777
Change-Id: I72c70f0ae1b587679203ea254c9c12a48e7aa782
2023-12-20 21:13:34 +01:00
|
|
|
// source vs prebuilt selection metadata module
|
|
|
|
`platform:all_apex_contributions`,
|
|
|
|
|
2021-04-21 15:10:42 +02:00
|
|
|
// The following are stubs.
|
2023-12-26 20:08:01 +01:00
|
|
|
`platform:android_stubs_current_exportable`,
|
|
|
|
`platform:android_system_stubs_current_exportable`,
|
|
|
|
`platform:android_test_stubs_current_exportable`,
|
|
|
|
`platform:legacy.core.platform.api.stubs.exportable`,
|
2021-04-21 15:10:42 +02:00
|
|
|
|
|
|
|
// Needed for generating the boot image.
|
2021-03-22 23:09:42 +01:00
|
|
|
`platform:dex2oatd`,
|
2021-04-21 15:10:42 +02:00
|
|
|
|
|
|
|
// The configured contents of BootJars.
|
2021-03-22 23:09:42 +01:00
|
|
|
`com.android.art:baz`,
|
|
|
|
`com.android.art:quuz`,
|
|
|
|
`platform:foo`,
|
2021-04-21 15:10:42 +02:00
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
// The configured contents of ApexBootJars.
|
2021-03-22 23:09:42 +01:00
|
|
|
`myapex:bar`,
|
2021-04-21 15:10:42 +02:00
|
|
|
|
|
|
|
// The fragments.
|
2021-04-07 21:35:11 +02:00
|
|
|
`com.android.art:art-bootclasspath-fragment`,
|
2021-06-16 02:42:33 +02:00
|
|
|
`myapex:my-bootclasspath-fragment`,
|
2021-03-22 23:09:42 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-19 10:36:09 +02:00
|
|
|
// TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when
|
2021-09-08 22:56:18 +02:00
|
|
|
// AlwaysUsePrebuiltSdk() returns true.
|
2021-05-19 10:36:09 +02:00
|
|
|
func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithPlatformBootclasspath,
|
|
|
|
prepareForTestWithMyapex,
|
|
|
|
// Configure two libraries, the first is a java_sdk_library whose prebuilt will be used because
|
2021-09-08 22:56:18 +02:00
|
|
|
// of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order
|
|
|
|
// matters, so that the dependencies resolved by the platform_bootclasspath matches the
|
|
|
|
// configured list.
|
2021-07-21 15:23:52 +02:00
|
|
|
java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
|
2021-05-19 10:36:09 +02:00
|
|
|
java.PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
|
2023-12-26 20:08:01 +01:00
|
|
|
variables.BuildFlags = map[string]string{
|
|
|
|
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
|
|
|
|
}
|
2021-05-19 10:36:09 +02:00
|
|
|
}),
|
|
|
|
java.FixtureWithPrebuiltApis(map[string][]string{
|
|
|
|
"current": {},
|
|
|
|
"30": {"foo"},
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
bootclasspath_fragments: [
|
|
|
|
"mybootclasspath-fragment",
|
|
|
|
],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
permitted_packages: ["bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
shared_library: false,
|
|
|
|
public: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
permitted_packages: ["foo"],
|
|
|
|
}
|
|
|
|
|
2021-09-08 22:56:18 +02:00
|
|
|
prebuilt_apex {
|
|
|
|
name: "myapex",
|
|
|
|
src: "myapex.apex",
|
|
|
|
exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
|
|
|
|
}
|
|
|
|
|
2021-05-19 10:36:09 +02:00
|
|
|
// A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
|
|
|
|
// because AlwaysUsePrebuiltSdks() is true.
|
|
|
|
java_sdk_library_import {
|
|
|
|
name: "foo",
|
|
|
|
prefer: false,
|
|
|
|
shared_library: false,
|
2021-07-15 14:35:26 +02:00
|
|
|
permitted_packages: ["foo"],
|
2021-05-19 10:36:09 +02:00
|
|
|
public: {
|
|
|
|
jars: ["sdk_library/public/foo-stubs.jar"],
|
|
|
|
stub_srcs: ["sdk_library/public/foo_stub_sources"],
|
|
|
|
current_api: "sdk_library/public/foo.txt",
|
|
|
|
removed_api: "sdk_library/public/foo-removed.txt",
|
|
|
|
sdk_version: "current",
|
|
|
|
},
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
// This always depends on the source foo module, its dependencies are not affected by the
|
|
|
|
// AlwaysUsePrebuiltSdks().
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "mybootclasspath-fragment",
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
contents: [
|
|
|
|
"foo", "bar",
|
|
|
|
],
|
2022-03-31 16:42:30 +02:00
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
2021-05-19 10:36:09 +02:00
|
|
|
}
|
|
|
|
|
2021-09-08 22:56:18 +02:00
|
|
|
prebuilt_bootclasspath_fragment {
|
|
|
|
name: "mybootclasspath-fragment",
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
contents: [
|
|
|
|
"foo",
|
|
|
|
],
|
|
|
|
hidden_api: {
|
|
|
|
stub_flags: "",
|
|
|
|
annotation_flags: "",
|
|
|
|
metadata: "",
|
|
|
|
index: "",
|
|
|
|
all_flags: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-05-19 10:36:09 +02:00
|
|
|
platform_bootclasspath {
|
|
|
|
name: "myplatform-bootclasspath",
|
2021-06-16 02:42:33 +02:00
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
apex: "myapex",
|
|
|
|
module:"mybootclasspath-fragment",
|
|
|
|
},
|
|
|
|
],
|
2021-05-19 10:36:09 +02:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
)
|
|
|
|
|
|
|
|
java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
|
|
|
|
// The configured contents of BootJars.
|
2021-09-08 22:56:18 +02:00
|
|
|
"myapex:prebuilt_foo",
|
2021-05-19 10:36:09 +02:00
|
|
|
"myapex:bar",
|
|
|
|
})
|
|
|
|
|
|
|
|
// Make sure that the myplatform-bootclasspath has the correct dependencies.
|
|
|
|
CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
|
Use the correct bootjars for hiddneapi when multiple prebuilts exist
hiddenapi processing require boot jars from apexes to determine the full
set of methods available at runtime.
When building with prebuilts, this comes via
java_import/java_sdk_library_import, which acts as a hook for
prebuilt_apex/apex_set. If we have multiple apexes in the tree, this
hook becomes 1:many. This CL prepares platform_bootclasspath to select the right
deapexerd .jar files when mutliple prebuilts exist.
Implementation details
- Create a dependency edge from platform_bootclasspath to
all_apex_contributions (DepsMutator)
- For every boot jar, query all_apex_contributions to get the path to
dexjar file (GenerateAndroidBuildActions)
Some other important details
- This CL does not drop the old mechanism to get the dex file (i.e. by
creating a dep on java_library). Once all mainline
modules have been flagged using apex_contributions, the old mechanism
will be dropped
- This CL has a functional change when building with source apexes. At
ToT, the unecoded hiddenapi dex jar is used for package check and
generating the monolithic stub file. After this change, the hiddenapi
encoded file will be used for these operations.
This should be fine since the
package and dex signature do not change across the encoded and
unencoded dex file. In fact, we already have a split today. When
building with prebuilts, we use the encoded dex file. When building
with source, we use the unecoded dex file.
Test: Added a unit test
Test: Manual testing in internal described below
- lunch cf_x86_64_phone-next-userdebug
- flagged com.google.android.adservices using apex_contributions
- aninja -t commands out/soong/hiddenapi/hiddenapi-stubs-flags.txt # no
diff before and after
Bug: 308790777
Change-Id: I72c70f0ae1b587679203ea254c9c12a48e7aa782
2023-12-20 21:13:34 +01:00
|
|
|
// source vs prebuilt selection metadata module
|
|
|
|
`platform:all_apex_contributions`,
|
|
|
|
|
2021-05-19 10:36:09 +02:00
|
|
|
// The following are stubs.
|
|
|
|
"platform:prebuilt_sdk_public_current_android",
|
|
|
|
"platform:prebuilt_sdk_system_current_android",
|
|
|
|
"platform:prebuilt_sdk_test_current_android",
|
|
|
|
|
|
|
|
// Not a prebuilt as no prebuilt existed when it was added.
|
2023-12-26 20:08:01 +01:00
|
|
|
"platform:legacy.core.platform.api.stubs.exportable",
|
2021-05-19 10:36:09 +02:00
|
|
|
|
|
|
|
// The platform_bootclasspath intentionally adds dependencies on both source and prebuilt
|
|
|
|
// modules when available as it does not know which one will be preferred.
|
|
|
|
"myapex:foo",
|
2021-09-08 22:56:18 +02:00
|
|
|
"myapex:prebuilt_foo",
|
2021-05-19 10:36:09 +02:00
|
|
|
|
|
|
|
// Only a source module exists.
|
|
|
|
"myapex:bar",
|
2021-06-16 02:42:33 +02:00
|
|
|
|
|
|
|
// The fragments.
|
|
|
|
"myapex:mybootclasspath-fragment",
|
2021-09-08 22:56:18 +02:00
|
|
|
"myapex:prebuilt_mybootclasspath-fragment",
|
2021-05-19 10:36:09 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-22 23:09:42 +01:00
|
|
|
// CheckModuleDependencies checks the dependencies of the selected module against the expected list.
|
|
|
|
//
|
|
|
|
// The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the
|
|
|
|
// name of the apex, or platform is it is not part of an apex and <module> is the module name.
|
|
|
|
func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
|
|
|
|
t.Helper()
|
|
|
|
module := ctx.ModuleForTests(name, variant).Module()
|
|
|
|
modules := []android.Module{}
|
|
|
|
ctx.VisitDirectDeps(module, func(m blueprint.Module) {
|
|
|
|
modules = append(modules, m.(android.Module))
|
|
|
|
})
|
|
|
|
|
|
|
|
pairs := java.ApexNamePairsFromModules(ctx, modules)
|
|
|
|
android.AssertDeepEquals(t, "module dependencies", expected, pairs)
|
|
|
|
}
|
2021-06-15 18:49:10 +02:00
|
|
|
|
|
|
|
// TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in
|
|
|
|
// platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config
|
|
|
|
// by setting generate_classpaths_proto property to false.
|
|
|
|
func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithPlatformBootclasspath,
|
|
|
|
prepareForTestWithMyapex,
|
2021-07-21 15:23:52 +02:00
|
|
|
java.FixtureConfigureApexBootJars("myapex:foo"),
|
2021-06-15 18:49:10 +02:00
|
|
|
android.FixtureWithRootAndroidBp(`
|
|
|
|
platform_bootclasspath {
|
|
|
|
name: "platform-bootclasspath",
|
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
apex: "myapex",
|
|
|
|
module:"foo-fragment",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
bootclasspath_fragments: ["foo-fragment"],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "foo-fragment",
|
|
|
|
generate_classpaths_proto: false,
|
|
|
|
contents: ["foo"],
|
|
|
|
apex_available: ["myapex"],
|
2022-03-31 16:42:30 +02:00
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
2021-06-15 18:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
system_modules: "none",
|
|
|
|
sdk_version: "none",
|
|
|
|
compile_dex: true,
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
permitted_packages: ["foo"],
|
|
|
|
}
|
|
|
|
`),
|
|
|
|
).RunTest(t)
|
|
|
|
|
|
|
|
java.CheckClasspathFragmentProtoContentInfoProvider(t, result,
|
|
|
|
true, // proto should be generated
|
|
|
|
"myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath
|
|
|
|
"bootclasspath.pb",
|
|
|
|
"out/soong/target/product/test_device/system/etc/classpaths",
|
|
|
|
)
|
|
|
|
}
|
2021-08-06 14:20:28 +02:00
|
|
|
|
|
|
|
func TestBootJarNotInApex(t *testing.T) {
|
|
|
|
android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithPlatformBootclasspath,
|
|
|
|
PrepareForTestWithApexBuildComponents,
|
|
|
|
prepareForTestWithMyapex,
|
|
|
|
java.FixtureConfigureApexBootJars("myapex:foo"),
|
|
|
|
).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
|
|
|
|
`dependency "foo" of "myplatform-bootclasspath" missing variant`)).
|
|
|
|
RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "not-in-apex-fragment",
|
|
|
|
contents: [
|
|
|
|
"foo",
|
|
|
|
],
|
2022-03-31 16:42:30 +02:00
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
2021-08-06 14:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_bootclasspath {
|
|
|
|
name: "myplatform-bootclasspath",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBootFragmentNotInApex(t *testing.T) {
|
|
|
|
android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithPlatformBootclasspath,
|
|
|
|
PrepareForTestWithApexBuildComponents,
|
|
|
|
prepareForTestWithMyapex,
|
|
|
|
java.FixtureConfigureApexBootJars("myapex:foo"),
|
|
|
|
).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
|
|
|
|
`library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
java_libs: ["foo"],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
permitted_packages: ["foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "not-in-apex-fragment",
|
|
|
|
contents: ["foo"],
|
2022-03-31 16:42:30 +02:00
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
2021-08-06 14:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_bootclasspath {
|
|
|
|
name: "myplatform-bootclasspath",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNonBootJarInFragment(t *testing.T) {
|
|
|
|
android.GroupFixturePreparers(
|
|
|
|
prepareForTestWithPlatformBootclasspath,
|
|
|
|
PrepareForTestWithApexBuildComponents,
|
|
|
|
prepareForTestWithMyapex,
|
|
|
|
java.FixtureConfigureApexBootJars("myapex:foo"),
|
|
|
|
).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
|
|
|
|
`in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)).
|
|
|
|
RunTestWithBp(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
bootclasspath_fragments: ["apex-fragment"],
|
|
|
|
updatable: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
permitted_packages: ["foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
installable: true,
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
permitted_packages: ["bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
bootclasspath_fragment {
|
|
|
|
name: "apex-fragment",
|
|
|
|
contents: ["foo", "bar"],
|
|
|
|
apex_available:[ "myapex" ],
|
2022-03-31 16:42:30 +02:00
|
|
|
hidden_api: {
|
|
|
|
split_packages: ["*"],
|
|
|
|
},
|
2021-08-06 14:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_bootclasspath {
|
|
|
|
name: "myplatform-bootclasspath",
|
|
|
|
fragments: [{
|
|
|
|
apex: "myapex",
|
|
|
|
module:"apex-fragment",
|
|
|
|
}],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|