From 123e44d8c5f22a6c7ac03a9c27972c359ba810ad Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 2 Nov 2015 12:32:09 -0800 Subject: [PATCH] build: Populate mcVersion through ldflags By default binary built through 'go get github.com/minio/mc'. Will be considered UNOFFICIAL.GOGET with not versioning, 'go get' binaries cannot use 'mc update' functionality. First reasoning towards this is - go build tools have no way to specifying versions and releases unlike `npm`. For this reason alone we have to differentiate OFFICIAL and UNOFFICIAL. Now a 'make' will build appropriate binaries, while 'go get' becomes UNOFFICIAL. --- Makefile | 18 +++------ appveyor.yml | 3 ++ build-constants.go | 24 ++++++++++++ buildscripts/gen-ldflags.go | 70 +++++++++++++++++++++++++++++++++ buildscripts/genversion.go | 77 ------------------------------------- common-methods.go | 2 +- globals.go | 1 - main.go | 1 + update-main.go | 16 ++++++-- version-main.go | 9 +++-- version.go | 7 ---- 11 files changed, 122 insertions(+), 106 deletions(-) create mode 100644 build-constants.go create mode 100644 buildscripts/gen-ldflags.go delete mode 100644 buildscripts/genversion.go delete mode 100644 version.go diff --git a/Makefile b/Makefile index 4e7f9859..a7d15245 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -## filter multiple GOPATH +LDFLAGS = $(shell go run buildscripts/gen-ldflags.go) + all: install checkdeps: @@ -42,27 +43,18 @@ deadcode: @echo "Running $@:" @GO15VENDOREXPERIMENT=1 deadcode -build: getdeps verifiers +build: verifiers @echo "Installing mc:" -test: getdeps verifiers +test: verifiers @echo "Running all testing:" @GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) ./ @GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/mc/pkg... gomake-all: build - @GO15VENDOREXPERIMENT=1 go install github.com/minio/mc + @GO15VENDOREXPERIMENT=1 go build -ldflags $(LDFLAGS) -o $(GOPATH)/bin/mc @mkdir -p $(HOME)/.mc -release: genversion - @echo "Installing mc with new version.go:" - @GO15VENDOREXPERIMENT=1 go install github.com/minio/mc - @mkdir -p $(HOME)/.mc - -genversion: - @echo "Generating a new version.go:" - @GO15VENDOREXPERIMENT=1 go run buildscripts/genversion.go - coverage: @GO15VENDOREXPERIMENT=1 go test -race -coverprofile=cover.out ./ @go tool cover -html=cover.out && echo "Visit your browser" diff --git a/appveyor.yml b/appveyor.yml index 307b5c28..c502d192 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,6 +26,9 @@ build_script: - go test -race . - go test github.com/minio/mc/pkg... - go test -race github.com/minio/mc/pkg... + - go run buildscripts/gen-ldflags.go > temp.txt + - set /p LDFLAGS=