Skip to content

Commit

Permalink
Merge pull request #112 from mdehoog/set-version-at-build-time
Browse files Browse the repository at this point in the history
  • Loading branch information
trianglesphere authored Aug 19, 2023
2 parents f7376a2 + b3c4be0 commit 628d300
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ func buildFlags(env build.Environment, staticLinking bool, buildTags []string) (
ld = append(ld, "-X", "github.com/ethereum/go-ethereum/internal/version.gitCommit="+env.Commit)
ld = append(ld, "-X", "github.com/ethereum/go-ethereum/internal/version.gitDate="+env.Date)
}
if env.Tag != "" {
ld = append(ld, "-X", "github.com/ethereum/go-ethereum/params.gitTag="+env.Tag)
}
// Strip DWARF on darwin. This used to be required for certain things,
// and there is no downside to this, so we just keep doing it.
if runtime.GOOS == "darwin" {
Expand Down
24 changes: 23 additions & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package params

import (
"fmt"
"regexp"
"strconv"
)

// Version is the version of upstream geth
Expand All @@ -29,13 +31,33 @@ const (
)

// OPVersion is the version of op-geth
const (
var (
OPVersionMajor = 0 // Major version component of the current release
OPVersionMinor = 1 // Minor version component of the current release
OPVersionPatch = 0 // Patch version component of the current release
OPVersionMeta = "unstable" // Version metadata to append to the version string
)

// This is set at build-time by the linker when the build is done by build/ci.go.
var gitTag string

// Override the version variables if the gitTag was set at build time.
var _ = func() (_ string) {
semver := regexp.MustCompile("^v([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$")
version := semver.FindStringSubmatch(gitTag)
if version == nil {
return
}
if version[4] == "" {
version[4] = "stable"
}
OPVersionMajor, _ = strconv.Atoi(version[1])
OPVersionMinor, _ = strconv.Atoi(version[2])
OPVersionPatch, _ = strconv.Atoi(version[3])
OPVersionMeta = version[4]
return
}()

// Version holds the textual version string.
var Version = func() string {
return fmt.Sprintf("%d.%d.%d", OPVersionMajor, OPVersionMinor, OPVersionPatch)
Expand Down

0 comments on commit 628d300

Please sign in to comment.