diff options
| author | Colin Cross <ccross@android.com> | 2015-04-10 15:47:33 -0700 |
|---|---|---|
| committer | Colin Cross <ccross@android.com> | 2015-04-10 16:12:49 -0700 |
| commit | 9b6826f7cf654f3f7e947bd65448ef318f14278f (patch) | |
| tree | 467adac6a575ce3efd12847b52ea5cb70ee8a8f9 /common | |
| parent | 24679676cad44947ea8752d1d193b0541d942a16 (diff) | |
| download | build_soong-9b6826f7cf654f3f7e947bd65448ef318f14278f.tar.gz build_soong-9b6826f7cf654f3f7e947bd65448ef318f14278f.tar.bz2 build_soong-9b6826f7cf654f3f7e947bd65448ef318f14278f.zip | |
Quote glob exclude options
Put quotes around the glob exclude options to avoid accidentally
expanding globs during execution.
Change-Id: Ia6fc7fa7dbe1d75e97d6039642e1c89be027689a
Diffstat (limited to 'common')
| -rw-r--r-- | common/glob.go | 7 | ||||
| -rw-r--r-- | common/util.go | 27 |
2 files changed, 28 insertions, 6 deletions
diff --git a/common/glob.go b/common/glob.go index 7bb623df..f4e083a4 100644 --- a/common/glob.go +++ b/common/glob.go @@ -17,7 +17,6 @@ package common import ( "fmt" "path/filepath" - "strings" "github.com/google/blueprint" "github.com/google/blueprint/bootstrap" @@ -113,10 +112,6 @@ func Glob(ctx AndroidModuleContext, globPattern string, excludes []string) []str func GlobRule(ctx AndroidModuleContext, globPattern string, excludes []string, fileListFile, depFile string) { - var excludeArgs []string - for _, e := range excludes { - excludeArgs = append(excludeArgs, "-e "+e) - } // Create a rule to rebuild fileListFile if a directory in depFile changes. fileListFile // will only be rewritten if it has changed, preventing unnecesary build.ninja regenerations. @@ -126,7 +121,7 @@ func GlobRule(ctx AndroidModuleContext, globPattern string, excludes []string, Implicits: []string{globCmd}, Args: map[string]string{ "glob": globPattern, - "excludes": strings.Join(excludeArgs, " "), + "excludes": JoinWithPrefixAndQuote(excludes, "-e "), }, }) diff --git a/common/util.go b/common/util.go index 190e0925..599b3b17 100644 --- a/common/util.go +++ b/common/util.go @@ -38,3 +38,30 @@ func JoinWithPrefix(strs []string, prefix string) string { } return string(ret) } + +func JoinWithPrefixAndQuote(strs []string, prefix string) string { + if len(strs) == 0 { + return "" + } + + if len(strs) == 1 { + return prefix + `"` + strs[0] + `"` + } + + n := len(" ") * (len(strs) - 1) + for _, s := range strs { + n += len(prefix) + len(s) + len(`""`) + } + + ret := make([]byte, 0, n) + for i, s := range strs { + if i != 0 { + ret = append(ret, ' ') + } + ret = append(ret, prefix...) + ret = append(ret, '"') + ret = append(ret, s...) + ret = append(ret, '"') + } + return string(ret) +} |
