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

# usage: why_dont_you $action $package1 $package2 ...

# investigate, why a certain operation is not done with certain packages

. "${0%/*}/../conf/default.conf"

action="$1"
shift

case "${action}" in

  'build')

    for pkg in "$@"; do
      grep "^$(str_to_regex "${pkg}") " "${work_dir}/build-list" | \
        while read -r package git_revision mod_git_revision repository; do

          if [ -f "${work_dir}/package-states/${package}.${git_revision}.${mod_git_revision}.${repository}.done" ] ||
            [ -f "${work_dir}/package-states/${package}.${git_revision}.${mod_git_revision}.${repository}.testing" ]; then
            echo 'has been built'
            continue
          fi

          if package_locked_or_blocked "${package}" "${git_revision}" "${mod_git_revision}" "${repository}"; then
            printf '"%s" is locked or blocked\n' "${pkg}"
            continue
          fi

          if [ -n "$(
            (
              cat "${work_dir}/package-infos/${package}.${git_revision}.${mod_git_revision}.needs"
              grep -vxF 'break_loops' "${work_dir}/build-list" | \
                awk '{print $1 "." $2 "." $3}' | \
                sed "
                  s|^|${work_dir}/package-infos/|
                  s|\$|\.builds|
                " | \
                xargs -r cat | \
                sort -u
            ) | \
              sort | \
              uniq -d
            )" ]; then
            printf '"%s" has unmet dependencies:\n' "${package}"
            (
              cat "${work_dir}/package-infos/${package}.${git_revision}.${mod_git_revision}.needs"
              grep -vxF 'break_loops' "${work_dir}/build-list" | \
                awk '{print $1 "." $2 "." $3}' | \
                sed "
                  s|^|${work_dir}/package-infos/|
                  s|\$|\.builds|
                " | \
                xargs -r cat | \
                sort -u
            ) | \
              sort | \
              uniq -d | \
              while read -r dep; do
                grep -lxF "${dep}" "${work_dir}/package-infos/"*".builds" | \
                  sed '
                    s|^.*/||
                    s|\(\.[^.]\+\)\{3\}||
                  '
              done | \
              sort -u
            printf '\n'

            continue
          fi

          if [ -f "${work_dir}/package-states/${package}.${git_revision}.${mod_git_revision}.${repository}.broken" ]; then
            printf '"%s" is broken (%sx built), but would be built\n' \
              "${pkg}" \
              "$(wc -l < "${work_dir}/package-states/${package}.${git_revision}.${mod_git_revision}.${repository}.broken")"
          else
            printf '"%s" would be built\n' "${pkg}"
          fi
        done

    done

  ;;

  'unstage')

    for pkg in "$@"; do

      if ! ls -1 "${work_dir}/package-states" | \
        grep -q "^$(str_to_regex "${pkg}")\(\.[^.]\+\)\{3\}\.done\$"; then
        printf '"%s" is not in staging!\n' "${pkg}"
        continue
      fi

      dependent_packages="$(
        grep -lxF "${pkg}" "${work_dir}/package-infos/"*".depends" | \
          sed '
            s|^.*/||
            s|\.depends$||
          '
      )"

      build_list_items_file="$(mktemp)"
      dependent_packages_file="$(mktemp)"

      grep -vxF 'break_loops' "${work_dir}/build-list" | \
        awk '{print $1 "." $2 "." $3 " " $4}' | \
        sort -u > \
        "${build_list_items_file}"

      printf '%s\n' "${dependent_packages}" | \
        sort -u > \
        "${dependent_packages_file}"

      dependent_still_on_build_list="$(
        join -1 1 -2 1 -o 1.1,1.2 \
          "${build_list_items_file}" \
          "${dependent_packages_file}"
      )"

      rm -f \
        "${build_list_items_file}" \
        "${dependent_packages_file}"

      if [ -n "${dependent_still_on_build_list}" ]; then
        printf 'The following packages are dependent on "%s", but still on the build list:\n' "${pkg}"
        echo "${dependent_still_on_build_list}"
        printf '\n'
        continue
      fi

      dependent_still_in_staging="$(
        echo "${dependent_packages}" | \
          while read -r sf; do
            if [ -f "${work_dir}/package-states/$sf."*".done" ]; then
              echo "${sf}"
            fi
          done
      )"

      if [ -n "${dependent_still_in_staging}" ]; then
        printf 'The following packages are dependent on "%s" and still in staging - maybe they cannot be unstaged:\n' "${pkg}"
        echo "${dependent_still_in_staging}"
        printf '\n'
        continue
      fi

      printf 'Package "%s" can be unstaged.\n' "${pkg}"

    done

  ;;

  *)
    >&2 printf 'unknown action "%s"\n' "${action}"
    exit 1

esac