cleanup build scripts. (#3192)

This commit is contained in:
Bala FA 2016-11-07 13:28:41 -08:00 committed by Harshavardhana
parent 85a5c358d8
commit 5eb4002bf7
2 changed files with 114 additions and 148 deletions

View File

@ -23,12 +23,19 @@ _init() {
GIT_VERSION="1.0" GIT_VERSION="1.0"
GO_VERSION="1.7.1" GO_VERSION="1.7.1"
OSX_VERSION="10.8" OSX_VERSION="10.8"
UNAME=$(uname -sm) KNAME=$(uname -s)
ARCH=$(uname -m)
## Check all dependencies are present
MISSING=""
} }
## FIXME:
## In OSX, 'readlink -f' option does not exist, hence
## we have our own readlink -f behaviour here.
## Once OSX has the option, below function is good enough.
##
## readlink() {
## return /bin/readlink -f "$1"
## }
##
readlink() { readlink() {
TARGET_FILE=$1 TARGET_FILE=$1
@ -50,152 +57,114 @@ readlink() {
echo $RESULT echo $RESULT
} }
### ## FIXME:
# ## In OSX, 'sort -V' option does not exist, hence
# Takes two arguments ## we have our own version compare function.
# arg1: version number in `x.x.x` format ## Once OSX has the option, below function is good enough.
# arg2: version number in `x.x.x` format ##
# ## check_minimum_version() {
# example: check_version "$version1" "$version2" ## versions=($(echo -e "$1\n$2" | sort -V))
# ## return [ "$1" == "${versions[0]}" ]
# returns: ## }
# 0 - Installed version is equal to required ##
# 1 - Installed version is greater than required check_minimum_version() {
# 2 - Installed version is lesser than required IFS='.' read -r -a varray1 <<< "$1"
# 3 - If args have length zero IFS='.' read -r -a varray2 <<< "$2"
#
####
check_version() {
## validate args
[[ -z "$1" ]] && return 3
[[ -z "$2" ]] && return 3
if [[ $1 == $2 ]]; then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++)); do
if [[ -z ${ver2[i]} ]]; then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]})); then
for i in "${!varray1[@]}"; do
if [[ ${varray1[i]} < ${varray2[i]} ]]; then
return 0
elif [[ ${varray1[i]} > ${varray2[i]} ]]; then
return 1 return 1
fi fi
if ((10#${ver1[i]} < 10#${ver2[i]})); then
## Installed version is lesser than required - Bad condition
return 2
fi
done done
return 0 return 0
} }
check_golang_env() { assert_is_supported_arch() {
echo ${GOPATH:?} 2>&1 >/dev/null case "${ARCH}" in
if [ $? -eq 1 ]; then x86_64 | amd64 | aarch64 | arm* )
return
;;
*)
echo "ERROR"
echo "Arch '${ARCH}' not supported."
echo "Supported Arch: [x86_64, amd64, aarch64, arm*]"
exit 1
esac
}
assert_is_supported_os() {
case "${KNAME}" in
Linux | FreeBSD )
return
;;
Darwin )
osx_host_version=$(env sw_vers -productVersion)
if ! check_minimum_version "${OSX_VERSION}" "${osx_host_version}"; then
echo "ERROR"
echo "OSX version '${osx_host_version}' not supported."
echo "Minimum supported version: ${OSX_VERSION}"
exit 1
fi
return
;;
*)
echo "ERROR"
echo "OS '${KNAME}' is not supported."
echo "Supported OS: [Linux, FreeBSD, Darwin]"
exit 1
esac
}
assert_check_golang_env() {
if ! which go >/dev/null 2>&1; then
echo "ERROR" echo "ERROR"
echo "GOPATH environment variable missing, please refer to Go installation document" echo "Cannot find go binary in your PATH configuration, please refer to Go installation document at"
echo "https://github.com/minio/minio/blob/master/INSTALLGO.md#install-go-13" echo "https://docs.minio.io/docs/how-to-install-golang"
exit 1 exit 1
fi fi
local go_binary_path=$(which go) installed_go_version=$(go version | sed 's/^.* go\([0-9.]*\).*$/\1/')
if [ -z "${go_binary_path}" ] ; then if ! check_minimum_version "${GO_VERSION}" "${installed_go_version}"; then
echo "Cannot find go binary in your PATH configuration, please refer to Go installation document" echo "ERROR"
echo "https://github.com/minio/minio/blob/master/INSTALLGO.md#install-go-13" echo "Go version '${installed_go_version}' not supported."
exit -1 echo "Minimum supported version: ${GO_VERSION}"
fi exit 1
}
is_supported_os() {
case ${UNAME%% *} in
"Linux")
os="linux"
;;
"FreeBSD")
os="freebsd"
;;
"Darwin")
osx_host_version=$(env sw_vers -productVersion)
check_version "${osx_host_version}" "${OSX_VERSION}"
[[ $? -ge 2 ]] && die "Minimum OSX version supported is ${OSX_VERSION}"
;;
"*")
echo "Exiting.. unsupported operating system found"
exit 1;
esac
}
is_supported_arch() {
local supported
case ${UNAME##* } in
"x86_64" | "amd64")
supported=1
;;
"arm"*)
supported=1
;;
*)
supported=0
;;
esac
if [ $supported -eq 0 ]; then
echo "Invalid arch: ${UNAME} not supported, please use x86_64/amd64"
exit 1;
fi
}
check_deps() {
go_version=$(env go version 2>/dev/null)
check_version "$(echo ${go_version} | sed 's/^.* go\([0-9.]*\).*$/\1/')" "${GO_VERSION}"
if [ $? -ge 2 ]; then
MISSING="${MISSING} golang(${GO_VERSION})"
fi fi
check_version "$(env git --version 2>/dev/null | sed -e 's/^.* \([0-9.\].*\).*$/\1/' -e 's/^\([0-9.\]*\).*/\1/g')" "${GIT_VERSION}" if [ -z "${GOPATH}" ]; then
if [ $? -ge 2 ]; then echo "ERROR"
MISSING="${MISSING} git" echo "GOPATH environment variable missing, please refer to Go installation document"
echo "https://docs.minio.io/docs/how-to-install-golang"
exit 1
fi
}
assert_check_deps() {
installed_git_version=$(git version | awk '{print $NF}')
if ! check_minimum_version "${GIT_VERSION}" "${installed_git_version}"; then
echo "ERROR"
echo "Git version '${installed_git_version}' not supported."
echo "Minimum supported version: ${GIT_VERSION}"
exit 1
fi fi
} }
main() { main() {
echo -n "Check for supported arch.. " ## Check for supported arch
is_supported_arch assert_is_supported_arch
echo -n "Check for supported os.. " ## Check for supported os
is_supported_os assert_is_supported_os
echo -n "Checking if proper environment variables are set.. " ## Check for Go environment
check_golang_env assert_check_golang_env
echo "Done" ## Check for dependencies
echo "Using GOPATH=${GOPATH}" assert_check_deps
echo -n "Checking dependencies for Minio.. "
check_deps
## If dependencies are missing, warn the user and abort
if [ "x${MISSING}" != "x" ]; then
echo "ERROR"
echo
echo "The following build tools are missing:"
echo
echo "** ${MISSING} **"
echo
echo "Please install them "
echo "${MISSING}"
echo
echo "Follow https://docs.minio.io/docs/how-to-install-golang for further instructions"
exit 1
fi
echo "Done"
} }
_init && main "$@" _init && main "$@"

View File

@ -15,26 +15,23 @@
# limitations under the License. # limitations under the License.
# #
_init() {
shopt -s extglob
PWD=$(pwd -P)
GOPATH=$(cd "$(go env GOPATH)" ; env pwd -P)
}
main() { main() {
echo "Checking if project is at ${GOPATH}" echo "Checking project is in GOPATH:"
for minio in $(echo ${GOPATH} | tr ':' ' '); do
if [ ! -d ${minio}/src/github.com/minio/minio ]; then IFS=':' read -r -a paths <<< "$GOPATH"
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" \ for path in "${paths[@]}"; do
&& exit 1 minio_path="$path/src/github.com/minio/minio"
fi if [ -d "$minio_path" ]; then
if [ "x${minio}/src/github.com/minio/minio" != "x${PWD}" ]; then if [ "$minio_path" == "$PWD" ]; then
echo "Build outside of ${minio}, two source checkouts found. Exiting." && exit 1 exit 0
fi
fi fi
done done
echo "ERROR"
echo "Project not found in ${GOPATH}."
echo "Follow instructions at https://github.com/minio/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository"
exit 1
} }
_init && main main