use LDFLAGS -x to set buildVersion

master
Oliver Tonnhofer 2016-11-28 09:41:20 +01:00
parent f147798335
commit 7a020b28d5
2 changed files with 7 additions and 12 deletions

View File

@ -7,26 +7,19 @@ GOFILES=$(shell find . \( -name \*.go ! -name version.go \) )
# for protoc-gen-go
export PATH := $(GOPATH)/bin:$(PATH)
GOLDFLAGS=-ldflags '-r $${ORIGIN}/lib'
GOLDFLAGS=-ldflags '-r $${ORIGIN}/lib $(VERSION_LDFLAGS)'
GO:=$(if $(shell go version |grep 'go1.5'),GO15VENDOREXPERIMENT=1,) go
BUILD_DATE=$(shell date +%Y%m%d)
BUILD_REV=$(shell git rev-parse --short HEAD)
BUILD_VERSION=dev-$(BUILD_DATE)-$(BUILD_REV)
VERSION_LDFLAGS=-X github.com/omniscale/imposm3.buildVersion=$(BUILD_VERSION)
all: build test
update_version:
@perl -p -i -e 's/buildVersion = ".*"/buildVersion = "$(BUILD_VERSION)"/' version.go
revert_version:
@perl -p -i -e 's/buildVersion = ".*"/buildVersion = ""/' version.go
imposm3: $(PBGOFILES) $(GOFILES)
$(MAKE) update_version
$(GO) build $(GOLDFLAGS) ./cmd/imposm3
$(MAKE) revert_version
build: imposm3
@ -68,4 +61,4 @@ build-license-deps:
(echo -e "========== $$dep ==========\n"; cat $$1; echo -e "\n\n") \
| fold -s -w 80 \
>> LICENSE.deps \
' _ {} \;
' _ {} \;

View File

@ -2,9 +2,11 @@ package imposm3
var Version string
// buidVersion gets replaced while building with
// go build -ldflags "-X github.com/omniscale/imposm3.buildVersion 1234"
var buildVersion string
func init() {
// buidVersion gets replaced during build with make
var buildVersion = ""
Version = "0.2.0"
Version += buildVersion
}