-
Notifications
You must be signed in to change notification settings - Fork 14
/
run-docker-builder
executable file
·123 lines (110 loc) · 3.08 KB
/
run-docker-builder
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
set -e
LOCAL_FILE=$(realpath "$1")
COMPILER=$2
OPTIM_FLAG=$3
VERSION_FLAG=$4
CLEAN_CACHE=$6
LIB_VERSION=$7
FILE_NAME=$8.cpp
RECORD_ASM=$9
RECORD_PP=${10}
ADDITIONAL_FLAGS=${*:11}
if ! [[ $COMPILER == "clang-"?*"."? || $COMPILER == "gcc-"?*"."? ]] ; then
>&2 echo "Unknown compiler"
exit 1
fi
if [ "$OPTIM_FLAG" == 0 ]; then
OPTIM=""
elif [ "$OPTIM_FLAG" == 1 ]; then
OPTIM="-O1"
elif [ "$OPTIM_FLAG" == 2 ]; then
OPTIM="-O2"
elif [ "$OPTIM_FLAG" == 3 ]; then
OPTIM="-O3"
elif [ "$OPTIM_FLAG" == "S" ]; then
OPTIM="-Os"
elif [ "$OPTIM_FLAG" == "G" ]; then
OPTIM="-Og"
elif [ "$OPTIM_FLAG" == "F" ]; then
OPTIM="-Ofast"
else
>&2 echo "Unsupported optimization flag ${OPTIM_FLAG}"
exit 1
fi
if [[ $VERSION_FLAG =~ c\+\+[0-9][0-9a-z] ]]; then
VERSION="-std=${VERSION_FLAG}"
else
>&2 echo "Unknown STD version"
exit 1
fi
if [[ $ADDITIONAL_FLAGS =~ \B(?!\-f) ]]; then
>&2 echo "Unsupported flag"
exit 1
fi
LOCK=$LOCAL_FILE.lock
lockfile "$LOCK"
INFILE=$LOCAL_FILE.cpp
OUTFILE=$LOCAL_FILE.build
INCLUDES=$LOCAL_FILE.inc
ASM=$LOCAL_FILE.s
PP=$LOCAL_FILE.i
CIDFILE=$LOCAL_FILE.cid
CONTAINERFILE=$LOCAL_FILE.cont
if [ "$CLEAN_CACHE" = true ] && [ -f "$OUTFILE" ]; then
rm "$OUTFILE"
rm -f "$INCLUDES"
rm -f "$ASM"
rm -f "$PP"
fi
if [ -f "$OUTFILE" ]; then
>&2 echo "Showing cached results"
else
touch "$OUTFILE"
chmod 666 "$OUTFILE"
touch "$INCLUDES"
chmod 666 "$INCLUDES"
if [ -z "$UNLIMITED_RESOURCES" ]; then
MEMORY_LIMITS='--memory=500m --cpu-period=100000 --cpu-quota=25000'
fi
if [[ $LIB_VERSION == llvm ]] && [[ $COMPILER == clang* ]]; then
BUILD_COMMAND=time-build-libcxx
PREBUILD_COMMAND=prebuild-libcxx
else
BUILD_COMMAND=time-build
PREBUILD_COMMAND=prebuild
fi
if [ "$RECORD_PP" = true ]; then
touch "$PP"
chmod 666 "$PP"
PP_OUT="docker cp \$CONTAINER:/home/builder/bench.i $PP"
fi
if [ "$RECORD_ASM" != "none" ]; then
touch "$ASM"
chmod 666 "$ASM"
ASM_OUT="docker cp \$CONTAINER:/home/builder/bench.s $ASM"
fi
PREBUILD_PARAMS="$RECORD_PP $RECORD_ASM"
if [ -z ${BB_TIMEOUT+x} ]; then
ENV_PARAMS="-e BB_TIMEOUT=$BB_TIMEOUT"
fi
if [ -z ${BB_MAX_ITERATION+x} ]; then
ENV_PARAMS="$ENV_PARAMS -e BB_MAX=$BB_MAX_ITERATION"
fi
CONTAINER=$(docker create $ANNOTATE $MEMORY_LIMITS \
--cidfile="$CIDFILE" \
$ENV_PARAMS \
fredtingaud/quick-bench:"$COMPILER" /bin/bash -c "./$PREBUILD_COMMAND $FILE_NAME $PREBUILD_PARAMS $OPTIM $VERSION $ADDITIONAL_FLAGS && ./$BUILD_COMMAND $FILE_NAME $OPTIM $VERSION $ADDITIONAL_FLAGS"
)
echo "$CONTAINER" > "$CONTAINERFILE"
docker cp "$INFILE" "$CONTAINER":/home/builder/"$FILE_NAME"
docker start -a "$CONTAINER"
docker cp "$CONTAINER":/home/builder/bench.out "$OUTFILE"
docker cp "$CONTAINER":/home/builder/bench.inc "$INCLUDES"
eval $PP_OUT
eval $ASM_OUT
docker rm "$CONTAINER"
rm "$CONTAINERFILE"
rm "$CIDFILE"
fi
rm -f "$LOCK"