Skip to content

Commit a9e689a

Browse files
committed
fix: expandOutputs() wasn't expanding the empty set
Which should expand to the full set of outputs.
1 parent 0fee65f commit a9e689a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

engine/engine.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto/sha256"
55
"errors"
66
"fmt"
7+
"io"
78
"os"
89
"os/exec"
910
"path/filepath"
@@ -392,6 +393,9 @@ func (e *Engine) Build(outputs []string) error {
392393

393394
// Glob-expand outputs.
394395
func (e *Engine) expandOutputs(outputs []string) ([]string, error) {
396+
if len(outputs) == 0 {
397+
return e.Outputs(), nil
398+
}
395399
expanded := []string{}
396400
for _, output := range outputs {
397401
normalised, err := e.normalisePath(output)
@@ -555,12 +559,17 @@ func (e *Engine) realRefHasher(target *Target, ref *parser.Ref) (Hasher, error)
555559
if err != nil {
556560
return 0, err
557561
}
558-
559562
h.Int(uint64(info.Mode()))
560-
if !info.IsDir() {
561-
h.Int(uint64(info.Size()))
562-
h.Int(uint64(info.ModTime().UnixNano()))
563+
if info.IsDir() {
564+
return h, nil
565+
}
566+
567+
r, err := os.Open(ref.Text)
568+
if err != nil {
569+
return 0, err
563570
}
571+
defer r.Close()
572+
_, _ = io.Copy(&h, r)
564573
return h, nil
565574
}
566575

engine/hasher.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func HashSlice[T string | uint64 | []byte | Hasher](hasher *Hasher, slice []T) {
3636

3737
func NewHasher() Hasher { return offset64 }
3838

39+
func (h *Hasher) Write(data []byte) (int, error) {
40+
h.Bytes(data)
41+
return len(data), nil
42+
}
43+
3944
// Int updates the hash with a uint64.
4045
func (h *Hasher) Int(data uint64) {
4146
f := *h

0 commit comments

Comments
 (0)