aboutsummaryrefslogtreecommitdiffstats
path: root/deptools
diff options
context:
space:
mode:
authorChristian Zander <czander@google.com>2015-01-12 11:37:17 -0800
committerJamie Gennis <jgennis@replicant.com>2015-04-14 23:34:24 -0400
commitc4d07d8fb530e724a8960d9e70bc93632818f9c2 (patch)
treea62d30c1d7f41168d1d1e9e2484f77517a7864b5 /deptools
parente28dbe4d0c90d0edc2c83d1b66be71df30f4a77e (diff)
downloadplatform_build_blueprint-c4d07d8fb530e724a8960d9e70bc93632818f9c2.tar.gz
platform_build_blueprint-c4d07d8fb530e724a8960d9e70bc93632818f9c2.tar.bz2
platform_build_blueprint-c4d07d8fb530e724a8960d9e70bc93632818f9c2.zip
Make WriteDepFile escape spaces and special characters
This commit makes deptools.WriteDepFile() escape spaces and the following set of special characters in the dependencies it writes to files used as Ninja depfiles: \, #, *, [, |. Without this change, dependencies with paths including any of the above may not function as intended. Change-Id: I3560a34de930932422200985fb479515a21d9508
Diffstat (limited to 'deptools')
-rw-r--r--deptools/depfile.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/deptools/depfile.go b/deptools/depfile.go
index cc114f6..bfcf2ce 100644
--- a/deptools/depfile.go
+++ b/deptools/depfile.go
@@ -20,6 +20,16 @@ import (
"strings"
)
+var (
+ pathEscaper = strings.NewReplacer(
+ `\`, `\\`,
+ ` `, `\ `,
+ `#`, `\#`,
+ `*`, `\*`,
+ `[`, `\[`,
+ `|`, `\|`)
+)
+
// WriteDepFile creates a new gcc-style depfile and populates it with content
// indicating that target depends on deps.
func WriteDepFile(filename, target string, deps []string) error {
@@ -29,8 +39,14 @@ func WriteDepFile(filename, target string, deps []string) error {
}
defer f.Close()
+ var escapedDeps []string
+
+ for _, dep := range deps {
+ escapedDeps = append(escapedDeps, pathEscaper.Replace(dep))
+ }
+
_, err = fmt.Fprintf(f, "%s: \\\n %s\n", target,
- strings.Join(deps, " \\\n "))
+ strings.Join(escapedDeps, " \\\n "))
if err != nil {
return err
}