Skip to content

Commit

Permalink
remove debug; fix build issue on missing buildinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
zuzuleinen committed Dec 16, 2022
1 parent 57320fe commit 7a421fe
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 45 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install bob
run: make install-prod

- name: bob login
- name: bob login
run: bob auth init --token ${{ secrets.BOB_TOKEN }}

- name: Install nix derivations
Expand All @@ -39,12 +39,6 @@ jobs:
- name: Lint code
run: bob build lint

- name: Ls
run: ls -la

- name: Check buildinfos
run: ls ~/.bobcache/buildinfos

- name: Build
run: bob build --push

Expand Down
4 changes: 2 additions & 2 deletions bob/playbook/build_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func (p *Playbook) build(ctx context.Context, task *bobtask.Task) (err error) {
err = p.pullArtifact(ctx, hashIn, task, false)
errz.Fatal(err)

success, err := task.ArtifactExtract(hashIn, nil)
success, err := task.ArtifactExtract(hashIn, rebuild.VerifyResult.InvalidFiles)
if err != nil {
// if local artifact is corrupted due to incomplete previous download, try a fresh download
if errors.Is(err, io.ErrUnexpectedEOF) {
err = p.pullArtifact(ctx, hashIn, task, true)
errz.Fatal(err)
success, err = task.ArtifactExtract(hashIn, nil)
success, err = task.ArtifactExtract(hashIn, rebuild.VerifyResult.InvalidFiles)
}
}

Expand Down
2 changes: 0 additions & 2 deletions bob/playbook/compute_buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
func (p *Playbook) computeBuildinfo(taskname string) (_ *buildinfo.I, err error) {
defer errz.Recover(&err)

fmt.Println("computeBuildinfo", taskname)

task, ok := p.Tasks[taskname]
if !ok {
return nil, usererror.Wrap(boberror.ErrTaskDoesNotExistF(taskname))
Expand Down
17 changes: 13 additions & 4 deletions bob/playbook/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo RebuildInfo, e
if task.TargetExists() {
t, err := ts.Target()
errz.Fatal(err)
for _, v := range t.FilesystemEntriesRaw() {
invalidFiles[v] = []target.Reason{target.ReasonForcedByNoCache}
}
invalidFiles = t.AsInvalidFiles(target.ReasonForcedByNoCache)
}

return RebuildInfo{IsRequired: true, Cause: TaskForcedRebuild, VerifyResult: target.VerifyResult{
Expand All @@ -64,7 +62,18 @@ func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo RebuildInfo, e
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

invalidFiles := make(map[string][]target.Reason)
if task.TargetExists() {
t, err := ts.Target()
errz.Fatal(err)
invalidFiles = t.AsInvalidFiles(target.ReasonMissing)
}

return RebuildInfo{IsRequired: true, Cause: InputNotFoundInBuildInfo, VerifyResult: target.VerifyResult{
TargetIsValid: len(invalidFiles) > 0,
InvalidFiles: invalidFiles,
}}, nil
}

// Check rebuild due to invalidated targets
Expand Down
2 changes: 1 addition & 1 deletion bobtask/artifact_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func shouldFetchFromCache(filename string, invalidFiles map[string][]target.Reas
return false
}
for _, reason := range invalidFiles[filename] {
if reason == target.ReasonHashChanged || reason == target.ReasonDeleted {
if reason == target.ReasonHashChanged || reason == target.ReasonMissing {
return true
}
}
Expand Down
19 changes: 0 additions & 19 deletions bobtask/target/buildinfo.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package target

import (
"bytes"
"encoding/hex"
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"

"github.com/benchkram/bob/bobtask/buildinfo"
Expand Down Expand Up @@ -42,27 +40,10 @@ func (t *T) BuildInfo() (bi *buildinfo.Targets, err error) {
func (t *T) buildinfoFiles(paths []string) (bi buildinfo.BuildInfoFiles, _ error) {
bi = *buildinfo.NewBuildInfoFiles()

fmt.Println("buildinfoFiles")

cmd := exec.Command("ls")

var out bytes.Buffer
cmd.Stdout = &out

err := cmd.Run()
if err != nil {
return bi, err
}

fmt.Println("LISTING FILES")
fmt.Println(out.String())

h := filehash.New()
for _, path := range paths {
path = filepath.Join(t.dir, path)

fmt.Println("search for", path)

if !file.Exists(path) {
return buildinfo.BuildInfoFiles{}, usererror.Wrapm(ErrTargetDoesNotExist, fmt.Sprintf("[path: %q]", path))
}
Expand Down
18 changes: 13 additions & 5 deletions bobtask/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ type Target interface {
FilesystemEntriesPlain() []string
FilesystemEntriesRaw() []string
FilesystemEntriesRawPlain() []string
// Exists() bool

WithExpected(*buildinfo.Targets) *T

// Paths() []string
// PathsPlain() []string
// Type() targettype.T
DockerImages() []string

// AsInvalidFiles returns all FilesystemEntriesRaw as invalid with the specified reason
AsInvalidFiles(reason Reason) map[string][]Reason
}

type T struct {
Expand Down Expand Up @@ -123,3 +121,13 @@ func (t *T) WithExpected(expected *buildinfo.Targets) *T {
func (t *T) DockerImages() []string {
return t.dockerImages
}

// AsInvalidFiles returns all FilesystemEntriesRaw as invalid with the specified reason
func (t *T) AsInvalidFiles(reason Reason) map[string][]Reason {
invalidFiles := make(map[string][]Reason)

for _, v := range t.FilesystemEntriesRaw() {
invalidFiles[v] = []Reason{reason}
}
return invalidFiles
}
6 changes: 3 additions & 3 deletions bobtask/target/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
ReasonCreatedAfterBuild Reason = "CREATED-AFTER-BUILD"
ReasonSizeChanged Reason = "SIZE-CHANGED"
ReasonHashChanged Reason = "HASH-CHANGED"
ReasonDeleted Reason = "DELETED"
ReasonMissing Reason = "MISSING"
ReasonForcedByNoCache Reason = "FORCED-BY-NO-CACHE"
)

Expand Down Expand Up @@ -96,10 +96,10 @@ func (t *T) verifyFilesystemShallow(v *VerifyResult) bool {
return true
}

// check for deleted files
// check for deleted/never created files
for k := range t.expected.Filesystem.Files {
if !sliceutil.Contains(*t.filesystemEntries, k) {
v.AddInvalidReason(k, ReasonDeleted)
v.AddInvalidReason(k, ReasonMissing)
}
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/buildinfostore/protostore.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func (ps *ps) NewBuildInfo(id string, info *buildinfo.I) (err error) {
func (ps *ps) GetBuildInfo(id string) (info *buildinfo.I, err error) {
defer errz.Recover(&err)

fmt.Println("GetBuildInfo", id, filepath.Join(ps.dir, id))

f, err := os.Open(filepath.Join(ps.dir, id))
if err != nil {
return nil, ErrBuildInfoDoesNotExist
Expand Down

0 comments on commit 7a421fe

Please sign in to comment.