Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/build-master-status
blob: 72b9f7e862e40e30e758ea4aac861e5bbdf43a44 (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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
#!/bin/sh

# report about status of build master

# shellcheck source=conf/default.conf
. "${0%/*}/../conf/default.conf"

usage() {
  >&2 echo ''
  >&2 echo 'build-master-status: report about status of build master'
  >&2 echo ''
  >&2 echo 'possible options:'
  >&2 echo '  -w|--web:'
  >&2 echo '    Output to webserver instead of stdout.'
  >&2 echo '  -h|--help:'
  >&2 echo '    Show this help and exit.'
  [ -z "$1" ] && exit 1 || exit "$1"
}

eval set -- "$(
  getopt -o hw \
    --long help \
    --long web \
    -n "$(basename "$0")" -- "$@" || \
  echo usage
)"

web=false

while true
do
  case "$1" in
    -h|--help)
      usage 0
    ;;
    -w|--web)
      web=true
    ;;
    --)
      shift
      break
    ;;
    *)
      >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.'
      exit 42
    ;;
  esac
  shift
done

if [ $# -ne 0 ]; then
  >&2 echo 'Too many arguments.'
  usage
fi

tmp_dir=$(mktemp -d)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT

stable=$(
  ls_master_mirror 'i686' | \
    grep -v 'testing$\|staging$\|-unstable$' | \
    while read -r dir; do
      ls_master_mirror "i686/${dir}"
    done | \
    grep -c '\.pkg\.tar\.xz$'
)
tasks=$(
  grep -c '^\S\+ \S\+ \S\+ \S\+$' \
    "${work_dir}/build-list"
) || true
pending_packages=$(
  grep '^\S\+ \S\+ \S\+ \S\+$' "${work_dir}/build-list" | \
    tr ' ' '.' | \
    while read -r package; do
      generate_package_metadata "${package}" 2>&1 > /dev/null
      cat "${work_dir}/package-infos/${package}.packages"
    done |
    wc -l
)
next_tasks=$(
  (
    grep -vxF 'break_loops' "${work_dir}/build-list"
    find "${work_dir}/package-states" -maxdepth 1 -name '*.broken' -printf '%f\n' | \
      sed '
        s|\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)\.[^.]\+$| \1 \2 \3|
        p
      '
  ) | \
    sort | \
    uniq -u | \
    while read -r package git_revision mod_git_revision repository; do
      if [ -z "$(find_dependencies_on_build_list "${package}" "${git_revision}" "${mod_git_revision}" "${repository}")" ]; then
        echo "${package}" "${git_revision}" "${mod_git_revision}" "${repository}"
      fi
    done | \
    wc -l
)
staging=$(
  ls_master_mirror 'i686' | \
    grep 'staging$' | \
    while read -r dir; do
      ls_master_mirror "i686/${dir}"
    done | \
    grep -c '\.pkg\.tar\.xz$'
) || true
testing=$(
  ls_master_mirror 'i686' | \
    grep 'testing$' | \
    while read -r dir; do
      ls_master_mirror "i686/${dir}"
    done | \
    grep -c '\.pkg\.tar\.xz$'
) || true
(
  find "${work_dir}/package-states/" -maxdepth 1 -name '*.broken' -printf '%f\n' | \
    sed 's|\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)\.[^.]\+$| \1 \2 \3|' | \
    while read -r pkg rev mod_rev repo; do
      if [ -z "$(find_dependencies_on_build_list "${pkg}" "${rev}" "${mod_rev}" "${repo}")" ]; then
        echo "${pkg}"
      fi
    done
  (
    find "${work_dir}/build-list.loops" -maxdepth 1 -regextype grep \
      -regex '.*/loop_[0-9]\+' \
      -exec cat {} \; | \
      sort -u
    find "${work_dir}/package-states/" -maxdepth 1 -name '*.broken' -printf '%f\n' | \
      sed 's|\(\.[^.]\+\)\{4\}||' | \
      sort -u
  ) | \
    sort | \
    uniq -d
) | \
  sort -u > \
  "${tmp_dir}/broken-packages-names"
broken=$(
  wc -l < \
    "${tmp_dir}/broken-packages-names"
)
blocked=$(
  find "${work_dir}/package-states/" -maxdepth 1 -name '*.blocked' | \
    wc -l
)
locked=$(
  find "${work_dir}/package-states/" -maxdepth 1 -name '*.locked' | \
    wc -l
)
loops=$(
  find "${work_dir}/build-list.loops" -maxdepth 1 | \
    grep -c '/loop_[0-9]\+$'
) || true
looped_packages=$(
  find "${work_dir}/build-list.loops" -maxdepth 1 | \
    grep '/loop_[0-9]\+$' | \
    xargs -r cat | \
    sort -u | \
    wc -l
)

