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/hiddenapi_modular.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'java/hiddenapi_modular.go') diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index c3caa084f..a51286064 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -291,7 +291,7 @@ func hiddenAPIRetrieveDexJarBuildPath(ctx android.ModuleContext, module android. if sdkLibrary, ok := module.(SdkLibraryDependency); ok { dexJar = sdkLibrary.SdkApiStubDexJar(ctx, kind) } else if j, ok := module.(UsesLibraryDependency); ok { - dexJar = j.DexJarBuildPath() + dexJar = j.DexJarBuildPath(ctx) } else { ctx.ModuleErrorf("dependency %s of module type %s does not support providing a dex jar", module, ctx.OtherModuleType(module)) return nil @@ -1457,7 +1457,9 @@ func handleMissingDexBootFile(ctx android.ModuleContext, module android.Module, // However, under certain conditions, e.g. errors, or special build configurations it will return // a path to a fake file. func retrieveEncodedBootDexJarFromModule(ctx android.ModuleContext, module android.Module) android.Path { - bootDexJar := module.(interface{ DexJarBuildPath() OptionalDexJarPath }).DexJarBuildPath() + bootDexJar := module.(interface { + DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath + }).DexJarBuildPath(ctx) if !bootDexJar.Valid() { fake := android.PathForModuleOut(ctx, fmt.Sprintf("fake/encoded-dex/%s.jar", module.Name())) handleMissingDexBootFile(ctx, module, fake, bootDexJar.InvalidReason()) -- cgit v1.2.3-59-g8ed1b