Skip to content

Commit

Permalink
no need for pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
zuzuleinen committed Dec 14, 2022
1 parent 464b8c0 commit be8ddb2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
6 changes: 2 additions & 4 deletions bob/playbook/build_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ func (p *Playbook) build(ctx context.Context, task *bobtask.Task) (err error) {
return p.TaskNoRebuildRequired(task.Name())
}

if rebuild.VerifyResult != nil {
err = task.Clean(rebuild.VerifyResult.InvalidFiles)
errz.Fatal(err)
}
err = task.Clean(rebuild.VerifyResult.InvalidFiles)
errz.Fatal(err)

err = task.Run(ctx, p.namePad, p.nixCache, p.nixShellCache)
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions bob/playbook/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ type RebuildInfo struct {
// Cause tells why the rebuild is required
Cause RebuildCause
// VerifyResult is the result of target filesystem verification
VerifyResult *target.VerifyResult
VerifyResult target.VerifyResult
}

// TaskNeedsRebuild check if a tasks need a rebuild by looking at its hash value
// and its child tasks.
func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo *RebuildInfo, err error) {
func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo RebuildInfo, err error) {
ts, ok := p.Tasks[taskName]
if !ok {
return &RebuildInfo{}, usererror.Wrap(boberror.ErrTaskDoesNotExistF(taskName))
return RebuildInfo{}, usererror.Wrap(boberror.ErrTaskDoesNotExistF(taskName))
}
task := ts.Task
coloredName := task.ColoredName()

// Rebuild strategy set to `always`
if task.Rebuild() == bobtask.RebuildAlways {
boblog.Log.V(3).Info(fmt.Sprintf("%-*s\tNEEDS REBUILD\t(rebuild set to always)", p.namePad, coloredName))
return &RebuildInfo{IsRequired: true, Cause: TaskForcedRebuild}, nil
return RebuildInfo{IsRequired: true, Cause: TaskForcedRebuild}, nil
}

// Did a child task change?
if p.didChildTaskChange(task.Name()) {
boblog.Log.V(3).Info(fmt.Sprintf("%-*s\tNEEDS REBUILD\t(dependecy changed)", p.namePad, coloredName))
return &RebuildInfo{IsRequired: true, Cause: DependencyChanged}, nil
return RebuildInfo{IsRequired: true, Cause: DependencyChanged}, nil
}

// Did the current task change?
Expand All @@ -50,31 +50,31 @@ func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo *RebuildInfo,
errz.Fatal(err)
if rebuildRequired {
boblog.Log.V(3).Info(fmt.Sprintf("%-*s\tNEEDS REBUILD\t(input changed)", p.namePad, coloredName))
return &RebuildInfo{IsRequired: true, Cause: InputNotFoundInBuildInfo}, nil
return RebuildInfo{IsRequired: true, Cause: InputNotFoundInBuildInfo}, nil
}

// Check rebuild due to invalidated targets
target, err := task.Target()
if err != nil {
return &RebuildInfo{IsRequired: true, Cause: ""}, nil
return RebuildInfo{IsRequired: true, Cause: ""}, nil
}
if target != nil {
verifyResult := target.VerifyShallow()
if !verifyResult.TargetIsValid {
boblog.Log.V(3).Info(fmt.Sprintf("%-*s\tNEEDS REBUILD\t(invalid targets)", p.namePad, coloredName))
return &RebuildInfo{IsRequired: true, Cause: TargetInvalid, VerifyResult: verifyResult}, nil
return RebuildInfo{IsRequired: true, Cause: TargetInvalid, VerifyResult: verifyResult}, nil
}

// Check if target exists in local store
hashIn, err := task.HashIn()
errz.Fatal(err)
if !task.ArtifactExists(hashIn) {
boblog.Log.V(3).Info(fmt.Sprintf("%-*s\tNEEDS REBUILD\t(target does not exist in localstore)", p.namePad, coloredName))
return &RebuildInfo{IsRequired: true, Cause: TargetNotInLocalStore, VerifyResult: verifyResult}, nil
return RebuildInfo{IsRequired: true, Cause: TargetNotInLocalStore, VerifyResult: verifyResult}, nil
}
}

return &RebuildInfo{IsRequired: false}, err
return RebuildInfo{IsRequired: false}, err
}

// didChildTaskChange iterates through all child tasks to verify if any of them changed.
Expand Down
2 changes: 1 addition & 1 deletion bobtask/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Target interface {
BuildInfo() (*buildinfo.Targets, error)

Verify() bool
VerifyShallow() *VerifyResult
VerifyShallow() VerifyResult
Resolve() error

FilesystemEntries() []string
Expand Down
11 changes: 5 additions & 6 deletions bobtask/target/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import (
// Docker targets are verified similarly as in plain verify
// as there is no performance penalty.
// In case the expected buildinfo does not exist Verify checks against filesystemEntriesRaw.
func (t *T) VerifyShallow() *VerifyResult {
func (t *T) VerifyShallow() VerifyResult {
r := NewVerifyResult()
r.TargetIsValid = t.verifyFilesystemShallow(r) && t.verifyDocker()

r.TargetIsValid = t.verifyFilesystemShallow(&r) && t.verifyDocker()
return r
}

Expand All @@ -36,14 +35,14 @@ type VerifyResult struct {
}

// NewVerifyResult initializes a new VerifyResult
func NewVerifyResult() *VerifyResult {
func NewVerifyResult() VerifyResult {
var v VerifyResult
v.InvalidFiles = make(map[string][]Reason)
return &v
return v
}

// AddInvalidReason adds a reason for invalidation to a certain filePath
func (v *VerifyResult) AddInvalidReason(filePath string, reason Reason) {
func (v VerifyResult) AddInvalidReason(filePath string, reason Reason) {
if _, ok := v.InvalidFiles[filePath]; ok {
v.InvalidFiles[filePath] = append(v.InvalidFiles[filePath], reason)
} else {
Expand Down

0 comments on commit be8ddb2

Please sign in to comment.