Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/cli/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"context"
"fmt"
"os"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -35,7 +36,7 @@ func (c *downCmd) run(ctx context.Context, args []string) error {
})
defer analyticsService.Flush(time.Second)

manifests, globalYaml, _, err := tiltfile.Load(ctx, c.fileName, nil)
manifests, globalYaml, _, err := tiltfile.Load(ctx, c.fileName, nil, os.Stdout)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/demo/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/windmilleng/tilt/internal/store"
"github.com/windmilleng/tilt/internal/tiltfile"
"golang.org/x/sync/errgroup"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
)

type RepoBranch string
Expand Down Expand Up @@ -174,7 +174,8 @@ func (s Script) Run(ctx context.Context) error {
}

tfPath := filepath.Join(dir, tiltfile.FileName)
manifests, _, _, err := tiltfile.Load(ctx, tfPath, nil)
// TODO(dmiller): not this?
manifests, _, _, err := tiltfile.Load(ctx, tfPath, nil, os.Stdout)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/engine/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/windmilleng/tilt/internal/k8s"
"github.com/windmilleng/tilt/internal/model"
"github.com/windmilleng/tilt/internal/store"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
)

type ErrorAction struct {
Expand Down Expand Up @@ -161,3 +161,9 @@ type DockerComposeLogAction struct {
}

func (DockerComposeLogAction) Action() {}

type TiltfileLogAction struct {
Log []byte
}

func (TiltfileLogAction) Action() {}
4 changes: 3 additions & 1 deletion internal/engine/configs_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func (cc *ConfigsController) OnChange(ctx context.Context, st store.RStore) {
return
}

manifests, globalYAML, configFiles, err := tiltfile.Load(ctx, tiltfilePath, matching)
tlw := NewTiltfileLogWriter(st)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also want to fork the logger in ctx so that anything that writes to the logger makes it into the tiltfile log.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's true, we want them to be two separate streams.


manifests, globalYAML, configFiles, err := tiltfile.Load(ctx, tiltfilePath, matching, tlw)
st.Dispatch(ConfigsReloadedAction{
Manifests: manifests,
GlobalYAML: globalYAML,
Expand Down
18 changes: 18 additions & 0 deletions internal/engine/tiltfile_log_writer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package engine

import "github.com/windmilleng/tilt/internal/store"

type tiltfileLogWriter struct {
store store.RStore
}

func NewTiltfileLogWriter(s store.RStore) *tiltfileLogWriter {
return &tiltfileLogWriter{s}
}

func (w *tiltfileLogWriter) Write(p []byte) (n int, err error) {
w.store.Dispatch(TiltfileLogAction{
Log: append([]byte{}, p...),
})
return len(p), nil
}
16 changes: 12 additions & 4 deletions internal/engine/upper.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func (u Upper) Start(ctx context.Context, args []string, watchMounts bool, trigg
matching[arg] = true
}

manifests, globalYAML, configFiles, err := tiltfile.Load(ctx, fileName, matching)
// TODO(dmiller) hmm, can I do this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like can I just pass u.store in to this, or will that cause problems?

tlw := NewTiltfileLogWriter(u.store)
manifests, globalYAML, configFiles, err := tiltfile.Load(ctx, fileName, matching, tlw)

return u.Init(ctx, InitAction{
WatchMounts: watchMounts,
Expand Down Expand Up @@ -176,6 +178,8 @@ var UpperReducer = store.Reducer(func(ctx context.Context, state *store.EngineSt
handleStartProfilingAction(state)
case hud.StopProfilingAction:
handleStopProfilingAction(state)
case TiltfileLogAction:
handleTiltfileLogAction(state, action)
default:
err = fmt.Errorf("unrecognized action: %T", action)
}
Expand Down Expand Up @@ -423,6 +427,7 @@ func handleConfigsReloadStarted(
state *store.EngineState,
event ConfigsReloadStartedAction,
) {
state.CurrentTiltfileBuild = model.BuildRecord{}
state.PendingConfigFileChanges = make(map[string]bool)
}

Expand Down Expand Up @@ -766,7 +771,6 @@ func handleInitAction(ctx context.Context, engineState *store.EngineState, actio
FinishTime: action.FinishTime,
Error: action.Err,
Reason: model.BuildReasonFlagInit,
// TODO(nick): Send tiltfile stdout to the build status log
}
setLastTiltfileBuild(engineState, status)

Expand All @@ -782,8 +786,8 @@ func handleInitAction(ctx context.Context, engineState *store.EngineState, actio

func setLastTiltfileBuild(state *store.EngineState, status model.BuildRecord) {
if status.Error != nil {
log := []byte(fmt.Sprintf("Tiltfile error:\n%v\n", status.Error))
handleLogAction(state, LogAction{Log: log})
log := []byte(fmt.Sprintf("%v\n", status.Error))
handleTiltfileLogAction(state, TiltfileLogAction{log})
}
state.LastTiltfileBuild = status
}
Expand Down Expand Up @@ -849,3 +853,7 @@ func handleDockerComposeLogAction(state *store.EngineState, action DockerCompose
dcState, _ := ms.ResourceState.(dockercompose.State)
ms.ResourceState = dcState.WithCurrentLog(append(dcState.CurrentLog, action.Log...))
}

func handleTiltfileLogAction(state *store.EngineState, action TiltfileLogAction) {
state.CurrentTiltfileBuild.Log = append(state.CurrentTiltfileBuild.Log, action.Log...)
}
6 changes: 3 additions & 3 deletions internal/engine/upper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ func TestHudUpdated(t *testing.T) {
err = f.Stop()
assert.Equal(t, nil, err)

assert.Equal(t, 1, len(f.hud.LastView.Resources))
assert.Equal(t, 2, len(f.hud.LastView.Resources))
rv := f.hud.LastView.Resources[0]
assert.Equal(t, manifest.Name, model.ManifestName(rv.Name))
assert.Equal(t, ".", rv.DirectoriesWatched[0])
Expand Down Expand Up @@ -2382,7 +2382,7 @@ func (f *testFixture) assertAllBuildsConsumed() {
}

func (f *testFixture) loadAndStart() {
manifests, _, _, err := tiltfile.Load(f.ctx, f.JoinPath(tiltfile.FileName), nil)
manifests, _, _, err := tiltfile.Load(f.ctx, f.JoinPath(tiltfile.FileName), nil, os.Stdout)
if err != nil {
f.T().Fatal(err)
}
Expand Down Expand Up @@ -2419,7 +2419,7 @@ func (f *testFixture) setupDCFixture() (redis, server model.Manifest) {

f.WriteFile("Tiltfile", `docker_compose('docker-compose.yml')`)

manifests, _, _, err := tiltfile.Load(f.ctx, f.JoinPath("Tiltfile"), nil)
manifests, _, _, err := tiltfile.Load(f.ctx, f.JoinPath("Tiltfile"), nil, os.Stdout)
if err != nil {
f.T().Fatal(err)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/hud/buildstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func makeBuildStatus(res view.Resource, triggerMode model.TriggerMode) buildStat
deployTime := time.Time{}
reason := model.BuildReason(0)

if res.IsTiltfile {
return buildStatus{
status: "OK",
}
}

if !res.CurrentBuild.Empty() && !res.CurrentBuild.Reason.IsCrashOnly() {
status = "Building"
duration = time.Since(res.CurrentBuild.StartTime)
Expand Down
17 changes: 4 additions & 13 deletions internal/hud/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (r *Renderer) layout(v view.View, vs view.ViewState) rty.Component {
l.Add(rty.NewLine())
}

l.Add(r.renderTiltfileError(v))
l.Add(r.renderResourceHeader(v))
l.Add(r.renderResources(v, vs))
l.Add(r.renderPaneHeader(vs))
Expand Down Expand Up @@ -236,6 +235,10 @@ func bestLogs(res view.Resource) string {
}
}

if res.IsTiltfile {
return string(res.CurrentBuild.Log)
}

return string(res.LastBuild().Log) + "\n" + res.ResourceInfo.RuntimeLog()
}

Expand Down Expand Up @@ -327,18 +330,6 @@ func (r *Renderer) renderResource(res view.Resource, rv view.ResourceViewState,
return NewResourceView(res, rv, triggerMode, selected, r.clock).Build()
}

func (r *Renderer) renderTiltfileError(v view.View) rty.Component {
if v.TiltfileErrorMessage != "" {
c := rty.NewConcatLayout(rty.DirVert)
c.Add(rty.TextString("Tiltfile error: "))
c.Add(rty.TextString(v.TiltfileErrorMessage))
c.Add(rty.NewFillerString('─'))
return c
}

return rty.NewLines()
}

func (r *Renderer) SetUp() (chan tcell.Event, error) {
r.mu.Lock()
defer r.mu.Unlock()
Expand Down
11 changes: 0 additions & 11 deletions internal/hud/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,6 @@ func TestRenderNarrationMessage(t *testing.T) {
rtf.run("narration message", 60, 20, v, vs)
}

func TestRenderTiltfileError(t *testing.T) {
rtf := newRendererTestFixture(t)
v := view.View{
TiltfileErrorMessage: "Tiltfile error!",
}

vs := view.ViewState{}

rtf.run("tiltfile error", 60, 20, v, vs)
}

func TestAutoCollapseModes(t *testing.T) {
rtf := newRendererTestFixture(t)

Expand Down
7 changes: 6 additions & 1 deletion internal/hud/resourceview.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func (v *ResourceView) resourceTitle() rty.Component {
}

func statusColor(res view.Resource, triggerMode model.TriggerMode) tcell.Color {
if res.IsTiltfile && res.CrashLog == "" {
return cGood
} else if res.IsTiltfile && res.CrashLog != "" {
return cBad
}
if !res.CurrentBuild.Empty() && !res.CurrentBuild.Reason.IsCrashOnly() {
return cPending
} else if !res.PendingBuildSince.IsZero() && !res.PendingBuildReason.IsCrashOnly() {
Expand Down Expand Up @@ -109,7 +114,7 @@ func (v *ResourceView) titleTextName() rty.Component {
sb.Fg(color).Textf(" ● ")

name := v.res.Name.String()
if color == cPending {
if color == cPending && !v.res.IsTiltfile {
name = fmt.Sprintf("%s %s", v.res.Name, v.spinner())
}
sb.Fg(tcell.ColorDefault).Text(name)
Expand Down
2 changes: 2 additions & 0 deletions internal/hud/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type Resource struct {
// If a pod had to be killed because it was crashing, we keep the old log around
// for a little while.
CrashLog string

IsTiltfile bool
}

func (r Resource) DockerComposeTarget() DCResourceInfo {
Expand Down
19 changes: 17 additions & 2 deletions internal/store/engine_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type EngineState struct {
TriggerQueue []model.ManifestName

IsProfiling bool

CurrentTiltfileBuild model.BuildRecord
}

func (e *EngineState) ManifestNameForTargetID(id model.TargetID) model.ManifestName {
Expand Down Expand Up @@ -662,16 +664,29 @@ func StateToView(s EngineState) view.View {
ret.Resources = append(ret.Resources, r)
}

ret.Log = string(s.Log)

tfb := s.LastTiltfileBuild
tfb.Log = s.CurrentTiltfileBuild.Log
tr := view.Resource{
Name: "(Tiltfile)",
IsTiltfile: true,
CurrentBuild: tfb,
BuildHistory: []model.BuildRecord{
tfb,
},
}
if !s.LastTiltfileBuild.Empty() {
err := s.LastTiltfileBuild.Error
if err == nil && s.IsEmpty() {
tr.CrashLog = emptyTiltfileMsg
ret.TiltfileErrorMessage = emptyTiltfileMsg
} else if err != nil {
tr.CrashLog = err.Error()
ret.TiltfileErrorMessage = err.Error()
}
}
ret.Resources = append(ret.Resources, tr)

ret.Log = string(s.Log)

return ret
}
Expand Down
6 changes: 3 additions & 3 deletions internal/store/engine_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestStateToViewMultipleMounts(t *testing.T) {
map[string]time.Time{"/a/b/d": time.Now(), "/a/b/c/d/e": time.Now()}
v := StateToView(*state)

if !assert.Equal(t, 1, len(v.Resources)) {
if !assert.Equal(t, 2, len(v.Resources)) {
return
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func TestStateViewYAMLManifestNoYAML(t *testing.T) {
state := newState([]model.Manifest{}, m)
v := StateToView(*state)

assert.Equal(t, 0, len(v.Resources))
assert.Equal(t, 1, len(v.Resources))
}

func TestStateViewYAMLManifestWithYAML(t *testing.T) {
Expand All @@ -76,7 +76,7 @@ func TestStateViewYAMLManifestWithYAML(t *testing.T) {
state.ConfigFiles = []string{"global.yaml"}
v := StateToView(*state)

assert.Equal(t, 1, len(v.Resources))
assert.Equal(t, 2, len(v.Resources))

r := v.Resources[0]
assert.Equal(t, nil, r.LastBuild().Error)
Expand Down
11 changes: 9 additions & 2 deletions internal/tiltfile/tiltfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package tiltfile
import (
"context"
"fmt"
"io"
"log"
"os"
"path/filepath"

"github.com/pkg/errors"
Expand All @@ -24,16 +27,20 @@ func init() {
}

// Load loads the Tiltfile in `filename`, and returns the manifests matching `matching`.
func Load(ctx context.Context, filename string, matching map[string]bool) (manifests []model.Manifest, global model.Manifest, configFiles []string, err error) {
func Load(ctx context.Context, filename string, matching map[string]bool, logs io.Writer) (manifests []model.Manifest, global model.Manifest, configFiles []string, err error) {
l := log.New(logs, "", log.LstdFlags)
absFilename, err := ospath.RealAbs(filename)
if err != nil {
if os.IsNotExist(err) {
return nil, model.Manifest{}, nil, fmt.Errorf("No Tiltfile found at %s. Check out https://docs.tilt.build/write_your_tiltfile.html", filename)
}
absFilename, _ = filepath.Abs(filename)
return nil, model.Manifest{}, []string{absFilename}, err
}

tfRoot, _ := filepath.Split(absFilename)

s := newTiltfileState(ctx, absFilename, tfRoot)
s := newTiltfileState(ctx, absFilename, tfRoot, l)
defer func() {
configFiles = s.configFiles
}()
Expand Down
Loading