Merge pull request #953 from harshavardhana/ldflags-style

build: Versioning now populated through ldflags
master
Harshavardhana 9 years ago
commit 2601b3c487
  1. 1
      .gitignore
  2. 12
      Makefile
  3. 3
      appveyor.yml
  4. 26
      build-constants.go
  5. 55
      buildscripts/gen-ldflags.go
  6. 4
      update-main.go

1
.gitignore vendored

@ -1,4 +1,3 @@
/build-constants.go
**/*.swp **/*.swp
cover.out cover.out
*~ *~

@ -1,3 +1,5 @@
LDFLAGS = $(shell go run buildscripts/gen-ldflags.go)
all: install all: install
checkdeps: checkdeps:
@ -7,6 +9,7 @@ checkdeps:
checkgopath: checkgopath:
@echo "Checking if project is at ${GOPATH}" @echo "Checking if project is at ${GOPATH}"
@for miniopath in $(echo ${GOPATH} | sed 's/:/\n/g'); do if [ ! -d ${miniopath}/src/github.com/minio/minio ]; then echo "Project not found in ${miniopath}, please follow instructions provided at https://github.com/minio/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi done @for miniopath in $(echo ${GOPATH} | sed 's/:/\n/g'); do if [ ! -d ${miniopath}/src/github.com/minio/minio ]; then echo "Project not found in ${miniopath}, please follow instructions provided at https://github.com/minio/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi done
@echo "Setting LDFLAGS: ${LDFLAGS}"
getdeps: checkdeps checkgopath getdeps: checkdeps checkgopath
@go get -u github.com/golang/lint/golint && echo "Installed golint:" @go get -u github.com/golang/lint/golint && echo "Installed golint:"
@ -38,7 +41,7 @@ cyclo:
@GO15VENDOREXPERIMENT=1 gocyclo -over 65 *.go @GO15VENDOREXPERIMENT=1 gocyclo -over 65 *.go
@GO15VENDOREXPERIMENT=1 gocyclo -over 65 pkg @GO15VENDOREXPERIMENT=1 gocyclo -over 65 pkg
build: constants getdeps verifiers build: getdeps verifiers
@echo "Installing minio:" @echo "Installing minio:"
deadcode: deadcode:
@ -50,11 +53,7 @@ test: build
@GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/minio/pkg... @GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/minio/pkg...
gomake-all: build gomake-all: build
@GO15VENDOREXPERIMENT=1 go install github.com/minio/minio @GO15VENDOREXPERIMENT=1 go build -ldflags $(LDFLAGS) -o $(GOPATH)/bin/minio
constants:
@echo "Generating new build-constants.go"
@GO15VENDOREXPERIMENT=1 go run buildscripts/gen-constants.go
pkg-add: pkg-add:
@GO15VENDOREXPERIMENT=1 govendor add $(PKG) @GO15VENDOREXPERIMENT=1 govendor add $(PKG)
@ -69,7 +68,6 @@ install: gomake-all
clean: clean:
@echo "Cleaning up all the generated files:" @echo "Cleaning up all the generated files:"
@rm -fv build-constants.go
@rm -fv cover.out @rm -fv cover.out
@rm -fv minio @rm -fv minio
@rm -fv minio.test @rm -fv minio.test

@ -26,6 +26,9 @@ build_script:
- go test -race . - go test -race .
- go test github.com/minio/minio/pkg... - go test github.com/minio/minio/pkg...
- go test -race github.com/minio/minio/pkg... - go test -race github.com/minio/minio/pkg...
- go run buildscripts/gen-ldflags.go > temp.txt
- set /p LDFLAGS=<temp.txt
- go build -ldflags=%LDFLAGS% -o %GOPATH%\bin\minio.exe
# to disable automatic tests # to disable automatic tests
test: off test: off

