diff options
| author | Fumitoshi Ukai <fumitoshi.ukai@gmail.com> | 2015-07-13 13:14:41 +0900 |
|---|---|---|
| committer | Fumitoshi Ukai <fumitoshi.ukai@gmail.com> | 2015-07-13 13:14:41 +0900 |
| commit | e08e9ee8144a4de8faab210e56a56519b5c7fa96 (patch) | |
| tree | 5bf3df01335f4459246010fb211c07ff1deb75c6 /ninja.go | |
| parent | 923b128513994626c606f61a7495a95dc161e8fe (diff) | |
[go] backport [C++] Automatically generate shortcuts
commit 2aec79e79f856d5ca62e369fdb0d912a358a14d4
Diffstat (limited to 'ninja.go')
| -rw-r--r-- | ninja.go | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -21,6 +21,7 @@ import ( "path/filepath" "regexp" "runtime" + "sort" "strings" "time" ) @@ -32,9 +33,10 @@ type ninjaGenerator struct { ctx *execContext - ruleID int - done map[string]bool - gomaDir string + ruleID int + done map[string]bool + shortNames map[string][]string + gomaDir string } var ccRE = regexp.MustCompile(`^prebuilts/(gcc|clang)/.*(gcc|g\+\+|clang|clang\+\+) .* -c `) @@ -245,6 +247,11 @@ func (n *ninjaGenerator) emitNode(node *DepNode) error { return nil } + base := filepath.Base(node.Output) + if base != node.Output { + n.shortNames[base] = append(n.shortNames[base], node.Output) + } + runners, _, err := createRunners(n.ctx, node) if err != nil { return err @@ -361,6 +368,20 @@ func (n *ninjaGenerator) generateNinja() (err error) { return err } } + + fmt.Fprintf(n.f, "\n# shortcuts:\n") + var names []string + for name := range n.shortNames { + names = append(names, name) + } + sort.Strings(names) + for _, name := range names { + if len(n.shortNames[name]) != 1 { + // we generate shortcuts only for targets whose basename are unique. + continue + } + fmt.Fprintf(n.f, "build %s: phony %s\n", name, n.shortNames[name][0]) + } return nil } |
