Tools for building 32-bit archlinux packages from archlinux.org's official, 64-bit tested PKGBUILDs et al.

why-dont-you 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. #!/bin/sh
  2. # usage: why_dont_you $action $package1 $package2 ...
  3. # shellcheck disable=SC2119,SC2120
  4. # investigate, why a certain operation is not done with certain packages
  5. # shellcheck source=../lib/load-configuration
  6. . "${0%/*}/../lib/load-configuration"
  7. # TODO: reintrocude "keep", "stubbornly_keep", "stabilize" and "unstage"
  8. # using information from the database.
  9. action="$1"
  10. shift
  11. tmp_dir=$(mktemp -d 'tmp.why-dont-you.XXXXXXXXXX' --tmpdir)
  12. trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT
  13. case "${action}" in
  14. 'build')
  15. # shellcheck disable=SC2016
  16. {
  17. printf 'CREATE TEMPORARY TABLE `searches` (`search` VARCHAR(64));\n'
  18. printf 'INSERT INTO `searches` VALUES '
  19. # shellcheck disable=SC2046
  20. printf '(from_base64("%s")),' \
  21. $(
  22. printf '%s\n' "$@" | \
  23. base64_encode_each
  24. ) | \
  25. sed 's/,$/;\n/'
  26. # we select everything which is possibly of any interest:
  27. # - id (to see if it actually is on the build-list)
  28. # - build_assignments.architecture.name
  29. # - to_build.is_broken
  30. # - failed_builds_count
  31. # - to_build.is_blocked
  32. # - deps.pkgbase (any dependency pending?)
  33. # - build_slaves.name (is anyone building this?)
  34. # - pkgbase
  35. printf 'SELECT DISTINCT `to_build`.`ba_id`,'
  36. printf '`to_build`.`baa_name`,'
  37. printf 'If(`to_build`.`is_broken`,1,0),'
  38. printf '('
  39. printf 'SELECT COUNT(1)'
  40. printf ' FROM `failed_builds`'
  41. printf 'WHERE `failed_builds`.`build_assignment`=`to_build`.`ba_id`'
  42. printf ')'
  43. printf ',replace(to_base64(`%s`.`%s`),"\\n","")' \
  44. 'to_build' 'is_blocked' \
  45. 'deps' 'pkgbase' \
  46. 'build_slaves' 'name' \
  47. 'to_build' 'pkgbase'
  48. # at least one row for each given `search`
  49. printf ' FROM `searches`'
  50. printf ' LEFT JOIN '
  51. printf '('
  52. # join the tables for the to-be-built packages:
  53. # package_source, build_assignment, binary_package, repostory
  54. printf 'SELECT DISTINCT '
  55. printf '`tb_ps`.`pkgbase`,'
  56. printf '`tb_bin`.`id` AS `bin_id`,'
  57. printf '`tb_ba`.`id` AS `ba_id`,'
  58. printf '`tb_ba`.`is_blocked`,'
  59. printf '`tb_ba`.`is_broken`,'
  60. printf '`tb_baa`.`name` AS `baa_name`'
  61. printf ' FROM `package_sources` AS `tb_ps`'
  62. mysql_join_package_sources_build_assignments 'tb_ps' 'tb_ba'
  63. mysql_join_build_assignments_architectures 'tb_ba' 'tb_baa'
  64. mysql_join_build_assignments_binary_packages 'tb_ba' 'tb_bin'
  65. mysql_join_binary_packages_binary_packages_in_repositories 'tb_bin' 'tb_bir'
  66. printf ' WHERE `tb_bir`.`repository`=%s' \
  67. "${repository_ids__any_build_list}"
  68. printf ') AS `to_build`'
  69. printf ' ON ('
  70. printf '`to_build`.`pkgbase`=`searches`.`search`'
  71. printf ' OR `searches`.`search`=CONCAT(`to_build`.`baa_name`,"/",`to_build`.`pkgbase`)'
  72. printf ') LEFT JOIN '
  73. printf '('
  74. # same join as above, but with different names - for the
  75. # potential dependencies
  76. printf 'SELECT DISTINCT `dep_ps`.`pkgbase`,`dependencies`.`dependent`'
  77. printf ' FROM `package_sources` AS `dep_ps`'
  78. mysql_join_package_sources_build_assignments 'dep_ps' 'dep_ba'
  79. mysql_join_build_assignments_binary_packages 'dep_ba' 'dep_bin'
  80. mysql_join_binary_packages_binary_packages_in_repositories 'dep_bin' 'dep_bir'
  81. # now we have some (=3) additional joins,
  82. # because we are interested in dependency relations to `to_build`
  83. mysql_join_binary_packages_install_target_providers 'dep_bin'
  84. mysql_join_install_target_providers_dependencies_with_versions
  85. mysql_join_dependencies_dependency_types
  86. printf ' WHERE `dep_bir`.`repository`=%s' \
  87. "${repository_ids__any_build_list}"
  88. printf ' AND `dependency_types`.`relevant_for_building`'
  89. printf ') AS `deps`'
  90. printf ' ON `deps`.`dependent`=`to_build`.`bin_id`'
  91. # now we join with build slaves to see if someone builds this
  92. printf ' LEFT JOIN `build_slaves`'
  93. printf ' ON `build_slaves`.`currently_building`=`to_build`.`ba_id`'
  94. printf ';\n'
  95. } | \
  96. mysql_run_query | \
  97. tr '\t' ' ' | \
  98. sort -k8,8 -k7,7 -k6,6 | \
  99. sed '
  100. / NULL \S\+$/ b multi-dep
  101. :multi-slave
  102. $!N
  103. s/^\(\(\S\+ \)\{6\}\)\(\S\+\)\( \S\+\)\n\(\S\+ \)\{6\}\(\S\+\)\4/\1\3,\6\4/
  104. t multi-slave
  105. P
  106. D
  107. :multi-dep
  108. / NULL\( \S\+\)\{3\}$/! b
  109. $!N
  110. s/^\(\(\S\+ \)\{5\}\)\(\S\+\)\(\( \S\+\)\{2\}\)\n\(\S\+ \)\{5\}\(\S\+\)\4/\1\3,\7\4/
  111. t multi-dep
  112. P
  113. D
  114. ' | \
  115. sed '
  116. s/NULL,//g
  117. ' | \
  118. while read -r id ba_arch is_broken trials is_blocked dependency slave pkgbase; do
  119. pkgbase=$(
  120. printf '%s' "${pkgbase}" | \
  121. base64 -d
  122. )
  123. if [ "${id}" = 'NULL' ]; then
  124. >&2 printf '"%s" is not on the build list.\n' \
  125. "${pkgbase}"
  126. continue
  127. fi
  128. if [ "${slave}" != 'NULL' ]; then
  129. # beware: A slave named "5BË" will look exactly like this!
  130. printf '"%s/%s" is locked by %s.\n' \
  131. "${ba_arch}" \
  132. "${pkgbase}" \
  133. "$(
  134. printf '%s\n' "${slave}" | \
  135. tr ',' '\n' | \
  136. while read -r line; do
  137. printf '%s\n' "${line}" | \
  138. base64 -d
  139. printf ','
  140. done | \
  141. sed 's/,$//'
  142. )"
  143. continue
  144. fi
  145. if [ "${is_blocked}" != 'NULL' ]; then
  146. # beware: A block-reason "5BË" will look exactly like this!
  147. printf '"%s/%s" is blocked: "%s".\n' \
  148. "${ba_arch}" \
  149. "${pkgbase}" \
  150. "$(
  151. printf '%s' "${is_blocked}" | \
  152. base64 -d
  153. )"
  154. continue
  155. fi
  156. if [ "${dependency}" != 'NULL' ]; then
  157. printf '"%s/%s" has unmet dependencies:\n' \
  158. "${ba_arch}" \
  159. "${pkgbase}"
  160. printf '%s\n' "${dependency}" | \
  161. tr ',' '\n' | \
  162. while read -r line; do
  163. printf ' '
  164. printf '%s\n' "${line}" | \
  165. base64 -d
  166. printf '\n'
  167. done
  168. continue
  169. fi
  170. if [ "${is_broken}" = '1' ]; then
  171. printf '"%s/%s" is broken (%sx built), but would be built.\n' \
  172. "${ba_arch}" \
  173. "${pkgbase}" \
  174. "${trials}"
  175. continue
  176. fi
  177. printf '"%s/%s" would be built.\n' \
  178. "${ba_arch}" \
  179. "${pkgbase}"
  180. done
  181. ;;
  182. 'stabilize'|'unstage')
  183. if [ "${action}" = 'stabilize' ]; then
  184. # shellcheck disable=SC2154
  185. from_stability=${repository_stability_ids__testing}
  186. # shellcheck disable=SC2154
  187. to_stability=${repository_stability_ids__stable}
  188. # shellcheck disable=SC2016
  189. test_filter='`binary_packages`.`is_tested`'
  190. else
  191. # shellcheck disable=SC2154
  192. from_stability=${repository_stability_ids__staging}
  193. # shellcheck disable=SC2154
  194. to_stability=${repository_stability_ids__testing}
  195. test_filter='1'
  196. fi
  197. for pkgname in "$@"; do
  198. infos=$(
  199. # shellcheck disable=SC2016
  200. {
  201. printf 'SELECT'
  202. printf ' `binary_packages_in_repositories`.`id`,'
  203. printf ' IF(%s,1,0),' "${test_filter}"
  204. printf ' IF(`binary_packages`.`has_issues`,1,0)'
  205. printf ' FROM `binary_packages_in_repositories`'
  206. mysql_join_binary_packages_in_repositories_repositories
  207. mysql_join_binary_packages_in_repositories_binary_packages
  208. printf ' WHERE `repositories`.`stability`=%s' \
  209. "${from_stability}"
  210. printf ' AND `binary_packages`.`pkgname`=from_base64("%s")' \
  211. "$(
  212. printf '%s' "${pkgname}" | \
  213. base64 -w0
  214. )"
  215. } | \
  216. mysql_run_query | \
  217. tr '\t' ' '
  218. )
  219. if [ -z "${infos}" ]; then
  220. printf 'Cannot find "%s"\n' \
  221. "${pkgname}"
  222. continue
  223. fi
  224. bpir="${infos%% *}"
  225. infos="${infos#* }"
  226. if [ "${infos% *}" = '0' ]; then
  227. printf '"%s" is not tested.\n' \
  228. "${pkgname}"
  229. continue
  230. fi
  231. infos="${infos#* }"
  232. if [ "${infos}" = '1' ]; then
  233. printf 'There are unresolved bugs reported against "%s".\n' \
  234. "${pkgname}"
  235. continue
  236. fi
  237. printf '%s %s\n' "${bpir}" "${pkgname}" >> \
  238. "${tmp_dir}/packages"
  239. done
  240. if [ ! -s "${tmp_dir}/packages" ]; then
  241. exit
  242. fi
  243. # shellcheck disable=SC2016
  244. {
  245. printf 'CREATE TEMPORARY TABLE `moveable_bpir` (`id` BIGINT, `to_repository` BIGINT, UNIQUE KEY `id`(`id`));\n'
  246. printf 'CREATE TEMPORARY TABLE `replaceable_bpir` (`id` BIGINT, `replaced_by` BIGINT, UNIQUE KEY `id`(`id`));\n'
  247. for copy in '' '_copy'; do
  248. printf 'CREATE TEMPORARY TABLE `knots%s` (' \
  249. "${copy}"
  250. printf '`id` BIGINT NOT NULL AUTO_INCREMENT,'
  251. printf ' `and` BIT,'
  252. printf ' `content_id` BIGINT,'
  253. printf ' `content_type` ENUM("bpir","it"),'
  254. printf ' `reason_length` MEDIUMINT,'
  255. printf ' `active` BIT,'
  256. printf ' `relevant` BIT,'
  257. printf ' UNIQUE KEY (`id`),'
  258. printf ' UNIQUE KEY `content`(`content_id`,`content_type`));\n'
  259. printf 'CREATE TEMPORARY TABLE `edges%s` (' \
  260. "${copy}"
  261. printf '`cause` BIGINT,'
  262. printf ' `impact` BIGINT,'
  263. printf ' `invert` BIT,'
  264. printf ' UNIQUE KEY `content` (`cause`,`impact`));\n'
  265. done
  266. printf 'INSERT IGNORE INTO `moveable_bpir` (`id`,`to_repository`)'
  267. printf ' SELECT '
  268. printf '`binary_packages_in_repositories`.`id`,'
  269. printf '`repository_moves`.`to_repository`'
  270. printf ' FROM `binary_packages_in_repositories`'
  271. mysql_join_binary_packages_in_repositories_repositories
  272. mysql_join_binary_packages_in_repositories_binary_packages
  273. mysql_join_binary_packages_build_assignments
  274. mysql_join_build_assignments_package_sources
  275. mysql_join_package_sources_upstream_repositories
  276. mysql_join_upstream_repositories_repository_moves
  277. printf ' AND `repository_moves`.`from_repository`=`repositories`.`id`'
  278. printf ' WHERE `repositories`.`stability`=%s' \
  279. "${from_stability}"
  280. printf ' AND %s' \
  281. "${test_filter}"
  282. printf ' AND NOT `binary_packages`.`has_issues`;\n'
  283. printf 'INSERT IGNORE INTO `replaceable_bpir` (`id`,`replaced_by`)'
  284. printf ' SELECT `r_bpir`.`id`,`m_bpir`.`id`'
  285. printf ' FROM `moveable_bpir`'
  286. printf ' JOIN `binary_packages_in_repositories` AS `m_bpir`'
  287. printf ' ON `m_bpir`.`id`=`moveable_bpir`.`id`'
  288. mysql_join_binary_packages_in_repositories_binary_packages 'm_bpir' 'm_bp'
  289. printf ' JOIN `binary_packages` AS `r_bp`'
  290. printf ' ON `r_bp`.`pkgname`=`m_bp`.`pkgname`'
  291. mysql_join_binary_packages_binary_packages_in_repositories 'r_bp' 'r_bpir'
  292. mysql_join_binary_packages_in_repositories_repositories 'r_bpir' 'r_r'
  293. printf ' JOIN `repositories` AS `m_r`'
  294. printf ' ON `m_r`.`id`=`moveable_bpir`.`to_repository`'
  295. printf ' AND `m_r`.`architecture`=`r_r`.`architecture`'
  296. printf ' JOIN `repository_stability_relations` AS `rsr`'
  297. printf ' ON `rsr`.`more_stable`=`r_r`.`stability`'
  298. printf ' AND `rsr`.`less_stable`=`m_r`.`stability`'
  299. printf ' WHERE NOT EXISTS ('
  300. printf 'SELECT 1'
  301. printf ' FROM `binary_packages_in_repositories` AS `subst_bpir`'
  302. mysql_join_binary_packages_in_repositories_repositories 'subst_bpir' 'subst_r'
  303. mysql_join_binary_packages_in_repositories_binary_packages 'subst_bpir' 'subst_bp'
  304. printf ' JOIN `repository_stability_relations` AS `rsr_a`'
  305. printf ' ON `rsr_a`.`more_stable`=`subst_r`.`stability`'
  306. printf ' JOIN `repository_stability_relations` AS `rsr_b`'
  307. printf ' ON `rsr_b`.`less_stable`=`subst_r`.`stability`'
  308. printf ' WHERE `subst_bp`.`pkgname`=`r_bp`.`pkgname`'
  309. printf ' AND `subst_bp`.`id`=`r_bp`.`id`'
  310. printf ' AND `rsr_a`.`less_stable`=`m_r`.`stability`'
  311. printf ' AND `rsr_b`.`more_stable`=`r_r`.`stability`'
  312. printf ');\n'
  313. # we generate a graph with bpir and it as knots
  314. printf 'INSERT INTO `knots` (`and`,`content_id`,`content_type`)'
  315. printf ' SELECT 1,`moveable_bpir`.`id`,"bpir"'
  316. printf ' FROM `moveable_bpir`;\n'
  317. printf 'INSERT INTO `knots` (`and`,`content_id`,`content_type`)'
  318. printf ' SELECT 1,`binary_packages_in_repositories`.`id`,"bpir"'
  319. printf ' FROM `binary_packages_in_repositories`'
  320. mysql_join_binary_packages_in_repositories_repositories
  321. mysql_join_binary_packages_in_repositories_binary_packages
  322. printf ' JOIN `repository_stability_relations`'
  323. printf ' ON `repository_stability_relations`.`less_stable`=%s' \
  324. "${to_stability}"
  325. printf ' AND `repository_stability_relations`.`more_stable`=`repositories`.`stability`'
  326. printf ' WHERE NOT EXISTS('
  327. printf 'SELECT 1'
  328. printf ' FROM `binary_packages_in_repositories` AS `subst_bpir`'
  329. mysql_join_binary_packages_in_repositories_repositories 'subst_bpir' 'subst_r'
  330. printf ' JOIN `repository_stability_relations` AS `rsr_a`'
  331. printf ' ON `rsr_a`.`less_stable`=%s' \
  332. "${to_stability}"
  333. printf ' AND `rsr_a`.`more_stable`=`subst_r`.`stability`'
  334. printf ' JOIN `repository_stability_relations` AS `rsr_b`'
  335. printf ' ON `rsr_b`.`less_stable`=`subst_r`.`stability`'
  336. mysql_join_binary_packages_in_repositories_binary_packages 'subst_bpir' 'subst_bp'
  337. printf ' WHERE `subst_bp`.`pkgname`=`binary_packages`.`pkgname`'
  338. printf ' AND `subst_bpir`.`id`!=`binary_packages_in_repositories`.`id`'
  339. printf ' AND `rsr_b`.`more_stable`=`repositories`.`stability`'
  340. printf ');\n'
  341. printf 'INSERT INTO `knots` (`and`,`content_id`,`content_type`)'
  342. printf ' SELECT 0,`install_targets`.`id`,"it"'
  343. printf ' FROM `install_targets`;\n'
  344. # create copy
  345. printf 'INSERT INTO `knots_copy`'
  346. printf ' SELECT *'
  347. printf ' FROM `knots`;\n'
  348. # "available" bpir requires available install_target
  349. printf 'INSERT INTO `edges` (`cause`,`impact`,`invert`)'
  350. printf ' SELECT DISTINCT `c`.`id`,`i`.`id`,0'
  351. printf ' FROM `knots` AS `i`'
  352. printf ' JOIN `binary_packages_in_repositories`'
  353. printf ' ON `binary_packages_in_repositories`.`id`=`i`.`content_id`'
  354. printf ' AND `i`.`content_type`="bpir"'
  355. mysql_join_binary_packages_in_repositories_dependencies
  356. mysql_join_dependencies_dependency_types
  357. printf ' AND `dependency_types`.`relevant_for_binary_packages`'
  358. printf ' JOIN `knots_copy` AS `c`'
  359. printf ' ON `dependencies`.`depending_on`=`c`.`content_id`'
  360. printf ' AND `c`.`content_type`="it";\n'
  361. # "available" install_target requires available bpir - but we
  362. # only care about bpir being moved or being more stable than
  363. # target stability
  364. for what in 'moveable' 'there'; do
  365. printf 'INSERT INTO `edges` (`cause`,`impact`,`invert`)'
  366. printf ' SELECT DISTINCT `c`.`id`,`i`.`id`,0'
  367. printf ' FROM `knots` AS `c`'
  368. printf ' JOIN `binary_packages_in_repositories`'
  369. printf ' ON `binary_packages_in_repositories`.`id`=`c`.`content_id`'
  370. printf ' AND `c`.`content_type`="bpir"'
  371. if [ "${what}" = 'moveable' ]; then
  372. printf ' JOIN `moveable_bpir`'
  373. printf ' ON `moveable_bpir`.`id`=`binary_packages_in_repositories`.`id`'
  374. else
  375. mysql_join_binary_packages_in_repositories_repositories
  376. printf ' JOIN `repository_stability_relations`'
  377. printf ' ON `repository_stability_relations`.`more_stable`=`repositories`.`stability`'
  378. printf ' AND `repository_stability_relations`.`less_stable`=%s' \
  379. "${to_stability}"
  380. fi
  381. mysql_join_binary_packages_in_repositories_install_target_providers
  382. printf ' JOIN `knots_copy` AS `i`'
  383. printf ' ON `install_target_providers`.`install_target`=`i`.`content_id`'
  384. printf ' AND `i`.`content_type`="it";\n'
  385. done
  386. # additionally, "available" moveable_bpir requires matching
  387. # replaceable_bpir unavailable
  388. printf 'INSERT INTO `edges` (`cause`,`impact`,`invert`)'
  389. printf ' SELECT `c`.`id`,`i`.`id`,1'
  390. printf ' FROM `replaceable_bpir`'
  391. printf ' JOIN `knots` AS `c`'
  392. printf ' ON `c`.`content_id`=`replaceable_bpir`.`id`'
  393. printf ' AND `c`.`content_type`="bpir"'
  394. printf ' JOIN `knots_copy` AS `i`'
  395. printf ' ON `i`.`content_id`=`replaceable_bpir`.`replaced_by`'
  396. printf ' AND `i`.`content_type`="bpir";\n'
  397. while read -r bpir pkgname; do
  398. printf 'CALL `find_the_culprit`(%s);\n' \
  399. "${bpir}"
  400. done < \
  401. "${tmp_dir}/packages"
  402. } | \
  403. mysql_run_query
  404. ;;
  405. 'keep'|'stubbornly_keep')
  406. printf 'Sry, "why-dont-you %s" is unavailable, until someone recodes it to look into the database.\n' "${action}"
  407. ;;
  408. *)
  409. >&2 printf 'unknown action "%s"\n' "${action}"
  410. exit 1
  411. esac