Closed jcvernaleo closed 7 years ago
+1 from me, I used to use the following to make sure I was on the right revision when testing:
go build -ldflags "-X main.appBuild=$(git describe --always)"
I guess adding the git sha1 is fine but what i'd really like is to default to appending -dev to the version when built without any special linker flags, and to use -release or nothing when doing an official release.
Unfortunately there is no way to add the git sha when doing a bare go build
or go install
. Best we can do there is to add makefiles or other build systems to all the projects, and tell people to use those.
So, without adding other build scripts, when building from source people would see versions like: 0.7.0-dev
. Releases would be like 0.7.0-release+66710f7
or 0.7.0+66710f7
, where 66710f7
is the output of git rev-parse --short HEAD
. This output also follows the naming conventions used by semver, even though the version numbers themselves do not follow semver.
@jolan git describe --always shows me:
PS C:\Users\jrick\go\src\github.com\decred\dcrwallet> git describe --always
BTCWALLET_0_5_0_ALPHA-386-g66710f7
Not sure exactly where that info is coming from but something isn't quite right...
Yeah, since there is no way to get the sha in there without imposing some Makefile or other build system I think @jrick's idea (-dev) appended to the version normally and excluded in release builds (where we can control how things are built).
@jrick and @jolan what do you think of this:
jcv@triforce dcrd $ go build -ldflags "-X main.releaseBuild=true"
jcv@triforce dcrd $ ./dcrd -V
dcrd version 0.6.1-beta
jcv@triforce dcrd $ go build
jcv@triforce dcrd $ ./dcrd -V
dcrd version 0.6.1-beta-dev
Then I would modify the build script for that.
Instead of a bool why not make the constant a string, and then we can pass in other additional info like the git sha if we want to?
Also see points 9 and 10: http://semver.org/#spec-item-9
Might want to put 'dev' or 'release' in the build metadata rather than the prerelease field.
dcrd version 0.6.1-beta+dev
dcrd version 0.6.1-beta+release
dcrd version 0.6.1-beta+release.66710f7
I'm opening this in the dcrd repo but really it applies to decred/dcrwallet, decred/gominer, decred/decrediton, decred/dcrticketbuyer, decred/dcrinstal, and any other that have a version number.
Currently we have:
There is no way to know if that is really the 0.6.1 release or some build from git after that.
go has the option
-ldflags "-X "
that can be used to pass something in at build time. We could make the build scripts pass in the version at build time and use the git commit hash for any other times like-X main.version
git rev-parse HEAD"
or possibly some other scheme.I believe @jrick brought this up on irc initially.
Thoughts, Opinions?