diff options
| author | Fumitoshi Ukai <fumitoshi.ukai@gmail.com> | 2015-07-13 12:53:30 +0900 |
|---|---|---|
| committer | Fumitoshi Ukai <fumitoshi.ukai@gmail.com> | 2015-07-13 12:53:30 +0900 |
| commit | 923b128513994626c606f61a7495a95dc161e8fe (patch) | |
| tree | 3a2654105f8c65b76e9de9d7ea6c51eb7f7f4495 /ninja.go | |
| parent | 8c409b82dc58fdfdd74c9fb8baa46f13644b4369 (diff) | |
[go] backport [C++] Emit "deps = gcc" in ninja file
commit 72a123098958c0304b4ffda1cc69fdc87f2a54e0
Diffstat (limited to 'ninja.go')
| -rw-r--r-- | ninja.go | 50 |
1 files changed, 30 insertions, 20 deletions
@@ -85,42 +85,51 @@ func getDepfileImpl(ss string) (string, error) { return stripExt(out) + ".d", nil } -func getDepfile(ss string) (string, error) { +// getDepfile gets depfile from cmdline, and returns cmdline and depfile. +func getDepfile(cmdline string) (string, string, error) { // A hack for Android - llvm-rs-cc seems not to emit a dep file. - if strings.Contains(ss, "bin/llvm-rs-cc ") { - return "", nil + if strings.Contains(cmdline, "bin/llvm-rs-cc ") { + return cmdline, "", nil } - r, err := getDepfileImpl(ss) - if r == "" || err != nil { - return r, err + depfile, err := getDepfileImpl(cmdline) + if depfile == "" || err != nil { + return cmdline, depfile, err } // A hack for Makefiles generated by automake. - mvCmd := "(mv -f " + r + " " - if i := strings.LastIndex(ss, mvCmd); i >= 0 { - rest := ss[i+len(mvCmd):] + mvCmd := "(mv -f " + depfile + " " + if i := strings.LastIndex(cmdline, mvCmd); i >= 0 { + rest := cmdline[i+len(mvCmd):] ei := strings.IndexByte(rest, ')') if ei < 0 { - return "", fmt.Errorf("unbalanced parenthes? %s", ss) + return cmdline, "", fmt.Errorf("unbalanced parenthes? %s", cmdline) } - return rest[:ei], nil + cmdline = cmdline[:i] + "(cp -f " + depfile + " " + rest + return cmdline, depfile, nil } // A hack for Android to get .P files instead of .d. - p := stripExt(r) + ".P" - if strings.Contains(ss, p) { - return p, nil + p := stripExt(depfile) + ".P" + if strings.Contains(cmdline, p) { + rmfCmd := "; rm -f " + depfile + ncmdline := strings.Replace(cmdline, rmfCmd, "", 1) + if ncmdline == cmdline { + return cmdline, "", fmt.Errorf("cannot find removal of .d file: %s", cmdline) + } + return ncmdline, p, nil } // A hack for Android. For .s files, GCC does not use // C preprocessor, so it ignores -MF flag. - as := "/" + stripExt(filepath.Base(r)) + ".s" - if strings.Contains(ss, as) { - return "", nil + as := "/" + stripExt(filepath.Base(depfile)) + ".s" + if strings.Contains(cmdline, as) { + return cmdline, "", nil } - return r, nil + cmdline += fmt.Sprintf(" && cp %s %s.tmp", depfile, depfile) + depfile += ".tmp" + return cmdline, depfile, nil } func stripShellComment(s string) string { @@ -252,12 +261,13 @@ func (n *ninjaGenerator) emitNode(node *DepNode) error { if ulp { useLocalPool = true } - depfile, err := getDepfile(ss) + cmdline, depfile, err := getDepfile(ss) if err != nil { return err } if depfile != "" { fmt.Fprintf(n.f, " depfile = %s\n", depfile) + fmt.Fprintf(n.f, " deps = gcc\n") } // It seems Linux is OK with ~130kB. // TODO: Find this number automatically. @@ -267,7 +277,7 @@ func (n *ninjaGenerator) emitNode(node *DepNode) error { fmt.Fprintf(n.f, " rspfile_content = %s\n", ss) ss = "sh $out.rsp" } - fmt.Fprintf(n.f, " command = %s\n", ss) + fmt.Fprintf(n.f, " command = %s\n", cmdline) } n.emitBuild(node.Output, ruleName, getDepString(node)) |
