Skip to content

Commit

Permalink
cmd/cue: revert version string change
Browse files Browse the repository at this point in the history
In 370fac9 we slightly changed the way that the cue version string is
determined. For builds of cmd/cue that resolve the cuelang.org/go as a
dependency, the only noticeable change would have been the inclusion of
the sum of that module (which is harmless, but arguably superfluous).
However for development builds the change meant that we were left with
"devel" as the version string:

    cue version devel linux/amd64

Rather than the now-default +$commit(-dirty)? Go default:

    cue version +eb18b74c linux/amd64

We need/want the latter, hence we revert this particular change, adding
a more explicit comment that the use of the ldflags mechanism to set the
version string is legacy.

Signed-off-by: Paul Jolly <[email protected]>
Change-Id: I26aed99031921a2d32e0fe94a78d9a73089c75c4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/521406
  • Loading branch information
myitcv committed Jul 28, 2021
1 parent 370fac9 commit ecb17c9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/cue/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,26 @@ func newVersionCmd(c *Command) *cobra.Command {
return cmd
}

const (
defaultVersion = "devel"
)

// version be set by a builder using
// -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=<version>'.
// However, people should prefer building via a mechanism which
// resolves cuelang.org/go as a dependency (and not the main
// module), in which case the version information is determined
// from the *debug.BuildInfo (see below). So this mechanism is
// really considered legacy.
var (
version = defaultVersion
)

func runVersion(cmd *Command, args []string) error {
w := cmd.OutOrStdout()
var version = "devel"
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Sum != "" {
version = fmt.Sprintf("%s (%s)", bi.Main.Version, bi.Main.Sum)
if bi, ok := debug.ReadBuildInfo(); ok && version == defaultVersion {
// No specific version provided via version
version = bi.Main.Version
}
fmt.Fprintf(w, "cue version %v %s/%s\n",
version,
Expand Down

0 comments on commit ecb17c9

Please sign in to comment.