Renato Golin | 8ad9fca | 2016-10-12 12:24:29 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # This script builds LLVM overnight in debug mode, so that daily investigations |
| 4 | # of buildbot breakage can be done quickly without requiring a full build. |
| 5 | # |
| 6 | # The script is meant to be set on a cronjab for early morning build. It'll |
| 7 | # default to debug build, as this is the most useful build for investigations. |
| 8 | # |
| 9 | # Syntax: env <environment variables> llvm-cron-build <environment-name> |
| 10 | # |
| 11 | # If the environment's name is "arm", it'll add -marm flags, if the name is |
| 12 | # "thumb", it'll add -mthumb. Otherwise, it'll be a simple call to llvm-build. |
| 13 | # Both ARM and Thumb builds will have "-mcpu=cortex-a15" added to match bots. |
| 14 | # |
| 15 | # Since these environments are just for debugging, we'll also force Clang+RT |
| 16 | # projects, instead of leaving it free to choose. |
| 17 | # |
| 18 | # The environment variables tracked are CC/CXX and CFLAGS/CXXFLAGS. |
| 19 | # |
| 20 | # To install in the crontab every midnight, use: |
| 21 | # 0 0 * * * bash -i <path-to-helpers>/llvm-cron-build <name> |
| 22 | |
| 23 | # Pre-run checks, make sure we only run when we can |
| 24 | ROOT=$(dirname "$0") |
| 25 | BIN=$(basename "$0") |
| 26 | log="$HOME/$1.llvm-cron.log" |
| 27 | err="$HOME/$1.llvm-cron.err" |
| 28 | |
| 29 | if [ "$1" = "" ]; then |
| 30 | echo "Syntax: $BIN <environment-name>" > "$err" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | # Make sure we're not already running |
| 35 | if [ "$(ps awwux | grep -v grep | grep "$BIN")" != "" ]; then |
| 36 | echo "Already running, won't flog" > "$err" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | # Make sure machine is idle for long enough (load avg in cents) |
| 41 | loadavg=$(awk '{print $1}' /proc/loadavg | sed -e 's/0*\.0*//') |
| 42 | if [[ $loadavg -gt 100 ]]; then |
| 43 | echo "Machine too busy or still recuperating" > "$err" |
| 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | # Crontab-specific, make sure the helpers directory is in the path |
| 48 | if [ $(echo "$PATH" | grep "$ROOT") == "" ]; then |
| 49 | PATH="$PATH":"$ROOT" |
| 50 | fi |
| 51 | |
| 52 | # Start the actual script |
| 53 | . llvm-common |
| 54 | |
| 55 | # Update compiler flags |
| 56 | case $1 in |
| 57 | arm) |
| 58 | CFLAGS="$CFLAGS -mcpu=cortex-a15 -marm" |
| 59 | CXXFLAGS="$CXXFLAGS -mcpu=cortex-a15 -marm" |
| 60 | ;; |
| 61 | thumb) |
| 62 | CFLAGS="$CFLAGS -mcpu=cortex-a15 -mthumb" |
| 63 | CXXFLAGS="$CXXFLAGS -mcpu=cortex-a15 -mthumb" |
| 64 | ;; |
| 65 | *) |
| 66 | ;; |
| 67 | esac |
| 68 | |
| 69 | echo "Start date: $(date)" > "$log" |
| 70 | |
| 71 | PS1=" " # hack to trick llvm-env |
| 72 | # Checkout the environment (create if doesn't exist) in debug mode |
| 73 | safe_run . llvm-env "$1" -d >> "$log" 2>&1 |
| 74 | # Update the projects to Clang+RT |
| 75 | safe_run llvm-projs rt >> "$log" 2>&1 |
| 76 | # Pull recent changes |
| 77 | safe_run llvm-sync >> "$log" 2>&1 |
| 78 | # Call llvm-build (no tests wanted) |
| 79 | env CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" llvm-build >> "$log" 2>&1 |
| 80 | |
| 81 | echo "Finish date: $(date)" > "$log" |