Skip to content

Commit

Permalink
Fixed buggy weaver version output.
Browse files Browse the repository at this point in the history
`weaver version` is supposed to print out the weaver module version,
something like:

```
$ weaver version
weaver v0.15.0
```

Previously, we used [`runtime.ReadBuildInfo`][ReadBuildInfo] to read the
version of the main module. However, I realized that this version was
always the string `(devel)`. At first, I thought the version was
`(devel)` when on a non-tagged commit, but later realized that it is
literally always `(devel)`: golang/go#29228.

I did some Googling to figure out how to print out the current module
version, but it seems impossible? This PR gives up and sticks with
showing the git commit. It's not as clear, but you can look up the
commit in the repo history to find the module version.

[ReadBuildInfo]: https://pkg.go.dev/runtime/debug#ReadBuildInfo
  • Loading branch information
mwhittaker committed Jun 23, 2023
1 parent e7a0ddf commit 99a2cf7
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions runtime/tool/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ func VersionCmd(tool string) *Command {
Fn: func(context.Context, []string) error {
deployerAPI := fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch)
codegenAPI := fmt.Sprintf("%d.%d.0", codegen.Major, codegen.Minor)
release := "?"
commit := "?"
if info, ok := debug.ReadBuildInfo(); ok {
release = info.Main.Version
for _, setting := range info.Settings {
// vcs.revision stores the commit at which the weaver tool
// was built. See [1] for more information.
Expand All @@ -50,9 +48,9 @@ func VersionCmd(tool string) *Command {
}
}
}
fmt.Printf("%s %s\n", tool, release)
fmt.Printf("target: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf("tool: %s\n", tool)
fmt.Printf("commit: %s\n", commit)
fmt.Printf("target: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf("deployer API: %s\n", deployerAPI)
fmt.Printf("codegen API: %s\n", codegenAPI)
return nil
Expand Down

0 comments on commit 99a2cf7

Please sign in to comment.