aboutsummaryrefslogtreecommitdiff
path: root/exec.go
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-04-29 03:34:07 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-04-29 03:34:07 +0900
commitb41fd50af601454e29aa717c7e97d0ae27dc47a1 (patch)
tree8f8789ae8ef69b4899722b68a94e9eac9d340e83 /exec.go
parent212abfb18ea3e5210f539428e56cef65adfc1552 (diff)
downloadkati-b41fd50af601454e29aa717c7e97d0ae27dc47a1.tar.gz
Add an experimental --eager_cmd_eval flag
Maybe we should remove this later. This step seems to take only 5 seconds, cannot be a bottleneck.
Diffstat (limited to 'exec.go')
-rw-r--r--exec.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/exec.go b/exec.go
index c6b0647..4ba8302 100644
--- a/exec.go
+++ b/exec.go
@@ -245,3 +245,73 @@ func (ex *Executor) Exec(roots []*DepNode) error {
ex.wm.Wait()
return nil
}
+
+func (ex *Executor) createRunners(n *DepNode, avoidIO bool) ([]runner, bool) {
+ var restores []func()
+ defer func() {
+ for _, restore := range restores {
+ restore()
+ }
+ }()
+
+ ex.varsLock.Lock()
+ restores = append(restores, func() { ex.varsLock.Unlock() })
+ // For automatic variables.
+ ex.currentOutput = n.Output
+ ex.currentInputs = n.ActualInputs
+ for k, v := range n.TargetSpecificVars {
+ restores = append(restores, ex.vars.save(k))
+ ex.vars[k] = v
+ }
+
+ ev := newEvaluator(ex.vars)
+ ev.avoidIO = avoidIO
+ ev.filename = n.Filename
+ ev.lineno = n.Lineno
+ var runners []runner
+ Log("Building: %s cmds:%q", n.Output, n.Cmds)
+ r := runner{
+ output: n.Output,
+ echo: true,
+ shell: ex.shell,
+ }
+ for _, cmd := range n.Cmds {
+ for _, r := range evalCmd(ev, r, cmd) {
+ if len(r.cmd) != 0 {
+ runners = append(runners, r)
+ }
+ }
+ }
+ return runners, ev.hasIO
+}
+
+func EvalCommands(nodes []*DepNode, vars Vars) {
+ ioCnt := 0
+ ex := NewExecutor(vars)
+ for i, n := range nodes {
+ runners, hasIO := ex.createRunners(n, true)
+ if hasIO {
+ ioCnt++
+ if ioCnt % 100 == 0 {
+ LogStats("%d/%d rules have IO", ioCnt, i+1)
+ }
+ continue
+ }
+
+ n.Cmds = []string{}
+ n.TargetSpecificVars = make(Vars)
+ for _, r := range runners {
+ cmd := r.cmd
+ // TODO: Do not preserve the effect of dryRunFlag.
+ if r.echo {
+ cmd = "@" + cmd
+ }
+ if r.ignoreError {
+ cmd = "-" + cmd
+ }
+ n.Cmds = append(n.Cmds, cmd)
+ }
+ }
+
+ LogStats("%d/%d rules have IO", ioCnt, len(nodes))
+}