Remove deapex support from java_*_import

prebuilt_apex/apex_set currently supports its deapexed contents to be
returned via a sibling java_import/java_sdk_import module. This is
necesssary for
1. dexpreopt/hiddenapi processing
2. usage as shared library

(1) is no longer necessary. this information is provided by the
top-level prebuilt apexes now

(2) is no longer possible since `exported_java_libs` has been removed in
https://r.android.com/3272110

This CL uses a hack for java_sdk_library_improt. Even though (1) is
provided by the top-level apex, there are still some places where
dexpreopt/hiddenapi processing visits the import modules. This CL uses
a bogus path to make analysis work. If this bogus path gets used, there
will be an error during ninja execution

Test: go test ./apex
Test: in internal lunch cf_x86_64_phone-next-userdebug (uses mainline
prebuilts)
Test: verified that file_list.txt is same
Bug: 368337090

Change-Id: I0ea2327f648f0fc60e337b232f7265e140772ffd
This commit is contained in:
Spandan Das
2024-09-19 21:02:52 +00:00
parent f771470d8c
commit a326b320ab
4 changed files with 25 additions and 276 deletions

View File

@@ -4907,23 +4907,6 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
}),
)
checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) {
t.Helper()
s := ctx.ModuleForTests("dex_bootjars", "android_common")
foundLibfooJar := false
base := stem + ".jar"
for _, output := range s.AllOutputs() {
if filepath.Base(output) == base {
foundLibfooJar = true
buildRule := s.Output(output)
android.AssertStringEquals(t, "boot dex jar path", bootDexJarPath, buildRule.Input.String())
}
}
if !foundLibfooJar {
t.Errorf("Rule for libfoo.jar missing in dex_bootjars singleton outputs %q", android.StringPathsRelativeToTop(ctx.Config().SoongOutDir(), s.AllOutputs()))
}
}
checkHiddenAPIIndexFromClassesInputs := func(t *testing.T, ctx *android.TestContext, expectedIntermediateInputs string) {
t.Helper()
platformBootclasspath := ctx.ModuleForTests("platform-bootclasspath", "android_common")
@@ -4996,8 +4979,6 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
`
ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
@@ -5066,8 +5047,6 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
`
ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
@@ -5259,8 +5238,6 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
`
ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
@@ -5359,8 +5336,6 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
`
ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/my-bootclasspath-fragment/android_common_myapex/hiddenapi-modular/encoded/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/my-bootclasspath-fragment/android_common_myapex/hiddenapi-modular/encoded/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
@@ -5472,8 +5447,6 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
)
ctx := testDexpreoptWithApexes(t, bp, "", preparer2, fragment)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
@@ -7973,189 +7946,6 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.F
return result.TestContext
}
func TestDuplicateDeapexersFromPrebuiltApexes(t *testing.T) {
preparers := android.GroupFixturePreparers(
java.PrepareForTestWithJavaDefaultModules,
prepareForTestWithBootclasspathFragment,
dexpreopt.FixtureSetTestOnlyArtBootImageJars("com.android.art:libfoo"),
PrepareForTestWithApexBuildComponents,
).
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
"Multiple installable prebuilt APEXes provide ambiguous deapexers: prebuilt_com.android.art and prebuilt_com.mycompany.android.art"))
bpBase := `
apex_set {
name: "com.android.art",
installable: true,
exported_bootclasspath_fragments: ["art-bootclasspath-fragment"],
set: "myapex.apks",
}
apex_set {
name: "com.mycompany.android.art",
apex_name: "com.android.art",
installable: true,
exported_bootclasspath_fragments: ["art-bootclasspath-fragment"],
set: "company-myapex.apks",
}
prebuilt_bootclasspath_fragment {
name: "art-bootclasspath-fragment",
apex_available: ["com.android.art"],
hidden_api: {
annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv",
metadata: "my-bootclasspath-fragment/metadata.csv",
index: "my-bootclasspath-fragment/index.csv",
stub_flags: "my-bootclasspath-fragment/stub-flags.csv",
all_flags: "my-bootclasspath-fragment/all-flags.csv",
},
%s
}
`
t.Run("java_import", func(t *testing.T) {
_ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+`
java_import {
name: "libfoo",
jars: ["libfoo.jar"],
apex_available: ["com.android.art"],
}
`)
})
t.Run("java_sdk_library_import", func(t *testing.T) {
_ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+`
java_sdk_library_import {
name: "libfoo",
public: {
jars: ["libbar.jar"],
},
shared_library: false,
apex_available: ["com.android.art"],
}
`)
})
t.Run("prebuilt_bootclasspath_fragment", func(t *testing.T) {
_ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `
image_name: "art",
contents: ["libfoo"],
`)+`
java_sdk_library_import {
name: "libfoo",
public: {
jars: ["libbar.jar"],
},
shared_library: false,
apex_available: ["com.android.art"],
}
`)
})
}
func TestDuplicateButEquivalentDeapexersFromPrebuiltApexes(t *testing.T) {
preparers := android.GroupFixturePreparers(
java.PrepareForTestWithJavaDefaultModules,
PrepareForTestWithApexBuildComponents,
)
errCtx := moduleErrorfTestCtx{}
bpBase := `
apex_set {
name: "com.android.myapex",
installable: true,
exported_bootclasspath_fragments: ["my-bootclasspath-fragment"],
set: "myapex.apks",
}
apex_set {
name: "com.android.myapex_compressed",
apex_name: "com.android.myapex",
installable: true,
exported_bootclasspath_fragments: ["my-bootclasspath-fragment"],
set: "myapex_compressed.apks",
}
prebuilt_bootclasspath_fragment {
name: "my-bootclasspath-fragment",
apex_available: [
"com.android.myapex",
"com.android.myapex_compressed",
],
hidden_api: {
annotation_flags: "annotation-flags.csv",
metadata: "metadata.csv",
index: "index.csv",
signature_patterns: "signature_patterns.csv",
},
%s
}
`
t.Run("java_import", func(t *testing.T) {
result := preparers.RunTestWithBp(t,
fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+`
java_import {
name: "libfoo",
jars: ["libfoo.jar"],
apex_available: [
"com.android.myapex",
"com.android.myapex_compressed",
],
}
`)
module := result.Module("libfoo", "android_common_com.android.myapex")
usesLibraryDep := module.(java.UsesLibraryDependency)
android.AssertPathRelativeToTopEquals(t, "dex jar path",
"out/soong/.intermediates/prebuilt_com.android.myapex.deapexer/android_common/deapexer/javalib/libfoo.jar",
usesLibraryDep.DexJarBuildPath(errCtx).Path())
})
t.Run("java_sdk_library_import", func(t *testing.T) {
result := preparers.RunTestWithBp(t,
fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+`
java_sdk_library_import {
name: "libfoo",
public: {
jars: ["libbar.jar"],
},
apex_available: [
"com.android.myapex",
"com.android.myapex_compressed",
],
compile_dex: true,
}
`)
module := result.Module("libfoo", "android_common_com.android.myapex")
usesLibraryDep := module.(java.UsesLibraryDependency)
android.AssertPathRelativeToTopEquals(t, "dex jar path",
"out/soong/.intermediates/prebuilt_com.android.myapex.deapexer/android_common/deapexer/javalib/libfoo.jar",
usesLibraryDep.DexJarBuildPath(errCtx).Path())
})
t.Run("prebuilt_bootclasspath_fragment", func(t *testing.T) {
_ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `
image_name: "art",
contents: ["libfoo"],
`)+`
java_sdk_library_import {
name: "libfoo",
public: {
jars: ["libbar.jar"],
},
apex_available: [
"com.android.myapex",
"com.android.myapex_compressed",
],
compile_dex: true,
}
`)
})
}
func TestUpdatable_should_set_min_sdk_version(t *testing.T) {
testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, `
apex {