Fix the 'toolbox --version' output

Even though the actual release is 0.0.91, 'toolbox --version' was
showing 0.0.90.
This commit is contained in:
Debarshi Ray 2020-07-03 15:36:51 +02:00
parent ba60453d21
commit 52cbc50450
4 changed files with 187 additions and 9 deletions

View File

@ -0,0 +1,173 @@
From 982f10e29bd9def93272ef48a2b5ae8a20831b8a Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi@fedoraproject.org>
Date: Fri, 3 Jul 2020 14:48:37 +0200
Subject: [PATCH 1/3] pkg/version: Mark variable as private since there's an
accessor for it
Clients of this package should use the GetVersion function to get the
version as a string. The variable that actually stores the version
information is an implementation detail and meant to be private.
https://github.com/containers/toolbox/pull/487
---
src/pkg/version/version.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/pkg/version/version.go b/src/pkg/version/version.go
index 13c4449ec1b0..b35d9f94351e 100644
--- a/src/pkg/version/version.go
+++ b/src/pkg/version/version.go
@@ -25,8 +25,8 @@ type Version struct {
Micro int
}
-// CurrentVersion holds the information about current build version
-var CurrentVersion = Version{
+// currentVersion holds the information about current build version
+var currentVersion = Version{
Major: 0,
Minor: 0,
Micro: 90,
@@ -34,5 +34,5 @@ var CurrentVersion = Version{
// GetVersion returns string with the version of Toolbox
func GetVersion() string {
- return fmt.Sprintf("%d.%d.%d", CurrentVersion.Major, CurrentVersion.Minor, CurrentVersion.Micro)
+ return fmt.Sprintf("%d.%d.%d", currentVersion.Major, currentVersion.Minor, currentVersion.Micro)
}
--
2.25.4
From ad87a30caf7a51b8862b993c38170eee128feb74 Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi@fedoraproject.org>
Date: Fri, 3 Jul 2020 14:52:51 +0200
Subject: [PATCH 2/3] pkg/version: Use a string, not a struct, to for the
version information
The subsequent commit will automatically embed the project's version
encoded in Meson into the toolbox binary during the build. This will
remove the need to manually update the version information in the Go
source code. Consolidating the version information reduces the chances
of human error while making a new release. Note, how the 0.0.91 release
forgot to update the version in the Go sources.
This will be done by feeding the version string from Meson into
go-build-wrapper, which will use Go's -X linker flag to embed it into
the final toolbox binary. Since Meson stores the version information
as a string, it's convenient to have the Go code do the same.
https://github.com/containers/toolbox/pull/487
---
src/pkg/version/version.go | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/src/pkg/version/version.go b/src/pkg/version/version.go
index b35d9f94351e..bbee41f9cde6 100644
--- a/src/pkg/version/version.go
+++ b/src/pkg/version/version.go
@@ -16,23 +16,12 @@
package version
-import "fmt"
-
-// Version is the version of Toolbox
-type Version struct {
- Major int
- Minor int
- Micro int
-}
-
// currentVersion holds the information about current build version
-var currentVersion = Version{
- Major: 0,
- Minor: 0,
- Micro: 90,
-}
+var (
+ currentVersion = "0.0.90"
+)
// GetVersion returns string with the version of Toolbox
func GetVersion() string {
- return fmt.Sprintf("%d.%d.%d", currentVersion.Major, currentVersion.Minor, currentVersion.Micro)
+ return currentVersion
}
--
2.25.4
From b5552d3351135096de6b0f4301746e15e1e4c59e Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi@fedoraproject.org>
Date: Fri, 3 Jul 2020 15:01:23 +0200
Subject: [PATCH 3/3] build, pkg/version: Embed the version from Meson into the
binary
This removes the need to manually update the version in the Go source
code when making a release.
https://github.com/containers/toolbox/pull/487
---
src/go-build-wrapper | 6 +++---
src/meson.build | 7 ++++++-
src/pkg/version/version.go | 2 +-
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/go-build-wrapper b/src/go-build-wrapper
index 9bc4e68a6f2a..e05b629755b0 100755
--- a/src/go-build-wrapper
+++ b/src/go-build-wrapper
@@ -16,9 +16,9 @@
#
-if [ "$#" -ne 2 ]; then
+if [ "$#" -ne 3 ]; then
echo "go-build-wrapper: wrong arguments" >&2
- echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR]" >&2
+ echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION]" >&2
exit 1
fi
@@ -27,5 +27,5 @@ if ! cd "$1"; then
exit 1
fi
-go build -o "$2"
+go build -ldflags "-X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2"
exit "$?"
diff --git a/src/meson.build b/src/meson.build
index 0122bc45a066..770d6dc4f63c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -22,7 +22,12 @@ sources = files(
custom_target(
'toolbox',
build_by_default: true,
- command: [go_build_wrapper_program, meson.current_source_dir(), meson.current_build_dir()],
+ command: [
+ go_build_wrapper_program,
+ meson.current_source_dir(),
+ meson.current_build_dir(),
+ meson.project_version(),
+ ],
input: sources,
install: true,
install_dir: get_option('bindir'),
diff --git a/src/pkg/version/version.go b/src/pkg/version/version.go
index bbee41f9cde6..2aa6cad6c939 100644
--- a/src/pkg/version/version.go
+++ b/src/pkg/version/version.go
@@ -18,7 +18,7 @@ package version
// currentVersion holds the information about current build version
var (
- currentVersion = "0.0.90"
+ currentVersion string
)
// GetVersion returns string with the version of Toolbox
--
2.25.4

View File

@ -1,4 +1,4 @@
From e3cadcdeb59996eb28ee6499d43ebc4b9b656a21 Mon Sep 17 00:00:00 2001
From cfd98ecda0e92c237a6b65dccea14dd98b579044 Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi@fedoraproject.org>
Date: Mon, 29 Jun 2020 17:57:47 +0200
Subject: [PATCH] build: Make the build flags match Fedora's %{gobuild} for
@ -29,16 +29,16 @@ explicitly specify the name of the output binary.
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/go-build-wrapper b/src/go-build-wrapper
index 9bc4e68a6f2a..d62d684b78d3 100755
index e05b629755b0..ec6b9f68bb05 100755
--- a/src/go-build-wrapper
+++ b/src/go-build-wrapper
@@ -27,5 +27,6 @@ if ! cd "$1"; then
exit 1
fi
-go build -o "$2"
-go build -ldflags "-X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2"
+unset LDFLAGS
+go build -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -extldflags '-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '" -a -v -x -o "$2/toolbox"
+go build -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -extldflags '-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -a -v -x -o "$2/toolbox"
exit "$?"
--
2.25.4

View File

@ -1,4 +1,4 @@
From f4471c7921bf5a779a586a9375b5fbb252a35857 Mon Sep 17 00:00:00 2001
From 9d5cf38e4e7a07f4850bb4cfae5dac8d6e9bb33a Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi@fedoraproject.org>
Date: Mon, 29 Jun 2020 17:57:47 +0200
Subject: [PATCH] build: Make the build flags match Fedora's %{gobuild}
@ -28,16 +28,16 @@ explicitly specify the name of the output binary.
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/go-build-wrapper b/src/go-build-wrapper
index 9bc4e68a6f2a..41aed1ca3d9f 100755
index e05b629755b0..a0caf628435a 100755
--- a/src/go-build-wrapper
+++ b/src/go-build-wrapper
@@ -27,5 +27,6 @@ if ! cd "$1"; then
exit 1
fi
-go build -o "$2"
-go build -ldflags "-X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2"
+unset LDFLAGS
+go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -extldflags '-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '" -a -v -x -o "$2/toolbox"
+go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -extldflags '-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -a -v -x -o "$2/toolbox"
exit "$?"
--
2.25.4

View File

@ -4,7 +4,7 @@ Version: 0.0.91
%global goipath github.com/containers/%{name}
%gometa
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Unprivileged development environment
License: ASL 2.0
@ -12,6 +12,7 @@ URL: https://github.com/containers/%{name}
Source0: https://github.com/containers/%{name}/releases/download/%{version}/%{name}-%{version}.tar.xz
Patch0: toolbox-Make-it-build-on-aarch64.patch
Patch1: toolbox-Embed-the-version-from-Meson-into-the-binary.patch
# Fedora specific
Patch100: toolbox-Don-t-use-Go-s-semantic-import-versioning.patch
@ -112,6 +113,7 @@ Dockerfile if the image isn't based on the fedora-toolbox image.
%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch100 -p1
%ifnarch ppc64
@ -156,6 +158,9 @@ ln -s src/pkg pkg
%changelog
* Fri Jul 03 2020 Debarshi Ray <rishi@fedoraproject.org> - 0.0.91-2
- Fix the 'toolbox --version' output
* Tue Jun 30 2020 Harry Míchal <harrymichal@seznam.cz> - 0.0.91-1
- Update to 0.0.91