For archive's sake, let me tell my solution.
I carefully added a preprocessing command into my build steps. Before compiling, the following command is run:
sed -E -i 's:(Version\s*=\s*)".*":\1"'$(DOCKER_CLI_VERSION)'":' \
$(@D)/cli/version/version.go \
&& sed -E -i 's:(GitCommit\s*=\s*)".*":\1"'$(shell git rev-parse --short HEAD)'":' \
$(@D)/cli/version/version.go
The regexes match patterns in
Version = "xxx"
Format and replaces the string inside the double quotes while keeping all the whitespaces and other relevant characters intact, so repeatedly calling the same substitution is safe and does the expected thing. Same for the GitCommit, except it uses a shell command instead of an environment variable.
Happy Hacking
Atilla