{
  printf 'The mirror master contains %d stable packages (vs. ca. %d planned).\n' \
    "${stable}" \
    "$((staging+testing+pending_packages))"
  printf 'The build list contains %d tasks (incl. broken: %d, leading to %d packages), of which %s can be built immediately.\n' \
    "$((tasks-broken))" \
    "${tasks}" \
    "${pending_packages}" \
    "${next_tasks}"
  printf 'There are %d testing and %d staging packages.\n' \
    "${testing}" \
    "${staging}"
  printf 'There are %d broken package builds.\n' \
    "${broken}"
  if [ "${loops}" -ne 0 ]; then
    printf 'There are %d loops containing %d package builds.\n' \
      "${loops}" \
      "${looped_packages}"
  fi
  if [ $((broken+testing+staging)) -ne 0 ]; then
    printf '%.1f%% of all packages are broken.\n' \
      "$(
        echo "scale=10; 100*${broken}/(${broken}+${testing}+${staging})" | \
          bc
      )"
  fi
  if [ $((testing+staging+pending_packages-broken)) -ne 0 ]; then
    printf '%.1f%% of the planned work has been done.\n' \
      "$(
        echo "scale=10; 100*(${testing}+${staging})/(${testing}+${staging}+${pending_packages}-${broken})" | \
          bc
      )"
  fi
} > \
  "${tmp_dir}/build-master-status.html"

