Move globbing on top of pathtools.GlobWithExcludes
pathtools.GlobWithExcludes contains all the features of glob.GlobWithDepFile now, make GlobWithDepFile a wrapper around GlobWithExcludes that writes the results to a file. Change-Id: Ie75d9042845505f499aac7fa00d3c90f8ecab4f7
This commit is contained in:
parent
d8e780df69
commit
6f23ef6bf3
|
@ -62,6 +62,7 @@ bootstrap_go_package {
|
||||||
pkgPath: "android/soong/glob",
|
pkgPath: "android/soong/glob",
|
||||||
deps: [
|
deps: [
|
||||||
"blueprint-deptools",
|
"blueprint-deptools",
|
||||||
|
"blueprint-pathtools",
|
||||||
],
|
],
|
||||||
srcs: [
|
srcs: [
|
||||||
"glob/glob.go",
|
"glob/glob.go",
|
||||||
|
|
|
@ -53,7 +53,7 @@ rule g.bootstrap.link
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_go_binary
|
# Type: bootstrap_go_binary
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
|
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
|
||||||
# Defined: build/soong/Blueprints:160:1
|
# Defined: build/soong/Blueprints:161:1
|
||||||
|
|
||||||
build .bootstrap/androidmk/obj/androidmk.a: g.bootstrap.gc $
|
build .bootstrap/androidmk/obj/androidmk.a: g.bootstrap.gc $
|
||||||
${g.bootstrap.srcDir}/build/soong/androidmk/cmd/androidmk/android.go $
|
${g.bootstrap.srcDir}/build/soong/androidmk/cmd/androidmk/android.go $
|
||||||
|
@ -79,7 +79,7 @@ default .bootstrap/bin/androidmk
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_go_package
|
# Type: bootstrap_go_package
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
||||||
# Defined: build/soong/Blueprints:173:1
|
# Defined: build/soong/Blueprints:174:1
|
||||||
|
|
||||||
build .bootstrap/androidmk-parser/pkg/android/soong/androidmk/parser.a: $
|
build .bootstrap/androidmk-parser/pkg/android/soong/androidmk/parser.a: $
|
||||||
g.bootstrap.gc $
|
g.bootstrap.gc $
|
||||||
|
@ -310,7 +310,7 @@ default .bootstrap/soong-art/pkg/android/soong/art.a
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_go_package
|
# Type: bootstrap_go_package
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
||||||
# Defined: build/soong/Blueprints:93:1
|
# Defined: build/soong/Blueprints:94:1
|
||||||
|
|
||||||
build .bootstrap/soong-cc/pkg/android/soong/cc.a: g.bootstrap.gc $
|
build .bootstrap/soong-cc/pkg/android/soong/cc.a: g.bootstrap.gc $
|
||||||
${g.bootstrap.srcDir}/build/soong/cc/builder.go $
|
${g.bootstrap.srcDir}/build/soong/cc/builder.go $
|
||||||
|
@ -342,7 +342,7 @@ default .bootstrap/soong-cc/pkg/android/soong/cc.a
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_go_package
|
# Type: bootstrap_go_package
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
||||||
# Defined: build/soong/Blueprints:71:1
|
# Defined: build/soong/Blueprints:72:1
|
||||||
|
|
||||||
build .bootstrap/soong-common/pkg/android/soong/common.a: g.bootstrap.gc $
|
build .bootstrap/soong-common/pkg/android/soong/common.a: g.bootstrap.gc $
|
||||||
${g.bootstrap.srcDir}/build/soong/common/arch.go $
|
${g.bootstrap.srcDir}/build/soong/common/arch.go $
|
||||||
|
@ -384,7 +384,7 @@ default .bootstrap/soong-env/pkg/android/soong/env.a
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_go_package
|
# Type: bootstrap_go_package
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
||||||
# Defined: build/soong/Blueprints:117:1
|
# Defined: build/soong/Blueprints:118:1
|
||||||
|
|
||||||
build .bootstrap/soong-genrule/pkg/android/soong/genrule.a: g.bootstrap.gc $
|
build .bootstrap/soong-genrule/pkg/android/soong/genrule.a: g.bootstrap.gc $
|
||||||
${g.bootstrap.srcDir}/build/soong/genrule/genrule.go | $
|
${g.bootstrap.srcDir}/build/soong/genrule/genrule.go | $
|
||||||
|
@ -411,8 +411,9 @@ default .bootstrap/soong-genrule/pkg/android/soong/genrule.a
|
||||||
|
|
||||||
build .bootstrap/soong-glob/pkg/android/soong/glob.a: g.bootstrap.gc $
|
build .bootstrap/soong-glob/pkg/android/soong/glob.a: g.bootstrap.gc $
|
||||||
${g.bootstrap.srcDir}/build/soong/glob/glob.go | ${g.bootstrap.gcCmd} $
|
${g.bootstrap.srcDir}/build/soong/glob/glob.go | ${g.bootstrap.gcCmd} $
|
||||||
.bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a
|
.bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
|
||||||
incFlags = -I .bootstrap/blueprint-deptools/pkg
|
.bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a
|
||||||
|
incFlags = -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-pathtools/pkg
|
||||||
pkgPath = android/soong/glob
|
pkgPath = android/soong/glob
|
||||||
default .bootstrap/soong-glob/pkg/android/soong/glob.a
|
default .bootstrap/soong-glob/pkg/android/soong/glob.a
|
||||||
|
|
||||||
|
@ -421,7 +422,7 @@ default .bootstrap/soong-glob/pkg/android/soong/glob.a
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_go_package
|
# Type: bootstrap_go_package
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
|
||||||
# Defined: build/soong/Blueprints:137:1
|
# Defined: build/soong/Blueprints:138:1
|
||||||
|
|
||||||
build .bootstrap/soong-java/pkg/android/soong/java.a: g.bootstrap.gc $
|
build .bootstrap/soong-java/pkg/android/soong/java.a: g.bootstrap.gc $
|
||||||
${g.bootstrap.srcDir}/build/soong/java/app_builder.go $
|
${g.bootstrap.srcDir}/build/soong/java/app_builder.go $
|
||||||
|
@ -514,14 +515,15 @@ build .bootstrap/soong_glob/obj/soong_glob.a: g.bootstrap.gc $
|
||||||
${g.bootstrap.srcDir}/build/soong/cmd/soong_glob/soong_glob.go | $
|
${g.bootstrap.srcDir}/build/soong/cmd/soong_glob/soong_glob.go | $
|
||||||
${g.bootstrap.gcCmd} $
|
${g.bootstrap.gcCmd} $
|
||||||
.bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
|
.bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
|
||||||
|
.bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
|
||||||
.bootstrap/soong-glob/pkg/android/soong/glob.a
|
.bootstrap/soong-glob/pkg/android/soong/glob.a
|
||||||
incFlags = -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/soong-glob/pkg
|
incFlags = -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/soong-glob/pkg
|
||||||
pkgPath = soong_glob
|
pkgPath = soong_glob
|
||||||
default .bootstrap/soong_glob/obj/soong_glob.a
|
default .bootstrap/soong_glob/obj/soong_glob.a
|
||||||
|
|
||||||
build .bootstrap/soong_glob/obj/a.out: g.bootstrap.link $
|
build .bootstrap/soong_glob/obj/a.out: g.bootstrap.link $
|
||||||
.bootstrap/soong_glob/obj/soong_glob.a | ${g.bootstrap.linkCmd}
|
.bootstrap/soong_glob/obj/soong_glob.a | ${g.bootstrap.linkCmd}
|
||||||
libDirFlags = -L .bootstrap/blueprint-deptools/pkg -L .bootstrap/soong-glob/pkg
|
libDirFlags = -L .bootstrap/blueprint-deptools/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/soong-glob/pkg
|
||||||
default .bootstrap/soong_glob/obj/a.out
|
default .bootstrap/soong_glob/obj/a.out
|
||||||
|
|
||||||
build .bootstrap/bin/soong_glob: g.bootstrap.cp $
|
build .bootstrap/bin/soong_glob: g.bootstrap.cp $
|
||||||
|
@ -533,7 +535,7 @@ default .bootstrap/bin/soong_glob
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_go_binary
|
# Type: bootstrap_go_binary
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
|
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
|
||||||
# Defined: build/soong/Blueprints:130:1
|
# Defined: build/soong/Blueprints:131:1
|
||||||
|
|
||||||
build .bootstrap/soong_jar/obj/soong_jar.a: g.bootstrap.gc $
|
build .bootstrap/soong_jar/obj/soong_jar.a: g.bootstrap.gc $
|
||||||
${g.bootstrap.srcDir}/build/soong/cmd/soong_jar/soong_jar.go | $
|
${g.bootstrap.srcDir}/build/soong/cmd/soong_jar/soong_jar.go | $
|
||||||
|
|
51
glob/glob.go
51
glob/glob.go
|
@ -21,6 +21,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/blueprint/deptools"
|
"github.com/google/blueprint/deptools"
|
||||||
|
"github.com/google/blueprint/pathtools"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsGlob(glob string) bool {
|
func IsGlob(glob string) bool {
|
||||||
|
@ -36,55 +37,11 @@ func IsGlob(glob string) bool {
|
||||||
//
|
//
|
||||||
// Returns a list of file paths, and an error.
|
// Returns a list of file paths, and an error.
|
||||||
func GlobWithDepFile(glob, fileListFile, depFile string, excludes []string) (files []string, err error) {
|
func GlobWithDepFile(glob, fileListFile, depFile string, excludes []string) (files []string, err error) {
|
||||||
globPattern := filepath.Base(glob)
|
files, dirs, err := pathtools.GlobWithExcludes(glob, excludes)
|
||||||
globDir := filepath.Dir(glob)
|
if err != nil {
|
||||||
recursive := false
|
return nil, err
|
||||||
|
|
||||||
if filepath.Base(globDir) == "**" {
|
|
||||||
recursive = true
|
|
||||||
globDir = filepath.Dir(globDir)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var dirs []string
|
|
||||||
|
|
||||||
err = filepath.Walk(globDir,
|
|
||||||
func(path string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if info.Mode().IsDir() {
|
|
||||||
dirs = append(dirs, path)
|
|
||||||
if !recursive && path != globDir {
|
|
||||||
return filepath.SkipDir
|
|
||||||
}
|
|
||||||
} else if info.Mode().IsRegular() {
|
|
||||||
match, err := filepath.Match(globPattern, info.Name())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if match {
|
|
||||||
for _, e := range excludes {
|
|
||||||
var excludeMatch bool
|
|
||||||
if filepath.Base(e) == e {
|
|
||||||
excludeMatch, err = filepath.Match(e, info.Name())
|
|
||||||
} else {
|
|
||||||
excludeMatch, err = filepath.Match(e, path)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if excludeMatch {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
files = append(files, path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
fileList := strings.Join(files, "\n") + "\n"
|
fileList := strings.Join(files, "\n") + "\n"
|
||||||
|
|
||||||
writeFileIfChanged(fileListFile, []byte(fileList), 0666)
|
writeFileIfChanged(fileListFile, []byte(fileList), 0666)
|
||||||
|
|
Loading…
Reference in New Issue