Allow common.Glob to be called by singletons

Make common.Glob take an interface that is the intersection of
blueprint.ModuleContext and blueprint.SingletonContext used by
Glob and GlobRule, allowing it to be called on either.  Also
move ExpandSources and Glob into AndroidModuleContext.

Change-Id: I8d1a3160c5dd201033afdb37210e82d8065b137d
diff --git a/common/module.go b/common/module.go
index 327aeca..33c586c 100644
--- a/common/module.go
+++ b/common/module.go
@@ -18,6 +18,8 @@
 	"path/filepath"
 	"runtime"
 
+	"android/soong/glob"
+
 	"github.com/google/blueprint"
 )
 
@@ -49,6 +51,9 @@
 	blueprint.ModuleContext
 	androidBaseContext
 
+	ExpandSources(srcFiles []string) []string
+	Glob(globPattern string, excludes []string) []string
+
 	InstallFile(installPath, srcPath string, deps ...string) string
 	InstallFileName(installPath, name, srcPath string, deps ...string) string
 	CheckbuildFile(srcPath string)
@@ -465,7 +470,7 @@
 	return ok
 }
 
-func ExpandSources(ctx AndroidModuleContext, srcFiles []string) []string {
+func (ctx *androidModuleContext) ExpandSources(srcFiles []string) []string {
 	prefix := ModuleSrcDir(ctx)
 	for i, srcFile := range srcFiles {
 		if srcFile[0] == '-' {
@@ -475,8 +480,37 @@
 		}
 	}
 
-	srcFiles = expandGlobs(ctx, srcFiles)
-	return srcFiles
+	if !hasGlob(srcFiles) {
+		return srcFiles
+	}
+
+	var excludes []string
+	for _, s := range srcFiles {
+		if s[0] == '-' {
+			excludes = append(excludes, s[1:])
+		}
+	}
+
+	globbedSrcFiles := make([]string, 0, len(srcFiles))
+	for _, s := range srcFiles {
+		if s[0] == '-' {
+			continue
+		} else if glob.IsGlob(s) {
+			globbedSrcFiles = append(globbedSrcFiles, ctx.Glob(s, excludes)...)
+		} else {
+			globbedSrcFiles = append(globbedSrcFiles, s)
+		}
+	}
+
+	return globbedSrcFiles
+}
+
+func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) []string {
+	ret, err := Glob(ctx, ModuleOutDir(ctx), globPattern, excludes)
+	if err != nil {
+		ctx.ModuleErrorf("glob: %s", err.Error())
+	}
+	return ret
 }
 
 func BuildTargetSingleton() blueprint.Singleton {