Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/build-master-status
blob: 455eb8f3dd731e26ce7712b89a90e00fe589abf9 (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
#!/bin/sh

# report about status of build master

# shellcheck disable=SC2119,SC2120

# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"

tmp_dir=$(mktemp -d 'tmp.build-master-status.XXXXXXXXXX' --tmpdir)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT

# do not block if locked
exec 9> "${status_lock_file}"
if ! verbose_flock -n 9; then
  >&2 echo 'Saving status skipped, cannot acquire lock.'
  exit
fi

# update todos
find "${base_dir}/bin/" "${base_dir}/conf/" "${base_dir}/lib/" -type f \
  -exec grep -nHF '' '{}' \; | \
  sed 's,^'"$(str_to_regex "${base_dir}")"'/,,' | \
  sed -n '
    /^[^:]\+:[0-9]\+:\s*#\s*TODO:/ {
      :a
      $! {
        N
        s/\n[^:[:space:]]\+:[0-9]\+:\s*\([^#[:space:]].*\)\?$//
        Ta
      }
      s/\n[^:[:space:]]\+:[0-9]\+:\s*#\s*/\\\\n/g
      s/^\([^:]\+\):\([0-9]\+\):\s*#\s*TODO:\s*/\1\t\2\t/
      p
    }
  ' > "${tmp_dir}/todos"

if [ -s "${tmp_dir}/todos" ]; then
  # shellcheck disable=SC2016
  {
    printf 'SHOW CREATE TABLE `todos`' | \
      mysql_run_query 'unimportant' | \
      sed '
        1s/^\S\+\s\+CREATE TABLE `todos` /CREATE TEMPORARY TABLE `td` /
        s/ NOT NULL AUTO_INCREMENT/ NULL/
        s/PRIMARY KEY/INDEX/
      '
    printf ';\n'
    printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `td` (`file`,`line`,`description`);\n' \
      "${tmp_dir}/todos"

    for matches in 'file line description' 'file description' 'file line' 'description'; do
      printf 'UPDATE `td`'
      printf ' JOIN `todos`'
      for match in ${matches}; do
        printf ' AND `td`.`%s`=`todos`.`%s`' \
          "${match}" "${match}"
      done | \
        sed 's/^ AND / ON /'
      printf ' SET `td`.`id`=`todos`.`id`'
      printf ' WHERE `td`.`id` IS NULL;\n'
    done

    printf 'UPDATE `todos`'
    printf ' JOIN `td` ON `todos`.`id`=`td`.`id`'
    printf ',`todos`.`%s`=`td`.`%s`' \
      'file' 'file' \
      'line' 'line' \
      'description' 'description' | \
      sed 's/^,/ SET /'
    printf ';\n'

    printf 'INSERT IGNORE INTO `todos` (`file`,`line`,`description`)'
    printf ' SELECT `td`.`file`,`td`.`line`,`td`.`description`'
    printf ' FROM `td`'
    printf ' WHERE `td`.`id` IS NULL;\n'

    printf 'DELETE FROM `todos` WHERE NOT EXISTS ('
    printf 'SELECT 1 FROM `td`'
    printf ' AND `td`.`%s`=`todos`.`%s`' \
      'file' 'file' \
      'line' 'line' \
      'description' 'description' | \
      sed 's/^ AND / WHERE /'
    printf ');\n'
    printf 'DROP TEMPORARY TABLE `td`;\n'
    printf 'DELETE FROM `todo_links` WHERE NOT EXISTS ('
      printf 'SELECT 1 FROM `todos` '
      printf 'WHERE `todos`.`id`=`todo_links`.`depending_on`'
    printf ') OR NOT EXISTS ('
      printf 'SELECT 1 FROM `todos` '
      printf 'WHERE `todos`.`id`=`todo_links`.`dependent`'
    printf ');\n'
  } | \
    mysql_run_query 'unimportant'
fi
rm -f "${tmp_dir}/todos"

# TODO: accellerate this query by using "GROUP BY"?
if [ ! -s "${work_dir}/build-master-sanity" ]; then
  # shellcheck disable=SC2016
  {
    printf 'SELECT `architectures`.`id`'
    printf ' FROM `architectures`;\n'
  } | \
    mysql_run_query 'unimportant' | \
    while read -r arch_id; do
      printf 'INSERT IGNORE INTO `statistics` ('
      printf '`%s`,' \
        'stable_packages_count' \
        'pending_tasks_count' \
        'pending_packages_count' \
        'staging_packages_count' \
        'testing_packages_count' \
        'tested_packages_count' \
        'broken_tasks_count' \
        'dependency_loops_count' \
        'dependency_looped_tasks_count' \
        'locked_tasks_count' \
        'blocked_tasks_count' \
        'next_tasks_count' \
        'architecture' | \
        sed 's/,$//'
      printf ') VALUES ('
      # stable_packages_count
      printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
      printf ' `binary_packages`'
      mysql_join_binary_packages_binary_packages_in_repositories
      mysql_join_binary_packages_in_repositories_repositories
      # shellcheck disable=SC2154
      printf ' WHERE `repositories`.`stability`=%s' \
        "${repository_stability_ids__stable}"
      printf ' AND `repositories`.`architecture`=%s),' \
        "${arch_id}"
      # pending_tasks_count
      printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
      printf ' `build_assignments`'
      mysql_join_build_assignments_binary_packages
      mysql_join_binary_packages_binary_packages_in_repositories
      printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
        "${repository_ids__any_build_list}"
      printf ' AND `build_assignments`.`architecture`=%s),' \
        "${arch_id}"
      # pending_packages_count
      printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
      printf ' `binary_packages`'
      mysql_join_binary_packages_binary_packages_in_repositories
      mysql_join_binary_packages_build_assignments
      printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
        "${repository_ids__any_build_list}"
      printf ' AND `build_assignments`.`architecture`=%s),' \
        "${arch_id}"
      # staging_packages_count
      printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
      printf ' `binary_packages`'
      mysql_join_binary_packages_binary_packages_in_repositories
      mysql_join_binary_packages_in_repositories_repositories
      # shellcheck disable=SC2154
      printf ' WHERE `repositories`.`stability`=%s' \
        "${repository_stability_ids__staging}"
      printf ' AND `repositories`.`architecture`=%s),' \
        "${arch_id}"
      # testing_packages_count
      printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
      printf ' `binary_packages`'
      mysql_join_binary_packages_binary_packages_in_repositories
      mysql_join_binary_packages_in_repositories_repositories
      # shellcheck disable=SC2154
      printf ' WHERE `repositories`.`stability`=%s' \
        "${repository_stability_ids__testing}"
      printf ' AND NOT `binary_packages`.`is_tested`'
      printf ' AND `repositories`.`architecture`=%s),' \
        "${arch_id}"
      # tested_packages_count
      printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
      printf ' `binary_packages`'
      mysql_join_binary_packages_binary_packages_in_repositories
      mysql_join_binary_packages_in_repositories_repositories
      printf ' WHERE `repositories`.`stability`=%s' \
        "${repository_stability_ids__testing}"
      printf ' AND `binary_packages`.`is_tested`'
      printf ' AND `repositories`.`architecture`=%s),' \
        "${arch_id}"
      # broken_tasks_count
      printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
      printf ' `build_assignments`'
      mysql_join_build_assignments_binary_packages
      mysql_join_binary_packages_binary_packages_in_repositories
      printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
        "${repository_ids__any_build_list}"
      printf ' AND `build_assignments`.`is_broken`'
      printf ' AND `build_assignments`.`architecture`=%s),' \
        "${arch_id}"
      # dependency_loops_count
      printf '(SELECT COUNT(DISTINCT `build_dependency_loops`.`loop`) FROM'
      printf ' `build_dependency_loops`'
      mysql_join_build_dependency_loops_build_assignments
      printf ' WHERE `build_assignments`.`architecture`=%s),' \
        "${arch_id}"
      # dependency_looped_tasks_count
      printf '(SELECT COUNT(DISTINCT `build_dependency_loops`.`build_assignment`) FROM'
      printf ' `build_dependency_loops`'
      mysql_join_build_dependency_loops_build_assignments
      printf ' WHERE `build_assignments`.`architecture`=%s),' \
        "${arch_id}"
      # locked_tasks_count
      printf '(SELECT COUNT(DISTINCT `build_slaves`.`currently_building`) FROM'
      printf ' `build_slaves`'
      mysql_join_build_slaves_build_assignments
      mysql_join_build_assignments_binary_packages
      mysql_join_binary_packages_binary_packages_in_repositories
      printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
        "${repository_ids__any_build_list}"
      printf ' AND `build_assignments`.`architecture`=%s),' \
        "${arch_id}"
      # blocked_tasks_count
      printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
      printf ' `build_assignments`'
      mysql_join_build_assignments_binary_packages
      mysql_join_binary_packages_binary_packages_in_repositories
      printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
        "${repository_ids__any_build_list}"
      printf ' AND `build_assignments`.`is_blocked` IS NOT NULL'
      printf ' AND `build_assignments`.`architecture`=%s),' \
        "${arch_id}"
      # next_tasks_count
      printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
      printf ' `build_assignments`'
      mysql_join_build_assignments_binary_packages
      mysql_join_binary_packages_binary_packages_in_repositories
      printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
        "${repository_ids__any_build_list}"
      printf ' AND ('
        printf 'NOT EXISTS ('
          printf 'SELECT 1 FROM `dependencies`'
          mysql_join_dependencies_dependency_types
          printf ' AND `dependency_types`.`relevant_for_building`'
          mysql_join_dependencies_install_target_providers_with_versions
          mysql_join_install_target_providers_binary_packages '' 'prov_bp'
          mysql_join_binary_packages_binary_packages_in_repositories 'prov_bp' 'prov_bpir'
          printf ' WHERE `prov_bpir`.`repository`=%s' \
            "${repository_ids__any_build_list}"
          printf ' AND `dependencies`.`dependent`=`binary_packages`.`id`'
        printf ') OR EXISTS ('
          printf 'SELECT 1 FROM `build_dependency_loops`'
          printf ' WHERE `build_dependency_loops`.`build_assignment`=`build_assignments`.`id`'
        printf ')'
      printf ')'
      printf ' AND `build_assignments`.`architecture`=%s),' \
        "${arch_id}"
      # architecture
      printf '%s' \
        "${arch_id}"
      printf ');\n'
    done | \
    mysql_run_query 'unimportant'
fi