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
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 51903ce3..c6cb6c2 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -19,11 +19,13 @@
"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 @@
// 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 @@
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 @@
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 @@
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
`),
)
}