summaryrefslogtreecommitdiff
path: root/src/stage3/prepare_deptree.sh
blob: 3b7038aa5aad26a6d48628cf9454bf7b59473760 (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
#!/bin/bash
 ##############################################################################
 #                      parabola-riscv64-bootstrap                            #
 #                                                                            #
 #    Copyright (C) 2018  Andreas Grapentin                                   #
 #                                                                            #
 #    This program is free software: you can redistribute it and/or modify    #
 #    it under the terms of the GNU General Public License as published by    #
 #    the Free Software Foundation, either version 3 of the License, or       #
 #    (at your option) any later version.                                     #
 #                                                                            #
 #    This program is distributed in the hope that it will be useful,         #
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of          #
 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           #
 #    GNU General Public License for more details.                            #
 #                                                                            #
 #    You should have received a copy of the GNU General Public License       #
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.   #
 ##############################################################################

set -euo pipefail

msg "preparing transitive dependency tree for $_groups (Stage 3)"

echo -n "checking for complete deptree ... "
[ -f "$_deptree".FULL ] && _have_deptree=yes || _have_deptree=no
echo $_have_deptree

if [ "x$_have_deptree" == "xno" ]; then
  declare -A _tree
  _frontier=($(pacman -Sg $_groups | awk '{print $2}'))

  while [ ${#_frontier[@]} -gt 0 ]; do
    # pop pkg from frontier
    _pkgname=$(echo ${_frontier[0]})
    _frontier=("${_frontier[@]:1}")

    # if seen before, skip, otherwise create entry in dependency tree
    [[ -v _tree[$_pkgname] ]] && continue
    _tree[$_pkgname]=""

    echo -en "\r  pkges: ${#_tree[@]} "

    _pkgdeps=$(pacman -Si $_pkgname | grep '^Depends' | cut -d':' -f2 | sed 's/None//')

    # tweak some build-time dependencies
    case $_pkgname in
      binutils)
        _pkgdeps+=" git dejagnu bc" ;;
      blas|cblas|lapack|lapacke|lapack-doc)
        _pkgdeps+=" cmake" ;;
      boost-libs|boost)
        _pkgdeps+=" python-numpy python2-numpy openmpi" ;;
      dbus)
        _pkgdeps+=" autoconf-archive" ;;
      gcc-libs)
        _pkgdeps+=" dejagnu libmpc mpfr gmp" ;;
      git)
        _pkgdeps="${_pkgdeps/curl}"
        _pkgdeps="${_pkgdeps/shadow}" ;;
      glib2)
        _pkgdeps+=" python" ;;
      gmp)
        _pkgdeps="${_pkgdeps/gcc-libs}" ;;
      gobject-introspection-runtime)
        _pkgdeps+=" python-mako" ;;
      jsoncpp)
        _pkgdeps+=" meson" ;;
      libaio)
        _pkgdeps+=" git" ;;
      libatomic_ops)
        _pkgdeps+=" git" ;;
      libdaemon)
        _pkgdeps+=" git" ;;
      libffi)
        _pkgdeps+=" dejagnu git" ;;
      libpsl)
        _pkgdeps+=" libxslt" ;;
      libsasl)
        _pkgdeps+=" libldap krb5 openssl sqlite" ;;
      libseccomp)
        _pkgdeps+=" git" ;;
      libsecret)
        _pkgdeps+=" gobject-introspection git intltool gtk-doc" ;;
      libtool)
        _pkgdeps+=" git help2man" ;;
      libxcb)
        _pkgdeps+=" libxslt python xorg-util-macros" ;;
      libxdmcp)
        _pkgdeps+=" xorg-util-macros" ;;
      libxml2)
        _pkgdeps+=" git python python2" ;;
      lz4)
        _pkgdeps+=" git" ;;
      ninja)
        _pkgdeps+=" python2 re2c" ;;
      nss-*|libudev|libsystemd*)
        _pkgdeps+=" libutil-linux pcre2 git meson gperf python-lxml quota-tools" ;;
      patch)
        _pkgdeps+=" ed" ;;
      python-lxml)
        _pkgdeps+=" cython cython2" ;;
      python-markupsafe)
        _pkgdeps+=" python-setuptools python2-setuptools" ;;
      shadow)
        _pkgdeps+=" gnome-doc-utils python2" ;;
    esac

    # iterate dependencies for pkg
    for _dep in $_pkgdeps; do
      # translate dependency string to actual package
      realdep=$(pacman --noconfirm -Sddw "$_dep" | grep '^Packages' | awk '{print $3}')
      realdep=${realdep%-*-*}
      # add dependency to tree and frontier
      _tree[$_pkgname]="${_tree[$_pkgname]} $realdep"
      _frontier+=($realdep)
    done
  done

  echo -en "\r"

  _tree[libldap]="${_tree[libldap]/libsasl}"

  # write package dependency tree
  truncate -s0 "$_deptree".FULL
  for i in bash make; do
    echo "$i-decross : [ ]" >> "$_deptree".FULL
  done
  for i in "${!_tree[@]}"; do
    echo "$i : [${_tree[$i]} ]" >> "$_deptree".FULL
  done
fi

[ -f "$_deptree" ] || cp "$_deptree"{.FULL,}
chown $SUDO_USER "$_deptree"

echo "  total pkges:      $(cat "$_deptree".FULL | wc -l)"
echo "  remaining pkges:  $(cat "$_deptree" | wc -l)"