diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..d1273eaf9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +/pkg/types/version.go export-subst diff --git a/pkg/types/version.go b/pkg/types/version.go index 1f0184a94..3bfe7c98d 100644 --- a/pkg/types/version.go +++ b/pkg/types/version.go @@ -4,11 +4,15 @@ import ( "flag" "fmt" "runtime/debug" + "strings" ) var ( // set using the '-X github.com/containers/gvisor-tap-vsock/pkg/types.ModuleVersion' linker flag gitVersion = "" + // set through .gitattributes when `git archive` is used + // see https://icinga.com/blog/2022/05/25/embedding-git-commit-information-in-go-binaries/ + gitArchiveVersion = "$Format:%(describe)$" ) type version struct { @@ -36,6 +40,9 @@ func (ver *version) ShowVersion() bool { func moduleVersion() string { switch { + // This will be substituted when building from a GitHub tarball + case !strings.HasPrefix(gitArchiveVersion, "$Format:"): + return gitArchiveVersion // This will be set when building from git using make case gitVersion != "": return gitVersion diff --git a/rpm/gvisor-tap-vsock.spec b/rpm/gvisor-tap-vsock.spec index 2233b11f4..c691daebf 100644 --- a/rpm/gvisor-tap-vsock.spec +++ b/rpm/gvisor-tap-vsock.spec @@ -92,8 +92,8 @@ CGO_CFLAGS=$(echo $CGO_CFLAGS | sed 's/-specs=\/usr\/lib\/rpm\/redhat\/redhat-an export CGO_CFLAGS+=" -m64 -mtune=generic -fcf-protection=full" %endif -# reset LDFLAGS for plugins and gvisor binaries, but ensure gvproxy --version and such is set -LDFLAGS="-X github.com/containers/gvisor-tap-vsock/pkg/types.PackageVersion=%{version}" +# reset LDFLAGS for plugins and gvisor binaries +LDFLAGS='' # build gvisor-tap-vsock binaries %gobuild -o bin/gvproxy ./cmd/gvproxy