Skip to content

Commit

Permalink
assure input hash comparison is similar to input hash during build
Browse files Browse the repository at this point in the history
  • Loading branch information
Equanox committed Mar 31, 2023
1 parent 9ffcf03 commit de0f9c6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
13 changes: 13 additions & 0 deletions bob/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/benchkram/errz"

"github.com/benchkram/bob/bob/bobfile"
"github.com/benchkram/bob/bob/playbook"
)

Expand Down Expand Up @@ -45,3 +46,15 @@ func (b *B) Build(ctx context.Context, taskName string) (err error) {

return nil
}

func (b *B) AggregateWithNixDeps(taskName string) (aggregate *bobfile.Bobfile, err error) {
defer errz.Recover(&err)

ag, err := b.Aggregate()
errz.Fatal(err)

err = b.nix.BuildNixDependenciesInPipeline(ag, taskName)
errz.Fatal(err)

return ag, nil
}
4 changes: 2 additions & 2 deletions bobtask/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (i *I) Describe() string {
fmt.Fprintln(buf, "\ttask:", i.Meta.Task)
fmt.Fprintln(buf, "\tinput hash", i.Meta.InputHash)

fmt.Fprintln(buf, "Filesystem:")
fmt.Fprintln(buf, "Filesystem-Targets:")
fmt.Fprintln(buf, "\thash of all files", i.Target.Filesystem.Hash)
fmt.Fprintln(buf, "\t# of files", len(i.Target.Filesystem.Files))
fmt.Fprintln(buf, "\tfiles:")
Expand All @@ -42,7 +42,7 @@ func (i *I) Describe() string {

for _, filename := range sortedFiles {
v := i.Target.Filesystem.Files[filename]
fmt.Fprintln(buf, "\t", filename, v.Size)
fmt.Fprintln(buf, "\t", filename, v.Size, v.Hash)
}

return buf.String()
Expand Down
6 changes: 6 additions & 0 deletions bobtask/target/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/fs"
"os"
"path/filepath"
"sort"

"github.com/benchkram/bob/bobtask/buildinfo"
"github.com/benchkram/bob/pkg/file"
Expand Down Expand Up @@ -41,6 +42,11 @@ func (t *T) buildinfoFiles(paths []string) (bi buildinfo.BuildInfoFiles, _ error
bi = *buildinfo.NewBuildInfoFiles()

h := filehash.New()

// Use a sorted path array to assure the hash of all files
// is computed in a consistent order.
sort.Strings(paths)

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

Expand Down
30 changes: 27 additions & 3 deletions cli/cmd_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/benchkram/bob/bob"
"github.com/benchkram/bob/pkg/boblog"
"github.com/benchkram/bob/pkg/filehash"
"github.com/benchkram/bob/pkg/usererror"
"github.com/benchkram/errz"
"github.com/logrusorgru/aurora"
Expand Down Expand Up @@ -161,7 +162,7 @@ func runInspectInputs(taskname string) {
b, err := bob.Bob()
boblog.Log.Error(err, "Unable to initialise bob")

bobfile, err := b.Aggregate()
bobfile, err := b.AggregateWithNixDeps(taskname)
boblog.Log.Error(err, "Unable to aggregate bob file")

task, ok := bobfile.BTasks[taskname]
Expand All @@ -175,10 +176,33 @@ func runInspectInputs(taskname string) {
inputs := task.Inputs()
sort.Strings(inputs)
for _, e := range inputs {
fmt.Println(e)
contentHash, err := filehash.HashOfFile(e)
if err != nil {
boblog.Log.Error(err, "unable to compute hash of file")
exit(1)
}

info, err := os.Stat(e)
if err != nil {
boblog.Log.Error(err, "unable to stat ffile hash of file")
exit(1)
}

fmt.Printf("\t%s %d %s\n", e, info.Size(), contentHash)
}

hash, err := task.HashIn()
if err != nil {
boblog.Log.Error(err, "unable to compute hash")
exit(1)
}

fmt.Printf("Task %s has %d inputs\n", taskname, len(inputs))
fmt.Println()
fmt.Println()
fmt.Printf("Summary:\n")
fmt.Printf("\ttask-name: %s\n", taskname)
fmt.Printf("\t# of inputs: %d\n", len(inputs))
fmt.Printf("\tinput hash: %s\n", hash)
}

var inspectBuildInfoCmd = &cobra.Command{
Expand Down

0 comments on commit de0f9c6

Please sign in to comment.