blob: 5ec4a4ca0879d7139111cc297ed31b4af8b169a4 [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
35if [ "$(ps awwux | grep -v grep | grep "$BIN")" != "" ]; then
36 echo "Already running, won't flog" > "$err"
37 exit 1
38fi
39
40# Make sure machine is idle for long enough (load avg in cents)
41loadavg=$(awk '{print $1}' /proc/loadavg | sed -e 's/0*\.0*//')
42if [[ $loadavg -gt 100 ]]; then
43 echo "Machine too busy or still recuperating" > "$err"
44 exit 1
45fi
46
47# Crontab-specific, make sure the helpers directory is in the path
48if [ $(echo "$PATH" | grep "$ROOT") == "" ]; then
49 PATH="$PATH":"$ROOT"
50fi
51
52# Start the actual script
53. llvm-common
54
55# Update compiler flags
56case $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 ;;
67esac
68
69echo "Start date: $(date)" > "$log"
70
71PS1=" " # hack to trick llvm-env
72# Checkout the environment (create if doesn't exist) in debug mode
73safe_run . llvm-env "$1" -d >> "$log" 2>&1
74# Update the projects to Clang+RT
75safe_run llvm-projs rt >> "$log" 2>&1
76# Pull recent changes
77safe_run llvm-sync >> "$log" 2>&1
78# Call llvm-build (no tests wanted)
79env CC="$CC" CXX="$CXX" CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" llvm-build >> "$log" 2>&1
80
81echo "Finish date: $(date)" > "$log"