diff options
-rw-r--r-- | cmd/kati/main.go | 54 | ||||
-rw-r--r-- | depgraph.go | 7 | ||||
-rw-r--r-- | exec.go | 24 | ||||
-rw-r--r-- | serialize.go | 1 | ||||
-rw-r--r-- | strutil.go | 1 |
5 files changed, 34 insertions, 53 deletions
diff --git a/cmd/kati/main.go b/cmd/kati/main.go index 364e775..f8f2a82 100644 --- a/cmd/kati/main.go +++ b/cmd/kati/main.go @@ -127,27 +127,17 @@ func (t memStatsDumper) dump() { } } -func findPara() string { - switch runtime.GOOS { - case "linux": - katicmd, err := os.Readlink("/proc/self/exe") - if err != nil { - panic(err) - } - return filepath.Join(filepath.Dir(katicmd), "para") - default: - panic(fmt.Sprintf("unknown OS: %s", runtime.GOOS)) - } -} - -func load(req kati.LoadReq) (*kati.DepGraph, error) { +func load(req kati.LoadReq) (*kati.DepGraph, bool, error) { if loadGOB != "" { - return kati.GOB.Load(loadGOB) + g, err := kati.GOB.Load(loadGOB) + return g, true, err } if loadJSON != "" { - return kati.JSON.Load(loadJSON) + g, err := kati.JSON.Load(loadJSON) + return g, true, err } - return kati.Load(req) + g, err := kati.Load(req) + return g, false, err } func save(g *kati.DepGraph, targets []string) error { @@ -284,16 +274,16 @@ func katiMain(args []string) error { req.UseCache = useCache req.EagerEvalCommand = eagerCmdEvalFlag - g, err := load(req) + g, cached, err := load(req) if err != nil { return err } - nodes := g.Nodes() - vars := g.Vars() - err = save(g, req.Targets) - if err != nil { - return err + if !cached { + err = save(g, req.Targets) + if err != nil { + return err + } } if generateNinja { @@ -309,28 +299,14 @@ func katiMain(args []string) error { return nil } - // TODO: Handle target specific variables. - ev := kati.NewEvaluator(vars) - for name, export := range g.Exports() { - if export { - v, err := ev.EvaluateVar(name) - if err != nil { - return err - } - os.Setenv(name, v) - } else { - os.Unsetenv(name) - } - } - execOpt := &kati.ExecutorOpt{ NumJobs: jobsFlag, } - ex, err := kati.NewExecutor(vars, execOpt) + ex, err := kati.NewExecutor(execOpt) if err != nil { return err } - err = ex.Exec(nodes) + err = ex.Exec(g) if err != nil { return err } diff --git a/depgraph.go b/depgraph.go index a844aaa..2e921fc 100644 --- a/depgraph.go +++ b/depgraph.go @@ -28,7 +28,6 @@ type DepGraph struct { vars Vars accessedMks []*accessedMakefile exports map[string]bool - isCached bool } // Nodes returns all rules. @@ -37,12 +36,6 @@ func (g *DepGraph) Nodes() []*DepNode { return g.nodes } // Vars returns all variables. func (g *DepGraph) Vars() Vars { return g.vars } -// Exports returns map for export variables. -func (g *DepGraph) Exports() map[string]bool { return g.exports } - -// IsCached indicates the DepGraph is loaded from cache. -func (g *DepGraph) IsCached() bool { return g.isCached } - // LoadReq is a request to load makefile. type LoadReq struct { Makefile string @@ -16,6 +16,7 @@ package kati import ( "fmt" + "os" "time" ) @@ -129,7 +130,7 @@ type ExecutorOpt struct { } // NewExecutor creates new Executor. -func NewExecutor(vars Vars, opt *ExecutorOpt) (*Executor, error) { +func NewExecutor(opt *ExecutorOpt) (*Executor, error) { if opt == nil { opt = &ExecutorOpt{NumJobs: 1} } @@ -140,21 +141,34 @@ func NewExecutor(vars Vars, opt *ExecutorOpt) (*Executor, error) { if err != nil { return nil, err } - ctx := newExecContext(vars, false) ex := &Executor{ rules: make(map[string]*rule), suffixRules: make(map[string][]*rule), done: make(map[string]*job), wm: wm, - ctx: ctx, } return ex, nil } // Exec executes to build roots. -func (ex *Executor) Exec(roots []*DepNode) error { +func (ex *Executor) Exec(g *DepGraph) error { + ex.ctx = newExecContext(g.vars, false) + + // TODO: Handle target specific variables. + for name, export := range g.exports { + if export { + v, err := ex.ctx.ev.EvaluateVar(name) + if err != nil { + return err + } + os.Setenv(name, v) + } else { + os.Unsetenv(name) + } + } + startTime := time.Now() - for _, root := range roots { + for _, root := range g.nodes { err := ex.makeJobs(root, nil) if err != nil { break diff --git a/serialize.go b/serialize.go index 9987f9c..33ca981 100644 --- a/serialize.go +++ b/serialize.go @@ -788,7 +788,6 @@ func loadCache(makefile string, roots []string) (*DepGraph, error) { } } } - g.isCached = true logAlways("Cache found!") return g, nil } @@ -328,7 +328,6 @@ func findLiteralChar(s []byte, stop1, stop2 byte) int { } return i } - return -1 } func removeComment(line []byte) ([]byte, bool) { |