aboutsummaryrefslogtreecommitdiff
path: root/helpers/llvm-cron-build
blob: a0af6803cd13f0deb90add565d9cebb7bc5714e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/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
if ps awwux | grep -v grep | grep -v $$ | 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 >> "$log" 2>&1

echo "Finish date: $(date)" > "$log"