if ${web}; then
  "${base_dir}/bin/calculate-dependent-packages"
  (
    printf '%s\n' \
      '<html>' \
      '<head>' \
      '<title>Status of archlinux32 build master</title>' \
      '<link rel="stylesheet" type="text/css" href="/static/style.css">' \
      '</head>' \
      '<body>'
    sed 's|$|<br>|' "${tmp_dir}/build-master-status.html"
    printf '%s\n' \
      '<br>' \
      'currently building packages:<br>' \
      '<table>'
    printf '<tr>'
    printf '<th>%s</th>' \
      'since (UTC)' \
      'pkgname' \
      'git revision' \
      'modification git revision' \
      'package repository' \
      'build slave'
    printf '</tr>'
    find "${work_dir}/package-states" -maxdepth 1 -name '*.locked' -printf '%T@ <tr><td>%TY-%Tm-%Td %TH:%TM</td><td>%f ' -execdir head -n1 {} \; | \
      sort -k1n,1 | \
      sed '
        s|^\S\+ ||
        s|$|</td></tr>|
        s|\.locked |</td><td>|
        s|\.\([^.]\+\)$|</td><td>\1|
        s|\.\([^.]\+\)$|</td><td>\1|
        s|\.\([^.]\+\)$|</td><td>\1|
      '
    printf '%s\n' \
      '</table>' \
      '</body>' \
      '</html>'
  ) | \
    sponge "${tmp_dir}/build-master-status.html"
  end=$(($(date +%s)-7*24*60*60))
  (
    [ -f "${webserver_directory}/statistics" ] && \
      cat "${webserver_directory}/statistics"
    printf '%s ' \
      "$(date +%s)" \
      "${stable}" \
      "${tasks}" \
      "${pending_packages}" \
      "${staging}" \
      "${testing}" \
      "${broken}" \
      "${loops}" \
      "${looped_packages}" \
      "${locked}" \
      "${blocked}" \
      "${next_tasks}" | \
      sed 's| $|\n|'
    echo "${end}"
  ) | \
    sort -k1nr,1 | \
    sed -n "
      /^${end}\$/q
      p
    " | \
    tac > \
    "${tmp_dir}/statistics"

  {
    printf '%s\n' \
      '<html>' \
      '<head>' \
      '<title>List of broken package builds</title>' \
      '<link rel="stylesheet" type="text/css" href="/static/style.css">' \
      '</head>' \
      '<body>' \
      '<a href="build-logs/">build logs</a><br>' \
      '<table>' \
      '<tr>'
    printf '<th>%s</th>' \
      'package' \
      'git revision' \
      'modification git revision' \
      'package repository' \
      'compilations' \
      'dependent' \
      'blocked'
    printf '</tr>\n'
    find "${work_dir}/package-states" -maxdepth 1 -name '*.broken' -printf '%f\n' | \
      sed 's|\.broken$||' | \
      sed 's|^\(\(.\+\)\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)\)$|\1 \2 \3 \4 \5|' | \
      while read -r sf pkg rev mod_rev repo; do
        if grep -qxF "${pkg}" "${tmp_dir}/broken-packages-names"; then
          printf '1 '
        else
          printf '0 '
        fi
        printf '%s ' \
          "${pkg}" \
          "${rev}" \
          "${mod_rev}" \
          "${repo}" \
          "$(wc -l < "${work_dir}/package-states/${sf}.broken")" \
          "$(
            # shellcheck disable=SC2010
            ls -t "${webserver_directory}/build-logs" | \
              grep -m1 "^$(str_to_regex "${sf}.")[^.]\+\.build-log\.gz\$"
          )" \
          "$(
            (
              grep -m1 "^$(str_to_regex "${sf}") " "${work_dir}/dependent-count" || \
                echo 'x &nbsp;'
            ) | \
              cut -d' ' -f2
          )"
        if [ -f "${work_dir}/package-states/${sf}.blocked" ]; then
          while read -r blocked_reason; do
            if echo "${blocked_reason}" | \
              grep -q '^wait for '; then
              printf 'wait for '
              echo "${blocked_reason}" | \
                sed '
                  s|^wait for ||
                  s@\( and \| or \)@\n\1\n@
                ' | \
                while read -r reason; do
                  if [ "FS#${reason#FS#}" = "${reason}" ]; then
                    printf '<a href="https://bugs.archlinux.org/task/%s">%s</a>' \
                      "${reason#FS#}" \
                      "${reason}"
                  elif grep -q "^$(str_to_regex "${reason}") " "${work_dir}/build-list"; then
                    printf '<a href="graphs/%s.png">%s</a>' \
                      "${reason}" \
                      "${reason}"
                  elif [ "${reason% *}" != "${reason}" ]; then
                    printf '%s' \
                      "${reason}"
                  else
                    printf '<font color="red">%s</font>' \
                      "${reason}"
                  fi
                  if read -r operator; then
                    printf ' %s ' "${operator}"
                  fi
                done
            else
              echo "${blocked_reason}"
            fi
          done < \
            "${work_dir}/package-states/${sf}.blocked" | \
            tr '\n' ' '
        else
          printf '&nbsp;'
        fi
        printf '\n'
      done | \
      sort -k6n,6 | \
      while read -r buildable pkg rev mod_rev repo count log_file dependent reason; do
        if [ "${buildable}" -eq 0 ]; then
          left='('
          right=')'
        else
          unset left
          unset right
        fi
        printf '<tr>'
        printf '<td>%s</td>' \
          '<a href="graphs/'"${pkg}"'.png">'"${left}${pkg}${right}"'</a>' \
          "${rev}" \
          "${mod_rev}" \
          "${repo}" \
          '<a href="build-logs/'"${log_file}"'">'"${count}"'</a>' \
          "${dependent}" \
          "${reason}"
        printf '</tr>\n'
      done
    printf '%s\n' \
      '</table>' \
      '</body>' \
      '</html>'
  } > \
    "${tmp_dir}/broken-packages.html"

  rm -f "${tmp_dir}/broken-packages-names"

  {
    printf '%s\n' \
      '<html>' \
      '<head>' \
      '<title>Todos in the build scripts</title>' \
      '</head>' \
      '<body>'
    find "${base_dir}/bin/" "${base_dir}/conf/" -type f \
      -exec sed -n '
        /^\s*#\s*TODO:/{
          s/^\s*#\s*TODO:\s*//
          :a
            N
            s/\s*\n\s*#/\n/
            ta
          s/\n\n\+/\n/g
          s/\n[^\n]*$/\n/
          i {}
          =
          p
        }' {} \; | \
      sed '
        :a
        N
        /\n$/!ba
        s|^[^\n]*/\([^/\n]\+/[^/\n]\+\)\n\([0-9]\+\)\n|\1 (line \2):\n|
      ' | \
      sed '
        s|$|<br>|
      '
    printf '%s\n' \
      '</body>' \
      '</html>'
  } > \
    "${tmp_dir}/todos.html"

  {
    printf '%s\n' \
      '<html>' \
      '<head>' \
      '<title>Blacklisted packages</title>' \
      '<link rel="stylesheet" type="text/css" href="/static/style.css">' \
      '</head>' \
      '<body>' \
      '<table>'
    printf '<tr>'
    printf '<th>%s</th>' \
      'package' \
      'reason'
    printf '</tr>\n'
    git -C "${repo_paths__archlinux32}" archive "$(cat "${work_dir}/archlinux32.revision")" -- 'blacklist' | \
      tar -Ox | \
      sed '
        s@FS#\([0-9]\+\)@<a href="https://bugs.archlinux.org/task/\1">\0</a>@
        /.#/!s/$/#/
        s|\(.\)#|\1</td><td>|
        /^\s*#/{
          s/^\s*#\s*//
          s|\s*\(</td><td>\)|</font></s>\1|
          s/^/<s><font color="#808080">/
        }
        s|^|<tr><td>|
        s|$|</td></tr>|
      '
    printf '%s\n' \
      '</table>' \
      '</body>' \
      '</html>'
  } > \
    "${tmp_dir}/blacklist.html"

  find "${tmp_dir}" -maxdepth 1 -type f | \
    while read -r file; do
      cat "${file}" > \
        "${webserver_directory}/${file##*/}"
    done

else
  cat "${tmp_dir}/build-master-status.html"
fi