Only check for ninja stuckness after it's been running for a bit

Bug: 62580037
Test: rm -rf out && m -j showcommands | grep "ninja may be stuck" || echo ok

Change-Id: I8ff1bd216b5f8349ce9e06e5465a9f8d0663f8c0
This commit is contained in:
Jeff Gaston
2017-06-13 12:51:50 -07:00
parent 193f2fb092
commit a6697e8b7f
2 changed files with 15 additions and 28 deletions

View File

@@ -30,9 +30,6 @@ type Cmd struct {
ctx Context ctx Context
config Config config Config
name string 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 { func Command(ctx Context, config Config, name string, executable string, args ...string) *Cmd {
@@ -44,7 +41,6 @@ func Command(ctx Context, config Config, name string, executable string, args ..
ctx: ctx, ctx: ctx,
config: config, config: config,
name: name, name: name,
doneChannel: make(chan bool),
} }
return ret return ret
@@ -61,10 +57,6 @@ func (c *Cmd) prepare() {
c.ctx.Verboseln(c.Path, c.Args) c.ctx.Verboseln(c.Path, c.Args)
} }
func (c *Cmd) teardown() {
close(c.doneChannel)
}
func (c *Cmd) Start() error { func (c *Cmd) Start() error {
c.prepare() c.prepare()
return c.Cmd.Start() return c.Cmd.Start()
@@ -72,21 +64,18 @@ func (c *Cmd) Start() error {
func (c *Cmd) Run() error { func (c *Cmd) Run() error {
c.prepare() c.prepare()
defer c.teardown()
err := c.Cmd.Run() err := c.Cmd.Run()
return err return err
} }
func (c *Cmd) Output() ([]byte, error) { func (c *Cmd) Output() ([]byte, error) {
c.prepare() c.prepare()
defer c.teardown()
bytes, err := c.Cmd.Output() bytes, err := c.Cmd.Output()
return bytes, err return bytes, err
} }
func (c *Cmd) CombinedOutput() ([]byte, error) { func (c *Cmd) CombinedOutput() ([]byte, error) {
c.prepare() c.prepare()
defer c.teardown()
bytes, err := c.Cmd.CombinedOutput() bytes, err := c.Cmd.CombinedOutput()
return bytes, err return bytes, err
} }
@@ -133,13 +122,3 @@ func (c *Cmd) CombinedOutputOrFatal() []byte {
c.reportError(err) c.reportError(err)
return ret return ret
} }
// Done() tells whether this command has finished executing
func (c *Cmd) Done() bool {
select {
case <-c.doneChannel:
return true
default:
return false
}
}

View File

@@ -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 // 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{} checker := &statusChecker{}
go func() { go func() {
for !cmd.Done() { for {
select {
case <-ticker.C:
checker.check(ctx, config, logPath) checker.check(ctx, config, logPath)
time.Sleep(ninjaHeartbeatDuration) case <-done:
return
}
} }
}() }()
@@ -127,5 +135,5 @@ func dumpStucknessDiagnostics(ctx Context, config Config, statusPath string, las
output := cmd.CombinedOutputOrFatal() output := cmd.CombinedOutputOrFatal()
ctx.Verbose(string(output)) ctx.Verbose(string(output))
ctx.Printf("done\n") ctx.Verbosef("done\n")
} }