-
Notifications
You must be signed in to change notification settings - Fork 4
/
mkconf
executable file
·229 lines (201 loc) · 6.47 KB
/
mkconf
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash
set -e
die() {
echo >&2 "ERROR: $*"
exit 1
}
# emulate gitalb-ci environment when run from working copy
: ${CI_COMMIT_REF_NAME:=$(git symbolic-ref --short HEAD)}
: ${CI_COMMIT_SHA:=$(git rev-parse "${CI_COMMIT_REF_NAME}")}
B=""
TEMPLATECONF=""
GEN=""
DL_DIR=""
HISTREPO=""
HISTREF=""
PRSERV=""
OEENV="poky/oe-init-build-env"
while [ $# -gt 1 ]; do
case "$1" in
--dir)
B="$2"
shift
;;
--template-conf)
TEMPLATECONF="$2"
shift
;;
--sstate-gen)
GEN="$2"
shift
;;
--download-dir)
DL_DIR="$2"
shift
;;
--buildhistory-repo)
HISTREPO="$2"
shift
;;
--buildhistory-ref)
HISTREF="$2"
shift
;;
--prserv)
PRSERV="$2"
shift
;;
--oe-env)
OEENV="${2}"
shift
;;
--)
shift
break
;;
-*)
die "unknown flag '$1'"
;;
*)
break
;;
esac
shift
done
[ -n "$B" ] || die "missing --dir"
[ -n "$TEMPLATECONF" ] || die "missing --template-conf"
[ -n "$GEN" ] || die "missing --sstate-gen"
[ -n "$DL_DIR" ] || die "missing --download-dir"
[ -r "$OEENV" ] || die "cannot read '$OEENV', adjust with --oe-env"
if [ -n "$HISTREPO" -a -z "$HISTREF" ]; then
die "--buildhistory-repo requries --buildhistory-ref"
fi
if [ -n "$HISTREF" -a -z "$HISTREPO" ]; then
die "--buildhistory-ref requries --buildhistory-repo"
fi
TOP=$(pwd)
SSTATE="${HOME}/sstate-cache-$GEN"
# make sure any old config has been migrated
if [ -n "$BASEGEN_ALLOWED_BRANCHES" ]; then
die "BASEGEN_ALLOWED_BRANCHES has been replaced with 'permissions' file in sstate"
fi
# check we have permission to contribute to this sstate
if [ -r "${SSTATE}/permissions" ]; then
# permissions provided: repo MUST match one line
while true; do
while IFS='|' read repo branches tagpatterns _futurestuff; do
if [ -n "$futurestuff" ]; then
die "this script only knows 'repo|branches|tagpatterns', cannot parse '$_futurestuff'"
fi
if [ "$repo" != "${CI_PROJECT_URL}" ]; then
# line does not describe this repo
continue
fi
# here repo has been found
if [ -n "${CI_COMMIT_TAG}" ]; then
if [ -z "$tagpatterns" ]; then
# no pattern: all tags accepted
break 2
fi
# "for tagpattern in $tagpatterns" while protecting from glob expansion
tmpfile=$(mktemp)
echo "$tagpatterns " | tr ' ' '\n' > "$tmpfile"
while < "$tmpfile" read tagpattern; do
case "${CI_COMMIT_TAG}" in
$tagpattern)
# tag matched
rm "$tmpfile"
break 3 ;;
esac
done
rm "$tmpfile"
die "REPO='${CI_PROJECT_URL}' is authorized by \"permissions\" file, but tag '${CI_COMMIT_TAG}' does not match any pattern in '${tagpatterns}'"
elif [ -n "${CI_COMMIT_BRANCH}" ]; then
if [ -z "$branches" ]; then
# empty list: all branches accepted
break 2
fi
for branch in $branches; do
if [ $branch = "${CI_COMMIT_BRANCH}" ]; then
# branch matched
break 3
fi
done
die "REPO='${CI_PROJECT_URL}' is authorized by \"permissions\" file, but BRANCH='${CI_COMMIT_BRANCH}' does not match any in '$branches'"
else
die "REPO='${CI_PROJECT_URL}' is authorized by \"permissions\" file, but '${CI_COMMIT_REF_NAME}' is not an authorized branch or tag"
fi
# not reached
die "internal error, reached unreachable statement at line $LINENO"
done < "${SSTATE}/permissions"
# repo was not found
die "sstate managed by \"permissions\" file, but REPO='${CI_PROJECT_URL}' is not authorized there"
done
# break's bring us here: permission granted
echo "permission granted to contribute to shared-state"
fi
SSTATE_MIRRORS=""
case "$GEN" in
*+*)
BASEGEN=$GEN
while true; do
case "$BASEGEN" in
*+*)
BASEGEN=${BASEGEN%+*}
SSTATE_MIRRORS="$SSTATE_MIRRORS ${HOME}/sstate-cache-$BASEGEN"
;;
*)
break
;;
esac
done
;;
esac
if [ -r "$B"/conf/local.conf ]; then
. "$OEENV" "$B"
else
TEMPLATECONF="$TEMPLATECONF" . "$OEENV" "$B"
echo "$OEENV" > conf/oe-env
# make sure the branch is current so shadow-image identifies
# BRANCHNAME (unless CI_COMMIT_REF_NAME does not match the sha -
# maybe for rebuilds of older versions ? Or should we just "git
# branch -f" all the time ?)
UPSTREAMSHA=$(git rev-parse "origin/${CI_COMMIT_REF_NAME}")
if [ "$UPSTREAMSHA" = "${CI_COMMIT_SHA}" ]; then
git branch -f "${CI_COMMIT_REF_NAME}" "origin/${CI_COMMIT_REF_NAME}"
git checkout "${CI_COMMIT_REF_NAME}"
# assert we did not change sha1
test $(git rev-parse HEAD) = ${CI_COMMIT_SHA}
fi
if [ -n "$HISTREPO" ]; then
git clone "$HISTREPO" buildhistory
git -C buildhistory checkout "$HISTREF"
cat >> "conf/local.conf" <<EOF
INHERIT += "buildhistory"
BUILDHISTORY_COMMIT = "1"
BUILDHISTORY_FEATURES = "image"
EOF
fi
# adjust conf
cat >> "conf/local.conf" <<EOF
DL_DIR = "${DL_DIR}"
SSTATE_DIR = "${SSTATE}"
RM_WORK_EXCLUDE = ""
INHERIT += "buildstats"
INHERIT += "buildstats-summary"
EOF
if [ -n "$SSTATE_MIRRORS" ]; then
echo 'SSTATE_MIRRORS ?= "\' >> "conf/local.conf"
for m in $SSTATE_MIRRORS; do
echo "file://.* file://$m/PATH \\n \\" >> "conf/local.conf"
done
echo '"' >> "conf/local.conf"
fi
if [ -n "$PRSERV" ]; then
sed -i 's/^PRSERV_HOST = .*/PRSERV_HOST = "'"$PRSERV"'"/' "conf/local.conf"
fi
if [ -r $TOP/ci-mkconf-hook.sh ]; then
echo "Running hook ci-mkconf-hook.sh"
. $TOP/ci-mkconf-hook.sh
fi
fi