diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-02-18 09:56:24 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-02-18 09:56:24 +0100 |
commit | a2216f4f15f92f6e4f6dc387b5b5ffaf48e0470b (patch) | |
tree | 2acd3efb59035e130c05189bd455ec1c6055e5f3 | |
parent | f196c39e26f58a561f5c127cba0734f488612c5c (diff) | |
download | bootstrap32-a2216f4f15f92f6e4f6dc387b5b5ffaf48e0470b.tar.xz |
some work on the dependency calculator for stage 2, stage 3
-rwxr-xr-x | compute_dependencies.sh | 156 |
1 files changed, 126 insertions, 30 deletions
diff --git a/compute_dependencies.sh b/compute_dependencies.sh index 5d52145..ca8db79 100755 --- a/compute_dependencies.sh +++ b/compute_dependencies.sh @@ -3,6 +3,15 @@ # shellcheck source=./default.conf . "./default.conf" +# TODO: getopts +DOT=1 + +# local cache dir +CACHE_DIR="$SCRIPT_DIR/cache" +if test ! -d "$CACHE_DIR"; then + mkdir -p "$CACHE_DIR" +fi + # Compute dependencies and make-dependencies to build packages in stage1, # stage2 or stage3 @@ -10,61 +19,148 @@ tmp_dir=$(mktemp -d 'tmp.compute-dependencies.0.XXXXXXXXXX' --tmpdir) trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT # all top-level packages in base and base-devel -TOP_PACKAGES=$(pacman -Qg base base-devel | cut -f 2 -d ' ') +if test ! -f "$CACHE_DIR/group.base"; then + echo "INFO: Caching packages for group 'base'.." >&2 + pacman -Qg base | cut -f 2 -d ' ' > "$CACHE_DIR/group.base" +fi +TOP_BASE_PACKAGES=$(cat "$CACHE_DIR/group.base") +if test ! -f "$CACHE_DIR/group.base-devel"; then + echo "INFO: Caching packages for group 'base-devel'.." >&2 + pacman -Qg base-devel | cut -f 2 -d ' ' > "$CACHE_DIR/group.base-devel" +fi +TOP_BASE_DEVEL_PACKAGES=$(cat "$CACHE_DIR/group.base-devel") +STAGE1_PACKAGES="iana-etc filesystem linux-api-headers tzdata ncurses readline bash joe attr acl gmp gdbm db perl openssl zlib pambase cracklib libtirpc pam libcap coreutils util-linux e2fsprogs expat bzip2 lz4 xz pcre less gzip tar libarchive curl pacman-mirrorlist archlinux-keyring archlinux32-keyring pacman elfutils sed texinfo grep findutils file diffutils ed patch fakeroot kbd procps-ng shadow inetutils bc kmod linux uinit nasm syslinux net-tools libmnl libnfnetlink iptables iproute2 libedit openssh make mpfr gawk libmpc binutils gcc glibc libunwind strace gdb" +TOP_PACKAGES="$TOP_BASE_PACKAGES $TOP_BASE_DEVEL_PACKAGES $STAGE1_PACKAGES" # get dependencies for package in $TOP_PACKAGES; do - pactree -l $package >>${tmp_dir}/dependencies + if test ! -f "$CACHE_DIR/$package.pactree"; then + echo "INFO: Caching pactree for $package.." >&2 + pactree -l "$package" > "$CACHE_DIR/$package.pactree" + fi done +mkdir "$tmp_dir/work" +cd "$tmp_dir/work" + +# get srcinfo +for package in $TOP_PACKAGES; do + if test ! -f "$CACHE_DIR/$package.srcinfo"; then + echo "INFO: Caching SRCINFO for $package.." >&2 + asp export $package >"$tmp_dir/$package.asp_output" 2>&1 + # asp makes redirects like '==>' ignore those and use the pointee + if test "$(head -n1 "$tmp_dir/$package.asp_output" | grep -c '==> .* is part of' )" == 1; then + _tmp=$(head -n1 "$tmp_dir/$package.asp_output" | sed 's/==> \(.*\)/\1/') + SUB_PACKAGE=$(echo "$_tmp" | cut -f 1 -d ' ') + ADD_PACKAGE=$(echo "$_tmp" | rev | cut -f 1 -d ' ' | rev) + # TODO: we should map sub packages to packages everywhere + echo "WARN: seen a redirect from $SUB_PACKAGE to $ADD_PACKAGE" >&2 + continue; + fi + if test -d "$package"; then + cd $package || exit 1 + makepkg --printsrcinfo > "$CACHE_DIR/$package.srcinfo" + fi + fi +done + +cat "$CACHE_DIR"/*.pactree > "$tmp_dir/dependencies" + # all packages needed -ALL_PACKAGES=$(cat ${tmp_dir}/dependencies | sort | uniq) +ALL_PACKAGES="$(cat "$tmp_dir/dependencies" | sort | uniq)" export CARCH='x86_64' +canonize_package( ) +{ + _p=$1 + if test $(echo $_p | grep -c '>=') -gt 0; then + _p=$(echo $_p | cut -f 1 -d '>') + fi +} + get_dependencies( ) { package=$1 mode=$2 - asp show $package >${tmp_dir}/$package.PKGBUILD - # temporary hotfix for FS#57524 - if test "$(head -n1 ${tmp_dir}/$package.PKGBUILD | grep -c '^\$Id\$$' )" == 1; then - sed -i 's/^\(\$Id\$\)$/#\1/' ${tmp_dir}/$package.PKGBUILD - fi + asp show $package >"${tmp_dir}/$package.PKGBUILD" # asp makes redirects like '==>' ignore those and use the pointee - if test "$(head -n1 ${tmp_dir}/$package.PKGBUILD | grep -c '==>' )" == 1; then - _tmp=$(head -n1 ${tmp_dir}/$package.PKGBUILD | sed 's/==> \(.*\)/\1/') - SUB_PACKAGE=$(echo $_tmp | cut -f 1 -d ' ') - ADD_PACKAGE=$(echo $_tmp | rev | cut -f 1 -d ' ' | rev) + if test "$(head -n1 "${tmp_dir}/$package.PKGBUILD" | grep -c '==>' )" == 1; then + _tmp=$(head -n1 "${tmp_dir}/$package.PKGBUILD" | sed 's/==> \(.*\)/\1/') + SUB_PACKAGE=$(echo "$_tmp" | cut -f 1 -d ' ') + ADD_PACKAGE=$(echo "$_tmp" | rev | cut -f 1 -d ' ' | rev) # TODO: we should map sub packages to packages everywhere echo "WARN: seen a redirect from $SUB_PACKAGE to $ADD_PACKAGE" >&2 + unset depends return fi _depends=$(. ${tmp_dir}/$package.PKGBUILD; echo "${depends[@]}") - for subpackage in "${_depends[@]}"; do - get_dependencies "$subpackage" "$mode" - done - depends+=( "${_depends[@]}" ) - #makedepends=$(. ${tmp_dir}/$package.PKGBUILD; echo "${makedepends[@]}") - # TODO handle version constraints - #checkdepends=$(. ${tmp_dir}/$package.PKGBUILD; echo "${checkdepends[@]}") - #echo $package - #printf "\tdepends: $depends\n" - #printf "\tmakedepends: $makedepends\n" - #printf "\tcheckdepends: $checkdepends\n" - #echo "${depends[@]}" - #echo "${makedepends[@]}" + if test "$_depends" != ""; then + for subpackage in $_depends; do + canonize_package "$subpackage" + subpackage=$_p + depends+=( "$subpackage" ) + #get_dependencies "$subpackage" "$mode" + done + fi } +if test "$DOT" = 1; then + cat <<EOF +digraph dependencies { + fontname=dejavu; +EOF +fi + +if test "$DOT" = 1;then + for package in $TOP_BASE_PACKAGES; do + cat <<EOF + "$package" [fontcolor="#00ff00"]; +EOF + done + for package in $TOP_BASE_DEVEL_PACKAGES; do + cat <<EOF + "$package" [fontcolor="#0000ff"]; +EOF + done + for package in $STAGE1_PACKAGES; do + cat <<EOF + "$package" [fontcolor="#ff0000"]; +EOF + done +fi + for package in $ALL_PACKAGES; do unset depends declare -a depends get_dependencies "$package" "depends" - echo "$package" "${depends[@]}" + if test -v depends; then + if test "$DOT" = 0; then + echo -n "$package: " + fi + for depend in "${depends[@]}"; do + if test "$DOT" = 1; then + cat <<EOF + "$package" -> "$depend" +EOF + else + echo -n "$depend " + fi + done + echo + fi done -# ./compute_dependencies.sh | tr -s ' ' '\n' | sort | uniq > depends -# ./compute_dependencies.sh | tr -s ' ' '\n' | sort | uniq > makedepends -# grep -xf depends makedepends > makedepends_already_depends -# grep -vxf depends makedepends > new_makedepends +if test "$DOT" = 1; then + cat <<EOF +} +EOF +fi + +# DOT=0 +# ./compute_dependencies.sh > stage2 + +# DOT=1 +# ./compute_dependencies.sh > graph.dot +# dot -Tpng -o graph.png graph.dot |