From 4ef3dcffc40412711053042e92fd1c2b4f1f0f15 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 8 Feb 2016 02:29:14 -0800 Subject: [PATCH] build: Now builds for all platforms and builds into 'release/experimental' directory. Two Makefile options are - make release - make experimental Currently supported OS and arch - - linux/386 - linux/amd64 - linux/arm - windows/386 - windows/amd64 - darwin/amd64 --- .gitignore | 2 ++ MAINTAINERS.md | 2 +- Makefile | 14 +++++----- build-constants.go | 6 ++--- buildscripts/build.sh | 26 +++++++++++++++++++ buildscripts/gen-ldflags.go | 2 +- pipe-main.go | 2 +- release.cmd | 5 ---- release.sh | 6 ----- update-main.go | 2 +- .../github.com/minio/minio/pkg/user/user.go | 18 +++++++------ vendor/vendor.json | 4 +-- 12 files changed, 55 insertions(+), 34 deletions(-) create mode 100755 buildscripts/build.sh delete mode 100644 release.cmd delete mode 100755 release.sh diff --git a/.gitignore b/.gitignore index e7c7771b..959621de 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ cover.out mc *~ *.test +release +experimental \ No newline at end of file diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 33a4c6e4..24466adc 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -38,4 +38,4 @@ $ `mc` doesn't follow semantic versioning style, `mc` instead uses the release date and time as the release versions. -`make release` will install new released binary into your `GOPATH` +`make release` will generate new binary into `release` directory. diff --git a/Makefile b/Makefile index 5b2c5e04..59a1fc4a 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,14 @@ LDFLAGS := $(shell go run buildscripts/gen-ldflags.go) -BUILD_LDFLAGS := '$(LDFLAGS)' all: install checkdeps: @echo "Checking deps:" - @(env bash $(PWD)/buildscripts/checkdeps.sh) + @(env bash buildscripts/checkdeps.sh) checkgopath: @echo "Checking if project is at ${GOPATH}" @for mcpath in $(echo ${GOPATH} | sed 's/:/\n/g'); do if [ ! -d ${mcpath}/src/github.com/minio/mc ]; then echo "Project not found in ${mcpath}, please follow instructions provided at https://github.com/minio/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi done - @echo "BUILD_LDFLAGS: ${BUILD_LDFLAGS}" getdeps: checkdeps checkgopath @go get github.com/golang/lint/golint && echo "Installed golint:" @@ -55,7 +53,7 @@ test: verifiers @GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/mc/pkg... gomake-all: build - @GO15VENDOREXPERIMENT=1 go build --ldflags $(BUILD_LDFLAGS) -o $(GOPATH)/bin/mc + @GO15VENDOREXPERIMENT=1 go build --ldflags "$(LDFLAGS)" -o $(GOPATH)/bin/mc @mkdir -p $(HOME)/.mc coverage: @@ -77,9 +75,13 @@ all-tests: test # TODO disable them for now. #@./tests/test-minio.sh -release: - @./release.sh +release: verifiers + @MC_RELEASE=RELEASE GO15VENDOREXPERIMENT=1 $(env bash buildscripts/build.sh) + +experimental: verifiers + @MC_RELEASE=EXPERIMENTAL GO15VENDOREXPERIMENT=1 $(env bash buildscripts/build.sh) clean: @rm -fv cover.out @rm -fv mc + @rm -frv release diff --git a/build-constants.go b/build-constants.go index 2095a528..0f5eb122 100644 --- a/build-constants.go +++ b/build-constants.go @@ -18,11 +18,11 @@ package main var ( // mcVersion - version time.RFC3339. - mcVersion = "UNOFFICIAL.GOGET" + mcVersion = "DEVELOPMENT.GOGET" // mcReleaseTag - release tag in TAG.%Y-%m-%dT%H-%M-%SZ. - mcReleaseTag = "UNOFFICIAL.GOGET" + mcReleaseTag = "DEVELOPMENT.GOGET" // mcCommitID - latest commit id. - mcCommitID = "UNOFFICIAL.GOGET" + mcCommitID = "DEVELOPMENT.GOGET" // mcShortCommitID - first 12 characters from mcCommitID. mcShortCommitID = mcCommitID[:12] ) diff --git a/buildscripts/build.sh b/buildscripts/build.sh new file mode 100755 index 00000000..1212509b --- /dev/null +++ b/buildscripts/build.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Save release LDFLAGS +LDFLAGS=$(go run buildscripts/gen-ldflags.go) + +# Extract of release tag +release_tag=$(echo $LDFLAGS | awk {'print $4'} | cut -f2 -d=) + +# Extract release string. +release_str=$(echo $MC_RELEASE | tr '[:upper:]' '[:lower:]') + +# List of supported architectures +SUPPORTED_OSARCH='linux/386 linux/amd64 linux/arm windows/386 windows/amd64 darwin/amd64' + +# Builds. +echo "Executing $release_str builds." +for osarch in ${SUPPORTED_OSARCH}; do + os=$(echo $osarch | cut -f1 -d'/') + arch=$(echo $osarch | cut -f2 -d'/') + package=$(go list -f '{{.ImportPath}}') + echo -n "-->" + printf "%15s:%s\n" "${osarch}" "${package}" + GOOS=$os GOARCH=$arch go build --ldflags "${LDFLAGS}" -o $release_str/$os-$arch/$(basename $package).$release_tag +done + + diff --git a/buildscripts/gen-ldflags.go b/buildscripts/gen-ldflags.go index 92e7773b..f3a659f9 100644 --- a/buildscripts/gen-ldflags.go +++ b/buildscripts/gen-ldflags.go @@ -37,7 +37,7 @@ func genLDFlags(version string) string { // genReleaseTag prints release tag to the console for easy git tagging. func releaseTag(version string) string { - relPrefix := "UNOFFICIAL" + relPrefix := "DEVELOPMENT" if prefix := os.Getenv("MC_RELEASE"); prefix != "" { relPrefix = prefix } diff --git a/pipe-main.go b/pipe-main.go index 4855c337..e1cc1d7d 100644 --- a/pipe-main.go +++ b/pipe-main.go @@ -55,7 +55,7 @@ EXAMPLES: 2. Write contents of stdin to an object on Amazon S3 cloud storage. $ mc {{.Name}} s3/personalbuck/meeting-notes.txt - 3. Copy an ISO image to an object on Amazon S3 cloud storage and Google Cloud Storage simultaneously. + 3. Copy an ISO image to an object on Amazon S3 cloud storage. $ cat debian-8.2.iso | mc {{.Name}} s3/ferenginar/gnuos.iso 4. Stream MySQL database dump to Amazon S3 directly. diff --git a/release.cmd b/release.cmd deleted file mode 100644 index 2ef3ff77..00000000 --- a/release.cmd +++ /dev/null @@ -1,5 +0,0 @@ -SET MC_RELEASE=OFFICIAL -SET GO15VENDOREXPERIMENT=1 -go run buildscripts/gen-ldflags.go > temp.txt -SET /p LDFLAGS=/dev/null -echo "Binaries built at ${GOPATH}/bin/mc" diff --git a/update-main.go b/update-main.go index 13aa4c93..546f5f54 100644 --- a/update-main.go +++ b/update-main.go @@ -144,7 +144,7 @@ func getReleaseUpdate(updateURL string) { data, e := http.Get(newUpdateURL) fatalIf(probe.NewError(e), "Unable to read from update URL ‘"+newUpdateURL+"’.") - if mcVersion == "UNOFFICIAL.GOGET" { + if strings.HasPrefix(mcVersion, "DEVELOPMENT.GOGET") { fatalIf(errDummy().Trace(newUpdateURL), "Update mechanism is not supported for ‘go get’ based binary builds. Please download official releases from https://minio.io/#minio") } diff --git a/vendor/github.com/minio/minio/pkg/user/user.go b/vendor/github.com/minio/minio/pkg/user/user.go index ee94ef5c..ea010829 100644 --- a/vendor/github.com/minio/minio/pkg/user/user.go +++ b/vendor/github.com/minio/minio/pkg/user/user.go @@ -39,14 +39,16 @@ func Current() (*user.User, error) { } return &user.User{Uid: "0", Gid: "0", Username: "root", Name: "root", HomeDir: wd}, nil } - if runtime.GOARCH == "386" && runtime.GOOS == "linux" { - return &user.User{ - Uid: strconv.Itoa(os.Getuid()), - Gid: strconv.Itoa(os.Getgid()), - Username: os.Getenv("USER"), - Name: os.Getenv("USER"), - HomeDir: os.Getenv("HOME"), - }, nil + if runtime.GOARCH == "386" { + if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { + return &user.User{ + Uid: strconv.Itoa(os.Getuid()), + Gid: strconv.Itoa(os.Getgid()), + Username: os.Getenv("USER"), + Name: os.Getenv("USER"), + HomeDir: os.Getenv("HOME"), + }, nil + } } user, e := user.Current() if e != nil { diff --git a/vendor/vendor.json b/vendor/vendor.json index f9c2d92e..74b443a1 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -49,8 +49,8 @@ }, { "path": "github.com/minio/minio/pkg/user", - "revision": "71876688282283e8af374bd8592c7d33c547df4d", - "revisionTime": "2015-12-07T14:59:57-08:00" + "revision": "4e328d7b2cdec323820ad90c83dcc0dffa7900f7", + "revisionTime": "2016-02-08T01:59:02-08:00" }, { "path": "github.com/minio/pb",