From ef5c212f9bf84d8b173707e03ea55bdc0ef12fac Mon Sep 17 00:00:00 2001 From: Ivan Andreev Date: Sun, 21 Mar 2021 15:13:09 +0300 Subject: [PATCH] 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. --- cmd/cmd.go | 9 +++++++-- cmd/version/version.go | 21 +++++++++++++-------- fs/rc/internal.go | 10 +++++++--- lib/buildinfo/cgo.go | 7 +++++++ lib/buildinfo/cmount.go | 7 +++++++ lib/buildinfo/tags.go | 30 ++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 lib/buildinfo/cgo.go create mode 100644 lib/buildinfo/cmount.go create mode 100644 lib/buildinfo/tags.go diff --git a/cmd/cmd.go b/cmd/cmd.go index fee58d61b..e2a03db5d 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -36,6 +36,7 @@ import ( "github.com/rclone/rclone/fs/rc/rcflags" "github.com/rclone/rclone/fs/rc/rcserver" "github.com/rclone/rclone/lib/atexit" + "github.com/rclone/rclone/lib/buildinfo" "github.com/rclone/rclone/lib/random" "github.com/rclone/rclone/lib/terminal" "github.com/spf13/cobra" @@ -74,9 +75,13 @@ const ( // ShowVersion prints the version to stdout func ShowVersion() { + linking, tagString := buildinfo.GetLinkingAndTags() fmt.Printf("rclone %s\n", fs.Version) - fmt.Printf("- os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) - fmt.Printf("- go version: %s\n", runtime.Version()) + fmt.Printf("- os/type: %s\n", runtime.GOOS) + 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. diff --git a/cmd/version/version.go b/cmd/version/version.go index 85a049b37..0ccfe8e3f 100644 --- a/cmd/version/version.go +++ b/cmd/version/version.go @@ -29,14 +29,21 @@ var commandDefinition = &cobra.Command{ Use: "version", Short: `Show the version number.`, 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 v1.41 - - os/arch: linux/amd64 - - go version: go1.10 + rclone v1.54 + - os/type: linux + - 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 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 } vs = strings.TrimSpace(string(bodyBytes)) - if strings.HasPrefix(vs, "rclone ") { - vs = vs[7:] - } + vs = strings.TrimPrefix(vs, "rclone ") vs = strings.TrimRight(vs, "β") date, err = http.ParseTime(resp.Header.Get("Last-Modified")) if err != nil { diff --git a/fs/rc/internal.go b/fs/rc/internal.go index a3018bc4a..4c8d8617f 100644 --- a/fs/rc/internal.go +++ b/fs/rc/internal.go @@ -17,6 +17,7 @@ import ( "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/config/obscure" "github.com/rclone/rclone/lib/atexit" + "github.com/rclone/rclone/lib/buildinfo" ) 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 - arch - cpu architecture in use according to Go - 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 { return nil, err } + linking, tagString := buildinfo.GetLinkingAndTags() out = Params{ "version": fs.Version, "decomposed": version.Slice(), @@ -198,6 +202,8 @@ func rcVersion(ctx context.Context, in Params) (out Params, err error) { "os": runtime.GOOS, "arch": runtime.GOARCH, "goVersion": runtime.Version(), + "linking": linking, + "goTags": tagString, } return out, nil } @@ -425,9 +431,7 @@ func rcRunCommand(ctx context.Context, in Params) (out Params, err error) { allArgs = append(allArgs, command) } // Add all from arg - for _, cur := range arg { - allArgs = append(allArgs, cur) - } + allArgs = append(allArgs, arg...) // 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 diff --git a/lib/buildinfo/cgo.go b/lib/buildinfo/cgo.go new file mode 100644 index 000000000..8009d3bea --- /dev/null +++ b/lib/buildinfo/cgo.go @@ -0,0 +1,7 @@ +// +build cgo + +package buildinfo + +func init() { + Tags = append(Tags, "cgo") +} diff --git a/lib/buildinfo/cmount.go b/lib/buildinfo/cmount.go new file mode 100644 index 000000000..67ffbbea5 --- /dev/null +++ b/lib/buildinfo/cmount.go @@ -0,0 +1,7 @@ +// +build cmount + +package buildinfo + +func init() { + Tags = append(Tags, "cmount") +} diff --git a/lib/buildinfo/tags.go b/lib/buildinfo/tags.go new file mode 100644 index 000000000..84b79bd19 --- /dev/null +++ b/lib/buildinfo/tags.go @@ -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 +}