in ibazel/ibazel.go [281:332]
func (i *IBazel) iteration(command string, commandToRun runnableCommand, targets []string, joinedTargets string) {
switch i.state {
case WAIT:
select {
case e := <-i.sourceFileWatcher.Events():
if _, ok := i.filesWatched[i.sourceFileWatcher][e.Name]; ok && e.Op&modifyingEvents != 0 {
log.Logf("Changed: %q. Rebuilding...", e.Name)
i.changeDetected(targets, "source", e.Name)
i.state = DEBOUNCE_RUN
}
case e := <-i.buildFileWatcher.Events():
if _, ok := i.filesWatched[i.buildFileWatcher][e.Name]; ok && e.Op&modifyingEvents != 0 {
log.Logf("Build graph changed: %q. Requerying...", e.Name)
i.changeDetected(targets, "graph", e.Name)
i.state = DEBOUNCE_QUERY
}
}
case DEBOUNCE_QUERY:
select {
case e := <-i.buildFileWatcher.Events():
if _, ok := i.filesWatched[i.buildFileWatcher][e.Name]; ok && e.Op&modifyingEvents != 0 {
i.changeDetected(targets, "graph", e.Name)
}
i.state = DEBOUNCE_QUERY
case <-time.After(i.debounceDuration):
i.state = QUERY
}
case QUERY:
// Query for which files to watch.
log.Logf("Querying for files to watch...")
i.watchFiles(fmt.Sprintf(buildQuery, joinedTargets), i.buildFileWatcher)
i.watchFiles(fmt.Sprintf(sourceQuery, joinedTargets), i.sourceFileWatcher)
i.state = RUN
case DEBOUNCE_RUN:
select {
case e := <-i.sourceFileWatcher.Events():
if _, ok := i.filesWatched[i.sourceFileWatcher][e.Name]; ok && e.Op&modifyingEvents != 0 {
i.changeDetected(targets, "source", e.Name)
}
i.state = DEBOUNCE_RUN
case <-time.After(i.debounceDuration):
i.state = RUN
}
case RUN:
log.Logf("%s %s", strings.Title(verb(command)), joinedTargets)
i.beforeCommand(targets, command)
outputBuffer, err := commandToRun(targets...)
i.interruptCount = 0
i.afterCommand(targets, command, err == nil, outputBuffer)
i.state = WAIT
}
}