From 408aa72146488e20c2af26b8fcb22606ae50b8a0 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 18 Feb 2016 17:16:41 -0800 Subject: [PATCH] build/vet: Fix all the shadowing reports with go1.6 Golang 1.6 is default version for the build now. Additionally set 'GODEBUG=cgocheck=0' for now, until we fix the erasure coding package. Readmore here https://tip.golang.org/doc/go1.6#cgo --- .gitignore | 3 ++- .travis.yml | 2 +- INSTALLGO.md | 12 +++++------ Makefile | 16 +++++++-------- appveyor.yml | 7 ++++++- buildscripts/checkdeps.sh | 3 +-- buildscripts/checkgopath.sh | 40 +++++++++++++++++++++++++++++++++++++ globals.go | 2 +- pkg/atomic/atomic.go | 4 ++-- pkg/erasure/INSTALLGO.md | 14 ++++++------- pkg/fs/fs.go | 4 ++-- pkg/ioutils/filepath.go | 2 +- pkg/xl/cache/data/data.go | 2 +- 13 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 buildscripts/checkgopath.sh diff --git a/.gitignore b/.gitignore index 449f2067e..6297c4fd5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ site/ build isa-l vendor/**/*.js -vendor/**/*.json \ No newline at end of file +vendor/**/*.json +release diff --git a/.travis.yml b/.travis.yml index b96b98026..87bb3e716 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ script: - make test GOFLAGS="-race" go: -- 1.5.3 +- 1.6 notifications: slack: diff --git a/INSTALLGO.md b/INSTALLGO.md index 4dd444dee..01df6b954 100644 --- a/INSTALLGO.md +++ b/INSTALLGO.md @@ -7,15 +7,15 @@ This installation document assumes Ubuntu 14.04+ on x86-64 platform. $ sudo apt-get install git build-essential ``` -##### Install Go 1.5+ +##### Install Go 1.6+ -Download Go 1.5+ from [https://golang.org/dl/](https://golang.org/dl/). +Download Go 1.6+ from [https://golang.org/dl/](https://golang.org/dl/). ```sh -$ wget https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz +$ wget https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz $ mkdir -p ${HOME}/bin/ $ mkdir -p ${HOME}/go/ -$ tar -C ${HOME}/bin/ -xzf go1.5.1.linux-amd64.tar.gz +$ tar -C ${HOME}/bin/ -xzf go1.6.linux-amd64.tar.gz ``` ##### Setup GOROOT and GOPATH @@ -25,7 +25,7 @@ and GOPATH specifies the location of your project workspace. ```sh export GOROOT=${HOME}/bin/go export GOPATH=${HOME}/go -export PATH=$PATH:${HOME}/bin/go/bin:${GOPATH}/bin +export PATH=${HOME}/bin/go/bin:${GOPATH}/bin:$PATH ``` ##### Source the new enviornment @@ -71,7 +71,7 @@ and GOPATH specifies the location of your project workspace. export GOPATH=${HOME}/go export GOVERSION=$(brew list go | head -n 1 | cut -d '/' -f 6) export GOROOT=$(brew --prefix)/Cellar/go/${GOVERSION}/libexec -export PATH=$PATH:${GOPATH}/bin +export PATH=${GOPATH}/bin:$PATH ``` ##### Source the new enviornment ```sh diff --git a/Makefile b/Makefile index 9543bf220..703e18ce5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ LDFLAGS := $(shell go run buildscripts/gen-ldflags.go) DOCKER_BIN := $(shell which docker) +PWD := $(shell pwd) +GOPATH := $(shell go env GOPATH) DOCKER_LDFLAGS := '$(LDFLAGS) -extldflags "-static"' BUILD_LDFLAGS := '$(LDFLAGS)' TAG := latest @@ -47,20 +49,16 @@ endif all: install -checkdeps: +checks: @echo "Checking deps:" @(env bash $(PWD)/buildscripts/checkdeps.sh) - -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 BUILD_LDFLAGS: ${BUILD_LDFLAGS}" + @(env bash $(PWD)/buildscripts/checkgopath.sh) checkdocker: @echo "Checking if docker is installed.. " @if [ -z ${DOCKER_BIN} ]; then echo "Docker not installed, cannot build docker image. Please install 'sudo apt-get install docker.io'" && exit 1; else echo "Docker installed at ${DOCKER_BIN}."; fi; -getdeps: checkdeps checkgopath +getdeps: checks @go get -u github.com/golang/lint/golint && echo "Installed golint:" @go get -u golang.org/x/tools/cmd/vet && echo "Installed vet:" @go get -u github.com/fzipp/gocyclo && echo "Installed gocyclo:" @@ -110,8 +108,8 @@ spelling: test: build @echo "Running all minio testing:" - @CGO_CPPFLAGS="-I$(PWD)/isa-l" CGO_LDFLAGS="$(PWD)/isa-l/isa-l.a" GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) . - @CGO_CPPFLAGS="-I$(PWD)/isa-l" CGO_LDFLAGS="$(PWD)/isa-l/isa-l.a" GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/minio/pkg... + @GODEBUG=cgocheck=0 CGO_CPPFLAGS="-I$(PWD)/isa-l" CGO_LDFLAGS="$(PWD)/isa-l/isa-l.a" GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) . + @GODEBUG=cgocheck=0 CGO_CPPFLAGS="-I$(PWD)/isa-l" CGO_LDFLAGS="$(PWD)/isa-l/isa-l.a" GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/minio/pkg... gomake-all: build @echo "Installing minio:" diff --git a/appveyor.yml b/appveyor.yml index ea22ce534..49eae896b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,16 +10,21 @@ environment: GOPATH: c:\gopath GO_EXTLINK_ENABLED: 0 GO15VENDOREXPERIMENT: 1 +# Remove this after fixing erasure code. + GODEBUG: cgocheck=0 # scripts that run after cloning repository install: - '"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64' - curl -fsSL -o c:\go\bin\yasm.exe http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% + - rd C:\Go /s /q + - appveyor DownloadFile https://storage.googleapis.com/golang/go1.6.windows-amd64.zip + - 7z x go1.6.windows-amd64.zip -oC:\ >nul - curl -fsSL -o mingw-w64.7z http://downloads.sourceforge.net/project/mingw-w64-dgn/mingw-w64/mingw-w64-bin-x86_64-20151206.7z - 7z x -oC:\ mingw-w64.7z > NUL - set PATH=C:\mingw64\bin;%PATH% - - x86_64-w64-mingw32-gcc --version + - x86_64-w64-mingw32-gcc --version - go version - go env - git clone https://github.com/minio/isa-l diff --git a/buildscripts/checkdeps.sh b/buildscripts/checkdeps.sh index cc64eab83..b2bd05f12 100644 --- a/buildscripts/checkdeps.sh +++ b/buildscripts/checkdeps.sh @@ -22,8 +22,7 @@ _init() { ## Minimum required versions for build dependencies GIT_VERSION="1.0" YASM_VERSION="1.2.0" - CURL_VERSION="7.12.0" - GO_VERSION="1.5.1" + GO_VERSION="1.6" OSX_VERSION="10.8" UNAME=$(uname -sm) diff --git a/buildscripts/checkgopath.sh b/buildscripts/checkgopath.sh new file mode 100644 index 000000000..0a2a28501 --- /dev/null +++ b/buildscripts/checkgopath.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# +# Minio Cloud Storage, (C) 2015, 2016 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. +# + +_init() { + + shopt -s extglob + + PWD=$(pwd) + GOPATH=$(go env GOPATH) +} + +main() { + echo "Checking if project is at ${GOPATH}" + for minio in $(echo ${GOPATH} | tr ':' ' '); do + if [ ! -d ${minio}/src/github.com/minio/minio ]; then + echo "Project not found in ${minio}, please follow instructions provided at https://github.com/minio/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" \ + && exit 1 + fi + if [ "x${minio}/src/github.com/minio/minio" != "x${PWD}" ]; then + echo "Build outside of ${minio}, two source checkouts found. Exiting." && exit 1 + fi + done +} + +_init && main + diff --git a/globals.go b/globals.go index 72d205813..f3ac1d2e9 100644 --- a/globals.go +++ b/globals.go @@ -18,5 +18,5 @@ package main // Global constants for Minio. const ( - minGoVersion = ">= 1.5.1" // Minio requires at least Go v1.5.1 + minGoVersion = ">= 1.6" // Minio requires at least Go v1.6 ) diff --git a/pkg/atomic/atomic.go b/pkg/atomic/atomic.go index 4e5fe10df..42d238ce7 100644 --- a/pkg/atomic/atomic.go +++ b/pkg/atomic/atomic.go @@ -85,8 +85,8 @@ func FileCreateWithPrefix(filePath string, prefix string) (*File, error) { if err != nil { return nil, err } - if err := os.Chmod(f.Name(), 0600); err != nil { - if err := os.Remove(f.Name()); err != nil { + if err = os.Chmod(f.Name(), 0600); err != nil { + if err = os.Remove(f.Name()); err != nil { return nil, err } return nil, err diff --git a/pkg/erasure/INSTALLGO.md b/pkg/erasure/INSTALLGO.md index d8319326f..718a98fbc 100644 --- a/pkg/erasure/INSTALLGO.md +++ b/pkg/erasure/INSTALLGO.md @@ -7,15 +7,15 @@ This installation document assumes Ubuntu 14.04+ on x86-64 platform. $ sudo apt-get install git build-essential yasm ``` -##### Install Go 1.5.1+ +##### Install Go 1.6+ -Download Go 1.5.1+ from [https://golang.org/dl/](https://golang.org/dl/). +Download Go 1.6+ from [https://golang.org/dl/](https://golang.org/dl/). ```sh -$ wget https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz +$ wget https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz $ mkdir -p ${HOME}/bin/ $ mkdir -p ${HOME}/go/ -$ tar -C ${HOME}/bin/ -xzf go1.5.1.linux-amd64.tar.gz +$ tar -C ${HOME}/bin/ -xzf go1.6.linux-amd64.tar.gz ``` ##### Setup GOROOT and GOPATH @@ -25,7 +25,7 @@ and GOPATH specifies the location of your project workspace. ```sh $ export GOROOT=${HOME}/bin/go $ export GOPATH=${HOME}/go -$ export PATH=$PATH:${HOME}/bin/go/bin:${GOPATH}/bin +$ export PATH=${HOME}/bin/go/bin:${GOPATH}/bin:$PATH ``` ## OS X (Yosemite) 10.10 @@ -42,7 +42,7 @@ $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/maste $ brew install git python yasm ``` -##### Install Go 1.5.1+ +##### Install Go 1.6+ Install golang binaries using `brew` @@ -60,5 +60,5 @@ and GOPATH specifies the location of your project workspace. $ export GOPATH=${HOME}/go $ export GOVERSION=$(brew list go | head -n 1 | cut -d '/' -f 6) $ export GOROOT=$(brew --prefix)/Cellar/go/${GOVERSION}/libexec -$ export PATH=$PATH:${GOPATH}/bin +$ export PATH=${GOPATH}/bin:$PATH ``` diff --git a/pkg/fs/fs.go b/pkg/fs/fs.go index a4a395a9c..b04675d93 100644 --- a/pkg/fs/fs.go +++ b/pkg/fs/fs.go @@ -72,7 +72,7 @@ func New(rootPath string, minFreeDisk int64) (Filesystem, *probe.Error) { Version: "1", ActiveSession: make(map[string]*MultipartSession), } - if err := saveMultipartsSession(*multiparts); err != nil { + if err = saveMultipartsSession(*multiparts); err != nil { return Filesystem{}, err.Trace() } } else { @@ -88,7 +88,7 @@ func New(rootPath string, minFreeDisk int64) (Filesystem, *probe.Error) { Version: "1", Metadata: make(map[string]*BucketMetadata), } - if err := saveBucketsMetadata(*buckets); err != nil { + if err = saveBucketsMetadata(*buckets); err != nil { return Filesystem{}, err.Trace() } } else { diff --git a/pkg/ioutils/filepath.go b/pkg/ioutils/filepath.go index 41a54f7ca..9a4b84f7d 100644 --- a/pkg/ioutils/filepath.go +++ b/pkg/ioutils/filepath.go @@ -126,7 +126,7 @@ func walk(path string, info os.FileInfo, walkFn FTWFunc) error { for _, fileInfo := range fis { filename := filepath.Join(path, fileInfo.Name()) if err != nil { - if err := walkFn(filename, fileInfo, err); err != nil && err != ErrSkipDir && err != ErrSkipFile { + if err = walkFn(filename, fileInfo, err); err != nil && err != ErrSkipDir && err != ErrSkipFile { return err } } else { diff --git a/pkg/xl/cache/data/data.go b/pkg/xl/cache/data/data.go index 56ccdd14c..a7451b553 100644 --- a/pkg/xl/cache/data/data.go +++ b/pkg/xl/cache/data/data.go @@ -135,7 +135,7 @@ func (r *Cache) Append(key interface{}, value []byte) bool { } ele, hit := r.reverseItems[key] if !hit { - ele := r.items.PushFront(&element{key, value}) + ele = r.items.PushFront(&element{key, value}) r.currentSize += valueLen r.reverseItems[key] = ele return true