2015-08-07 00:51:46 +03:00
|
|
|
# Copyright 2015, Google Inc. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can
|
|
|
|
# be found in the LICENSE file.
|
|
|
|
|
|
|
|
# Library of functions which are used by bootstrap.sh or the Makefile.
|
|
|
|
|
|
|
|
# goversion_min returns true if major.minor go version is at least some value.
|
|
|
|
function goversion_min() {
|
|
|
|
[[ "$(go version)" =~ go([0-9]+)\.([0-9]+) ]]
|
|
|
|
gotmajor=${BASH_REMATCH[1]}
|
|
|
|
gotminor=${BASH_REMATCH[2]}
|
|
|
|
[[ "$1" =~ ([0-9]+)\.([0-9]+) ]]
|
|
|
|
wantmajor=${BASH_REMATCH[1]}
|
|
|
|
wantminor=${BASH_REMATCH[2]}
|
|
|
|
[ "$gotmajor" -lt "$wantmajor" ] && return 1
|
|
|
|
[ "$gotmajor" -gt "$wantmajor" ] && return 0
|
|
|
|
[ "$gotminor" -lt "$wantminor" ] && return 1
|
|
|
|
return 0
|
|
|
|
}
|
2016-03-02 09:02:26 +03:00
|
|
|
|
|
|
|
# prepend_path returns $2 prepended the colon separated path $1.
|
|
|
|
# If it's already part of the path, it won't be added again.
|
|
|
|
# If $1 is a directory, it will also be prepended to $PATH.
|
|
|
|
function prepend_path() {
|
|
|
|
# $1 path variable
|
|
|
|
# $2 path to add
|
|
|
|
if [ -d "$2" ] && [[ ":$1:" != *":$2:"* ]]; then
|
|
|
|
echo "$2:$1"
|
|
|
|
else
|
|
|
|
echo "$1"
|
|
|
|
fi
|
|
|
|
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
|
|
|
|
export PATH="$1:$PATH"
|
|
|
|
fi
|
|
|
|
}
|