aboutsummaryrefslogtreecommitdiffstats
path: root/ninja.go
diff options
context:
space:
mode:
Diffstat (limited to 'ninja.go')
-rw-r--r--ninja.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/ninja.go b/ninja.go
index ac9748f..174e54a 100644
--- a/ninja.go
+++ b/ninja.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package main
+package kati
import (
"bytes"
@@ -33,9 +33,10 @@ type NinjaGenerator struct {
ruleID int
done map[string]bool
ccRe *regexp.Regexp
+ gomaDir string
}
-func NewNinjaGenerator(g *DepGraph) *NinjaGenerator {
+func NewNinjaGenerator(g *DepGraph, gomaDir string) *NinjaGenerator {
ccRe, err := regexp.Compile(`^prebuilts/(gcc|clang)/.*(gcc|g\+\+|clang|clang\+\+) .* -c `)
if err != nil {
panic(err)
@@ -46,6 +47,7 @@ func NewNinjaGenerator(g *DepGraph) *NinjaGenerator {
exports: g.exports,
done: make(map[string]bool),
ccRe: ccRe,
+ gomaDir: gomaDir,
}
}
@@ -172,8 +174,8 @@ func (n *NinjaGenerator) genShellScript(runners []runner) (string, bool) {
if cmd == "" {
cmd = "true"
}
- if gomaDir != "" && n.ccRe.MatchString(cmd) {
- cmd = fmt.Sprintf("%s/gomacc %s", gomaDir, cmd)
+ if n.gomaDir != "" && n.ccRe.MatchString(cmd) {
+ cmd = fmt.Sprintf("%s/gomacc %s", n.gomaDir, cmd)
useGomacc = true
}
@@ -193,7 +195,7 @@ func (n *NinjaGenerator) genShellScript(runners []runner) (string, bool) {
buf.WriteByte(')')
}
}
- return buf.String(), gomaDir != "" && !useGomacc
+ return buf.String(), n.gomaDir != "" && !useGomacc
}
func (n *NinjaGenerator) genRuleName() string {
@@ -283,7 +285,7 @@ func (n *NinjaGenerator) generateShell() {
}
defer f.Close()
- ev := newEvaluator(n.vars)
+ ev := NewEvaluator(n.vars)
shell := ev.EvaluateVar("SHELL")
if shell == "" {
shell = "/bin/sh"
@@ -296,7 +298,7 @@ func (n *NinjaGenerator) generateShell() {
fmt.Fprintf(f, "unset %s\n", name)
}
}
- if gomaDir == "" {
+ if n.gomaDir == "" {
fmt.Fprintln(f, `exec ninja "$@"`)
} else {
fmt.Fprintln(f, `exec ninja -j300 "$@"`)
@@ -319,19 +321,19 @@ func (n *NinjaGenerator) generateNinja() {
fmt.Fprintf(n.f, "# Generated by kati\n")
fmt.Fprintf(n.f, "\n")
- if gomaDir != "" {
+ if n.gomaDir != "" {
fmt.Fprintf(n.f, "pool local_pool\n")
fmt.Fprintf(n.f, " depth = %d\n", runtime.NumCPU())
}
- n.ex = NewExecutor(n.vars)
+ n.ex = NewExecutor(n.vars, nil)
for _, node := range n.nodes {
n.emitNode(node)
}
}
-func GenerateNinja(g *DepGraph) {
- n := NewNinjaGenerator(g)
+func GenerateNinja(g *DepGraph, gomaDir string) {
+ n := NewNinjaGenerator(g, gomaDir)
n.generateShell()
n.generateNinja()
}