forked from compiler-explorer/infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathone-off-cross.sh
executable file
·122 lines (100 loc) · 2.97 KB
/
one-off-cross.sh
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
#!/bin/bash
REPO=$1
SCRIPTNAME=$2
ARCHITECTURE=$3
VERSION=$4
TMPNAME="${REPO}_${ARCHITECTURE}_${VERSION}_$(date +%Y%m%d%H%M)"
showhelp() {
echo "Usage ./one-off-cross.sh <reponame> build.sh <architecture> <version>"
}
if [[ "${REPO}" == "" ]]; then
showhelp
exit
fi
if [[ "${SCRIPTNAME}" == "" ]]; then
showhelp
exit
fi
if [[ "${ARCHITECTURE}" == "" ]]; then
showhelp
exit
fi
if [[ "${VERSION}" == "" ]]; then
showhelp
exit
fi
set -exuo pipefail
finish() {
ce builder stop
}
trap finish EXIT
ce builder status
ce builder start
LOG_DIR=~/build_logs
BUILD_FAILED=0
run_on_build() {
local logdir=${LOG_DIR}/$1
local revisionfile=$2
mkdir -p "${logdir}"
shift 2
set +e
date >"${logdir}/begin"
local CE_BUILD_RESULT=""
if ! ce builder exec -- "$@" |& tee "${logdir}/log"; then
BUILD_FAILED=1
CE_BUILD_RESULT=FAILED
else
CE_BUILD_RESULT=OK
fi
local CE_BUILD_STATUS
CE_BUILD_STATUS=$(grep -P "^ce-build-status:" "${logdir}/log" | cut -d ':' -f 2-)
if [[ -z "${CE_BUILD_STATUS}" ]]; then
CE_BUILD_STATUS=${CE_BUILD_RESULT}
fi
echo "${CE_BUILD_STATUS}" >"${logdir}/status"
if [[ "${CE_BUILD_RESULT}" == "OK" ]]; then
local REVISION
REVISION=$(grep -P "^ce-build-revision:" "${logdir}/log" | cut -d ':' -f 2-)
if [[ -n "${REVISION}" ]]; then
echo "${REVISION}" >"${revisionfile}"
fi
fi
if [[ "${CE_BUILD_STATUS}" == "OK" ]]; then
date >"${logdir}/last_success"
fi
date >"${logdir}/end"
set -e
}
build_latest() {
local IMAGE=$1
local BUILD_NAME=$2
local COMMAND=$3
local BUILD=$4
local REVISION_FILENAME=/opt/.buildrevs/${BUILD_NAME}
local REVISION=""
if [[ -f "${REVISION_FILENAME}" ]]; then
REVISION=$(cat "${REVISION_FILENAME}")
fi
run_on_build "${BUILD_NAME}" "${REVISION_FILENAME}" \
sudo docker run --rm --name "${BUILD_NAME}.build" -v/home/ubuntu/.s3cfg:/root/.s3cfg:ro -e 'LOGSPOUT=ignore' \
"compilerexplorer/${IMAGE}-builder" \
bash "${COMMAND}" "${BUILD}" s3://compiler-explorer/opt/ "${REVISION}"
log_to_json ${LOG_DIR} admin
}
build_latest_cross() {
local IMAGE=$1
local BUILD_NAME=$2
local COMMAND=$3
local ARCH=$4
local BUILD=$5
# We don't support the "revision" for cross compilers. I looked briefly at adding it
# using `ct-ng sources` and similar magic, but the number of dependencies (e.g. linux source, gcc trunk)
# means we'll almost certainly be different every time anyway.
run_on_build "${BUILD_NAME}" /dev/null \
sudo docker run --rm --name "${BUILD_NAME}.build" -v/home/ubuntu/.s3cfg:/home/gcc-user/.s3cfg:ro -e 'LOGSPOUT=ignore' \
"compilerexplorer/${IMAGE}-cross-builder" \
bash "${COMMAND}" "${ARCH}" "${BUILD}" s3://compiler-explorer/opt/
log_to_json ${LOG_DIR} admin
}
build_latest_cross ${REPO} ${TMPNAME} ${SCRIPTNAME} ${ARCHITECTURE} ${VERSION}
exit ${BUILD_FAILED}