Skip to content

Commit 1c88e42

Browse files
karalabeholiman
authored andcommitted
build: get rid of ci.go -> common direct dependency (#30637)
1 parent 7a79f2f commit 1c88e42

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

build/ci.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import (
5454
"time"
5555

5656
"github.com/cespare/cp"
57-
"github.com/ethereum/go-ethereum/common"
5857
"github.com/ethereum/go-ethereum/crypto/signify"
5958
"github.com/ethereum/go-ethereum/internal/build"
6059
"github.com/ethereum/go-ethereum/params"
@@ -144,7 +143,7 @@ func executablePath(name string) string {
144143
func main() {
145144
log.SetFlags(log.Lshortfile)
146145

147-
if !common.FileExist(filepath.Join("build", "ci.go")) {
146+
if !build.FileExist(filepath.Join("build", "ci.go")) {
148147
log.Fatal("this script must be run from the root of the repository")
149148
}
150149
if len(os.Args) < 2 {
@@ -352,8 +351,8 @@ func downloadSpecTestFixtures(csdb *build.ChecksumDB, cachedir string) string {
352351
// hashAllSourceFiles iterates all files under the top-level project directory
353352
// computing the hash of each file (excluding files within the tests
354353
// subrepo)
355-
func hashAllSourceFiles() (map[string]common.Hash, error) {
356-
res := make(map[string]common.Hash)
354+
func hashAllSourceFiles() (map[string][32]byte, error) {
355+
res := make(map[string][32]byte)
357356
err := filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error {
358357
if strings.HasPrefix(path, filepath.FromSlash("tests/testdata")) {
359358
return filepath.SkipDir
@@ -370,7 +369,7 @@ func hashAllSourceFiles() (map[string]common.Hash, error) {
370369
if _, err := io.Copy(hasher, f); err != nil {
371370
return err
372371
}
373-
res[path] = common.Hash(hasher.Sum(nil))
372+
res[path] = [32]byte(hasher.Sum(nil))
374373
return nil
375374
})
376375
if err != nil {
@@ -381,8 +380,8 @@ func hashAllSourceFiles() (map[string]common.Hash, error) {
381380

382381
// hashSourceFiles iterates the provided set of filepaths (relative to the top-level geth project directory)
383382
// computing the hash of each file.
384-
func hashSourceFiles(files []string) (map[string]common.Hash, error) {
385-
res := make(map[string]common.Hash)
383+
func hashSourceFiles(files []string) (map[string][32]byte, error) {
384+
res := make(map[string][32]byte)
386385
for _, filePath := range files {
387386
f, err := os.OpenFile(filePath, os.O_RDONLY, 0666)
388387
if err != nil {
@@ -392,14 +391,14 @@ func hashSourceFiles(files []string) (map[string]common.Hash, error) {
392391
if _, err := io.Copy(hasher, f); err != nil {
393392
return nil, err
394393
}
395-
res[filePath] = common.Hash(hasher.Sum(nil))
394+
res[filePath] = [32]byte(hasher.Sum(nil))
396395
}
397396
return res, nil
398397
}
399398

400399
// compareHashedFilesets compares two maps (key is relative file path to top-level geth directory, value is its hash)
401400
// and returns the list of file paths whose hashes differed.
402-
func compareHashedFilesets(preHashes map[string]common.Hash, postHashes map[string]common.Hash) []string {
401+
func compareHashedFilesets(preHashes map[string][32]byte, postHashes map[string][32]byte) []string {
403402
updates := []string{}
404403
for path, postHash := range postHashes {
405404
preHash, ok := preHashes[path]
@@ -442,7 +441,7 @@ func doGenerate() {
442441
protocPath := downloadProtoc(*cachedir)
443442
protocGenGoPath := downloadProtocGenGo(*cachedir)
444443

445-
var preHashes map[string]common.Hash
444+
var preHashes map[string][32]byte
446445
if *verify {
447446
var err error
448447
preHashes, err = hashAllSourceFiles()
@@ -915,7 +914,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) {
915914
var idfile string
916915
if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 {
917916
idfile = filepath.Join(workdir, "sshkey")
918-
if !common.FileExist(idfile) {
917+
if !build.FileExist(idfile) {
919918
os.WriteFile(idfile, sshkey, 0600)
920919
}
921920
}

common/path.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func FileExist(filePath string) bool {
2727
if err != nil && os.IsNotExist(err) {
2828
return false
2929
}
30-
3130
return true
3231
}
3332

internal/build/file.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2024 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package build
18+
19+
import "os"
20+
21+
// FileExist checks if a file exists at path.
22+
func FileExist(path string) bool {
23+
_, err := os.Stat(path)
24+
if err != nil && os.IsNotExist(err) {
25+
return false
26+
}
27+
return true
28+
}

0 commit comments

Comments
 (0)