You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.4 KiB

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