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"
|
"time"
|
||||||
|
|
||||||
"github.com/cespare/cp"
|
"github.com/cespare/cp"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto/signify"
|
"github.com/ethereum/go-ethereum/crypto/signify"
|
||||||
"github.com/ethereum/go-ethereum/internal/build"
|
"github.com/ethereum/go-ethereum/internal/build"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -109,7 +108,7 @@ var (
|
||||||
// A debian package is created for all executables listed here.
|
// A debian package is created for all executables listed here.
|
||||||
debEthereum = debPackage{
|
debEthereum = debPackage{
|
||||||
Name: "ethereum",
|
Name: "ethereum",
|
||||||
Version: params.Version,
|
Version: version.Semantic,
|
||||||
Executables: debExecutables,
|
Executables: debExecutables,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,7 +143,7 @@ func executablePath(name string) string {
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.Lshortfile)
|
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")
|
log.Fatal("this script must be run from the root of the repository")
|
||||||
}
|
}
|
||||||
if len(os.Args) < 2 {
|
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
|
// hashAllSourceFiles iterates all files under the top-level project directory
|
||||||
// computing the hash of each file (excluding files within the tests
|
// computing the hash of each file (excluding files within the tests
|
||||||
// subrepo)
|
// subrepo)
|
||||||
func hashAllSourceFiles() (map[string]common.Hash, error) {
|
func hashAllSourceFiles() (map[string][32]byte, error) {
|
||||||
res := make(map[string]common.Hash)
|
res := make(map[string][32]byte)
|
||||||
err := filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error {
|
err := filepath.WalkDir(".", func(path string, d os.DirEntry, err error) error {
|
||||||
if strings.HasPrefix(path, filepath.FromSlash("tests/testdata")) {
|
if strings.HasPrefix(path, filepath.FromSlash("tests/testdata")) {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
|
|
@ -370,7 +369,7 @@ func hashAllSourceFiles() (map[string]common.Hash, error) {
|
||||||
if _, err := io.Copy(hasher, f); err != nil {
|
if _, err := io.Copy(hasher, f); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
res[path] = common.Hash(hasher.Sum(nil))
|
res[path] = [32]byte(hasher.Sum(nil))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != 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)
|
// hashSourceFiles iterates the provided set of filepaths (relative to the top-level geth project directory)
|
||||||
// computing the hash of each file.
|
// computing the hash of each file.
|
||||||
func hashSourceFiles(files []string) (map[string]common.Hash, error) {
|
func hashSourceFiles(files []string) (map[string][32]byte, error) {
|
||||||
res := make(map[string]common.Hash)
|
res := make(map[string][32]byte)
|
||||||
for _, filePath := range files {
|
for _, filePath := range files {
|
||||||
f, err := os.OpenFile(filePath, os.O_RDONLY, 0666)
|
f, err := os.OpenFile(filePath, os.O_RDONLY, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -392,14 +391,14 @@ func hashSourceFiles(files []string) (map[string]common.Hash, error) {
|
||||||
if _, err := io.Copy(hasher, f); err != nil {
|
if _, err := io.Copy(hasher, f); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res[filePath] = common.Hash(hasher.Sum(nil))
|
res[filePath] = [32]byte(hasher.Sum(nil))
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// compareHashedFilesets compares two maps (key is relative file path to top-level geth directory, value is its hash)
|
// 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.
|
// 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{}
|
updates := []string{}
|
||||||
for path, postHash := range postHashes {
|
for path, postHash := range postHashes {
|
||||||
preHash, ok := preHashes[path]
|
preHash, ok := preHashes[path]
|
||||||
|
|
@ -442,7 +441,7 @@ func doGenerate() {
|
||||||
protocPath := downloadProtoc(*cachedir)
|
protocPath := downloadProtoc(*cachedir)
|
||||||
protocGenGoPath := downloadProtocGenGo(*cachedir)
|
protocGenGoPath := downloadProtocGenGo(*cachedir)
|
||||||
|
|
||||||
var preHashes map[string]common.Hash
|
var preHashes map[string][32]byte
|
||||||
if *verify {
|
if *verify {
|
||||||
var err error
|
var err error
|
||||||
preHashes, err = hashAllSourceFiles()
|
preHashes, err = hashAllSourceFiles()
|
||||||
|
|
@ -632,7 +631,7 @@ func doArchive(cmdline []string) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
env = build.Env()
|
env = build.Env()
|
||||||
basegeth = archiveBasename(*arch, params.ArchiveVersion(env.Commit))
|
basegeth = archiveBasename(*arch, version.Archive(env.Commit))
|
||||||
geth = "geth-" + basegeth + ext
|
geth = "geth-" + basegeth + ext
|
||||||
alltools = "geth-alltools-" + basegeth + ext
|
alltools = "geth-alltools-" + basegeth + ext
|
||||||
)
|
)
|
||||||
|
|
@ -752,7 +751,7 @@ func doDockerBuildx(cmdline []string) {
|
||||||
case env.Branch == "master":
|
case env.Branch == "master":
|
||||||
tags = []string{"latest"}
|
tags = []string{"latest"}
|
||||||
case strings.HasPrefix(env.Tag, "v1."):
|
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
|
// Need to create a mult-arch builder
|
||||||
build.MustRunCommand("docker", "buildx", "create", "--use", "--name", "multi-arch-builder", "--platform", *platform)
|
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)
|
gethImage := fmt.Sprintf("%s%s", spec.base, tag)
|
||||||
build.MustRunCommand("docker", "buildx", "build",
|
build.MustRunCommand("docker", "buildx", "build",
|
||||||
"--build-arg", "COMMIT="+env.Commit,
|
"--build-arg", "COMMIT="+env.Commit,
|
||||||
"--build-arg", "VERSION="+params.VersionWithMeta,
|
"--build-arg", "VERSION="+version.WithMeta,
|
||||||
"--build-arg", "BUILDNUM="+env.Buildnum,
|
"--build-arg", "BUILDNUM="+env.Buildnum,
|
||||||
"--tag", gethImage,
|
"--tag", gethImage,
|
||||||
"--platform", *platform,
|
"--platform", *platform,
|
||||||
|
|
@ -915,7 +914,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) {
|
||||||
var idfile string
|
var idfile string
|
||||||
if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 {
|
if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 {
|
||||||
idfile = filepath.Join(workdir, "sshkey")
|
idfile = filepath.Join(workdir, "sshkey")
|
||||||
if !common.FileExist(idfile) {
|
if !build.FileExist(idfile) {
|
||||||
os.WriteFile(idfile, sshkey, 0600)
|
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
|
// 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
|
// built (don't mix building and packaging to keep cross compilation complexity to a
|
||||||
// minimum).
|
// minimum).
|
||||||
version := strings.Split(params.Version, ".")
|
ver := strings.Split(version.Semantic, ".")
|
||||||
if env.Commit != "" {
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("Failed to convert installer file path: %v", err)
|
log.Fatalf("Failed to convert installer file path: %v", err)
|
||||||
}
|
}
|
||||||
build.MustRunCommand("makensis.exe",
|
build.MustRunCommand("makensis.exe",
|
||||||
"/DOUTPUTFILE="+installer,
|
"/DOUTPUTFILE="+installer,
|
||||||
"/DMAJORVERSION="+version[0],
|
"/DMAJORVERSION="+ver[0],
|
||||||
"/DMINORVERSION="+version[1],
|
"/DMINORVERSION="+ver[1],
|
||||||
"/DBUILDVERSION="+version[2],
|
"/DBUILDVERSION="+ver[2],
|
||||||
"/DARCH="+*arch,
|
"/DARCH="+*arch,
|
||||||
filepath.Join(*workdir, "geth.nsi"),
|
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"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ourPath = "github.com/ethereum/go-ethereum" // Path to our module
|
const ourPath = "github.com/ethereum/go-ethereum" // Path to our module
|
||||||
|
|
@ -59,7 +59,7 @@ func ClientName(clientIdentifier string) string {
|
||||||
git, _ := VCS()
|
git, _ := VCS()
|
||||||
return fmt.Sprintf("%s/v%v/%v-%v/%v",
|
return fmt.Sprintf("%s/v%v/%v-%v/%v",
|
||||||
strings.Title(clientIdentifier),
|
strings.Title(clientIdentifier),
|
||||||
params.VersionWithCommit(git.Commit, git.Date),
|
version.WithCommit(git.Commit, git.Date),
|
||||||
runtime.GOOS, runtime.GOARCH,
|
runtime.GOOS, runtime.GOARCH,
|
||||||
runtime.Version(),
|
runtime.Version(),
|
||||||
)
|
)
|
||||||
|
|
@ -71,13 +71,13 @@ func ClientName(clientIdentifier string) string {
|
||||||
// module path, it will print out commit and date VCS information. Otherwise,
|
// 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
|
// it will assume it's imported by a third-party and will return the imported
|
||||||
// version and whether it was replaced by another module.
|
// version and whether it was replaced by another module.
|
||||||
func Info() (version, vcs string) {
|
func Info() (ver, vcs string) {
|
||||||
version = params.VersionWithMeta
|
ver = version.WithMeta
|
||||||
buildInfo, ok := debug.ReadBuildInfo()
|
buildInfo, ok := debug.ReadBuildInfo()
|
||||||
if !ok {
|
if !ok {
|
||||||
return version, ""
|
return ver, ""
|
||||||
}
|
}
|
||||||
version = versionInfo(buildInfo)
|
ver = versionInfo(buildInfo)
|
||||||
if status, ok := VCS(); ok {
|
if status, ok := VCS(); ok {
|
||||||
modified := ""
|
modified := ""
|
||||||
if status.Dirty {
|
if status.Dirty {
|
||||||
|
|
@ -89,7 +89,7 @@ func Info() (version, vcs string) {
|
||||||
}
|
}
|
||||||
vcs = commit + "-" + status.Date + modified
|
vcs = commit + "-" + status.Date + modified
|
||||||
}
|
}
|
||||||
return version, vcs
|
return ver, vcs
|
||||||
}
|
}
|
||||||
|
|
||||||
// versionInfo returns version information for the currently executing
|
// 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
|
// Not our main package, so explicitly print out the module path and
|
||||||
// version.
|
// version.
|
||||||
var version string
|
var ver string
|
||||||
if info.Main.Path != "" && info.Main.Version != "" {
|
if info.Main.Path != "" && info.Main.Version != "" {
|
||||||
// These can be empty when invoked with "go run".
|
// 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)
|
mod := findModule(info, ourPath)
|
||||||
if mod == nil {
|
if mod == nil {
|
||||||
// If our module path wasn't imported, it's unclear which
|
// If our module path wasn't imported, it's unclear which
|
||||||
// version of our code they are running. Fallback to hardcoded
|
// version of our code they are running. Fallback to hardcoded
|
||||||
// version.
|
// 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
|
// Our package is a dependency for the main module. Return path and
|
||||||
// version data for both.
|
// 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 mod.Replace != nil {
|
||||||
// If our package was replaced by something else, also note that.
|
// 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.
|
// findModule returns the module at path.
|
||||||
|
|
|
||||||
|
|
@ -14,54 +14,54 @@
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// 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/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package params
|
package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VersionMajor = 1 // Major version component of the current release
|
Major = 1 // Major version component of the current release
|
||||||
VersionMinor = 14 // Minor version component of the current release
|
Minor = 14 // Minor version component of the current release
|
||||||
VersionPatch = 12 // Patch version component of the current release
|
Patch = 12 // Patch version component of the current release
|
||||||
VersionMeta = "unstable" // Version metadata to append to the version string
|
Meta = "unstable" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version holds the textual version string.
|
// Semantic holds the textual version string.
|
||||||
var Version = func() string {
|
var Semantic = func() string {
|
||||||
return fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
|
return fmt.Sprintf("%d.%d.%d", Major, Minor, Patch)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// VersionWithMeta holds the textual version string including the metadata.
|
// WithMeta holds the textual version string including the metadata.
|
||||||
var VersionWithMeta = func() string {
|
var WithMeta = func() string {
|
||||||
v := Version
|
v := Semantic
|
||||||
if VersionMeta != "" {
|
if Meta != "" {
|
||||||
v += "-" + VersionMeta
|
v += "-" + Meta
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// ArchiveVersion holds the textual version string used for Geth archives. e.g.
|
func WithCommit(gitCommit, gitDate string) string {
|
||||||
// "1.8.11-dea1ce05" for stable releases, or "1.8.13-unstable-21c059b6" for unstable
|
vsn := WithMeta
|
||||||
// releases.
|
|
||||||
func ArchiveVersion(gitCommit string) string {
|
|
||||||
vsn := Version
|
|
||||||
if VersionMeta != "stable" {
|
|
||||||
vsn += "-" + VersionMeta
|
|
||||||
}
|
|
||||||
if len(gitCommit) >= 8 {
|
if len(gitCommit) >= 8 {
|
||||||
vsn += "-" + gitCommit[:8]
|
vsn += "-" + gitCommit[:8]
|
||||||
}
|
}
|
||||||
return vsn
|
if (Meta != "stable") && (gitDate != "") {
|
||||||
}
|
|
||||||
|
|
||||||
func VersionWithCommit(gitCommit, gitDate string) string {
|
|
||||||
vsn := VersionWithMeta
|
|
||||||
if len(gitCommit) >= 8 {
|
|
||||||
vsn += "-" + gitCommit[:8]
|
|
||||||
}
|
|
||||||
if (VersionMeta != "stable") && (gitDate != "") {
|
|
||||||
vsn += "-" + gitDate
|
vsn += "-" + gitDate
|
||||||
}
|
}
|
||||||
return vsn
|
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