Permalink
Browse files

set buildVersion with '-ldflags -X'

  • Loading branch information...
olt committed Aug 4, 2015
1 parent ba5e987 commit daede3d67723650d3653c5ac8f20bcedd94be962
Showing with 6 additions and 5 deletions.
  1. +2 −3 crosscompile.sh
  2. +4 −2 version.go
View
@@ -13,7 +13,7 @@ BUILD_DATE=`date +%Y%m%d`
BUILD_REF=`git rev-parse --short HEAD`
BUILD_VERSION=dev-$BUILD_DATE-$BUILD_REF
perl -p -i -e 's/buildVersion = ".*"/buildVersion = "'${BUILD_VERSION}'"/' version.go
VERSION_LDFLAGS="-X github.com/omniscale/magnacarto.buildVersion ${BUILD_VERSION}"
# build os arch
function build() {
@@ -23,7 +23,7 @@ function build() {
mkdir -p $build_name
echo building $build_name
cd $build_name
env GOOS=$os GOARCH=$arch godep go build github.com/omniscale/magnacarto/cmd/magnacarto
env GOOS=$os GOARCH=$arch godep go build -ldflags "$VERSION_LDFLAGS" github.com/omniscale/magnacarto/cmd/magnacarto
cp ../../../{README.md,LICENSE} ./
cd ..
if [ $os = windows ]; then
@@ -45,4 +45,3 @@ build linux amd64
build darwin amd64
cd ../../
perl -p -i -e 's/buildVersion = ".*"/buildVersion = ""/' version.go
View
@@ -2,9 +2,11 @@ package magnacarto
var Version string
// buidVersion gets replaced while building with
// go build -ldflags "-X github.com/omniscale/magnacarto.buildVersion 1234"
var buildVersion string
func init() {
// buidVersion gets replaced during build with make
var buildVersion = ""
Version = "0.1"
Version += buildVersion
}

0 comments on commit daede3d

Please sign in to comment.