diff --git a/ui/build/exec.go b/ui/build/exec.go index 79310dc20..90fb19de2 100644 --- a/ui/build/exec.go +++ b/ui/build/exec.go @@ -30,9 +30,6 @@ type Cmd struct { ctx Context config Config name string - - // doneChannel closes to signal the command's termination - doneChannel chan bool } func Command(ctx Context, config Config, name string, executable string, args ...string) *Cmd { @@ -41,10 +38,9 @@ func Command(ctx Context, config Config, name string, executable string, args .. Environment: config.Environment().Copy(), Sandbox: noSandbox, - ctx: ctx, - config: config, - name: name, - doneChannel: make(chan bool), + ctx: ctx, + config: config, + name: name, } return ret @@ -61,10 +57,6 @@ func (c *Cmd) prepare() { c.ctx.Verboseln(c.Path, c.Args) } -func (c *Cmd) teardown() { - close(c.doneChannel) -} - func (c *Cmd) Start() error { c.prepare() return c.Cmd.Start() @@ -72,21 +64,18 @@ func (c *Cmd) Start() error { func (c *Cmd) Run() error { c.prepare() - defer c.teardown() err := c.Cmd.Run() return err } func (c *Cmd) Output() ([]byte, error) { c.prepare() - defer c.teardown() bytes, err := c.Cmd.Output() return bytes, err } func (c *Cmd) CombinedOutput() ([]byte, error) { c.prepare() - defer c.teardown() bytes, err := c.Cmd.CombinedOutput() return bytes, err } @@ -133,13 +122,3 @@ func (c *Cmd) CombinedOutputOrFatal() []byte { c.reportError(err) return ret } - -// Done() tells whether this command has finished executing -func (c *Cmd) Done() bool { - select { - case <-c.doneChannel: - return true - default: - return false - } -} diff --git a/ui/build/ninja.go b/ui/build/ninja.go index 22771e7b3..78d11707e 100644 --- a/ui/build/ninja.go +++ b/ui/build/ninja.go @@ -81,11 +81,19 @@ func runNinja(ctx Context, config Config) { } } // Poll the ninja log for updates; if it isn't updated enough, then we want to show some diagnostics + done := make(chan struct{}) + defer close(done) + ticker := time.NewTicker(ninjaHeartbeatDuration) + defer ticker.Stop() checker := &statusChecker{} go func() { - for !cmd.Done() { - checker.check(ctx, config, logPath) - time.Sleep(ninjaHeartbeatDuration) + for { + select { + case <-ticker.C: + checker.check(ctx, config, logPath) + case <-done: + return + } } }() @@ -127,5 +135,5 @@ func dumpStucknessDiagnostics(ctx Context, config Config, statusPath string, las output := cmd.CombinedOutputOrFatal() ctx.Verbose(string(output)) - ctx.Printf("done\n") + ctx.Verbosef("done\n") }