Skip to content

Commit

Permalink
build: Versioning now populated through ldflags
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshavardhana committed Nov 2, 2015
1 parent ef04507 commit 7845515
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 65 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/build-constants.go
**/*.swp
cover.out
*~
Expand Down
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
LDFLAGS = $(shell go run buildscripts/gen-ldflags.go)

all: install

checkdeps:
Expand All @@ -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:"
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 18 additions & 8 deletions build-constants.go
Original file line number Diff line number Diff line change
@@ -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 (
minioVersion = "UNOFFICIAL.GOGET"
minioReleaseTag = "UNOFFICIAL.GOGET"
minioCommitID = "UNOFFICIAL.GOGET"
)

var (
minioVersion = "UNOFFICIAL.GOGET"
minioReleaseTag = "UNOFFICIAL.GOGET"
minioCommitID = "UNOFFICIAL.GOGET"
minioShortCommitID = minioCommitID[:]
)
55 changes: 8 additions & 47 deletions buildscripts/gen-constants.go → buildscripts/gen-ldflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)))
}
4 changes: 2 additions & 2 deletions update-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 7845515

Please sign in to comment.