diff --git a/.travis.yml b/.travis.yml index d2127be83..ecf8532b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,8 @@ matrix: - diff -au <(gofmt -s -d cmd) <(printf "") - diff -au <(gofmt -s -d pkg) <(printf "") - for d in $(go list ./... | grep -v browser); do CGO_ENABLED=1 go test -v -race --timeout 15m "$d"; done + - make verifiers + - make crosscompile - make verify - make coverage - cd browser && yarn && yarn test && cd .. diff --git a/Makefile b/Makefile index 0be4b01c1..685b86977 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,9 @@ getdeps: @echo "Installing misspell" && go get -u github.com/client9/misspell/cmd/misspell @echo "Installing ineffassign" && go get -u github.com/gordonklaus/ineffassign +crosscompile: + @(env bash $(PWD)/buildscripts/cross-compile.sh) + verifiers: getdeps vet fmt lint cyclo deadcode spelling vet: diff --git a/buildscripts/cross-compile.sh b/buildscripts/cross-compile.sh new file mode 100755 index 000000000..edb8204a6 --- /dev/null +++ b/buildscripts/cross-compile.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Enable tracing if set. +[ -n "$BASH_XTRACEFD" ] && set -ex + +function _init() { + ## All binaries are static make sure to disable CGO. + export CGO_ENABLED=0 + + ## List of architectures and OS to test coss compilation. + SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64" +} + +function _build_and_sign() { + local osarch=$1 + IFS=/ read -r -a arr <<<"$osarch" + os="${arr[0]}" + arch="${arr[1]}" + package=$(go list -f '{{.ImportPath}}') + printf -- "--> %15s:%s\n" "${osarch}" "${package}" + + # Go build to build the binary. + export GOOS=$os + export GOARCH=$arch + go build -tags kqueue -o /dev/null +} + +function main() { + echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}" + for each_osarch in ${SUPPORTED_OSARCH}; do + _build_and_sign "${each_osarch}" + done +} + +_init && main "$@" diff --git a/cmd/bitrot.go b/cmd/bitrot.go index a0b2f4144..172a538e6 100644 --- a/cmd/bitrot.go +++ b/cmd/bitrot.go @@ -39,7 +39,7 @@ const ( SHA256 BitrotAlgorithm = 1 + iota // HighwayHash256 represents the HighwayHash-256 hash function HighwayHash256 - // HighwayHash256 represents the Streaming HighwayHash-256 hash function + // HighwayHash256S represents the Streaming HighwayHash-256 hash function HighwayHash256S // BLAKE2b512 represents the BLAKE2b-512 hash function BLAKE2b512 diff --git a/cmd/erasure.go b/cmd/erasure.go index cac06c1f9..10b46c17a 100644 --- a/cmd/erasure.go +++ b/cmd/erasure.go @@ -93,10 +93,12 @@ func (e *Erasure) DecodeDataAndParityBlocks(ctx context.Context, data [][]byte) return nil } +// ShardSize - returns actual shared size from erasure blockSize. func (e *Erasure) ShardSize() int64 { return ceilFrac(e.blockSize, int64(e.dataBlocks)) } +// ShardFileSize - returns final erasure size from original size. func (e *Erasure) ShardFileSize(totalLength int64) int64 { if totalLength == 0 { return 0 @@ -107,6 +109,7 @@ func (e *Erasure) ShardFileSize(totalLength int64) int64 { return numShards*e.ShardSize() + lastShardSize } +// ShardFileTillOffset - returns the effectiv eoffset where erasure reading begins. func (e *Erasure) ShardFileTillOffset(startOffset, length, totalLength int64) int64 { shardSize := e.ShardSize() shardFileSize := e.ShardFileSize(totalLength) diff --git a/cmd/posix.go b/cmd/posix.go index 5b0a16526..7ca778d90 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -1015,7 +1015,7 @@ func (s *posix) ReadFileStream(volume, path string, offset, length int64) (io.Re if _, err = file.Seek(offset, io.SeekStart); err != nil { return nil, err } - return &posixLimitedReader{io.LimitedReader{file, length}}, nil + return &posixLimitedReader{io.LimitedReader{R: file, N: length}}, nil } // CreateFile - creates the file. diff --git a/pkg/cpu/counter_linux.go b/pkg/cpu/counter_linux.go index 2a9f97d72..44449bc70 100644 --- a/pkg/cpu/counter_linux.go +++ b/pkg/cpu/counter_linux.go @@ -20,12 +20,8 @@ import ( "syscall" "time" "unsafe" -) -const ( - // ProcessClock corresponds to the High-resolution per-process - // timer from the CPU represented in stdlib as CLOCK_PROCESS_CPUTIME_ID - processClock = 2 + "golang.org/x/sys/unix" ) func newCounter() (counter, error) { @@ -34,7 +30,8 @@ func newCounter() (counter, error) { func (c counter) now() time.Time { var ts syscall.Timespec - syscall.Syscall(syscall.SYS_CLOCK_GETTIME, processClock, uintptr(unsafe.Pointer(&ts)), 0) + // Retrieve Per-process CPU-time clock + syscall.Syscall(syscall.SYS_CLOCK_GETTIME, unix.CLOCK_PROCESS_CPUTIME_ID, uintptr(unsafe.Pointer(&ts)), 0) sec, nsec := ts.Unix() return time.Unix(sec, nsec) } diff --git a/pkg/cpu/counter_darwin.go b/pkg/cpu/counter_other.go similarity index 81% rename from pkg/cpu/counter_darwin.go rename to pkg/cpu/counter_other.go index 1967c2de7..cc3e7ea73 100644 --- a/pkg/cpu/counter_darwin.go +++ b/pkg/cpu/counter_other.go @@ -1,3 +1,5 @@ +// +build darwin freebsd openbsd netbsd dragonfly windows + /* * Minio Cloud Storage, (C) 2019 Minio, Inc. * @@ -17,12 +19,13 @@ package cpu import ( - "errors" + "fmt" + "runtime" "time" ) func newCounter() (counter, error) { - return counter{}, errors.New("cpu metrics not implemented for darwin platform") + return counter{}, fmt.Errorf("cpu metrics not implemented for %s platform", runtime.GOOS) } func (c counter) now() time.Time { diff --git a/pkg/cpu/counter_windows.go b/pkg/cpu/counter_windows.go deleted file mode 100644 index 0ee5cbc68..000000000 --- a/pkg/cpu/counter_windows.go +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Minio Cloud Storage, (C) 2019 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 cpu - -import ( - "errors" - "time" -) - -func newCounter() (counter, error) { - return counter{}, errors.New("cpu metrics not implemented for windows platform") -} - -func (c counter) now() time.Time { - return time.Time{} -}