Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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]
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}
Expand Down
1 change: 0 additions & 1 deletion common/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func FileExist(filePath string) bool {
if err != nil && os.IsNotExist(err) {
return false
}

return true
}

Expand Down
28 changes: 28 additions & 0 deletions internal/build/file.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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
}