Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/why_dont_you
blob: 6424335b9971bddb23e0eec898c238b550ddd3c7 (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
#!/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}.${git_revision}.${mod_git_revision}.${repository}.done" ] ||
            [ -f "${work_dir}/${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
            echo 'is locked or blocked'
            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
            echo 'has unmet dependencies:'
            (
              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

            continue
          fi

          echo 'would be built'
        done

    done

  ;;

  'unstage')

    for pkg in "$@"; do

      if ! ls -1 "${work_dir}/package-states" | \
        grep -q "^$(str_to_regex "${pkg}")\(\.[^.]\+\)\{3\}\.done\$"; then
        printf 'Package "%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}"
        continue
      fi

      echo 'No dependencies left on build list.'
      echo "${dependent_packages}"

    done

  ;;

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

esac