diff --git a/context_test.go b/context_test.go index 2ea7801..1a1fb0d 100644 --- a/context_test.go +++ b/context_test.go @@ -1492,7 +1492,7 @@ func TestSourceRootDirs(t *testing.T) { "foo_dir1", }, expectedErrs: []string{ - "Android.bp:2:2: \"foo\" depends on undefined module \"foo_dir1\"", + `Android.bp:2:2: module "foo" depends on skipped module "foo_dir1"; "foo_dir1" was defined in files(s) [dir1/Android.bp], but was skipped for reason(s) ["dir1/Android.bp" is a descendant of "dir1", and that path prefix was not included in PRODUCT_SOURCE_ROOT_DIRS]`, }, }, { @@ -1506,7 +1506,7 @@ func TestSourceRootDirs(t *testing.T) { "foo_dir_ignored_special_case", }, expectedErrs: []string{ - "dir1/Android.bp:2:2: \"foo_dir1\" depends on undefined module \"foo_dir_ignored\"", + `dir1/Android.bp:2:2: module "foo_dir1" depends on skipped module "foo_dir_ignored"; "foo_dir_ignored" was defined in files(s) [dir_ignored/Android.bp], but was skipped for reason(s) ["dir_ignored/Android.bp" is a descendant of "", and that path prefix was not included in PRODUCT_SOURCE_ROOT_DIRS]`, }, }, { @@ -1520,7 +1520,7 @@ func TestSourceRootDirs(t *testing.T) { "foo_dir_ignored", }, expectedErrs: []string{ - "dir1/Android.bp:2:2: \"foo_dir1\" depends on undefined module \"foo_dir_ignored\"", + "dir1/Android.bp:2:2: module \"foo_dir1\" depends on skipped module \"foo_dir_ignored\"; \"foo_dir_ignored\" was defined in files(s) [dir_ignored/Android.bp], but was skipped for reason(s) [\"dir_ignored/Android.bp\" is a descendant of \"\", and that path prefix was not included in PRODUCT_SOURCE_ROOT_DIRS]", }, }, } @@ -1536,8 +1536,8 @@ func TestSourceRootDirs(t *testing.T) { _, actualErrs := ctx.ResolveDependencies(nil) stringErrs := []string(nil) - for i := range actualErrs { - stringErrs = append(stringErrs, fmt.Sprint(actualErrs[i])) + for _, err := range actualErrs { + stringErrs = append(stringErrs, err.Error()) } if !reflect.DeepEqual(tc.expectedErrs, stringErrs) { t.Errorf("expected to find errors %v; got %v", tc.expectedErrs, stringErrs) diff --git a/name_interface.go b/name_interface.go index c675ded..d4b3383 100644 --- a/name_interface.go +++ b/name_interface.go @@ -16,7 +16,6 @@ package blueprint import ( "fmt" - "os" "sort" "strings" ) @@ -62,6 +61,9 @@ type NameInterface interface { // Finds the module with the given name ModuleFromName(moduleName string, namespace Namespace) (group ModuleGroup, found bool) + // Finds if the module with the given name was skipped + SkippedModuleFromName(moduleName string, namespace Namespace) (skipInfos []SkippedModuleInfo, skipped bool) + // Returns an error indicating that the given module could not be found. // The error contains some diagnostic information about where the dependency can be found. MissingDependencyError(depender string, dependerNamespace Namespace, depName string) (err error) @@ -143,25 +145,14 @@ func (s *SimpleNameInterface) NewSkippedModule(ctx NamespaceContext, name string func (s *SimpleNameInterface) ModuleFromName(moduleName string, namespace Namespace) (group ModuleGroup, found bool) { group, found = s.modules[moduleName] - skipInfos, skipped := s.skippedModules[moduleName] - if skipped { - filesFound := make([]string, 0, len(skipInfos)) - reasons := make([]string, 0, len(skipInfos)) - for _, info := range skipInfos { - filesFound = append(filesFound, info.filename) - reasons = append(reasons, info.reason) - } - fmt.Fprintf( - os.Stderr, - "module %q was defined in files(s) [%v], but was skipped for reason(s) [%v]\n", - moduleName, - strings.Join(filesFound, ", "), - strings.Join(reasons, "; "), - ) - } return group, found } +func (s *SimpleNameInterface) SkippedModuleFromName(moduleName string, namespace Namespace) (skipInfos []SkippedModuleInfo, skipped bool) { + skipInfos, skipped = s.skippedModules[moduleName] + return +} + func (s *SimpleNameInterface) Rename(oldName string, newName string, namespace Namespace) (errs []error) { existingGroup, exists := s.modules[newName] if exists { @@ -207,6 +198,23 @@ func (s *SimpleNameInterface) AllModules() []ModuleGroup { } func (s *SimpleNameInterface) MissingDependencyError(depender string, dependerNamespace Namespace, dependency string) (err error) { + skipInfos, skipped := s.SkippedModuleFromName(dependency, dependerNamespace) + if skipped { + filesFound := make([]string, 0, len(skipInfos)) + reasons := make([]string, 0, len(skipInfos)) + for _, info := range skipInfos { + filesFound = append(filesFound, info.filename) + reasons = append(reasons, info.reason) + } + return fmt.Errorf( + "module %q depends on skipped module %q; %q was defined in files(s) [%v], but was skipped for reason(s) [%v]", + depender, + dependency, + dependency, + strings.Join(filesFound, ", "), + strings.Join(reasons, "; "), + ) + } return fmt.Errorf("%q depends on undefined module %q", depender, dependency) }