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
This commit is contained in:
Debarshi Ray 2020-07-03 15:01:23 +02:00
parent ad87a30caf
commit b5552d3351
3 changed files with 10 additions and 5 deletions

View file

@ -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 "$?"

View file

@ -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'),

View file

@ -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