improve error handling for SourceRootDirs

Previously, warnings about missing modules were printed directly to
stderr. Instead we can pass these messages along as errors using the
existing pathways.

Bug: 269457150
Test: m nothing
Test: add -external to PRODUCT_SOURCE_ROOT_DIRS and observe missing
  module errors
Change-Id: I7273c427f38024e3c288f1ecb31175ed04ac44a6
diff --git a/android/namespace.go b/android/namespace.go
index f357ca7..c47a1c5 100644
--- a/android/namespace.go
+++ b/android/namespace.go
@@ -245,6 +245,10 @@
 	return allModules
 }
 
+func (r *NameResolver) SkippedModuleFromName(moduleName string, namespace blueprint.Namespace) (skipInfos []blueprint.SkippedModuleInfo, skipped bool) {
+	return r.rootNamespace.moduleContainer.SkippedModuleFromName(moduleName, namespace)
+}
+
 // parses a fully-qualified path (like "//namespace_path:module_name") into a namespace name and a
 // module name
 func (r *NameResolver) parseFullyQualifiedName(name string) (namespaceName string, moduleName string, ok bool) {
@@ -333,11 +337,16 @@
 
 	// determine which namespaces the module can be found in
 	foundInNamespaces := []string{}
+	skippedDepErrors := []error{}
 	for _, namespace := range r.sortedNamespaces.sortedItems() {
 		_, found := namespace.moduleContainer.ModuleFromName(depName, nil)
 		if found {
 			foundInNamespaces = append(foundInNamespaces, namespace.Path)
 		}
+		_, skipped := namespace.moduleContainer.SkippedModuleFromName(depName, nil)
+		if skipped {
+			skippedDepErrors = append(skippedDepErrors, namespace.moduleContainer.MissingDependencyError(depender, dependerNamespace, depName))
+		}
 	}
 	if len(foundInNamespaces) > 0 {
 		// determine which namespaces are visible to dependerNamespace
@@ -350,6 +359,9 @@
 		text += fmt.Sprintf("\nModule %q is defined in namespace %q which can read these %v namespaces: %q", depender, dependerNs.Path, len(importedNames), importedNames)
 		text += fmt.Sprintf("\nModule %q can be found in these namespaces: %q", depName, foundInNamespaces)
 	}
+	for _, err := range skippedDepErrors {
+		text += fmt.Sprintf("\n%s", err.Error())
+	}
 
 	return fmt.Errorf(text)
 }