github.com/grahambrereton-form3/tilt@v0.10.18/internal/engine/live_update_state_tree.go (about) 1 package engine 2 3 import ( 4 "github.com/windmilleng/tilt/internal/container" 5 "github.com/windmilleng/tilt/internal/store" 6 "github.com/windmilleng/tilt/pkg/model" 7 ) 8 9 // A helper data structure that represents a live-update image and 10 // the files changed in all of its dependencies. 11 type liveUpdateStateTree struct { 12 iTarget model.ImageTarget 13 filesChanged []string 14 iTargetState store.BuildState 15 hasFileChangesIDs []model.TargetID 16 } 17 18 // Create a successful build result if the live update deploys successfully. 19 func (t liveUpdateStateTree) createResultSet() store.BuildResultSet { 20 iTargetID := t.iTarget.ID() 21 state := t.iTargetState 22 res := state.LastSuccessfulResult 23 24 liveUpdatedContainerIDs := []container.ID{} 25 for _, c := range state.RunningContainers { 26 liveUpdatedContainerIDs = append(liveUpdatedContainerIDs, c.ContainerID) 27 } 28 29 resultSet := store.BuildResultSet{} 30 resultSet[iTargetID] = store.NewLiveUpdateBuildResult( 31 res.TargetID(), store.ImageFromBuildResult(res), 32 liveUpdatedContainerIDs) 33 34 // Invalidate all the image builds for images we depend on. 35 // Otherwise, the image builder will think the existing image ID 36 // is valid and won't try to rebuild it. 37 for _, id := range t.hasFileChangesIDs { 38 if id != iTargetID { 39 resultSet[id] = nil 40 } 41 } 42 43 return resultSet 44 } 45 46 func createResultSet(trees []liveUpdateStateTree, luInfos []liveUpdInfo) store.BuildResultSet { 47 liveUpdatedTargetIDs := make(map[model.TargetID]bool) 48 for _, info := range luInfos { 49 liveUpdatedTargetIDs[info.iTarget.ID()] = true 50 } 51 52 resultSet := store.BuildResultSet{} 53 for _, t := range trees { 54 if !liveUpdatedTargetIDs[t.iTarget.ID()] { 55 // We didn't actually do a LiveUpdate for this tree 56 continue 57 } 58 resultSet = store.MergeBuildResultsSet(resultSet, t.createResultSet()) 59 } 60 return resultSet 61 }