@ -1,14 +1,24 @@
// -------- DO NOT EDIT -------- /*
// This file is autogenerated by buildscripts/gen-constants.go during the release process. * Minio Cloud Storage, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main package main
const (
minioVersion = "UNOFFICIAL.GOGET"
minioReleaseTag = "UNOFFICIAL.GOGET"
minioCommitID = "UNOFFICIAL.GOGET"
)
var ( var (
minioVersion = "UNOFFICIAL.GOGET"
minioReleaseTag = "UNOFFICIAL.GOGET"
minioCommitID = "UNOFFICIAL.GOGET"
minioShortCommitID = minioCommitID[:] minioShortCommitID = minioCommitID[:]
) )

@ -20,50 +20,19 @@ package main
import ( import (
"fmt" "fmt"
"net/http"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"text/template"
"time" "time"
) )
var constantsTemplate = `// -------- DO NOT EDIT -------- func genLDFlags(version string) string {
// This file is autogenerated by buildscripts/gen-constants.go during the release process. var ldflagsStr string
ldflagsStr = "\"-X main.minioVersion=" + version + " "
package main ldflagsStr = ldflagsStr + "-X main.minioReleaseTag=" + releaseTag(version) + " "
ldflagsStr = ldflagsStr + "-X main.minioCommitID=" + commitID() + " "
const ( ldflagsStr = ldflagsStr + "-X main.minioShortCommitID=" + commitID()[:12] + "\""
minioVersion = {{if .Version}}"{{.Version}}"{{else}}""{{end}} return ldflagsStr
minioReleaseTag = {{if .ReleaseTag}}"{{.ReleaseTag}}"{{else}}""{{end}}
minioCommitID = {{if .CommitID}}"{{.CommitID}}"{{else}}""{{end}}
)
var (
minioShortCommitID = minioCommitID[:12]
)
`
// genConstants generates ‘build-constants.go’.
func genConstants(version string) {
t := template.Must(template.New("constants").Parse(constantsTemplate))
constantsFile, e := os.OpenFile("build-constants.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if e != nil {
fmt.Printf("gen-constants: Unable to create ‘build-constants.go’. Error: %s.\n", e)
os.Exit(1)
}
defer constantsFile.Close()
e = t.Execute(constantsFile, struct {
Version string
ReleaseTag string
CommitID string
}{version, releaseTag(version), commitID()})
if e != nil {
fmt.Printf("gen-constants: Unable to generate ‘build-constants.go’. Error: %s.\n", e)
os.Exit(1)
}
} }
// genReleaseTag prints release tag to the console for easy git tagging. // genReleaseTag prints release tag to the console for easy git tagging.
@ -97,13 +66,5 @@ func commitID() string {
} }
func main() { func main() {
// Version is in HTTP TimeFormat. fmt.Println(genLDFlags(time.Now().UTC().Format(time.RFC3339)))
version := time.Now().UTC().Format(http.TimeFormat)
// generate ‘build-constants.go’ file.
genConstants(version)
fmt.Println("Version: \"" + version + "\"")
fmt.Println("Release-Tag: " + releaseTag(version))
fmt.Println("Commit-ID: " + commitID())
} }

@ -90,7 +90,7 @@ func (u updateMessage) JSON() string {
} }
func getExperimentalUpdate() { func getExperimentalUpdate() {
current, e := time.Parse(http.TimeFormat, minioVersion) current, e := time.Parse(time.RFC3339, minioVersion)
fatalIf(probe.NewError(e), "Unable to parse Version string as time.", nil) fatalIf(probe.NewError(e), "Unable to parse Version string as time.", nil)
if current.IsZero() { if current.IsZero() {
@ -133,7 +133,7 @@ func getExperimentalUpdate() {
} }
func getReleaseUpdate() { func getReleaseUpdate() {
current, e := time.Parse(http.TimeFormat, minioVersion) current, e := time.Parse(time.RFC3339, minioVersion)
fatalIf(probe.NewError(e), "Unable to parse Version string as time.", nil) fatalIf(probe.NewError(e), "Unable to parse Version string as time.", nil)
if current.IsZero() { if current.IsZero() {

Loading…
Cancel
Save