sequoia-sq: rebuild for capnproto-1.1.0.
[void-pkg.git] / common / xbps-src / shutils / bulk.sh
blob69e36f4a43f4e8bb631869f1c5d8fbbb3523a51c
1 # vim: set ts=4 sw=4 et:
3 bulk_getlink() {
4 local p="${1##*/}"
5 local target="$(readlink $XBPS_SRCPKGDIR/$p)"
7 if [ $? -eq 0 -a -n "$target" ]; then
8 p=$target
9 fi
10 echo $p
13 bulk_sortdeps() {
14 local _pkgs _pkg pkgs pkg found f x tmpf
16 _pkgs="$@"
17 # Iterate over the list and make sure that only real pkgs are
18 # added to our pkglist.
19 for pkg in ${_pkgs}; do
20 found=0
21 f=$(bulk_getlink $pkg)
22 for x in ${pkgs}; do
23 if [ "$x" = "${f}" ]; then
24 found=1
25 break
27 done
28 if [ $found -eq 0 ]; then
29 pkgs+="${f} "
31 done
33 tmpf=$(mktemp) || exit 1
34 # Now make the real dependency graph of all pkgs to build.
35 # Perform a topological sort of all pkgs but only with build dependencies
36 # that are found in previous step.
37 for pkg in ${pkgs}; do
38 _pkgs="$($XBPS_DISTDIR/xbps-src show-build-deps $pkg 2>/dev/null)"
39 found=0
40 for x in ${_pkgs}; do
41 _pkg=$(bulk_getlink $x)
42 for f in ${pkgs}; do
43 if [ "${f}" != "${_pkg}" ]; then
44 continue
46 found=1
47 echo "${pkg} ${f}" >> $tmpf
48 done
49 done
50 [ $found -eq 0 ] && echo "${pkg} ${pkg}" >> $tmpf
51 done
52 tsort $tmpf|tac
53 rm -f $tmpf
56 bulk_build() {
57 local bulk_build_cmd="$1"
58 local NPROCS=$(($(nproc)*2))
59 local NRUNNING=0
61 if [ "$XBPS_CROSS_BUILD" ]; then
62 source ${XBPS_COMMONDIR}/cross-profiles/${XBPS_CROSS_BUILD}.sh
63 export XBPS_ARCH=${XBPS_TARGET_MACHINE}
65 if ! command -v xbps-checkvers &>/dev/null; then
66 msg_error "xbps-src: cannot find xbps-checkvers(1) command!\n"
69 # Compare installed pkg versions vs srcpkgs
70 case "$bulk_build_cmd" in
71 installed)
72 bulk_sortdeps $(xbps-checkvers -f '%n' -I -D "$XBPS_DISTDIR")
73 return $?
75 local)
76 bulk_sortdeps $(xbps-checkvers -f '%n' -i -R "${XBPS_REPOSITORY}/bootstrap" -R "${XBPS_REPOSITORY}" -R "${XBPS_REPOSITORY}/nonfree" -D "$XBPS_DISTDIR")
77 return $?
79 esac
81 # compare repo pkg versions vs srcpkgs
82 for f in $(xbps-checkvers -f '%n' -D $XBPS_DISTDIR); do
83 if [ $NRUNNING -eq $NPROCS ]; then
84 NRUNNING=0
85 wait
87 NRUNNING=$((NRUNNING+1))
89 setup_pkg $f $XBPS_TARGET_MACHINE &>/dev/null
90 if show_avail &>/dev/null; then
91 echo "$f"
93 ) &
94 done
95 wait
96 return $?
99 bulk_update() {
100 local bulk_update_cmd="$1" pkgs f rval
102 pkgs="$(bulk_build "${bulk_update_cmd}")"
103 [[ -z $pkgs ]] && return 0
105 msg_normal "xbps-src: the following packages must be rebuilt and updated:\n"
106 for f in ${pkgs}; do
107 echo " $f"
108 done
109 for f in ${pkgs}; do
110 XBPS_TARGET_PKG=$f
111 read_pkg
112 msg_normal "xbps-src: building ${pkgver} ...\n"
113 if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
114 chroot_handler pkg $XBPS_TARGET_PKG
115 else
116 $XBPS_LIBEXECDIR/build.sh $f $f pkg $XBPS_CROSS_BUILD
118 if [ $? -eq 1 ]; then
119 msg_error "xbps-src: failed to build $pkgver pkg!\n"
121 done
122 if [ -n "$pkgs" -a "$bulk_update_cmd" == installed ]; then
123 echo
124 msg_normal "xbps-src: updating your system, confirm to proceed...\n"
125 ${XBPS_SUCMD} "xbps-install --repository=$XBPS_REPOSITORY/bootstrap --repository=$XBPS_REPOSITORY --repository=$XBPS_REPOSITORY/nonfree -u ${pkgs//[$'\n']/ }" || return 1