-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathninja_manifest.go
114 lines (108 loc) · 2.1 KB
/
ninja_manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"fmt"
"sort"
)
// NinjaRule represents a rule for ninja.
type NinjaRule struct {
Name string
Command string
Description string
Deps string
DepFile string
}
// NinjaBuild represents a build statement for ninja.
type NinjaBuild struct {
Rule string
Outputs []string
Inputs []string
ImplicitOuts []string
ImplicitDeps []string
Variables map[string]string
Pool string
}
// ToString converts a ninja rule to a string.
func (r *NinjaRule) ToString() (str string) {
str += fmt.Sprintln("rule", r.Name)
if len(r.Description) > 0 {
str += fmt.Sprintln(" description =", r.DepFile)
}
str += fmt.Sprintln(" command =", r.Command)
if len(r.Deps) > 0 {
str += fmt.Sprintln(" deps =", r.Deps)
}
if len(r.DepFile) > 0 {
str += fmt.Sprintln(" depfile =", r.DepFile)
}
return str
}
// ToString converts a ninja definition to a string.
func (e *NinjaBuild) ToString() (str string) {
useMultiLine := (len(e.Outputs)+len(e.ImplicitOuts) > 1) || (len(e.Inputs)+len(e.ImplicitDeps) > 1)
str += "build"
if len(e.Outputs) > 0 {
if len(e.Outputs)+len(e.ImplicitOuts) > 1 {
str += " $\n "
} else {
str += " "
}
}
for i, f := range e.Outputs {
if i > 0 {
str += " $\n "
}
str += f
}
if len(e.ImplicitOuts) > 0 {
str += " | "
if useMultiLine {
str += "$\n "
}
}
for i, f := range e.ImplicitOuts {
if i > 0 {
str += " $\n "
}
str += f
}
str += ": "
str += e.Rule
if len(e.Inputs) > 0 {
if useMultiLine {
str += " $\n "
} else {
str += " "
}
}
for i, f := range e.Inputs {
if i > 0 {
str += " $\n "
}
str += f
}
if len(e.ImplicitDeps) > 0 {
str += " | "
if useMultiLine {
str += "$\n "
}
}
for i, f := range e.ImplicitDeps {
if i > 0 {
str += " $\n "
}
str += f
}
str += "\n"
if len(e.Pool) > 0 {
str += fmt.Sprintf(" pool = %s\n", e.Pool)
}
var variables []string
for k, v := range e.Variables {
variables = append(variables, fmt.Sprintf(" %s = %s\n", k, v))
}
sort.Strings(variables)
for _, v := range variables {
str += v
}
return str
}