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. 22
      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
cover.out
*~

@ -1,3 +1,5 @@
LDFLAGS = $(shell go run buildscripts/gen-ldflags.go)
all: install
checkdeps:
@ -7,6 +9,7 @@ checkdeps:
checkgopath:
@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
@echo "Setting LDFLAGS: ${LDFLAGS}"
getdeps: checkdeps checkgopath
@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 pkg
build: constants getdeps verifiers
build: getdeps verifiers
@echo "Installing minio:"
deadcode:
@ -50,11 +53,7 @@ test: build
@GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/minio/pkg...
gomake-all: build
@GO15VENDOREXPERIMENT=1 go install github.com/minio/minio
constants:
@echo "Generating new build-constants.go"
@GO15VENDOREXPERIMENT=1 go run buildscripts/gen-constants.go
@GO15VENDOREXPERIMENT=1 go build -ldflags $(LDFLAGS) -o $(GOPATH)/bin/minio
pkg-add:
@GO15VENDOREXPERIMENT=1 govendor add $(PKG)
@ -69,7 +68,6 @@ install: gomake-all
clean:
@echo "Cleaning up all the generated files:"
@rm -fv build-constants.go
@rm -fv cover.out
@rm -fv minio
@rm -fv minio.test

@ -26,6 +26,9 @@ build_script:
- go test -race .
- go test 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
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
const (
var (
minioVersion = "UNOFFICIAL.GOGET"
minioReleaseTag = "UNOFFICIAL.GOGET"
minioCommitID = "UNOFFICIAL.GOGET"
)
var (
minioShortCommitID = minioCommitID[:]
)

@ -20,50 +20,19 @@ package main
import (
"fmt"
"net/http"
"os"
"os/exec"
"strings"
"text/template"
"time"
)
var constantsTemplate = `// -------- DO NOT EDIT --------
// This file is autogenerated by buildscripts/gen-constants.go during the release process.
package main
const (
minioVersion = {{if .Version}}"{{.Version}}"{{else}}""{{end}}
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)
}
func genLDFlags(version string) string {
var ldflagsStr string
ldflagsStr = "\"-X main.minioVersion=" + version + " "
ldflagsStr = ldflagsStr + "-X main.minioReleaseTag=" + releaseTag(version) + " "
ldflagsStr = ldflagsStr + "-X main.minioCommitID=" + commitID() + " "
ldflagsStr = ldflagsStr + "-X main.minioShortCommitID=" + commitID()[:12] + "\""
return ldflagsStr
}
// genReleaseTag prints release tag to the console for easy git tagging.
@ -97,13 +66,5 @@ func commitID() string {
}
func main() {
// Version is in HTTP TimeFormat.
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())
fmt.Println(genLDFlags(time.Now().UTC().Format(time.RFC3339)))
}

@ -90,7 +90,7 @@ func (u updateMessage) JSON() string {
}
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)
if current.IsZero() {
@ -133,7 +133,7 @@ func getExperimentalUpdate() {
}
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)
if current.IsZero() {

Loading…
Cancel
Save