/scripts/automated_build_scripts/opensrc-build.sh

https://bitbucket.org/lindenlab/viewer-beta/ · Shell · 391 lines · 299 code · 47 blank · 45 comment · 50 complexity · 4bb4ec4d90406adaf71eeee16b152704 MD5 · raw file

  1. #!/bin/sh
  2. # This is the build script used by Linden Lab's autmated build system.
  3. #
  4. set -x
  5. export PATH=/bin:/usr/bin:$PATH
  6. arch=`uname | cut -b-6`
  7. here=`echo $0 | sed 's:[^/]*$:.:'`
  8. year=`date +%Y`
  9. branch=`svn info | grep '^URL:' | sed 's:.*/::'`
  10. revision=`svn info | grep '^Revision:' | sed 's/.*: //'`
  11. [ x"$WGET_CACHE" = x ] && export WGET_CACHE=/var/tmp/parabuild/wget
  12. [ x"$S3GET_URL" = x ] && export S3GET_URL=http://viewer-source-downloads.s3.amazonaws.com/$year
  13. [ x"$S3PUT_URL" = x ] && export S3PUT_URL=https://s3.amazonaws.com/viewer-source-downloads/$year
  14. [ x"$PUBLIC_URL" = x ] && export PUBLIC_URL=http://secondlife.com/developers/opensource/downloads/$year
  15. [ x"$PUBLIC_EMAIL" = x ] && export PUBLIC_EMAIL=sldev-commits@lists.secondlife.com
  16. # Make sure command worked and bail out if not, reporting failure to parabuild
  17. fail()
  18. {
  19. release_lock
  20. echo "BUILD FAILED" $@
  21. exit 1
  22. }
  23. pass()
  24. {
  25. release_lock
  26. echo "BUILD SUCCESSFUL"
  27. exit 0
  28. }
  29. # Locking to avoid contention with u-s-c
  30. LOCK_CREATE=/usr/bin/lockfile-create
  31. LOCK_TOUCH=/usr/bin/lockfile-touch
  32. LOCK_REMOVE=/usr/bin/lockfile-remove
  33. LOCK_PROCESS=
  34. locking_available()
  35. {
  36. test -x "$LOCK_CREATE"\
  37. -a -x "$LOCK_TOUCH"\
  38. -a -x "$LOCK_REMOVE"
  39. }
  40. acquire_lock()
  41. {
  42. if locking_available
  43. then
  44. if "$LOCK_CREATE" /var/lock/update-system-config --retry 99
  45. then
  46. "$LOCK_TOUCH" /var/lock/update-system-config &
  47. LOCK_PROCESS="$!"
  48. else
  49. fail acquire lock
  50. fi
  51. else
  52. true
  53. fi
  54. }
  55. release_lock()
  56. {
  57. if locking_available
  58. then
  59. if test x"$LOCK_PROCESS" != x
  60. then
  61. kill "$LOCK_PROCESS"
  62. "$LOCK_REMOVE" /var/lock/update-system-config
  63. else
  64. echo No Lock Acquired >&2
  65. fi
  66. else
  67. true
  68. fi
  69. }
  70. get_asset()
  71. {
  72. mkdir -p "$WGET_CACHE" || fail creating WGET_CACHE
  73. local tarball=`basename "$1"`
  74. test -r "$WGET_CACHE/$tarball" || ( cd "$WGET_CACHE" && curl --location --remote-name "$1" || fail getting $1 )
  75. case "$tarball" in
  76. *.zip) unzip -qq -d .. -o "$WGET_CACHE/$tarball" || fail unzip $tarball ;;
  77. *.tar.gz|*.tgz) tar -C .. -xzf "$WGET_CACHE/$tarball" || fail untar $tarball ;;
  78. *) fail unrecognized filetype: $tarball ;;
  79. esac
  80. }
  81. s3_available()
  82. {
  83. test -x "$helpers/s3get.sh" -a -x "$helpers/s3put.sh" -a -r "$helpers/s3curl.pl"
  84. }
  85. build_dir_Darwin()
  86. {
  87. echo build-darwin-universal
  88. }
  89. build_dir_Linux()
  90. {
  91. echo viewer-linux-i686-`echo $1 | tr A-Z a-z`
  92. }
  93. build_dir_CYGWIN()
  94. {
  95. echo build-vc80
  96. }
  97. installer_Darwin()
  98. {
  99. ls -1td "`build_dir_Darwin Release`/newview/"*.dmg 2>/dev/null | sed 1q
  100. }
  101. installer_Linux()
  102. {
  103. ls -1td "`build_dir_Linux Release`/newview/"*.tar.bz2 2>/dev/null | sed 1q
  104. }
  105. installer_CYGWIN()
  106. {
  107. d=`build_dir_CYGWIN Release`
  108. p=`sed 's:.*=::' "$d/newview/Release/touched.bat"`
  109. echo "$d/newview/Release/$p"
  110. }
  111. # deal with aborts etc..
  112. trap fail 1 2 3 14 15
  113. # Check location
  114. cd "$here/../.."
  115. test -x ../linden/scripts/automated_build_scripts/opensrc-build.sh\
  116. || fail 'The parent dir of your checkout needs to be named "linden"'
  117. . doc/asset_urls.txt
  118. get_asset "$SLASSET_ART"
  119. # Set up platform specific stuff
  120. case "$arch" in
  121. # Note that we can only build the "Release" variant for Darwin, because of a compiler bug:
  122. # ld: bl out of range (-16777272 max is +/-16M)
  123. # from __static_initialization_and_destruction_0(int, int)at 0x033D319C
  124. # in __StaticInit of
  125. # indra/build-darwin-universal/newview/SecondLife.build/Debug/Second Life.build/Objects-normal/ppc/llvoicevisualizer.o
  126. # to ___cxa_atexit$island_2 at 0x023D50F8
  127. # in __text of
  128. # indra/build-darwin-universal/newview/SecondLife.build/Debug/Second Life.build/Objects-normal/ppc/Second Life
  129. # in __static_initialization_and_destruction_0(int, int)
  130. # from indra/build-darwin-universal/newview/SecondLife.build/Debug/Second Life.build/Objects-normal/ppc/llvoicevisualizer.o
  131. Darwin)
  132. helpers=/usr/local/buildscripts/generic_vc
  133. variants="Release"
  134. cmake_generator="Xcode"
  135. fmod=fmodapi375mac
  136. fmod_tar="$fmod.zip"
  137. fmod_so=libfmod.a
  138. fmod_lib=lib
  139. target_dirs="libraries/universal-darwin/lib_debug
  140. libraries/universal-darwin/lib_release
  141. libraries/universal-darwin/lib_release_client"
  142. other_archs="$S3GET_URL/$branch/$revision/CYGWIN $S3GET_URL/$branch/$revision/Linux"
  143. mail="$helpers"/mail.py
  144. all_done="$helpers"/all_done.py
  145. get_asset "$SLASSET_LIBS_DARWIN"
  146. ;;
  147. CYGWIN)
  148. helpers=/cygdrive/c/buildscripts
  149. variants="Debug RelWithDebInfo Release"
  150. #variants="Release"
  151. cmake_generator="vc80"
  152. fmod=fmodapi375win
  153. fmod_tar=fmodapi375win.zip
  154. fmod_so=fmodvc.lib
  155. fmod_lib=lib
  156. target_dirs="libraries/i686-win32/lib/debug
  157. libraries/i686-win32/lib/release"
  158. other_archs="$S3GET_URL/$branch/$revision/Darwin $S3GET_URL/$branch/$revision/Linux"
  159. export PATH="/cygdrive/c/Python25:/cygdrive/c/Program Files/Cmake 2.6/bin":$PATH
  160. export PERL="/cygdrive/c/Perl/bin/perl.exe"
  161. export S3CURL="C:\\buildscripts\s3curl.pl"
  162. export CURL="C:\\cygwin\\bin\\curl.exe"
  163. mail="C:\\buildscripts\\mail.py"
  164. all_done="C:\\buildscripts\\all_done.py"
  165. get_asset "$SLASSET_LIBS_WIN32"
  166. ;;
  167. Linux)
  168. helpers=/var/opt/parabuild/buildscripts/generic_vc
  169. [ x"$CXX" = x ] && test -x /usr/bin/g++-4.1 && export CXX=/usr/bin/g++-4.1
  170. acquire_lock
  171. variants="Debug RelWithDebInfo Release"
  172. #variants="Release"
  173. cmake_generator="Unix Makefiles"
  174. fmod=fmodapi375linux
  175. fmod_tar="$fmod".tar.gz
  176. fmod_so=libfmod-3.75.so
  177. fmod_lib=.
  178. target_dirs="libraries/i686-linux/lib_debug
  179. libraries/i686-linux/lib_release
  180. libraries/i686-linux/lib_release_client"
  181. other_archs="$S3GET_URL/$branch/$revision/Darwin $S3GET_URL/$branch/$revision/CYGWIN"
  182. mail="$helpers"/mail.py
  183. all_done="$helpers"/all_done.py
  184. # Change the DISTCC_DIR to be somewhere that the parabuild process can write to
  185. if test -r /etc/debian_version
  186. then
  187. [ x"$DISTCC_DIR" = x ] && export DISTCC_DIR=/var/tmp/parabuild
  188. case `cat /etc/debian_version` in
  189. 3.*) [ x"$DISTCC_HOSTS" = x ]\
  190. && export DISTCC_HOSTS="build-linux-1
  191. build-linux-2
  192. build-linux-3
  193. build-linux-4
  194. build-linux-5" ;;
  195. 4.*) [ x"$DISTCC_HOSTS" = x ]\
  196. && export DISTCC_HOSTS="build-linux-6
  197. build-linux-7
  198. build-linux-8
  199. build-linux-9" ;;
  200. esac
  201. fi
  202. get_asset "$SLASSET_LIBS_LINUXI386"
  203. ;;
  204. *) fail undefined $arch ;;
  205. esac
  206. get_asset "http://www.fmod.org/index.php/release/version/$fmod_tar"
  207. # Special case for Mac...
  208. case "$arch" in
  209. Darwin)
  210. if lipo -create -output "../$fmod"/api/$fmod_lib/libfmod-universal.a\
  211. "../$fmod"/api/$fmod_lib/libfmod.a\
  212. "../$fmod"/api/$fmod_lib/libfmodx86.a
  213. then
  214. mv "../$fmod"/api/$fmod_lib/libfmod.a "../$fmod"/api/$fmod_lib/libfmodppc.a
  215. mv "../$fmod"/api/$fmod_lib/libfmod-universal.a "../$fmod"/api/$fmod_lib/libfmod.a
  216. echo Created fat binary
  217. else
  218. fail running lipo
  219. fi
  220. ;;
  221. esac
  222. # ensure helpers are up to date
  223. ( cd "$helpers" && svn up )
  224. # First, go into the directory where the code was checked out by Parabuild
  225. cd indra
  226. # This is the way it works now, but it will soon work on a variant dependent way
  227. for target_dir in $target_dirs
  228. do
  229. mkdir -p "../$target_dir"
  230. cp -f "../../$fmod/api/$fmod_lib/$fmod_so" "../$target_dir"
  231. done
  232. mkdir -p "../libraries/include"
  233. cp -f "../../$fmod/api/inc/"* "../libraries/include"
  234. # Special Windows case
  235. test -r "../../$fmod/api/fmod.dll" && cp -f "../../$fmod/api/fmod.dll" newview
  236. # Now run the build command over all variants
  237. succeeded=true
  238. cp /dev/null build.log
  239. ### TEST CODE - remove when done
  240. ### variants=
  241. ### echo "Artificial build failure to test notifications" > build.log
  242. ### succeeded=false
  243. ### END TEST CODE
  244. for variant in $variants
  245. do
  246. build_dir=`build_dir_$arch $variant`
  247. rm -rf "$build_dir"
  248. # This is the way it will work in future
  249. #for target_dir in $target_dirs
  250. #do
  251. # mkdir -p "$build_dir/$target_dir"
  252. # cp "../../$fmod/api/$fmod_lib/$fmod_so" "$build_dir/$target_dir"
  253. #done
  254. #mkdir -p "$build_dir/libraries/include"
  255. #cp "../../$fmod/api/inc/"* "$build_dir/libraries/include"
  256. echo "==== $variant ====" >> build.log
  257. if ./develop.py \
  258. --unattended \
  259. --incredibuild \
  260. -t $variant \
  261. -G "$cmake_generator" \
  262. configure \
  263. -DPACKAGE:BOOL=ON >>build.log 2>&1
  264. then
  265. if ./develop.py\
  266. --unattended\
  267. --incredibuild \
  268. -t $variant\
  269. -G "$cmake_generator" \
  270. build package >>build.log 2>&1
  271. then
  272. # run tests if needed
  273. true
  274. else
  275. succeeded=false
  276. fi
  277. else
  278. succeeded=false
  279. fi
  280. done
  281. # check statuis and upload results to S3
  282. subject=
  283. if $succeeded
  284. then
  285. package=`installer_$arch`
  286. test -r "$package" || fail not found: $package
  287. package_file=`echo $package | sed 's:.*/::'`
  288. if s3_available
  289. then
  290. echo "$PUBLIC_URL/$branch/$revision/$package_file" > "$arch"
  291. echo "$PUBLIC_URL/$branch/$revision/good-build.$arch" >> "$arch"
  292. "$helpers/s3put.sh" "$package" "$S3PUT_URL/$branch/$revision/$package_file" binary/octet-stream\
  293. || fail Uploading "$package"
  294. "$helpers/s3put.sh" build.log "$S3PUT_URL/$branch/$revision/good-build.$arch" text/plain\
  295. || fail Uploading build.log
  296. "$helpers/s3put.sh" "$arch" "$S3PUT_URL/$branch/$revision/$arch" text/plain\
  297. || fail Uploading token file
  298. if python "$all_done"\
  299. curl\
  300. "$S3GET_URL/$branch/$revision/$arch"\
  301. $other_archs > message
  302. then
  303. subject="Successful Build for $branch ($revision)"
  304. fi
  305. else
  306. true s3 is not available
  307. fi
  308. else
  309. if s3_available
  310. then
  311. "$helpers/s3put.sh" build.log "$S3PUT_URL/$branch/$revision/failed-build.$arch" text/plain\
  312. || fail Uploading build.log
  313. subject="Failed Build for $branch ($revision) on $arch"
  314. cat >message <<EOF
  315. Build for $branch ($revision) failed for $arch.
  316. Please see the build log for details:
  317. $PUBLIC_URL/$branch/$revision/failed-build.$arch
  318. EOF
  319. else
  320. true s3 is not available
  321. fi
  322. fi
  323. # We have something to say...
  324. if [ x"$subject" != x ]
  325. then
  326. # Extract change list since last build
  327. if [ x"$PARABUILD_CHANGE_LIST_NUMBER" = x ]
  328. then
  329. echo "No change information available" >> message
  330. elif [ x"$PARABUILD_PREVIOUS_CHANGE_LIST_NUMBER" = x ]
  331. then
  332. ( cd .. && svn log --verbose --stop-on-copy --limit 50 ) >>message
  333. else
  334. ( cd .. && svn log --verbose -r"$PARABUILD_PREVIOUS_CHANGE_LIST_NUMBER":"$PARABUILD_CHANGE_LIST_NUMBER" ) >>message
  335. fi
  336. # $PUBLIC_EMAIL can be a list, so no quotes
  337. python "$mail" "$subject" $PUBLIC_EMAIL <message
  338. fi
  339. if $succeeded
  340. then
  341. pass
  342. else
  343. fail
  344. fi