PageRenderTime 27ms CodeModel.GetById 2ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

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