Skip to content

Use build tags in the version and selfupdate commands - #5151

Merged
ivandeex merged 2 commits into
rclone:masterfrom
ivandeex:pr-buildtags
Mar 22, 2021
Merged

ivandeex merged 2 commits into
rclone:masterfrom
ivandeex:pr-buildtags

Conversation

@ivandeex

@ivandeex ivandeex commented Mar 21, 2021 •

Copy link
Copy Markdown
Member

Use build tags in the version and selfupdate commands

What is the purpose of this change?

Knowing build tags would be useful.
For example, only cmount builds support passing custom libfuse flags.
(See #3545 for an example why it matters).

As stated in golang/go#7007 (comment), golang does not and will not provide any runtime API for finding build tags on the fly:

Build tags are for building. I do not want them to be exposed in the runtime.
if you need to know ... you can write different files with different build tags and different initialized ... variables

This PR uses this very technique to initialize an internal array of build tags.
The technique has a limitation that every detectable tag must be known in advance.
Currently only the cmount and cgo tags are supported.

Knowing whether it is a CGO enabled build or not (so whether it is static or dynamic) would be really useful for debugging DNS problems.
As described in the go documentation (https://golang.org/cmd/cgo), when cgo builds a dynamic executable, it marks itself by the cgo build tag.

This PR makes rclone version show a list of predefined build tags or none.
The cgo tag will not be included in the list but used to determine whether the rclone binary is static or dynamic.

Additionally this PR makes rclone selfupdate aware of the cmount build tag to detect whether the FUSE support is in.
An update will be refused if the running executable supports FUSE semantics but the update would discard it and consequently break tooling wrappers.

Was the change discussed in an issue or in the forum before?

Proposed in https://forum.rclone.org/t/rclone-cmount-on-linux/22602/4

Fixes #5091

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

Testing

It is hard to test build capabilities automatically as CI/CD builds heavily depend on the build environment.
Instead, I will run the following manual test:

$ CGO_ENABLED=0 go build -o rclone-static . ; ./rclone-static version
rclone v1.55.0-DEV
- os/arch: linux/amd64
- go version: go1.16
- executable: static
- tags: none

$ CGO_ENABLED=1 go build -o rclone-dynamic . ; ./rclone-dynamic version
rclone v1.55.0-DEV
- os/arch: linux/amd64
- go version: go1.16
- executable: dynamic
- tags: none

$ xgo -image=billziss/xgo-cgofuse -targets=linux/amd64 -tags=cmount . ; ./rclone-linux-amd64 version
rclone v1.55.0-DEV
- os/arch: linux/amd64
- go version: go1.13.4
- executable: dynamic
- tags: cmount

Merging

I think this PR can be merged as two commits, where one patches the version command and the other patches selfupdate.

@albertony

Copy link
Copy Markdown
Contributor

LGTM.

An update will be refused if the running executable supports FUSE semantics but the update would discard it

Could have an option, e.g. --force, to override this. Just a thought, I have no idea how relevant it would be to use it...

@ivandeex

Copy link
Copy Markdown
Member Author

Could have an option, e.g. --force, to override this. Just a thought, I have no idea how relevant it would be to use it...

I feel reluctant to add flags, as usual. Let's see what Nick says during review. Opposed by two, I will instantly yield :-)

Comment thread cmd/cmount/arch.go Resolved
@darthShadow

Copy link
Copy Markdown
Member

I am also of the opinion to skip the --force flag for now. We can add it later if required. Best to keep the code as minimal/simple as possible.

Should we consider separating out the version info based on its type (os or go)? Something like this:

rclone v1.55.0-DEV
- os/arch: linux/amd64
- go/version: go1.13.4
- go/linking: dynamic
- go/tags: cmount

This does have the possibility of breaking any scripts that parse this output, however.

Comment thread cmd/cmd.go Resolved
@ivandeex

Copy link
Copy Markdown
Member Author
- go/version: go1.13.4

This does have the possibility of breaking any scripts that parse this output, however.

I feel like it's not going to wreak havoc. The go version line is rather internal to the rclone support team.

@ivandeex
ivandeex force-pushed the pr-buildtags branch 3 times, most recently from d705370 to cceb574 Compare March 22, 2021 19:06
@ivandeex

This comment has been minimized.

@darthShadow

Copy link
Copy Markdown
Member

One minor consideration: Do we want to split os/arch further to os/type & os/arch for the values of linux & amd64 respectively?

@ivandeex

Copy link
Copy Markdown
Member Author

One minor consideration: Do we want to split os/arch further to os/type & os/arch for the values of linux & amd64 respectively?

What would Nick say?

@albertony

Copy link
Copy Markdown
Contributor

One minor consideration: Do we want to split os/arch further to os/type & os/arch for the values of linux & amd64 respectively?

I'm thinking the same..

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

Copy link
Copy Markdown
Member Author

done

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both those commits look great - thanks.

Please merge when ready.

@ivandeex
ivandeex merged commit 1fe2460 into rclone:master Mar 22, 2021
@ivandeex
ivandeex deleted the pr-buildtags branch March 22, 2021 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd/version: add info about build

4 participants