diff --git a/.gitignore b/.gitignore index d13e0125..1c998afd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ cover.out mc +version.go diff --git a/Makefile b/Makefile index 6a5d61e1..0441cc31 100644 --- a/Makefile +++ b/Makefile @@ -40,14 +40,11 @@ deadcode: pre-build: @echo "Running pre-build:" -build-all: getdeps verifiers - @echo "Building Libraries:" - @godep go generate ./... - @godep go build -a ./... # no stale packages - -test-all: pre-build build-all - @echo "Running Test Suites:" - @godep go test -race ./... +gomake-all: getdeps verifiers + @echo "Installing mc:" + @go run make.go release + @go run make.go install + @mkdir -p $(HOME)/.mc save: @godep save ./... @@ -58,10 +55,7 @@ restore: env: @godep go env -install: test-all - @echo "Installing mc:" - @godep go install -a -ldflags "-X main.BuildDate `go run buildscripts/date.go`" github.com/minio/mc - @mkdir -p $(HOME)/.mc +install: gomake-all clean: @rm -fv cover.out diff --git a/cmd-update.go b/cmd-update.go index 818a7828..263fa2f6 100644 --- a/cmd-update.go +++ b/cmd-update.go @@ -58,9 +58,9 @@ func doUpdateCheck(config *hostConfig) (string, error) { if err != nil { return "No new update available at this time", nil } - current, _ := time.Parse(time.RFC3339Nano, BuildDate) + current, _ := time.Parse(time.RFC3339Nano, Version) if current.IsZero() { - return "BuildDate is empty, must be a custom build cannot update", nil + return "Version is empty, must be a custom build cannot update. Please download releases from http://dl.minio.io:9000 for proper updates", nil } if latest.Time.After(current) { printUpdateNotify("new", "old") diff --git a/hash-binary.go b/hash-binary.go deleted file mode 100644 index a10d3838..00000000 --- a/hash-binary.go +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Minio Client (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 - -import ( - "crypto/md5" - "fmt" - "io" - "os" - "os/exec" -) - -// hashBinary computes MD5SUM of a binary file on disk -func hashBinary(progName string) (string, error) { - path, err := exec.LookPath(progName) - if err != nil { - return "", err - } - - m := md5.New() - - file, err := os.Open(path) // For read access. - if err != nil { - return "", err - } - - io.Copy(m, file) - return fmt.Sprintf("%x", m.Sum(nil)), nil -} - -// mustHashBinarySelf masks any error returned by hashBinary -func mustHashBinarySelf() string { - hash, _ := hashBinary(os.Args[0]) - return hash -} diff --git a/main.go b/main.go index 7d0453ae..665aad62 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,6 @@ import ( "os/user" "runtime" "strconv" - "time" "github.com/minio/cli" "github.com/minio/mc/pkg/console" @@ -56,18 +55,6 @@ func checkConfig() { } } -// Build date -var BuildDate string - -// getBuildDate - -func getBuildDate() string { - t, _ := time.Parse(time.RFC3339Nano, BuildDate) - if t.IsZero() { - return "" - } - return t.Format(time.RFC1123) -} - // Get os/arch/platform specific information. // Returns a map of current os/arch/platform/memstats func getSystemData() map[string]string { @@ -94,9 +81,6 @@ func getSystemData() map[string]string { } } -// Version is based on MD5SUM of its binary -var Version = mustHashBinarySelf() - func main() { // register all the commands registerCmd(lsCmd) // List contents of a bucket @@ -120,7 +104,7 @@ func main() { app.Usage = "Minio Client for object storage and filesystems" app.Version = Version app.Commands = commands - app.Compiled = getBuildDate() + app.Compiled = getVersion() app.Flags = flags app.Author = "Minio.io" app.Before = func(ctx *cli.Context) error { @@ -176,9 +160,7 @@ GLOBAL FLAGS: {{range .Flags}}{{.}} {{end}}{{end}} VERSION: - {{.Version}} {{if .Compiled}} -BUILD: {{.Compiled}}{{end}} {{range $key, $value := .ExtraInfo}} {{$key}}: diff --git a/make.go b/make.go new file mode 100644 index 00000000..cc850682 --- /dev/null +++ b/make.go @@ -0,0 +1,119 @@ +// +build ignore + +/* + * Minio Client (C) 2014, 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 + +import ( + "bytes" + "fmt" + "os" + "os/exec" + "text/template" + "time" + + "github.com/minio/cli" + "github.com/minio/mc/pkg/console" +) + +type Version struct { + Date string +} + +func writeVersion(version Version) error { + var versionTemplate = `// -------- DO NOT EDIT -------- +// this is an autogenerated file + +package main + +import "time" + +// Version autogenerated +var Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}} + +// getVersion - +func getVersion() string { + t, _ := time.Parse(time.RFC3339Nano, Version) + if t.IsZero() { + return "" + } + return t.Format(time.RFC1123) +} +` + t := template.Must(template.New("version").Parse(versionTemplate)) + versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) + if err != nil { + return err + } + defer versionFile.Close() + err = t.Execute(versionFile, version) + if err != nil { + return err + } + return nil +} + +func runGoBuild(ctx *cli.Context) { + if ctx.Args().First() == "help" { + cli.ShowCommandHelpAndExit(ctx, "build", 1) // last argument is exit code + } + mcBuild := exec.Command("godep", "go", "build", "-a", "./...") + mcTest := exec.Command("godep", "go", "test", "-race", "./...") + mcInstall := exec.Command("godep", "go", "install", "-a", "github.com/minio/mc") + mcBuildErr := mcBuild.Run() + if mcBuildErr != nil { + console.Fatalln(mcBuildErr) + } + var mcTestOut bytes.Buffer + mcTest.Stdout = &mcTestOut + mcTestErr := mcTest.Run() + if mcTestErr != nil { + console.Fatalln(mcTestErr) + } + fmt.Print(mcTestOut.String()) + mcInstallErr := mcInstall.Run() + if mcInstallErr != nil { + console.Fatalln(mcInstallErr) + } +} + +func runReleaseCmd(ctx *cli.Context) { + if ctx.Args().First() == "help" { + cli.ShowCommandHelpAndExit(ctx, "release", 1) // last argument is exit code + } + version := Version{Date: time.Now().UTC().Format(time.RFC3339Nano)} + err := writeVersion(version) + if err != nil { + console.Fatalln(err) + } +} + +func main() { + app := cli.NewApp() + app.Usage = "Minio Client for object storage and filesystems" + app.Commands = []cli.Command{ + { + Name: "release", + Action: runReleaseCmd, + }, { + Name: "install", + Action: runGoBuild, + }, + } + app.Author = "Minio.io" + app.RunAndExitOnError() +}