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
This commit is contained in:
Colin Cross
2015-06-17 15:09:06 -07:00
parent 1f8c52be73
commit 8f101b45fc
7 changed files with 53 additions and 40 deletions

View File

@@ -531,7 +531,7 @@ func (c *CCBase) customCompileObjs(ctx common.AndroidModuleContext, flags CCFlag
buildFlags := ccFlagsToBuilderFlags(flags) buildFlags := ccFlagsToBuilderFlags(flags)
srcFiles = common.ExpandSources(ctx, srcFiles) srcFiles = ctx.ExpandSources(srcFiles)
srcFiles, deps := genSources(ctx, srcFiles, buildFlags) srcFiles, deps := genSources(ctx, srcFiles, buildFlags)
return TransformSourceToObj(ctx, subdir, srcFiles, buildFlags, deps) return TransformSourceToObj(ctx, subdir, srcFiles, buildFlags, deps)

View File

@@ -66,41 +66,20 @@ func hasGlob(in []string) bool {
return false return false
} }
func expandGlobs(ctx AndroidModuleContext, in []string) []string { // The subset of ModuleContext and SingletonContext needed by Glob
if !hasGlob(in) { type globContext interface {
return in Build(pctx *blueprint.PackageContext, params blueprint.BuildParams)
} AddNinjaFileDeps(deps ...string)
var excludes []string
for _, s := range in {
if s[0] == '-' {
excludes = append(excludes, s[1:])
}
}
out := make([]string, 0, len(in))
for _, s := range in {
if s[0] == '-' {
continue
} else if glob.IsGlob(s) {
out = append(out, Glob(ctx, s, excludes)...)
} else {
out = append(out, s)
}
}
return out
} }
func Glob(ctx AndroidModuleContext, globPattern string, excludes []string) []string { func Glob(ctx globContext, outDir string, globPattern string, excludes []string) ([]string, error) {
fileListFile := filepath.Join(ModuleOutDir(ctx), "glob", globToString(globPattern)) fileListFile := filepath.Join(outDir, "glob", globToString(globPattern))
depFile := fileListFile + ".d" depFile := fileListFile + ".d"
// Get a globbed file list, and write out fileListFile and depFile // Get a globbed file list, and write out fileListFile and depFile
files, err := glob.GlobWithDepFile(globPattern, fileListFile, depFile, excludes) files, err := glob.GlobWithDepFile(globPattern, fileListFile, depFile, excludes)
if err != nil { if err != nil {
ctx.ModuleErrorf("glob: %s", err.Error()) return nil, err
return []string{globPattern}
} }
GlobRule(ctx, globPattern, excludes, fileListFile, depFile) GlobRule(ctx, globPattern, excludes, fileListFile, depFile)
@@ -108,10 +87,10 @@ func Glob(ctx AndroidModuleContext, globPattern string, excludes []string) []str
// Make build.ninja depend on the fileListFile // Make build.ninja depend on the fileListFile
ctx.AddNinjaFileDeps(fileListFile) ctx.AddNinjaFileDeps(fileListFile)
return files return files, nil
} }
func GlobRule(ctx AndroidModuleContext, globPattern string, excludes []string, func GlobRule(ctx globContext, globPattern string, excludes []string,
fileListFile, depFile string) { fileListFile, depFile string) {
// Create a rule to rebuild fileListFile if a directory in depFile changes. fileListFile // Create a rule to rebuild fileListFile if a directory in depFile changes. fileListFile

View File

@@ -18,6 +18,8 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"android/soong/glob"
"github.com/google/blueprint" "github.com/google/blueprint"
) )
@@ -49,6 +51,9 @@ type AndroidModuleContext interface {
blueprint.ModuleContext blueprint.ModuleContext
androidBaseContext androidBaseContext
ExpandSources(srcFiles []string) []string
Glob(globPattern string, excludes []string) []string
InstallFile(installPath, srcPath string, deps ...string) string InstallFile(installPath, srcPath string, deps ...string) string
InstallFileName(installPath, name, srcPath string, deps ...string) string InstallFileName(installPath, name, srcPath string, deps ...string) string
CheckbuildFile(srcPath string) CheckbuildFile(srcPath string)
@@ -465,7 +470,7 @@ func isAndroidModule(m blueprint.Module) bool {
return ok return ok
} }
func ExpandSources(ctx AndroidModuleContext, srcFiles []string) []string { func (ctx *androidModuleContext) ExpandSources(srcFiles []string) []string {
prefix := ModuleSrcDir(ctx) prefix := ModuleSrcDir(ctx)
for i, srcFile := range srcFiles { for i, srcFile := range srcFiles {
if srcFile[0] == '-' { if srcFile[0] == '-' {
@@ -475,8 +480,37 @@ func ExpandSources(ctx AndroidModuleContext, srcFiles []string) []string {
} }
} }
srcFiles = expandGlobs(ctx, srcFiles) if !hasGlob(srcFiles) {
return 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 { func BuildTargetSingleton() blueprint.Singleton {

View File

@@ -132,7 +132,7 @@ func GenSrcsFactory() (blueprint.Module, []interface{}) {
properties := &genSrcsProperties{} properties := &genSrcsProperties{}
tasks := func(ctx common.AndroidModuleContext) []generateTask { tasks := func(ctx common.AndroidModuleContext) []generateTask {
srcFiles := common.ExpandSources(ctx, properties.Srcs) srcFiles := ctx.ExpandSources(properties.Srcs)
tasks := make([]generateTask, 0, len(srcFiles)) tasks := make([]generateTask, 0, len(srcFiles))
for _, in := range srcFiles { for _, in := range srcFiles {
out := pathtools.ReplaceExtension(in, properties.Output_extension) out := pathtools.ReplaceExtension(in, properties.Output_extension)
@@ -159,7 +159,7 @@ func GenRuleFactory() (blueprint.Module, []interface{}) {
tasks := func(ctx common.AndroidModuleContext) []generateTask { tasks := func(ctx common.AndroidModuleContext) []generateTask {
return []generateTask{ return []generateTask{
{ {
in: common.ExpandSources(ctx, properties.Srcs), in: ctx.ExpandSources(properties.Srcs),
out: filepath.Join(common.ModuleGenDir(ctx), properties.Out), out: filepath.Join(common.ModuleGenDir(ctx), properties.Out),
}, },
} }

View File

@@ -244,14 +244,14 @@ func (a *AndroidApp) aaptFlags(ctx common.AndroidModuleContext) ([]string, []str
var aaptDeps []string var aaptDeps []string
var hasResources bool var hasResources bool
for _, d := range resourceDirs { for _, d := range resourceDirs {
newDeps := common.Glob(ctx, filepath.Join(d, "**/*"), aaptIgnoreFilenames) newDeps := ctx.Glob(filepath.Join(d, "**/*"), aaptIgnoreFilenames)
aaptDeps = append(aaptDeps, newDeps...) aaptDeps = append(aaptDeps, newDeps...)
if len(newDeps) > 0 { if len(newDeps) > 0 {
hasResources = true hasResources = true
} }
} }
for _, d := range assetDirs { for _, d := range assetDirs {
newDeps := common.Glob(ctx, filepath.Join(d, "**/*"), aaptIgnoreFilenames) newDeps := ctx.Glob(filepath.Join(d, "**/*"), aaptIgnoreFilenames)
aaptDeps = append(aaptDeps, newDeps...) aaptDeps = append(aaptDeps, newDeps...)
} }

View File

@@ -292,7 +292,7 @@ func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
javacDeps = append(javacDeps, classpath...) javacDeps = append(javacDeps, classpath...)
} }
srcFiles := common.ExpandSources(ctx, j.properties.Srcs) srcFiles := ctx.ExpandSources(j.properties.Srcs)
srcFiles = j.genSources(ctx, srcFiles, flags) srcFiles = j.genSources(ctx, srcFiles, flags)

View File

@@ -47,7 +47,7 @@ func ResourceDirsToJarSpecs(ctx common.AndroidModuleContext, resourceDirs []stri
continue continue
} }
resourceDir := filepath.Join(common.ModuleSrcDir(ctx), resourceDir) resourceDir := filepath.Join(common.ModuleSrcDir(ctx), resourceDir)
dirs := common.Glob(ctx, resourceDir, nil) dirs := ctx.Glob(resourceDir, nil)
for _, dir := range dirs { for _, dir := range dirs {
fileListFile := filepath.Join(common.ModuleOutDir(ctx), "res", dir, "resources.list") fileListFile := filepath.Join(common.ModuleOutDir(ctx), "res", dir, "resources.list")
depFile := fileListFile + ".d" depFile := fileListFile + ".d"