mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
build, internal, version: break ci.go/version->common dependency
This commit is contained in:
parent
b6c62d5887
commit
437b0a0fc1
4 changed files with 92 additions and 65 deletions
43
build/ci.go
43
build/ci.go
|
|
@ -54,10 +54,9 @@ 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"
|
||||
"github.com/ethereum/go-ethereum/version"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -109,7 +108,7 @@ var (
|
|||
// A debian package is created for all executables listed here.
|
||||
debEthereum = debPackage{
|
||||
Name: "ethereum",
|
||||
Version: params.Version,
|
||||
Version: version.Semantic,
|
||||
Executables: debExecutables,
|
||||
}
|
||||
|
||||
|
|
@ -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()
|
||||
|
|
@ -632,7 +631,7 @@ func doArchive(cmdline []string) {
|
|||
|
||||
var (
|
||||
env = build.Env()
|
||||
basegeth = archiveBasename(*arch, params.ArchiveVersion(env.Commit))
|
||||
basegeth = archiveBasename(*arch, version.Archive(env.Commit))
|
||||
geth = "geth-" + basegeth + ext
|
||||
alltools = "geth-alltools-" + basegeth + ext
|
||||
)
|
||||
|
|
@ -752,7 +751,7 @@ func doDockerBuildx(cmdline []string) {
|
|||
case env.Branch == "master":
|
||||
tags = []string{"latest"}
|
||||
case strings.HasPrefix(env.Tag, "v1."):
|
||||
tags = []string{"stable", fmt.Sprintf("release-1.%d", params.VersionMinor), "v" + params.Version}
|
||||
tags = []string{"stable", fmt.Sprintf("release-1.%d", version.Minor), "v" + version.Semantic}
|
||||
}
|
||||
// Need to create a mult-arch builder
|
||||
build.MustRunCommand("docker", "buildx", "create", "--use", "--name", "multi-arch-builder", "--platform", *platform)
|
||||
|
|
@ -768,7 +767,7 @@ func doDockerBuildx(cmdline []string) {
|
|||
gethImage := fmt.Sprintf("%s%s", spec.base, tag)
|
||||
build.MustRunCommand("docker", "buildx", "build",
|
||||
"--build-arg", "COMMIT="+env.Commit,
|
||||
"--build-arg", "VERSION="+params.VersionWithMeta,
|
||||
"--build-arg", "VERSION="+version.WithMeta,
|
||||
"--build-arg", "BUILDNUM="+env.Buildnum,
|
||||
"--tag", gethImage,
|
||||
"--platform", *platform,
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -1140,19 +1139,19 @@ func doWindowsInstaller(cmdline []string) {
|
|||
// Build the installer. This assumes that all the needed files have been previously
|
||||
// built (don't mix building and packaging to keep cross compilation complexity to a
|
||||
// minimum).
|
||||
version := strings.Split(params.Version, ".")
|
||||
ver := strings.Split(version.Semantic, ".")
|
||||
if env.Commit != "" {
|
||||
version[2] += "-" + env.Commit[:8]
|
||||
ver[2] += "-" + env.Commit[:8]
|
||||
}
|
||||
installer, err := filepath.Abs("geth-" + archiveBasename(*arch, params.ArchiveVersion(env.Commit)) + ".exe")
|
||||
installer, err := filepath.Abs("geth-" + archiveBasename(*arch, version.Archive(env.Commit)) + ".exe")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to convert installer file path: %v", err)
|
||||
}
|
||||
build.MustRunCommand("makensis.exe",
|
||||
"/DOUTPUTFILE="+installer,
|
||||
"/DMAJORVERSION="+version[0],
|
||||
"/DMINORVERSION="+version[1],
|
||||
"/DBUILDVERSION="+version[2],
|
||||
"/DMAJORVERSION="+ver[0],
|
||||
"/DMINORVERSION="+ver[1],
|
||||
"/DBUILDVERSION="+ver[2],
|
||||
"/DARCH="+*arch,
|
||||
filepath.Join(*workdir, "geth.nsi"),
|
||||
)
|
||||
|
|
|
|||
28
internal/build/file.go
Normal file
28
internal/build/file.go
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ import (
|
|||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/version"
|
||||
)
|
||||
|
||||
const ourPath = "github.com/ethereum/go-ethereum" // Path to our module
|
||||
|
|
@ -59,7 +59,7 @@ func ClientName(clientIdentifier string) string {
|
|||
git, _ := VCS()
|
||||
return fmt.Sprintf("%s/v%v/%v-%v/%v",
|
||||
strings.Title(clientIdentifier),
|
||||
params.VersionWithCommit(git.Commit, git.Date),
|
||||
version.WithCommit(git.Commit, git.Date),
|
||||
runtime.GOOS, runtime.GOARCH,
|
||||
runtime.Version(),
|
||||
)
|
||||
|
|
@ -71,13 +71,13 @@ func ClientName(clientIdentifier string) string {
|
|||
// module path, it will print out commit and date VCS information. Otherwise,
|
||||
// it will assume it's imported by a third-party and will return the imported
|
||||
// version and whether it was replaced by another module.
|
||||
func Info() (version, vcs string) {
|
||||
version = params.VersionWithMeta
|
||||
func Info() (ver, vcs string) {
|
||||
ver = version.WithMeta
|
||||
buildInfo, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return version, ""
|
||||
return ver, ""
|
||||
}
|
||||
version = versionInfo(buildInfo)
|
||||
ver = versionInfo(buildInfo)
|
||||
if status, ok := VCS(); ok {
|
||||
modified := ""
|
||||
if status.Dirty {
|
||||
|
|
@ -89,7 +89,7 @@ func Info() (version, vcs string) {
|
|||
}
|
||||
vcs = commit + "-" + status.Date + modified
|
||||
}
|
||||
return version, vcs
|
||||
return ver, vcs
|
||||
}
|
||||
|
||||
// versionInfo returns version information for the currently executing
|
||||
|
|
@ -105,26 +105,26 @@ func versionInfo(info *debug.BuildInfo) string {
|
|||
}
|
||||
// Not our main package, so explicitly print out the module path and
|
||||
// version.
|
||||
var version string
|
||||
var ver string
|
||||
if info.Main.Path != "" && info.Main.Version != "" {
|
||||
// These can be empty when invoked with "go run".
|
||||
version = fmt.Sprintf("%s@%s ", info.Main.Path, info.Main.Version)
|
||||
ver = fmt.Sprintf("%s@%s ", info.Main.Path, info.Main.Version)
|
||||
}
|
||||
mod := findModule(info, ourPath)
|
||||
if mod == nil {
|
||||
// If our module path wasn't imported, it's unclear which
|
||||
// version of our code they are running. Fallback to hardcoded
|
||||
// version.
|
||||
return version + fmt.Sprintf("geth %s", params.VersionWithMeta)
|
||||
return ver + fmt.Sprintf("geth %s", version.WithMeta)
|
||||
}
|
||||
// Our package is a dependency for the main module. Return path and
|
||||
// version data for both.
|
||||
version += fmt.Sprintf("%s@%s", mod.Path, mod.Version)
|
||||
ver += fmt.Sprintf("%s@%s", mod.Path, mod.Version)
|
||||
if mod.Replace != nil {
|
||||
// If our package was replaced by something else, also note that.
|
||||
version += fmt.Sprintf(" (replaced by %s@%s)", mod.Replace.Path, mod.Replace.Version)
|
||||
ver += fmt.Sprintf(" (replaced by %s@%s)", mod.Replace.Path, mod.Replace.Version)
|
||||
}
|
||||
return version
|
||||
return ver
|
||||
}
|
||||
|
||||
// findModule returns the module at path.
|
||||
|
|
|
|||
|
|
@ -14,54 +14,54 @@
|
|||
// 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 params
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
VersionMajor = 1 // Major version component of the current release
|
||||
VersionMinor = 14 // Minor version component of the current release
|
||||
VersionPatch = 12 // Patch version component of the current release
|
||||
VersionMeta = "unstable" // Version metadata to append to the version string
|
||||
Major = 1 // Major version component of the current release
|
||||
Minor = 14 // Minor version component of the current release
|
||||
Patch = 12 // Patch version component of the current release
|
||||
Meta = "unstable" // Version metadata to append to the version string
|
||||
)
|
||||
|
||||
// Version holds the textual version string.
|
||||
var Version = func() string {
|
||||
return fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
|
||||
// Semantic holds the textual version string.
|
||||
var Semantic = func() string {
|
||||
return fmt.Sprintf("%d.%d.%d", Major, Minor, Patch)
|
||||
}()
|
||||
|
||||
// VersionWithMeta holds the textual version string including the metadata.
|
||||
var VersionWithMeta = func() string {
|
||||
v := Version
|
||||
if VersionMeta != "" {
|
||||
v += "-" + VersionMeta
|
||||
// WithMeta holds the textual version string including the metadata.
|
||||
var WithMeta = func() string {
|
||||
v := Semantic
|
||||
if Meta != "" {
|
||||
v += "-" + Meta
|
||||
}
|
||||
return v
|
||||
}()
|
||||
|
||||
// ArchiveVersion holds the textual version string used for Geth archives. e.g.
|
||||
// "1.8.11-dea1ce05" for stable releases, or "1.8.13-unstable-21c059b6" for unstable
|
||||
// releases.
|
||||
func ArchiveVersion(gitCommit string) string {
|
||||
vsn := Version
|
||||
if VersionMeta != "stable" {
|
||||
vsn += "-" + VersionMeta
|
||||
}
|
||||
func WithCommit(gitCommit, gitDate string) string {
|
||||
vsn := WithMeta
|
||||
if len(gitCommit) >= 8 {
|
||||
vsn += "-" + gitCommit[:8]
|
||||
}
|
||||
return vsn
|
||||
}
|
||||
|
||||
func VersionWithCommit(gitCommit, gitDate string) string {
|
||||
vsn := VersionWithMeta
|
||||
if len(gitCommit) >= 8 {
|
||||
vsn += "-" + gitCommit[:8]
|
||||
}
|
||||
if (VersionMeta != "stable") && (gitDate != "") {
|
||||
if (Meta != "stable") && (gitDate != "") {
|
||||
vsn += "-" + gitDate
|
||||
}
|
||||
return vsn
|
||||
}
|
||||
|
||||
// Archive holds the textual version string used for Geth archives. e.g.
|
||||
// "1.8.11-dea1ce05" for stable releases, or "1.8.13-unstable-21c059b6" for unstable
|
||||
// releases.
|
||||
func Archive(gitCommit string) string {
|
||||
vsn := Semantic
|
||||
if Meta != "stable" {
|
||||
vsn += "-" + Meta
|
||||
}
|
||||
if len(gitCommit) >= 8 {
|
||||
vsn += "-" + gitCommit[:8]
|
||||
}
|
||||
return vsn
|
||||
}
|
||||
Loading…
Reference in a new issue