1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
function retry() {
set +e
local cmd
local retries
local exitcode
cmd=$*
let retries=0
while [ $retries -le 10 ] ; do
echo `date` $cmd
bash -c "$cmd"
exitcode=$?
echo `date` $cmd $exitcode $retries
let retries=retries+1
if [ $exitcode -eq 0 ] ; then break; fi
sleep 10
done
set -e
test $exitcode = 0
}
github_use_ssh=0
github_token=
github_user=
function github_download() {
repo=$1; shift
rev=$1; shift
dest=$1; shift
mkdir $dest
if [ ! -z $github_token ] ; then
retry curl \
--header "Authorization:\\ token\\ $github_token" \
--location https://api.github.com/repos/$repo/tarball/$rev \
--output $dest.tar.gz
if [ $? != 0 ] ; then return; fi
tar --extract \
--gzip \
--directory=$dest \
--strip-components=1 \
--file $dest.tar.gz
if [ $? != 0 ] ; then return; fi
rm -f $dest.tar.gz
elif [ ! -z $github_user ] ; then
retry curl \
--user $github_user \
--location https://api.github.com/repos/$repo/tarball/$rev \
--output $dest.tar.gz
if [ $? != 0 ] ; then return; fi
tar --extract \
--gzip \
--directory=$dest \
--strip-components=1 \
--file $dest.tar.gz
if [ $? != 0 ] ; then return; fi
rm -f $dest.tar.gz
elif [ $github_use_ssh != 0 ] ; then
tempdir=$(TMPDIR=$PWD mktemp -d)
retry git clone git@github.com:${repo}.git $tempdir
if [ $? != 0 ] ; then return; fi
pushd $tempdir
if [ $? != 0 ] ; then return; fi
git checkout $rev
if [ $? != 0 ] ; then return; fi
popd
# export the right branch or tag
(cd $tempdir ;
git archive \
--format=tar \
$rev) | \
tar --extract \
--directory $dest
if [ $? != 0 ] ; then return; fi
rm -rf $tempdir
else
retry curl \
--location https://github.com/$repo/archive/${rev}.tar.gz \
--output $dest.tar.gz
tar --extract \
--gzip \
--directory=$dest \
--strip-components=1 \
--file $dest.tar.gz
if [ $? != 0 ] ; then return; fi
rm -f $dest.tar.gz
fi
}
# returns b if b is defined else returns a
function git_tree() {
set +u
local a=$1; shift
local b=$1; shift
if [ ! -z $b ] ; then
echo $b
else
echo $a;
fi
set -u
}
# compute the number of cpus in this system. used to parallelize the build.
function get_ncpus() {
local n
n=$(grep processor /proc/cpuinfo 2>/dev/null)
if [ $? = 0 ] ; then
echo "$n" | wc -l
else
n=$(sysctl -n hw.ncpu 2>/dev/null)
if [ $? = 0 ] ; then
echo $n
else
echo 1 # default is 1 cpu
fi
fi
}
# parse a mysqlbuild string and extract the mysql_distro, mysql_version, tokudb_distro, tokudb_version, target_system, and target_arch
# compute build_type, build_debug, and git_tag
function parse_mysqlbuild() {
local mysqlbuild=$1
local exitcode=0
if [[ $mysqlbuild =~ ((mysql|mariadb|percona\-server)-(.*))-((tokudb)-(.*))-(linux|darwin)-(x86_64|i386) ]] ; then
# extract distros and versions from the components
mysql=${BASH_REMATCH[1]}
mysql_distro=${BASH_REMATCH[2]}
mysql_version=${BASH_REMATCH[3]}
tokudb=${BASH_REMATCH[4]}
tokudb_distro=${BASH_REMATCH[5]}
tokudb_version=${BASH_REMATCH[6]}
target_system=${BASH_REMATCH[7]}
target_arch=${BASH_REMATCH[8]}
# verify targets
if [ $target_system != $system ] ; then exitcode=1; fi
if [ $target_arch != $arch ] ; then exitcode=1; fi
local temp_tokudb_version=$tokudb_version
# decode enterprise
if [[ $temp_tokudb_version =~ (.*)-e$ ]] ; then
build_type=enterprise
temp_tokudb_version=${BASH_REMATCH[1]}
else
build_type=community
fi
# decode debug
if [[ $temp_tokudb_version =~ (.*)-debug$ ]] ; then
build_debug=1
temp_tokudb_version=${BASH_REMATCH[1]}
cmake_build_type=Debug
else
build_debug=0
fi
# set tag or HEAD
if [[ $temp_tokudb_version =~ ^([0-9]+)\\.([0-9]+)\\.([0-9]+) ]] ; then
git_tag=tokudb-$temp_tokudb_version
else
git_tag=HEAD
# setup _tree defaults
if [ -z $mysql_tree ] ; then mysql_tree=$mysql_distro-$mysql_version; fi
if [ -z $jemalloc_tree ] ; then jemalloc_tree=$jemalloc_version; fi
fi
mysql_repo=$mysql_distro
if [[ $mysql_version =~ ^([0-9]+\.[0-9]+) ]] ; then mysql_repo=$mysql_distro-${BASH_REMATCH[1]}; else exitcode=1; fi
else
exitcode=1
fi
test $exitcode = 0
}
# split mysql into mysql_distro and mysql_version
function parse_mysql() {
local mysql=$1
if [[ $mysql =~ ^(mysql|mariadb)-(.*)$ ]] ; then
mysql_distro=${BASH_REMATCH[1]}
mysql_version=${BASH_REMATCH[2]}
mysql_repo=$mysql_distro
if [[ $mysql_version =~ ^([0-9]+\.[0-9]+) ]] ; then mysql_repo=$mysql_distro-${BASH_REMATCH[1]}; else exitcode=1; fi
exitcode=0
else
exitcode=1
fi
test $exitcode = 0
}
|