1
mirror of https://github.com/rclone/rclone synced 2024-11-23 00:06:55 +01:00

build: add build tag noselfupdate

Allow downstream packaging to build rclone without selfupdate command:
$ go build -tags noselfupdate

Fixes #5187
This commit is contained in:
Ivan Andreev 2021-04-03 14:39:04 +03:00
parent 7df57cd625
commit 9eab258ffb
12 changed files with 37 additions and 2 deletions

View File

@ -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)

View File

@ -1,3 +1,5 @@
// +build !noselfupdate
package selfupdate
// Note: "|" will be replaced by backticks in the help string below

View File

@ -0,0 +1,11 @@
// +build noselfupdate
package selfupdate
import (
"github.com/rclone/rclone/lib/buildinfo"
)
func init() {
buildinfo.Tags = append(buildinfo.Tags, "noselfupdate")
}

View File

@ -1,3 +1,5 @@
// +build !noselfupdate
package selfupdate
import (

View File

@ -1,3 +1,5 @@
// +build !noselfupdate
package selfupdate
import (

View File

@ -1,3 +1,5 @@
// +build !noselfupdate
package selfupdate
import (

View File

@ -1,4 +1,5 @@
// +build !windows,!plan9,!js
// +build !noselfupdate
package selfupdate

View File

@ -1,4 +1,5 @@
// +build plan9 js
// +build !noselfupdate
package selfupdate

View File

@ -1,4 +1,5 @@
// +build windows
// +build !noselfupdate
package selfupdate

View File

@ -0,0 +1,5 @@
// +build noselfupdate
package cmd
const selfupdateEnabled = false

View File

@ -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

View File

@ -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