summaryrefslogtreecommitdiff
path: root/sdk/java_sdk_test.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2022-10-20 17:21:40 +0100
committer Paul Duffin <paulduffin@google.com> 2022-11-14 10:14:10 +0000
commitc61783b20d70789d657dcb82050369480cc443c7 (patch)
treeb140b8138e863c0624020aecbdc81c76e96c5496 /sdk/java_sdk_test.go
parent7cc632d3d639d9ee316f4e2a5aa724a6af564846 (diff)
Improve error reporting when depending on prebuilt implementation jar
The sdk snapshot must not be including implementation code for boot libraries, the implementation is provided by dex jars within the corresponding APEX. However, the snapshot does need a module for each boot library so that the build can seamlessly access the dex files from the APEX. A java_library boot library (like core-oj) is represented in the snapshot by a java_import module which requires a jar file to be provided, otherwise it is disabled. However, that is provided purely to keep Soong happy and should never be used. Previously, the snapshot would contain an empty file for the jar. As an empty file is an invalid jar any tool (like compiler) that tried to consume it would fail which was the correct behavior. Unfortunately, the error message that was produced was not very helpful, it was just some variant on `invalid file` which lead to a lot of bugs being raised. This change replaces that empty file with a reference to the output from a genrule which runs a script which produces a more useful error message, with information on how to fix the issue, and fails the build. It also adds a Name() method to the SdkMemberProperties type as that is needed in AddInternalModule() to construct the name of the additional module. Tested as follows: In AOSP/master make the following changes: 1. Temporarily set visibility on core-oj and core-libart to //visibility:public. 2. Run packages/modules/common/build/mainline_modules_sdks.py to create the snapshots. For each of the S, T and latest snapshots I did the following in the s-aml-prebuilt-test, t-aml-prebuilt-test and aosp/master branches: 1. Created an Android.bp file containing the following: java_library { name: "broken", static_libs: [ "prebuilt_core-libart", "prebuilt_core-oj", ], } 2. Fix the visibility issues and run `m broken` where it fails with an invalid file. 3. Delete the contents of the prebuilts/module_sdk/art/current/sdk directory. 4. Unpack the relevant version of the art-module-sdk snapshot into the directory. 5. Run `m broken` where it fails with the helpful message. 6. Test the instructions on how to use the ninja -t path tool to identify the cause of the problem and fix it. Bug: 257969510 Test: See above. Change-Id: I125bde2d7202afff84c97daebcef37e21c548a3a
Diffstat (limited to 'sdk/java_sdk_test.go')
-rw-r--r--sdk/java_sdk_test.go44
1 files changed, 35 insertions, 9 deletions
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 51903ce39..c6cb6c220 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -19,11 +19,13 @@ import (
"testing"
"android/soong/android"
+ "android/soong/genrule"
"android/soong/java"
)
var prepareForSdkTestWithJava = android.GroupFixturePreparers(
java.PrepareForTestWithJavaBuildComponents,
+ genrule.PrepareForTestWithGenRuleBuildComponents,
PrepareForTestWithSdkBuildComponents,
// Ensure that all source paths are provided. This helps ensure that the snapshot generation is
@@ -34,6 +36,7 @@ var prepareForSdkTestWithJava = android.GroupFixturePreparers(
// Files needs by most of the tests.
android.MockFS{
"Test.java": nil,
+ "build/soong/java/invalid_implementation_jar.sh": nil,
}.AddToFixture(),
)
@@ -288,18 +291,26 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
- jars: ["java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar"],
+ jars: [":mysdk_myjavalib-error"],
permitted_packages: ["pkg.myjavalib"],
}
+
+genrule {
+ name: "mysdk_myjavalib-error",
+ visibility: ["//visibility:private"],
+ out: ["this-file-will-never-be-created.jar"],
+ tool_files: ["scripts/invalid_implementation_jar.sh"],
+ cmd: "$(location scripts/invalid_implementation_jar.sh) myjavalib",
+}
`),
checkAllCopyRules(`
-.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar
+build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
`),
)
}
func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) {
- runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) {
+ runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedGenRule, expectedCopyRule string) {
result := android.GroupFixturePreparers(
prepareForSdkTestWithJava,
android.FixtureMergeEnv(map[string]string{
@@ -334,20 +345,27 @@ java_import {
jars: ["%s"],
permitted_packages: ["pkg.media"],
}
-`, expectedJarPath)),
+%s`, expectedJarPath, expectedGenRule)),
checkAllCopyRules(expectedCopyRule),
)
}
t.Run("updatable-media in S", func(t *testing.T) {
- runTest(t, "S", "java/updatable-media.jar", `
+ runTest(t, "S", "java/updatable-media.jar", "", `
.intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar
`)
})
t.Run("updatable-media in T", func(t *testing.T) {
- runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", `
-.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar
+ runTest(t, "Tiramisu", ":mysdk_updatable-media-error", `
+genrule {
+ name: "mysdk_updatable-media-error",
+ visibility: ["//visibility:private"],
+ out: ["this-file-will-never-be-created.jar"],
+ tool_files: ["scripts/invalid_implementation_jar.sh"],
+ cmd: "$(location scripts/invalid_implementation_jar.sh) updatable-media",
+}`, `
+build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
`)
})
}
@@ -389,12 +407,20 @@ java_import {
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
- jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"],
+ jars: [":myexports_myjavalib-error"],
permitted_packages: ["pkg.myjavalib"],
}
+
+genrule {
+ name: "myexports_myjavalib-error",
+ visibility: ["//visibility:private"],
+ out: ["this-file-will-never-be-created.jar"],
+ tool_files: ["scripts/invalid_implementation_jar.sh"],
+ cmd: "$(location scripts/invalid_implementation_jar.sh) myjavalib",
+}
`),
checkAllCopyRules(`
-.intermediates/myexports/common_os/empty -> java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar
+build/soong/java/invalid_implementation_jar.sh -> scripts/invalid_implementation_jar.sh
`),
)
}