Skip to content

Commit

Permalink
fix: expandOutputs() wasn't expanding the empty set
Browse files Browse the repository at this point in the history
Which should expand to the full set of outputs.
  • Loading branch information
alecthomas committed Mar 10, 2024
1 parent 0fee65f commit a9e689a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 13 additions & 4 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha256"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -392,6 +393,9 @@ func (e *Engine) Build(outputs []string) error {

// Glob-expand outputs.
func (e *Engine) expandOutputs(outputs []string) ([]string, error) {
if len(outputs) == 0 {
return e.Outputs(), nil
}
expanded := []string{}
for _, output := range outputs {
normalised, err := e.normalisePath(output)
Expand Down Expand Up @@ -555,12 +559,17 @@ func (e *Engine) realRefHasher(target *Target, ref *parser.Ref) (Hasher, error)
if err != nil {
return 0, err
}

h.Int(uint64(info.Mode()))
if !info.IsDir() {
h.Int(uint64(info.Size()))
h.Int(uint64(info.ModTime().UnixNano()))
if info.IsDir() {
return h, nil
}

r, err := os.Open(ref.Text)
if err != nil {
return 0, err
}
defer r.Close()
_, _ = io.Copy(&h, r)
return h, nil
}

Expand Down
5 changes: 5 additions & 0 deletions engine/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func HashSlice[T string | uint64 | []byte | Hasher](hasher *Hasher, slice []T) {

func NewHasher() Hasher { return offset64 }

func (h *Hasher) Write(data []byte) (int, error) {
h.Bytes(data)
return len(data), nil
}

// Int updates the hash with a uint64.
func (h *Hasher) Int(data uint64) {
f := *h
Expand Down

0 comments on commit a9e689a

Please sign in to comment.