forked from mitchellh/gox
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16cc89c
commit 923936b
Showing
4 changed files
with
77 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package main | ||
|
||
const metaVersion = "1.1.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,38 @@ | ||
//go:build go1.16 | ||
// +build go1.16 | ||
|
||
package main | ||
|
||
const metaVersion = "1.1.1" | ||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// GoVersion reads the version of `go` that is on the PATH. This is done | ||
// instead of `runtime.Version()` because it is possible to run gox against | ||
// another Go version. | ||
func GoVersion() (string, error) { | ||
// NOTE: We use `go run` instead of `go version` because the output | ||
// of `go version` might change whereas the source is guaranteed to run | ||
// for some time thanks to Go's compatibility guarantee. | ||
|
||
td, err := os.MkdirTemp("", "gox") | ||
if err != nil { | ||
return "", err | ||
} | ||
defer os.RemoveAll(td) | ||
|
||
// Write the source code for the program that will generate the version | ||
sourcePath := filepath.Join(td, "version.go") | ||
if err := os.WriteFile(sourcePath, []byte(versionSource), 0644); err != nil { | ||
return "", err | ||
} | ||
|
||
// Execute and read the version, which will be the only thing on stdout. | ||
version, err := execGo(gobin, nil, "", "run", sourcePath) | ||
|
||
fmt.Printf("Detected Go Version: %s\n", version) | ||
|
||
return version, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//go:build !go1.16 | ||
// +build !go1.16 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// GoVersion reads the version of `go` that is on the PATH. This is done | ||
// instead of `runtime.Version()` because it is possible to run gox against | ||
// another Go version. | ||
func GoVersion() (string, error) { | ||
// NOTE: We use `go run` instead of `go version` because the output | ||
// of `go version` might change whereas the source is guaranteed to run | ||
// for some time thanks to Go's compatibility guarantee. | ||
|
||
td, err := ioutil.TempDir("", "gox") | ||
if err != nil { | ||
return "", err | ||
} | ||
defer os.RemoveAll(td) | ||
|
||
// Write the source code for the program that will generate the version | ||
sourcePath := filepath.Join(td, "version.go") | ||
if err := ioutil.WriteFile(sourcePath, []byte(versionSource), 0644); err != nil { | ||
return "", err | ||
} | ||
|
||
// Execute and read the version, which will be the only thing on stdout. | ||
version, err := execGo(gobin, nil, "", "run", sourcePath) | ||
|
||
fmt.Printf("Detected Go Version: %s\n", version) | ||
|
||
return version, err | ||
} |