From beae6ecbd4fd9cdf9c809ab9994103bc3e7be04b Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 11 Aug 2020 12:02:11 -0700 Subject: [PATCH] Shorten missing module panic message Only print the list of variants of the matching module when ctx.ModuleForTesting finds the module but not the variant. Test: all soong tests Change-Id: I51ffdde4645db39ec1d37ec018e0dea11d74280e --- android/testing.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/android/testing.go b/android/testing.go index 696efb6f8..f32d745c2 100644 --- a/android/testing.go +++ b/android/testing.go @@ -119,14 +119,24 @@ func (ctx *TestContext) ModuleForTests(name, variant string) TestingModule { if module == nil { // find all the modules that do exist - allModuleNames := []string{} + var allModuleNames []string + var allVariants []string ctx.VisitAllModules(func(m blueprint.Module) { - allModuleNames = append(allModuleNames, m.(Module).Name()+"("+ctx.ModuleSubDir(m)+")") + allModuleNames = append(allModuleNames, ctx.ModuleName(m)) + if ctx.ModuleName(m) == name { + allVariants = append(allVariants, ctx.ModuleSubDir(m)) + } }) sort.Strings(allModuleNames) + sort.Strings(allVariants) - panic(fmt.Errorf("failed to find module %q variant %q. All modules:\n %s", - name, variant, strings.Join(allModuleNames, "\n "))) + if len(allVariants) == 0 { + panic(fmt.Errorf("failed to find module %q. All modules:\n %s", + name, strings.Join(allModuleNames, "\n "))) + } else { + panic(fmt.Errorf("failed to find module %q variant %q. All variants:\n %s", + name, variant, strings.Join(allVariants, "\n "))) + } } return TestingModule{module}