From 59a4a2b8d210e74e6625794f954bd11bb6157002 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Tue, 9 Jan 2024 21:35:56 +0000 Subject: Replace panic with ModuleErrorf This is a followup cleanup for aosp/2876754 and replaces panic with ctx.ModuleErrorf. The latter creates a more expressive build error. Implementation details - export moduleErrorf interface from build/soong/android. This minimal interface will be used as a parameter for `DexJarBuildPath` - Add ModuleErrorf to the function signature of DexJarBuildPath. This parameter only gets used for Import and SdkLibraryImport structs. These two can have duplicate deapexer definitions, and ModuleErrorf will be used to report that error - Create a minimal implementation of `ModuleErrorf` in tests of java and apex Test: m nothing --no-skip-soong-tests Change-Id: I0febec651f40c3f04deb957e64133c94b80fbd78 --- java/java_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'java/java_test.go') diff --git a/java/java_test.go b/java/java_test.go index b9dc453b3..59a64beaf 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -528,6 +528,15 @@ func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) { } } +// A minimal context object for use with DexJarBuildPath +type moduleErrorfTestCtx struct { +} + +func (ctx moduleErrorfTestCtx) ModuleErrorf(format string, args ...interface{}) { +} + +var _ android.ModuleErrorfContext = (*moduleErrorfTestCtx)(nil) + func TestPrebuilts(t *testing.T) { ctx, _ := testJava(t, ` java_library { @@ -595,7 +604,8 @@ func TestPrebuilts(t *testing.T) { t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String()) } - barDexJar := barModule.Module().(*Import).DexJarBuildPath() + errCtx := moduleErrorfTestCtx{} + barDexJar := barModule.Module().(*Import).DexJarBuildPath(errCtx) if barDexJar.IsSet() { t.Errorf("bar dex jar build path expected to be set, got %s", barDexJar) } @@ -608,7 +618,7 @@ func TestPrebuilts(t *testing.T) { t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, bazJar.String()) } - bazDexJar := bazModule.Module().(*Import).DexJarBuildPath().Path() + bazDexJar := bazModule.Module().(*Import).DexJarBuildPath(errCtx).Path() expectedDexJar := "out/soong/.intermediates/baz/android_common/dex/baz.jar" android.AssertPathRelativeToTopEquals(t, "baz dex jar build path", expectedDexJar, bazDexJar) -- cgit v1.2.3-59-g8ed1b