From b5552d3351135096de6b0f4301746e15e1e4c59e Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 3 Jul 2020 15:01:23 +0200 Subject: [PATCH] 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 9bc4e68..e05b629 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 0122bc4..770d6dc 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 bbee41f..2aa6cad 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