forked from TrueCloudLab/rclone
version: show build tags and type of executable
This patch modifies the output of `rclone version`. The `os/arch` line is split into `os/type` and `os/arch`. The `go version` line is now tagged as `go/version` for consistency. Additionally the `go/linking` line tells whether the rclone was linked as a static or dynamic executable. The new `go/tags` line shows a space separated list of build tags. The info about linking and build tags is also added to the output of the `core/version` RC endpoint.
This commit is contained in:
parent
268a7ff7b8
commit
ef5c212f9b
6 changed files with 71 additions and 13 deletions
|
@ -36,6 +36,7 @@ import (
|
||||||
"github.com/rclone/rclone/fs/rc/rcflags"
|
"github.com/rclone/rclone/fs/rc/rcflags"
|
||||||
"github.com/rclone/rclone/fs/rc/rcserver"
|
"github.com/rclone/rclone/fs/rc/rcserver"
|
||||||
"github.com/rclone/rclone/lib/atexit"
|
"github.com/rclone/rclone/lib/atexit"
|
||||||
|
"github.com/rclone/rclone/lib/buildinfo"
|
||||||
"github.com/rclone/rclone/lib/random"
|
"github.com/rclone/rclone/lib/random"
|
||||||
"github.com/rclone/rclone/lib/terminal"
|
"github.com/rclone/rclone/lib/terminal"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -74,9 +75,13 @@ const (
|
||||||
|
|
||||||
// ShowVersion prints the version to stdout
|
// ShowVersion prints the version to stdout
|
||||||
func ShowVersion() {
|
func ShowVersion() {
|
||||||
|
linking, tagString := buildinfo.GetLinkingAndTags()
|
||||||
fmt.Printf("rclone %s\n", fs.Version)
|
fmt.Printf("rclone %s\n", fs.Version)
|
||||||
fmt.Printf("- os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
fmt.Printf("- os/type: %s\n", runtime.GOOS)
|
||||||
fmt.Printf("- go version: %s\n", runtime.Version())
|
fmt.Printf("- os/arch: %s\n", runtime.GOARCH)
|
||||||
|
fmt.Printf("- go/version: %s\n", runtime.Version())
|
||||||
|
fmt.Printf("- go/linking: %s\n", linking)
|
||||||
|
fmt.Printf("- go/tags: %s\n", tagString)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFsFile creates an Fs from a name but may point to a file.
|
// NewFsFile creates an Fs from a name but may point to a file.
|
||||||
|
|
|
@ -29,14 +29,21 @@ var commandDefinition = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: `Show the version number.`,
|
Short: `Show the version number.`,
|
||||||
Long: `
|
Long: `
|
||||||
Show the version number, the go version and the architecture.
|
Show the rclone version number, the go version, the build target OS and
|
||||||
|
architecture, build tags and the type of executable (static or dynamic).
|
||||||
|
|
||||||
Eg
|
For example:
|
||||||
|
|
||||||
$ rclone version
|
$ rclone version
|
||||||
rclone v1.41
|
rclone v1.54
|
||||||
- os/arch: linux/amd64
|
- os/type: linux
|
||||||
- go version: go1.10
|
- os/arch: amd64
|
||||||
|
- go/version: go1.16
|
||||||
|
- go/linking: static
|
||||||
|
- go/tags: none
|
||||||
|
|
||||||
|
Note: before rclone version 1.55 the os/type and os/arch lines were merged,
|
||||||
|
and the "go/version" line was tagged as "go version".
|
||||||
|
|
||||||
If you supply the --check flag, then it will do an online check to
|
If you supply the --check flag, then it will do an online check to
|
||||||
compare your version with the latest release and the latest beta.
|
compare your version with the latest release and the latest beta.
|
||||||
|
@ -89,9 +96,7 @@ func GetVersion(url string) (v *semver.Version, vs string, date time.Time, err e
|
||||||
return v, vs, date, err
|
return v, vs, date, err
|
||||||
}
|
}
|
||||||
vs = strings.TrimSpace(string(bodyBytes))
|
vs = strings.TrimSpace(string(bodyBytes))
|
||||||
if strings.HasPrefix(vs, "rclone ") {
|
vs = strings.TrimPrefix(vs, "rclone ")
|
||||||
vs = vs[7:]
|
|
||||||
}
|
|
||||||
vs = strings.TrimRight(vs, "β")
|
vs = strings.TrimRight(vs, "β")
|
||||||
date, err = http.ParseTime(resp.Header.Get("Last-Modified"))
|
date, err = http.ParseTime(resp.Header.Get("Last-Modified"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/lib/atexit"
|
"github.com/rclone/rclone/lib/atexit"
|
||||||
|
"github.com/rclone/rclone/lib/buildinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -179,6 +180,8 @@ This shows the current version of go and the go runtime
|
||||||
- os - OS in use as according to Go
|
- os - OS in use as according to Go
|
||||||
- arch - cpu architecture in use according to Go
|
- arch - cpu architecture in use according to Go
|
||||||
- goVersion - version of Go runtime in use
|
- goVersion - version of Go runtime in use
|
||||||
|
- linking - type of rclone executable (static or dynamic)
|
||||||
|
- goTags - space separated build tags or "none"
|
||||||
|
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
@ -190,6 +193,7 @@ func rcVersion(ctx context.Context, in Params) (out Params, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
linking, tagString := buildinfo.GetLinkingAndTags()
|
||||||
out = Params{
|
out = Params{
|
||||||
"version": fs.Version,
|
"version": fs.Version,
|
||||||
"decomposed": version.Slice(),
|
"decomposed": version.Slice(),
|
||||||
|
@ -198,6 +202,8 @@ func rcVersion(ctx context.Context, in Params) (out Params, err error) {
|
||||||
"os": runtime.GOOS,
|
"os": runtime.GOOS,
|
||||||
"arch": runtime.GOARCH,
|
"arch": runtime.GOARCH,
|
||||||
"goVersion": runtime.Version(),
|
"goVersion": runtime.Version(),
|
||||||
|
"linking": linking,
|
||||||
|
"goTags": tagString,
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
@ -425,9 +431,7 @@ func rcRunCommand(ctx context.Context, in Params) (out Params, err error) {
|
||||||
allArgs = append(allArgs, command)
|
allArgs = append(allArgs, command)
|
||||||
}
|
}
|
||||||
// Add all from arg
|
// Add all from arg
|
||||||
for _, cur := range arg {
|
allArgs = append(allArgs, arg...)
|
||||||
allArgs = append(allArgs, cur)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add flags to args for e.g. --max-depth 1 comes in as { max-depth 1 }.
|
// Add flags to args for e.g. --max-depth 1 comes in as { max-depth 1 }.
|
||||||
// Convert it to [ max-depth, 1 ] and append to args list
|
// Convert it to [ max-depth, 1 ] and append to args list
|
||||||
|
|
7
lib/buildinfo/cgo.go
Normal file
7
lib/buildinfo/cgo.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// +build cgo
|
||||||
|
|
||||||
|
package buildinfo
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Tags = append(Tags, "cgo")
|
||||||
|
}
|
7
lib/buildinfo/cmount.go
Normal file
7
lib/buildinfo/cmount.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// +build cmount
|
||||||
|
|
||||||
|
package buildinfo
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Tags = append(Tags, "cmount")
|
||||||
|
}
|
30
lib/buildinfo/tags.go
Normal file
30
lib/buildinfo/tags.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package buildinfo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tags contains slice of build tags
|
||||||
|
var Tags []string
|
||||||
|
|
||||||
|
// GetLinkingAndTags tells how the rclone executable was linked
|
||||||
|
// and returns space separated build tags or the string "none".
|
||||||
|
func GetLinkingAndTags() (linking, tagString string) {
|
||||||
|
linking = "static"
|
||||||
|
tagList := []string{}
|
||||||
|
for _, tag := range Tags {
|
||||||
|
if tag == "cgo" {
|
||||||
|
linking = "dynamic"
|
||||||
|
} else {
|
||||||
|
tagList = append(tagList, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(tagList) > 0 {
|
||||||
|
sort.Strings(tagList)
|
||||||
|
tagString = strings.Join(tagList, " ")
|
||||||
|
} else {
|
||||||
|
tagString = "none"
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue