Skip to content

Commit e29906f

Browse files
committed
build: fix doCheckGenerate not print changed files
1 parent 6452b7a commit e29906f

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

build/ci.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func buildFlags(env build.Environment, staticLinking bool, buildTags []string) (
343343
}
344344
ld = append(ld, "-extldflags", "'"+strings.Join(extld, " ")+"'")
345345
}
346-
// TODO(gballet): revisit after the input api has been defined
346+
// TODO(gballet): revisit after the input api has been defined
347347
if runtime.GOARCH == "wasm" {
348348
ld = append(ld, "-gcflags=all=-d=softfloat")
349349
}
@@ -462,9 +462,14 @@ func doCheckGenerate() {
462462
)
463463
pathList := []string{filepath.Join(protocPath, "bin"), protocGenGoPath, os.Getenv("PATH")}
464464

465+
excludes := []string{"tests/testdata", "build/cache", ".git"}
466+
for i := range excludes {
467+
excludes[i] = filepath.FromSlash(excludes[i])
468+
}
469+
465470
for _, mod := range goModules {
466471
// Compute the origin hashes of all the files
467-
hashes, err := build.HashFolder(mod, []string{"tests/testdata", "build/cache", ".git"})
472+
hashes, err := build.HashFolder(mod, excludes)
468473
if err != nil {
469474
log.Fatal("Error computing hashes", "err", err)
470475
}
@@ -474,7 +479,7 @@ func doCheckGenerate() {
474479
c.Dir = mod
475480
build.MustRun(c)
476481
// Check if generate file hashes have changed
477-
generated, err := build.HashFolder(mod, []string{"tests/testdata", "build/cache", ".git"})
482+
generated, err := build.HashFolder(mod, excludes)
478483
if err != nil {
479484
log.Fatalf("Error re-computing hashes: %v", err)
480485
}

internal/build/file.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ import (
2121
"io"
2222
"os"
2323
"path/filepath"
24-
"sort"
25-
"strings"
24+
"slices"
2625
)
2726

2827
// HashFolder iterates all files under the given directory, computing the hash
2928
// of each.
30-
func HashFolder(folder string, exlude []string) (map[string][32]byte, error) {
29+
func HashFolder(folder string, excludes []string) (map[string][32]byte, error) {
3130
res := make(map[string][32]byte)
3231
err := filepath.WalkDir(folder, func(path string, d os.DirEntry, _ error) error {
3332
// Skip anything that's exluded or not a regular file
34-
for _, skip := range exlude {
35-
if strings.HasPrefix(path, filepath.FromSlash(skip)) {
33+
// Skip anything that's excluded or not a regular file
34+
if slices.Contains(excludes, path) {
35+
if d.IsDir() {
3636
return filepath.SkipDir
3737
}
38+
return nil
3839
}
3940
if !d.Type().IsRegular() {
4041
return nil
@@ -71,6 +72,6 @@ func DiffHashes(a map[string][32]byte, b map[string][32]byte) []string {
7172
updates = append(updates, file)
7273
}
7374
}
74-
sort.Strings(updates)
75+
slices.Sort(updates)
7576
return updates
7677
}

0 commit comments

Comments
 (0)