Skip to content

Commit 3faaebd

Browse files
committed
version: use vcs.revision for version.Build in dlv version command
The build ID wasn't properly set/determined when calling `dlv version` command. It kept showing the very old hash (not git hash though) of `7e679e5860c17d90514f9c440e055355de831ce2`. This is because we are searching for the git hash in build info via `gitrevision` key's value which doesn't exist in the Go build info, and since we simply return without error if nothing is found, it kept using the old hash of `7e679e5860c17d90514f9c440e055355de831ce2` (note, I still couldn't determine where this comes from, so I've maintained backwards compatibility detailed below). Go build info's git revision hash key is `vcs.revision`. So, I added logic to search for that and attach its value to the version.Build field. If nothing is found and haven't return its value, then we try searching for `gitrevision` which maintains backwards compatibility. Fixes #3986
1 parent f0cc62b commit 3faaebd

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pkg/version/fixbuild.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,27 @@ func init() {
99
}
1010

1111
func buildInfoFixBuild(v *Version) {
12+
if v.Build != "$Id$" {
13+
return
14+
}
15+
1216
info, ok := debug.ReadBuildInfo()
1317
if !ok {
1418
return
1519
}
16-
for i := range info.Settings {
17-
if info.Settings[i].Key == "gitrevision" {
18-
v.Build = info.Settings[i].Value
19-
break
20+
21+
for _, setting := range info.Settings {
22+
if setting.Key == "vcs.revision" {
23+
v.Build = setting.Value
24+
return
25+
}
26+
}
27+
28+
// If we didn't find vcs.revision, try the old key for backward compatibility
29+
for _, setting := range info.Settings {
30+
if setting.Key == "gitrevision" {
31+
v.Build = setting.Value
32+
return
2033
}
2134
}
2235
}

0 commit comments

Comments
 (0)