index : builder | |
Archlinux32 build system | gitolite user |
summaryrefslogtreecommitdiff |
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-01-24 16:15:40 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-01-24 16:15:40 +0100 |
commit | ff768f012bfef1bf264d06214aead70a58c0ff90 (patch) | |
tree | 00fae2f78283cf61698b2b8fd2474a1f6a5802c8 /bin/mysql-functions | |
parent | d5280828118b27372c5ea9be1c0cd8e55c818ff0 (diff) | |
parent | cb4eedcdca4fc5f58e83abe2aadc9abb59b4918c (diff) |
-rwxr-xr-x | bin/mysql-functions | 266 |
diff --git a/bin/mysql-functions b/bin/mysql-functions index 7b9e724..ec2bf4c 100755 --- a/bin/mysql-functions +++ b/bin/mysql-functions @@ -37,20 +37,19 @@ mysql_add_package_source() { done values="${values% }" - ${mysql_command} -e "$( + { printf 'INSERT IGNORE INTO package_sources' - { - printf ' (' - printf '`%s`, ' ${names} - printf ') SELECT' - printf ' from_base64("%s"), ' ${values% *} - printf ' `upstream_repositories`.`id`' - printf ' FROM `upstream_repositories`' - printf ' WHERE `upstream_repositories`.`name` = from_base64("%s");' \ - "${values##* }" - } | \ - sed 's|, )|)|g' - )" + printf ' (' + printf '`%s`, ' ${names} + printf ') SELECT' + printf ' from_base64("%s"), ' ${values% *} + printf ' `upstream_repositories`.`id`' + printf ' FROM `upstream_repositories`' + printf ' WHERE `upstream_repositories`.`name` = from_base64("%s");' \ + "${values##* }" + } | \ + sed 's|, )|)|g' | \ + ${mysql_command} } # mysql_add_binary_package $pkgbase $git_revision $mod_git_revision $upstream_package_repository $pkgname $sub_pkgrel $architecture $repository @@ -68,33 +67,32 @@ mysql_add_binary_package() { shift done - ${mysql_command} -e "$( + { printf 'INSERT IGNORE INTO binary_packages' - { - printf ' (' - printf '`%s`, ' 'sub_pkgrel' 'pkgname' 'package_source' 'repository' 'architecture' - printf ') SELECT' - printf ' from_base64("%s"), ' "${sub_pkgrel}" "${pkgname}" - printf ' `%s`.`id`,' 'package_sources' 'repositories' 'architectures' - printf ' FROM' - printf ' `%s` JOIN' 'package_sources' 'repositories' 'architectures' - printf ' `upstream_repositories` ON `package_sources`.`upstream_package_repository` = `upstream_repositories`.`id`' - printf ' WHERE' - printf ' `%s`.`name` = from_base64("%s") AND' \ - 'repositories' "${repository}" \ - 'architectures' "${architecture}" - printf ' `package_sources`.`%s` = from_base64("%s") AND' \ - 'pkgbase' "${pkgbase}" \ - 'git_revision' "${git_revision}" \ - 'mod_git_revision' "${mod_git_revision}" - printf ' `upstream_repositories`.`name` = from_base64("%s")' \ - "${upstream_package_repository}" - } | \ - sed ' - s|, )|)|g - s|, FROM| FROM|g - ' - )" + printf ' (' + printf '`%s`, ' 'sub_pkgrel' 'pkgname' 'package_source' 'repository' 'architecture' + printf ') SELECT' + printf ' from_base64("%s"), ' "${sub_pkgrel}" "${pkgname}" + printf ' `%s`.`id`,' 'package_sources' 'repositories' 'architectures' + printf ' FROM' + printf ' `%s` JOIN' 'package_sources' 'repositories' 'architectures' + printf ' `upstream_repositories` ON `package_sources`.`upstream_package_repository` = `upstream_repositories`.`id`' + printf ' WHERE' + printf ' `%s`.`name` = from_base64("%s") AND' \ + 'repositories' "${repository}" \ + 'architectures' "${architecture}" + printf ' `package_sources`.`%s` = from_base64("%s") AND' \ + 'pkgbase' "${pkgbase}" \ + 'git_revision' "${git_revision}" \ + 'mod_git_revision' "${mod_git_revision}" + printf ' `upstream_repositories`.`name` = from_base64("%s")' \ + "${upstream_package_repository}" + } | \ + sed ' + s|, )|)|g + s|, FROM| FROM|g + ' | \ + ${mysql_command} } # mysql_show_binary_package $pkgname $pkgver $pkgrel $sub_pkgrel @@ -113,45 +111,44 @@ mysql_show_binary_package() { done local joint - ${mysql_command} -e "$( - { - printf 'SELECT' - printf ' `%s`.`%s`,' \ - 'repositories' 'name' \ - 'binary_packages' 'pkgname' \ - 'package_sources' 'pkgver' \ - 'package_sources' 'pkgrel' \ - 'binary_packages' 'sub_pkgrel' \ - 'architectures' 'name' \ - 'package_sources' 'pkgbase' \ - 'package_sources' 'git_revision' \ - 'package_sources' 'mod_git_revision' \ - 'upstream_repositories' 'name' - printf ' FROM `binary_packages`' - for joint in \ - 'architectures:binary_packages:architecture' \ - 'package_sources:binary_packages:package_source' \ - 'repositories:binary_packages:repository' \ - 'upstream_repositories:package_sources:upstream_package_repository'; do - printf ' JOIN `%s` ON `%s`.`id` =' \ - "${joint%%:*}" "${joint%%:*}" - joint="${joint#*:}" - printf ' `%s`.`%s`' \ - "${joint%:*}" "${joint#*:}" - done - printf ' WHERE' - printf ' `%s`.`%s` = from_base64("%s") AND' \ - 'binary_packages' 'pkgname' "${pkgname}" \ - 'binary_packages' 'sub_pkgrel' "${sub_pkgrel}" \ - 'package_sources' 'pkgver' "${pkgver}" \ - 'package_sources' 'pkgrel' "${pkgrel}" - printf ';' - } | \ - sed ' - s|, FROM| FROM|g - s|AND;|;|g - ' - )" --html + { + printf 'SELECT' + printf ' `%s`.`%s`,' \ + 'repositories' 'name' \ + 'binary_packages' 'pkgname' \ + 'package_sources' 'pkgver' \ + 'package_sources' 'pkgrel' \ + 'binary_packages' 'sub_pkgrel' \ + 'architectures' 'name' \ + 'package_sources' 'pkgbase' \ + 'package_sources' 'git_revision' \ + 'package_sources' 'mod_git_revision' \ + 'upstream_repositories' 'name' + printf ' FROM `binary_packages`' + for joint in \ + 'architectures:binary_packages:architecture' \ + 'package_sources:binary_packages:package_source' \ + 'repositories:binary_packages:repository' \ + 'upstream_repositories:package_sources:upstream_package_repository'; do + printf ' JOIN `%s` ON `%s`.`id` =' \ + "${joint%%:*}" "${joint%%:*}" + joint="${joint#*:}" + printf ' `%s`.`%s`' \ + "${joint%:*}" "${joint#*:}" + done + printf ' WHERE' + printf ' `%s`.`%s` = from_base64("%s") AND' \ + 'binary_packages' 'pkgname' "${pkgname}" \ + 'binary_packages' 'sub_pkgrel' "${sub_pkgrel}" \ + 'package_sources' 'pkgver' "${pkgver}" \ + 'package_sources' 'pkgrel' "${pkgrel}" + printf ';' + } | \ + sed ' + s|, FROM| FROM|g + s|AND;|;|g + ' | \ + ${mysql_command} --html } # mysql_add_install_target $install_target @@ -164,12 +161,12 @@ mysql_add_install_target() { base64 -w0 ) - ${mysql_command} -e "$( + { printf 'INSERT IGNORE INTO `install_targets` (`name`)' printf ' VALUES (from_base64("%s"))' \ "${install_target}" - printf '\n' - )" + } | \ + ${mysql_command} } # mysql_generate_package_metadata $package $git_revision $mod_git_revision $repository @@ -191,16 +188,19 @@ mysql_generate_package_metadata() { ''|*[!0-9]*) unset forced_sub_pkgrel current_repository=$( - echo 'build-list' | \ - base64_encode_each + printf 'build-list' | \ + base64 -w0 ) ;; *) - forced_sub_pkgrel="$1" + forced_sub_pkgrel=$( + printf '%s' "$1" | \ + base64 -w0 + ) shift current_repository=$( - echo "$1" | \ - base64_encode_each + printf '%s' "$1" | \ + base64 -w0 ) shift ;; @@ -292,7 +292,7 @@ mysql_generate_package_metadata() { } | \ while read -r arch; do printf 'INSERT IGNORE INTO `build_assignments` (`package_source`,`architecture`,`is_blocked`)' - printf ' SELECT `package_sources`.`id`,`architectures`.`id`,0' + printf ' SELECT `package_sources`.`id`,`architectures`.`id`,NULL' printf ' FROM `architectures` JOIN `package_sources`' printf ' WHERE `architectures`.`name` = from_base64("%s")' \ "$( @@ -400,30 +400,45 @@ mysql_generate_package_metadata() { sed 's/[<>=].*$//' | \ base64_encode_each ) - sub_pkgrel=$( - if [ -n "${forced_sub_pkgrel}" ]; then - echo "${forced_sub_pkgrel}" - else - ${mysql_command} -e "$( - printf 'SELECT count(*) FROM `binary_packages` JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id` WHERE' - printf ' `binary_packages`.`%s`=from_base64("%s") AND' \ - 'epoch' "${epoch}" \ - 'pkgver' "${pkgver}" \ - 'pkgrel' "${pkgrel}" \ - 'pkgname' "${pkgname}" - if printf '%s' "${arch}" | base64 -d | grep -qxF 'any'; then - # 'any' gets higher sub_pkgrel than any architecture - printf ' 1' - else - # not-'any' gets higher sub_pkgrel than same or 'any' architecture - printf ' (`architectures`.`name`=from_base64("%s") OR `architectures`.`name`="any")' \ - "${arch}" - fi - )" | \ - tail -n1 - fi | \ - base64_encode_each - ) + if [ -n "${forced_sub_pkgrel}" ]; then + sub_pkgrel='from_base64("'"${forced_sub_pkgrel}"'")' + else + sub_pkgrel=$( + printf '(SELECT COALESCE(' + # do not add binary packages which are currently on the build-list + printf '(SELECT `sub_pkgrel` FROM `binary_packages`' + printf ' JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`' + printf ' JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`' + printf ' WHERE' + printf ' `binary_packages`.`%s`=from_base64("%s") AND' \ + 'epoch' "${epoch}" \ + 'pkgver' "${pkgver}" \ + 'pkgrel' "${pkgrel}" \ + 'pkgname' "${pkgname}" + printf ' `architectures`.`name`=from_base64("%s")' \ + "${arch}" + printf ' AND `repositories`.`name`="build-list"),' + # max(sub_pkgrel)+1 + printf '(SELECT 1+MAX(`binary_packages`.`sub_pkgrel`) FROM `binary_packages`' + printf ' JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`' + printf ' WHERE' + printf ' `binary_packages`.`%s`=from_base64("%s") AND' \ + 'epoch' "${epoch}" \ + 'pkgver' "${pkgver}" \ + 'pkgrel' "${pkgrel}" \ + 'pkgname' "${pkgname}" + if printf '%s' "${arch}" | base64 -d | grep -qxF 'any'; then + # 'any' gets higher sub_pkgrel than any architecture + printf ' 1' + else + # not-'any' gets higher sub_pkgrel than same or 'any' architecture + printf ' (`architectures`.`name`=from_base64("%s") OR `architectures`.`name`="any")' \ + "${arch}" + fi + printf ')' + printf ',0))' + ) + fi { printf 'INSERT IGNORE INTO `binary_packages` (' printf '`%s`,' \ @@ -433,8 +448,8 @@ mysql_generate_package_metadata() { 'epoch' \ 'pkgver' \ 'pkgrel' \ - 'sub_pkgrel' \ 'pkgname' \ + 'sub_pkgrel' \ 'has_issues' \ 'is_tested' printf ') SELECT ' @@ -446,9 +461,9 @@ mysql_generate_package_metadata() { "${epoch}" \ "${pkgver}" \ "${pkgrel}" \ - "${sub_pkgrel}" \ "${pkgname}" - printf '0,0 FROM' + printf '%s,0,0 FROM' \ + "${sub_pkgrel}" printf ' `%s` JOIN' \ 'repositories' \ 'architectures' \ @@ -547,8 +562,9 @@ mysql_generate_package_metadata() { 'epoch' "${epoch}" \ 'pkgver' "${pkgver}" \ 'pkgrel' "${pkgrel}" \ - 'sub_pkgrel' "${sub_pkgrel}" \ 'pkgname' "${pkgname}" + printf ' `binary_packages`.`sub_pkgrel` = %s AND' \ + "${sub_pkgrel}" printf ' `architectures`.`name` = from_base64("%s") AND' \ "${arch}" printf ' `repositories`.`name` = from_base64("%s");\n' \ @@ -564,7 +580,7 @@ mysql_generate_package_metadata() { done printf '.' >&2 - ${mysql_command} -e "$( + { if [ -s "${temp_dir}/add-build-assignments-command" ]; then cat "${temp_dir}/add-build-assignments-command" fi @@ -574,7 +590,8 @@ mysql_generate_package_metadata() { if [ -s "${temp_dir}/add-install-targets-command" ]; then cat "${temp_dir}/add-install-targets-command" fi - )" + } | \ + ${mysql_command} printf '.' >&2 ) @@ -603,13 +620,14 @@ mysql_sanity_check() { "${temp_dir}/master-mirror-listing" # shellcheck disable=SC2016 - ${mysql_command} -e ' - SELECT `repositories`.`name`,`pkgname`,`epoch`,`pkgver`,`pkgrel`,`sub_pkgrel`,`architectures`.`name` - FROM `binary_packages` - JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id` - JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id` - WHERE `repositories`.`is_on_master_mirror` - ' --batch | \ + { + printf 'SELECT `repositories`.`name`,`pkgname`,`epoch`,`pkgver`,`pkgrel`,`sub_pkgrel`,`architectures`.`name`' + printf ' FROM `binary_packages`' + printf ' JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`' + printf ' JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`' + printf ' WHERE `repositories`.`is_on_master_mirror`' + } | \ + ${mysql_command} --batch | \ sed ' 1d s,\t,/, |