Skip to content

Commit c431e87

Browse files
committed
Show when bazel run exited with code
1 parent 91e44ae commit c431e87

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

internal/ibazel/command/command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Command interface {
4747
Terminate()
4848
Kill()
4949
NotifyOfChanges() *bytes.Buffer
50+
NotifyOfSubprocessExit()
5051
IsSubprocessRunning() bool
5152
}
5253

internal/ibazel/command/default_command.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ func (c *defaultCommand) NotifyOfChanges() *bytes.Buffer {
9090
return nil
9191
}
9292

93+
func (c *defaultCommand) NotifyOfSubprocessExit() {
94+
c.termSync.Do(func() {
95+
terminate(c.pg)
96+
})
97+
code := c.pg.RootProcess().ProcessState.ExitCode()
98+
log.Logf("Exited (%d)", code)
99+
c.pg = nil
100+
}
101+
93102
func (c *defaultCommand) IsSubprocessRunning() bool {
94103
return c.pg != nil && subprocessRunning(c.pg.RootProcess())
95104
}

internal/ibazel/command/notify_command.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ func (c *notifyCommand) NotifyOfChanges() *bytes.Buffer {
126126
return outputBuffer
127127
}
128128

129+
func (c *notifyCommand) NotifyOfSubprocessExit() {
130+
c.termSync.Do(func() {
131+
terminate(c.pg)
132+
})
133+
code := c.pg.RootProcess().ProcessState.ExitCode()
134+
log.Logf("Exited (%d)", code)
135+
c.pg = nil
136+
}
137+
129138
func (c *notifyCommand) IsSubprocessRunning() bool {
130139
return c.pg != nil && subprocessRunning(c.pg.RootProcess())
131140
}

internal/ibazel/ibazel.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func New(version string) (*IBazel, error) {
9999
i.workspaceFinder = &workspace.MainWorkspace{}
100100

101101
i.sigs = make(chan os.Signal, 1)
102-
signal.Notify(i.sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
102+
signal.Notify(i.sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGCHLD)
103103

104104
liveReload := live_reload.New()
105105
profiler := profiler.New(version)
@@ -130,9 +130,17 @@ func New(version string) (*IBazel, error) {
130130
}
131131

132132
func (i *IBazel) handleSignals() {
133-
// Got an OS signal (SIGINT, SIGTERM, SIGHUP).
133+
// Got an OS signal (SIGINT, SIGTERM, SIGHUP, SIGCHLD).
134134
sig := <-i.sigs
135135

136+
// SIGCHLD can be received without an active cmd, so processing it separately.
137+
if sig == syscall.SIGCHLD {
138+
if i.cmd != nil && i.cmd.IsSubprocessRunning() {
139+
i.cmd.NotifyOfSubprocessExit()
140+
}
141+
return
142+
}
143+
136144
if i.cmd == nil || !i.cmd.IsSubprocessRunning() {
137145
osExit(3)
138146
return

0 commit comments

Comments
 (0)