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/sdk_library.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'java/sdk_library.go') diff --git a/java/sdk_library.go b/java/sdk_library.go index ef34fb6cd..e696251cb 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -678,7 +678,7 @@ func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.Modul paths.stubsImplPath = lib.ImplementationJars libDep := dep.(UsesLibraryDependency) - paths.stubsDexJarPath = libDep.DexJarBuildPath() + paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) return nil } else { return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") @@ -2752,11 +2752,11 @@ func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleCont } // to satisfy UsesLibraryDependency interface -func (module *SdkLibraryImport) DexJarBuildPath() OptionalDexJarPath { +func (module *SdkLibraryImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath { // The dex implementation jar extracted from the .apex file should be used in preference to the // source. if module.dexJarFileErr != nil { - panic(module.dexJarFileErr.Error()) + ctx.ModuleErrorf(module.dexJarFileErr.Error()) } if module.dexJarFile.IsSet() { return module.dexJarFile @@ -2764,7 +2764,7 @@ func (module *SdkLibraryImport) DexJarBuildPath() OptionalDexJarPath { if module.implLibraryModule == nil { return makeUnsetDexJarPath() } else { - return module.implLibraryModule.DexJarBuildPath() + return module.implLibraryModule.DexJarBuildPath(ctx) } } -- cgit v1.2.3-59-g8ed1b