From 9eab258ffbb68edbfd91232a3e313031cfd6860c Mon Sep 17 00:00:00 2001 From: Ivan Andreev Date: Sat, 3 Apr 2021 14:39:04 +0300 Subject: [PATCH] build: add build tag noselfupdate Allow downstream packaging to build rclone without selfupdate command: $ go build -tags noselfupdate Fixes #5187 --- cmd/cmd.go | 2 +- cmd/selfupdate/help.go | 2 ++ cmd/selfupdate/noselfupdate.go | 11 +++++++++++ cmd/selfupdate/selfupdate.go | 2 ++ cmd/selfupdate/selfupdate_test.go | 2 ++ cmd/selfupdate/verify.go | 2 ++ cmd/selfupdate/writable_unix.go | 1 + cmd/selfupdate/writable_unsupported.go | 1 + cmd/selfupdate/writable_windows.go | 1 + cmd/selfupdate_disabled.go | 5 +++++ cmd/selfupdate_enabled.go | 7 +++++++ lib/buildinfo/tags.go | 3 ++- 12 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 cmd/selfupdate/noselfupdate.go create mode 100644 cmd/selfupdate_disabled.go create mode 100644 cmd/selfupdate_enabled.go diff --git a/cmd/cmd.go b/cmd/cmd.go index e2a03db5d..637b91b39 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -553,7 +553,7 @@ func Main() { setupRootCommand(Root) AddBackendFlags() if err := Root.Execute(); err != nil { - if strings.HasPrefix(err.Error(), "unknown command") { + if strings.HasPrefix(err.Error(), "unknown command") && selfupdateEnabled { Root.PrintErrf("You could use '%s selfupdate' to get latest features.\n\n", Root.CommandPath()) } log.Fatalf("Fatal error: %v", err) diff --git a/cmd/selfupdate/help.go b/cmd/selfupdate/help.go index 791f20d42..fe9a63158 100644 --- a/cmd/selfupdate/help.go +++ b/cmd/selfupdate/help.go @@ -1,3 +1,5 @@ +// +build !noselfupdate + package selfupdate // Note: "|" will be replaced by backticks in the help string below diff --git a/cmd/selfupdate/noselfupdate.go b/cmd/selfupdate/noselfupdate.go new file mode 100644 index 000000000..41afd1c94 --- /dev/null +++ b/cmd/selfupdate/noselfupdate.go @@ -0,0 +1,11 @@ +// +build noselfupdate + +package selfupdate + +import ( + "github.com/rclone/rclone/lib/buildinfo" +) + +func init() { + buildinfo.Tags = append(buildinfo.Tags, "noselfupdate") +} diff --git a/cmd/selfupdate/selfupdate.go b/cmd/selfupdate/selfupdate.go index bc48f0413..1789b9cb7 100644 --- a/cmd/selfupdate/selfupdate.go +++ b/cmd/selfupdate/selfupdate.go @@ -1,3 +1,5 @@ +// +build !noselfupdate + package selfupdate import ( diff --git a/cmd/selfupdate/selfupdate_test.go b/cmd/selfupdate/selfupdate_test.go index 567643716..a9a889ba7 100644 --- a/cmd/selfupdate/selfupdate_test.go +++ b/cmd/selfupdate/selfupdate_test.go @@ -1,3 +1,5 @@ +// +build !noselfupdate + package selfupdate import ( diff --git a/cmd/selfupdate/verify.go b/cmd/selfupdate/verify.go index 115119fed..0c135c75c 100644 --- a/cmd/selfupdate/verify.go +++ b/cmd/selfupdate/verify.go @@ -1,3 +1,5 @@ +// +build !noselfupdate + package selfupdate import ( diff --git a/cmd/selfupdate/writable_unix.go b/cmd/selfupdate/writable_unix.go index f7c8a59fb..30cb8a9bf 100644 --- a/cmd/selfupdate/writable_unix.go +++ b/cmd/selfupdate/writable_unix.go @@ -1,4 +1,5 @@ // +build !windows,!plan9,!js +// +build !noselfupdate package selfupdate diff --git a/cmd/selfupdate/writable_unsupported.go b/cmd/selfupdate/writable_unsupported.go index 40f1d2429..bc68073d6 100644 --- a/cmd/selfupdate/writable_unsupported.go +++ b/cmd/selfupdate/writable_unsupported.go @@ -1,4 +1,5 @@ // +build plan9 js +// +build !noselfupdate package selfupdate diff --git a/cmd/selfupdate/writable_windows.go b/cmd/selfupdate/writable_windows.go index 8270d3936..7e23f56dc 100644 --- a/cmd/selfupdate/writable_windows.go +++ b/cmd/selfupdate/writable_windows.go @@ -1,4 +1,5 @@ // +build windows +// +build !noselfupdate package selfupdate diff --git a/cmd/selfupdate_disabled.go b/cmd/selfupdate_disabled.go new file mode 100644 index 000000000..3d666700b --- /dev/null +++ b/cmd/selfupdate_disabled.go @@ -0,0 +1,5 @@ +// +build noselfupdate + +package cmd + +const selfupdateEnabled = false diff --git a/cmd/selfupdate_enabled.go b/cmd/selfupdate_enabled.go new file mode 100644 index 000000000..5ee10354a --- /dev/null +++ b/cmd/selfupdate_enabled.go @@ -0,0 +1,7 @@ +// +build !noselfupdate + +package cmd + +// This constant must be in the `cmd` package rather than `cmd/selfupdate` +// to prevent build failure due to dependency loop. +const selfupdateEnabled = true diff --git a/lib/buildinfo/tags.go b/lib/buildinfo/tags.go index 2982d7630..6e61a457d 100644 --- a/lib/buildinfo/tags.go +++ b/lib/buildinfo/tags.go @@ -5,8 +5,9 @@ import ( "strings" ) -// Tags contains slice of build tags +// Tags contains slice of build tags. // The `cmount` tag is added by cmd/cmount/mount.go only if build is static. +// The `noselfupdate` tag is added by cmd/selfupdate/noselfupdate.go // Other tags including `cgo` are detected in this package. var Tags []string