diff options
| author | Fumitoshi Ukai <ukai@google.com> | 2015-07-28 16:46:11 +0900 |
|---|---|---|
| committer | Fumitoshi Ukai <ukai@google.com> | 2015-07-28 16:46:11 +0900 |
| commit | b6adb3912c0a0e6294d47be0bce4c6907662e44e (patch) | |
| tree | c01784b99eef50c25c35ad459425c35f1639bca9 /ninja.go | |
| parent | 66c4ee1e41f02243c16edefd1c851117283f3eb4 (diff) | |
[go] fix preserve_single_dot.mk
ninja will normalize a/./b as a/b, so don't use ${out} or ${in}
for unnormalized output/inputs.
Diffstat (limited to 'ninja.go')
| -rw-r--r-- | ninja.go | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -373,6 +373,24 @@ func escapeShell(s string) string { return buf.String() } +func (n *NinjaGenerator) ninjaVars(s string, nv [][]string, esc func(string) string) string { + for _, v := range nv { + k, v := v[0], v[1] + if v == "" { + continue + } + if strings.Contains(v, "/./") || strings.Contains(v, "/../") { + // ninja will normalize this, so keep it as is + continue + } + if esc != nil { + v = esc(v) + } + s = strings.Replace(s, v, k, -1) + } + return s +} + func (n *NinjaGenerator) emitNode(node *DepNode) error { if n.done[node.Output] { return nil @@ -418,23 +436,21 @@ func (n *NinjaGenerator) emitNode(node *DepNode) error { fmt.Fprintf(n.f, " depfile = %s\n", depfile) fmt.Fprintf(n.f, " deps = gcc\n") } + nv := [][]string{ + []string{"${in}", inputs}, + []string{"${out}", escapeNinja(node.Output)}, + } // It seems Linux is OK with ~130kB. // TODO: Find this number automatically. ArgLenLimit := 100 * 1000 if len(cmdline) > ArgLenLimit { fmt.Fprintf(n.f, " rspfile = $out.rsp\n") - if inputs != "" { - cmdline = strings.Replace(cmdline, inputs, "${in}", -1) - } - cmdline = strings.Replace(cmdline, escapeNinja(node.Output), "${out}", -1) + cmdline = n.ninjaVars(cmdline, nv, nil) fmt.Fprintf(n.f, " rspfile_content = %s\n", cmdline) fmt.Fprintf(n.f, " command = %s $out.rsp\n", n.ctx.shell) } else { cmdline = escapeShell(cmdline) - if inputs != "" { - cmdline = strings.Replace(cmdline, escapeShell(inputs), "${in}", -1) - } - cmdline = strings.Replace(cmdline, escapeShell(escapeNinja(node.Output)), "${out}", -1) + cmdline = n.ninjaVars(cmdline, nv, escapeShell) fmt.Fprintf(n.f, " command = %s -c \"%s\"\n", n.ctx.shell, cmdline) } } |
