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 }