github.com/bir3/gocompiler@v0.9.2202/src/cmd/gocmd/internal/gover/local.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gover 6 7 import ( 8 "github.com/bir3/gocompiler/src/internal/goversion" 9 "runtime" 10 "strconv" 11 ) 12 13 // TestVersion is initialized in the go command test binary 14 // to be $TESTGO_VERSION, to allow tests to override the 15 // go command's idea of its own version as returned by Local. 16 var TestVersion string 17 18 // Local returns the local Go version, the one implemented by this go command. 19 func Local() string { 20 v, _ := local() 21 return v 22 } 23 24 // LocalToolchain returns the local toolchain name, the one implemented by this go command. 25 func LocalToolchain() string { 26 _, t := local() 27 return t 28 } 29 30 func local() (goVers, toolVers string) { 31 toolVers = runtime.Version() 32 if TestVersion != "" { 33 toolVers = TestVersion 34 } 35 goVers = FromToolchain(toolVers) 36 if goVers == "" { 37 // Development branch. Use "Dev" version with just 1.N, no rc1 or .0 suffix. 38 goVers = "1." + strconv.Itoa(goversion.Version) 39 toolVers = "go" + goVers 40 } 41 return goVers, toolVers 42 }