blob: d4339038cd0861684e02d012396a38742569837b [file] [log] [blame]
Renato Golin8ad9fca2016-10-12 12:24:29 +01001#!/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
24ROOT=$(dirname "$0")
25BIN=$(basename "$0")
26log="$HOME/$1.llvm-cron.log"
27err="$HOME/$1.llvm-cron.err"
28
29if [ "$1" = "" ]; then
30 echo "Syntax: $BIN <environment-name>" > "$err"
31 exit 1
32fi
33
34# Make sure we're not already running
Renato Golin22e10272016-10-20 16:03:20 +010035PID=$$
36PREVPID=$((PID-1)) # Cron starts sh -c '$JOB'
37if ps awwux | grep -v grep | grep -v "$PID" | grep -v "$PREVPID" | grep "$BIN" > /dev/null; then
Renato Golin8ad9fca2016-10-12 12:24:29 +010038 echo "Already running, won't flog" > "$err"
39 exit 1
40fi
41
42# Make sure machine is idle for long enough (load avg in cents)
43loadavg=$(awk '{print $1}' /proc/loadavg | sed -e 's/0*\.0*//')
44if [[ $loadavg -gt 100 ]]; then
45 echo "Machine too busy or still recuperating" > "$err"
46 exit 1
47fi
48
49# Crontab-specific, make sure the helpers directory is in the path
Renato Golin27a7ba12016-10-12 14:22:15 +010050if [ "$(echo "$PATH" | grep "$ROOT")" = "" ]; then
Renato Golin8ad9fca2016-10-12 12:24:29 +010051 PATH="$PATH":"$ROOT"
52fi
53
54# Start the actual script
55. llvm-common
56
57# Update compiler flags
58case $1 in
59 arm)
60 CFLAGS="$CFLAGS -mcpu=cortex-a15 -marm"
61 CXXFLAGS="$CXXFLAGS -mcpu=cortex-a15 -marm"
62 ;;
63 thumb)
64 CFLAGS="$CFLAGS -mcpu=cortex-a15 -mthumb"
65 CXXFLAGS="$CXXFLAGS -mcpu=cortex-a15 -mthumb"
66 ;;
67 *)
68 ;;
69esac
70
71echo "Start date: $(date)" > "$log"
72
73PS1=" " # hack to trick llvm-env
74# Checkout the environment (create if doesn't exist) in debug mode
75safe_run . llvm-env "$1" -d >> "$log" 2>&1
76# Update the projects to Clang+RT
77safe_run llvm-projs rt >> "$log" 2>&1
78# Pull recent changes
79safe_run llvm-sync >> "$log" 2>&1
80# Call llvm-build (no tests wanted)
81env CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" llvm-build >> "$log" 2>&1
82
83echo "Finish date: $(date)" > "$log"