| #!/usr/bin/env bash |
| # |
| # This script builds LLVM overnight in debug mode, so that daily investigations |
| # of buildbot breakage can be done quickly without requiring a full build. |
| # |
| # The script is meant to be set on a cronjab for early morning build. It'll |
| # default to debug build, as this is the most useful build for investigations. |
| # |
| # Syntax: env <environment variables> llvm-cron-build <environment-name> |
| # |
| # If the environment's name is "arm", it'll add -marm flags, if the name is |
| # "thumb", it'll add -mthumb. Otherwise, it'll be a simple call to llvm-build. |
| # Both ARM and Thumb builds will have "-mcpu=cortex-a15" added to match bots. |
| # |
| # Since these environments are just for debugging, we'll also force Clang+RT |
| # projects, instead of leaving it free to choose. |
| # |
| # The environment variables tracked are CC/CXX and CFLAGS/CXXFLAGS. |
| # |
| # To install in the crontab every midnight, use: |
| # 0 0 * * * bash -i <path-to-helpers>/llvm-cron-build <name> |
| |
| # Pre-run checks, make sure we only run when we can |
| ROOT=$(dirname "$0") |
| BIN=$(basename "$0") |
| log="$HOME/$1.llvm-cron.log" |
| err="$HOME/$1.llvm-cron.err" |
| |
| if [ "$1" = "" ]; then |
| echo "Syntax: $BIN <environment-name>" > "$err" |
| exit 1 |
| fi |
| |
| # Make sure we're not already running |
| PID=$$ |
| PREVPID=$((PID-1)) # Cron starts sh -c '$JOB' |
| if ps awwux | grep -v grep | grep -v "$PID" | grep -v "$PREVPID" | grep "$BIN" > /dev/null; then |
| echo "Already running, won't flog" > "$err" |
| exit 1 |
| fi |
| |
| # Make sure machine is idle for long enough (load avg in cents) |
| loadavg=$(awk '{print $1}' /proc/loadavg | sed -e 's/0*\.0*//') |
| if [[ $loadavg -gt 100 ]]; then |
| echo "Machine too busy or still recuperating" > "$err" |
| exit 1 |
| fi |
| |
| # Crontab-specific, make sure the helpers directory is in the path |
| if [ "$(echo "$PATH" | grep "$ROOT")" = "" ]; then |
| PATH="$PATH":"$ROOT" |
| fi |
| |
| # Start the actual script |
| . llvm-common |
| |
| # Update compiler flags |
| case $1 in |
| arm) |
| CFLAGS="$CFLAGS -mcpu=cortex-a15 -marm" |
| CXXFLAGS="$CXXFLAGS -mcpu=cortex-a15 -marm" |
| ;; |
| thumb) |
| CFLAGS="$CFLAGS -mcpu=cortex-a15 -mthumb" |
| CXXFLAGS="$CXXFLAGS -mcpu=cortex-a15 -mthumb" |
| ;; |
| *) |
| ;; |
| esac |
| |
| echo "Start date: $(date)" > "$log" |
| |
| PS1=" " # hack to trick llvm-env |
| # Checkout the environment (create if doesn't exist) in debug mode |
| safe_run . llvm-env "$1" -d >> "$log" 2>&1 |
| # Update the projects to Clang+RT |
| safe_run llvm-projs rt >> "$log" 2>&1 |
| # Pull recent changes |
| safe_run llvm-sync >> "$log" 2>&1 |
| # Call llvm-build (no tests wanted) |
| env CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" llvm-build -v >> "$log" 2>&1 |
| |
| echo "Finish date: $(date)" >> "$log" |