Commit ce85e17
committed
version: use package-level variables for linker flag support
The build ID wasn't properly being set by linker flags because struct
fields cannot be directly modified by the Go linker flags; only
package-level variables can be modified by the Go linker flags.
This change:
- Moves version information to package-level variables
- Updates initialization to use these variables
- Improves fallback mechanism to check for `vcs.revision` first
- Maintains backward compatibility with `gitrevision`
This addresses issue #3986 where the build ID was displaying a hardcoded
hash instead of the proper git commit hash or custom value.
Note: I could not determine why `gitrevision` was being used but it may
have been from historical linker flag usage, such as
`-ldflags "-X main.gitrevision=$(git rev-parse HEAD)"`. Since Go 1.18
`vcs.revision` is the standard now. I have maintained the `gitrevision`
look for backwards compatibility.
Fixes #39861 parent f0cc62b commit ce85e17
2 files changed
+31
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
20 | 33 | | |
21 | 34 | | |
22 | 35 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
8 | 17 | | |
9 | 18 | | |
10 | 19 | | |
| |||
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
19 | | - | |
20 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
21 | 33 | | |
22 | 34 | | |
23 | 35 | | |
| |||
0 commit comments