diff --git a/build/ci.go b/build/ci.go index 29a80dca5e..f5d5b53e32 100644 --- a/build/ci.go +++ b/build/ci.go @@ -54,7 +54,6 @@ import ( "time" "github.com/cespare/cp" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto/signify" "github.com/ethereum/go-ethereum/internal/build" "github.com/ethereum/go-ethereum/params" @@ -144,7 +143,7 @@ func executablePath(name string) string { func main() { log.SetFlags(log.Lshortfile) - if !common.FileExist(filepath.Join("build", "ci.go")) { + if !build.FileExist(filepath.Join("build", "ci.go")) { log.Fatal("this script must be run from the root of the repository") } if len(os.Args) < 2 { @@ -352,8 +351,8 @@ func downloadSpecTestFixtures(csdb *build.ChecksumDB, cachedir string) string { // hashAllSourceFiles iterates all files under the top-level project directory // computing the hash of each file (excluding files within the tests // subrepo) -func hashAllSourceFiles() (map[string]common.Hash, error) { - res := make(map[string]common.Hash) +func hashAllSourceFiles() (map[string][32]byte, error) { + res := make(map[string][32]byte) err := filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error { if strings.HasPrefix(path, filepath.FromSlash("tests/testdata")) { return filepath.SkipDir @@ -370,7 +369,7 @@ func hashAllSourceFiles() (map[string]common.Hash, error) { if _, err := io.Copy(hasher, f); err != nil { return err } - res[path] = common.Hash(hasher.Sum(nil)) + res[path] = [32]byte(hasher.Sum(nil)) return nil }) if err != nil { @@ -381,8 +380,8 @@ func hashAllSourceFiles() (map[string]common.Hash, error) { // hashSourceFiles iterates the provided set of filepaths (relative to the top-level geth project directory) // computing the hash of each file. -func hashSourceFiles(files []string) (map[string]common.Hash, error) { - res := make(map[string]common.Hash) +func hashSourceFiles(files []string) (map[string][32]byte, error) { + res := make(map[string][32]byte) for _, filePath := range files { f, err := os.OpenFile(filePath, os.O_RDONLY, 0666) if err != nil { @@ -392,14 +391,14 @@ func hashSourceFiles(files []string) (map[string]common.Hash, error) { if _, err := io.Copy(hasher, f); err != nil { return nil, err } - res[filePath] = common.Hash(hasher.Sum(nil)) + res[filePath] = [32]byte(hasher.Sum(nil)) } return res, nil } // compareHashedFilesets compares two maps (key is relative file path to top-level geth directory, value is its hash) // and returns the list of file paths whose hashes differed. -func compareHashedFilesets(preHashes map[string]common.Hash, postHashes map[string]common.Hash) []string { +func compareHashedFilesets(preHashes map[string][32]byte, postHashes map[string][32]byte) []string { updates := []string{} for path, postHash := range postHashes { preHash, ok := preHashes[path] @@ -442,7 +441,7 @@ func doGenerate() { protocPath := downloadProtoc(*cachedir) protocGenGoPath := downloadProtocGenGo(*cachedir) - var preHashes map[string]common.Hash + var preHashes map[string][32]byte if *verify { var err error preHashes, err = hashAllSourceFiles() @@ -915,7 +914,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) { var idfile string if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 { idfile = filepath.Join(workdir, "sshkey") - if !common.FileExist(idfile) { + if !build.FileExist(idfile) { os.WriteFile(idfile, sshkey, 0600) } } diff --git a/common/path.go b/common/path.go index c1e382fd29..49c6a5efc2 100644 --- a/common/path.go +++ b/common/path.go @@ -27,7 +27,6 @@ func FileExist(filePath string) bool { if err != nil && os.IsNotExist(err) { return false } - return true } diff --git a/internal/build/file.go b/internal/build/file.go new file mode 100644 index 0000000000..c159b51892 --- /dev/null +++ b/internal/build/file.go @@ -0,0 +1,28 @@ +// Copyright 2024 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package build + +import "os" + +// FileExist checks if a file exists at path. +func FileExist(path string) bool { + _, err := os.Stat(path) + if err != nil && os.IsNotExist(err) { + return false + } + return true +}