all: refactor goenv.Version to add the git sha1 if needed
Previously all (except one!) usage of goenv.Version manually added the git sha1 hash, leading to duplicate code. I've moved this to do it all in one place, to avoid this duplication.
Этот коммит содержится в:
родитель
2320b18953
коммит
5cd8ba2421
5 изменённых файлов: 17 добавлений и 21 удалений
|
@ -878,7 +878,7 @@ deb:
|
||||||
@mkdir -p build/release-deb/usr/local/lib
|
@mkdir -p build/release-deb/usr/local/lib
|
||||||
cp -ar build/release/tinygo build/release-deb/usr/local/lib/tinygo
|
cp -ar build/release/tinygo build/release-deb/usr/local/lib/tinygo
|
||||||
ln -sf ../lib/tinygo/bin/tinygo build/release-deb/usr/local/bin/tinygo
|
ln -sf ../lib/tinygo/bin/tinygo build/release-deb/usr/local/bin/tinygo
|
||||||
fpm -f -s dir -t deb -n tinygo -a $(DEB_ARCH) -v $(shell grep "const Version = " goenv/version.go | awk '{print $$NF}') -m '@tinygo-org' --description='TinyGo is a Go compiler for small places.' --license='BSD 3-Clause' --url=https://tinygo.org/ --deb-changelog CHANGELOG.md -p build/release.deb -C ./build/release-deb
|
fpm -f -s dir -t deb -n tinygo -a $(DEB_ARCH) -v $(shell grep "const version = " goenv/version.go | awk '{print $$NF}') -m '@tinygo-org' --description='TinyGo is a Go compiler for small places.' --license='BSD 3-Clause' --url=https://tinygo.org/ --deb-changelog CHANGELOG.md -p build/release.deb -C ./build/release-deb
|
||||||
|
|
||||||
ifneq ($(RELEASEONLY), 1)
|
ifneq ($(RELEASEONLY), 1)
|
||||||
release: build/release
|
release: build/release
|
||||||
|
|
|
@ -168,7 +168,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
||||||
CodeModel: config.CodeModel(),
|
CodeModel: config.CodeModel(),
|
||||||
RelocationModel: config.RelocationModel(),
|
RelocationModel: config.RelocationModel(),
|
||||||
SizeLevel: sizeLevel,
|
SizeLevel: sizeLevel,
|
||||||
TinyGoVersion: goenv.Version,
|
TinyGoVersion: goenv.Version(),
|
||||||
|
|
||||||
Scheduler: config.Scheduler(),
|
Scheduler: config.Scheduler(),
|
||||||
AutomaticStackSize: config.AutomaticStackSize(),
|
AutomaticStackSize: config.AutomaticStackSize(),
|
||||||
|
@ -220,14 +220,10 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
||||||
config.Options.GlobalValues = make(map[string]map[string]string)
|
config.Options.GlobalValues = make(map[string]map[string]string)
|
||||||
}
|
}
|
||||||
if config.Options.GlobalValues["runtime"]["buildVersion"] == "" {
|
if config.Options.GlobalValues["runtime"]["buildVersion"] == "" {
|
||||||
version := goenv.Version
|
|
||||||
if strings.HasSuffix(goenv.Version, "-dev") && goenv.GitSha1 != "" {
|
|
||||||
version += "-" + goenv.GitSha1
|
|
||||||
}
|
|
||||||
if config.Options.GlobalValues["runtime"] == nil {
|
if config.Options.GlobalValues["runtime"] == nil {
|
||||||
config.Options.GlobalValues["runtime"] = make(map[string]string)
|
config.Options.GlobalValues["runtime"] = make(map[string]string)
|
||||||
}
|
}
|
||||||
config.Options.GlobalValues["runtime"]["buildVersion"] = version
|
config.Options.GlobalValues["runtime"]["buildVersion"] = goenv.Version()
|
||||||
}
|
}
|
||||||
if config.TestConfig.CompileTestBinary {
|
if config.TestConfig.CompileTestBinary {
|
||||||
// The testing.testBinary is set to "1" when in a test.
|
// The testing.testBinary is set to "1" when in a test.
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
// Version of TinyGo.
|
// Version of TinyGo.
|
||||||
// Update this value before release of new version of software.
|
// Update this value before release of new version of software.
|
||||||
const Version = "0.30.0"
|
const version = "0.30.0"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// This variable is set at build time using -ldflags parameters.
|
// This variable is set at build time using -ldflags parameters.
|
||||||
|
@ -17,6 +17,16 @@ var (
|
||||||
GitSha1 string
|
GitSha1 string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Return TinyGo version, either in the form 0.30.0 or as a development version
|
||||||
|
// (like 0.30.0-dev-abcd012).
|
||||||
|
func Version() string {
|
||||||
|
v := version
|
||||||
|
if strings.HasSuffix(version, "-dev") && GitSha1 != "" {
|
||||||
|
v += "-" + GitSha1
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
// GetGorootVersion returns the major and minor version for a given GOROOT path.
|
// GetGorootVersion returns the major and minor version for a given GOROOT path.
|
||||||
// If the goroot cannot be determined, (0, 0) is returned.
|
// If the goroot cannot be determined, (0, 0) is returned.
|
||||||
func GetGorootVersion() (major, minor int, err error) {
|
func GetGorootVersion() (major, minor int, err error) {
|
||||||
|
|
13
main.go
13
main.go
|
@ -1212,15 +1212,10 @@ func getBMPPorts() (gdbPort, uartPort string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func usage(command string) {
|
func usage(command string) {
|
||||||
version := goenv.Version
|
|
||||||
if strings.HasSuffix(version, "-dev") && goenv.GitSha1 != "" {
|
|
||||||
version += "-" + goenv.GitSha1
|
|
||||||
}
|
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
default:
|
default:
|
||||||
fmt.Fprintln(os.Stderr, "TinyGo is a Go compiler for small places.")
|
fmt.Fprintln(os.Stderr, "TinyGo is a Go compiler for small places.")
|
||||||
fmt.Fprintln(os.Stderr, "version:", version)
|
fmt.Fprintln(os.Stderr, "version:", goenv.Version())
|
||||||
fmt.Fprintf(os.Stderr, "usage: %s <command> [arguments]\n", os.Args[0])
|
fmt.Fprintf(os.Stderr, "usage: %s <command> [arguments]\n", os.Args[0])
|
||||||
fmt.Fprintln(os.Stderr, "\ncommands:")
|
fmt.Fprintln(os.Stderr, "\ncommands:")
|
||||||
fmt.Fprintln(os.Stderr, " build: compile packages and dependencies")
|
fmt.Fprintln(os.Stderr, " build: compile packages and dependencies")
|
||||||
|
@ -1874,11 +1869,7 @@ func main() {
|
||||||
if s, err := goenv.GorootVersionString(); err == nil {
|
if s, err := goenv.GorootVersionString(); err == nil {
|
||||||
goversion = s
|
goversion = s
|
||||||
}
|
}
|
||||||
version := goenv.Version
|
fmt.Printf("tinygo version %s %s/%s (using go version %s and LLVM version %s)\n", goenv.Version(), runtime.GOOS, runtime.GOARCH, goversion, llvm.Version)
|
||||||
if strings.HasSuffix(goenv.Version, "-dev") && goenv.GitSha1 != "" {
|
|
||||||
version += "-" + goenv.GitSha1
|
|
||||||
}
|
|
||||||
fmt.Printf("tinygo version %s %s/%s (using go version %s and LLVM version %s)\n", version, runtime.GOOS, runtime.GOARCH, goversion, llvm.Version)
|
|
||||||
case "env":
|
case "env":
|
||||||
if flag.NArg() == 0 {
|
if flag.NArg() == 0 {
|
||||||
// Show all environment variables.
|
// Show all environment variables.
|
||||||
|
|
|
@ -10,8 +10,7 @@ func Callers(skip int, pc []uintptr) int {
|
||||||
var buildVersion string
|
var buildVersion string
|
||||||
|
|
||||||
// Version returns the Tinygo tree's version string.
|
// Version returns the Tinygo tree's version string.
|
||||||
// It is the same as goenv.Version, or in case of a development build,
|
// It is the same as goenv.Version().
|
||||||
// it will be the concatenation of goenv.Version and the git commit hash.
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return buildVersion
|
return buildVersion
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче