mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
build: Versioning now populated through ldflags
This commit is contained in:
@@ -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)))
|
||||
}
|
||||
Reference in New Issue
Block a user