Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdeptree: List dependencies of package (or find closest link) #314

Open
Anachron opened this issue Oct 15, 2023 · 6 comments
Open

xdeptree: List dependencies of package (or find closest link) #314

Anachron opened this issue Oct 15, 2023 · 6 comments

Comments

@Anachron
Copy link

Anachron commented Oct 15, 2023

Script to either show a full dependency tree of a package or find the closest link between two dependencies.

#!/bin/sh

base=$(mktemp -d "/tmp/xdeplink.XXXXXX") || exit 1
trap "rm -rf \"${base}\"" EXIT TERM
tree="${base}/tree"; store="${base}/store"

test "$#" -ge 1 || exit
mkdir "${tree}" "${store}"
cd "${tree}" || exit

handle() {
  deps=$(xbps-query -Rx "${1}")
  test -n "${deps}" || return
  for d in ${deps}; do
    d=$(xbps-uhelper getpkgdepname "${d}")
    test -n "${d}" || continue
    if ! test -e "${store}/${d}"; then
      mkdir "${d}"
      ln -s "${PWD}/${d}" "${store}/${d}"
      ( cd "${d}"; handle "${d}"; )
    else
      ln -s "${store}/${d}" "${d}"
    fi
  done
}

handle "${1}"
if test -n "${2}"; then
  find -name "${2}" -printf '%d %P\n' | sort -n | sed -E 's|^[0-9]+ ||g'
else
  find -mindepth 1 -printf '%P\n' | sort
fi

Example:

$ xdeptree mesa-dri ncurses-libs
libllvm15/ncurses-libs
libllvm15/libedit/ncurses-libs
libllvm15/libxml2/libreadline8/ncurses-libs

This shows that ncurses-libs gets pulled in by libllvm15 and that's why it's a dependency of mesa-dri.

Another Example:

$ xdeptree ffmpeg wayland
ffplay/SDL2/wayland
ffplay/SDL2/libdecor/wayland

A third one (print the whole tree)

$ xdeptree wayland
glibc
libffi
libffi/glib
@Anachron
Copy link
Author

Anachron commented Oct 15, 2023

Comment:
This is to be used in combination with xbps-query --fulldeptree -Rx <pkgname>.

Now, you don't need to wonder any longer what the dependency chain is! ;-)

@Anachron Anachron changed the title WIP: xdeplink xdeptree: List dependencies of package (or find closest link) Oct 16, 2023
@leahneukirchen
Copy link
Owner

I think the tool is useful, not sure about the implementation however.

Perhaps the output of xbps-dgraph -f is more suitable to work on, perhaps even with gvpr(1).

@Anachron
Copy link
Author

Happy to hear!

This is an improved version by feranur:

#!/bin/sh
set -eu

tmp="`mktemp -d`"
trap 'rm -rf "$tmp"' EXIT
trap 'exit 98' INT TERM HUP ALRM PIPE QUIT # ensure the EXIT trap is triggered on signals

tree="${tmp}/tree"
store="${tmp}/store"

test $# -ge 1
mkdir "${tree}" "${store}"
cd "${tree}"

handle() {
    deps=$(xbps-query -Rx "${1}")
    for d in ${deps:-} ; do
        d=$(xbps-uhelper getpkgdepname "${d}" || xbps-uhelper getpkgname "$d")
        test -n "${d:-}" || exit 99
        if ! test -e "${store}/${d}"; then
            mkdir "${d}"
            ln -s "${PWD}/${d}" "${store}/${d}"
            ( cd "${d}"; handle "${d}"; )
        else
            ln -s "${store}/${d}" "${d}"
        fi
    done
}

handle "${1}"
if test -n "${2:-}" ; then
    find . -name "${2}" -printf '%d %P\n' | sort -n | sed -E 's/^[0-9]+ //'
else
    find . -mindepth 1 -printf '%P\n' | sort
fi

@leahneukirchen
Copy link
Owner

prototype:

xbps-dgraph mesa -f | gvpr '
  BEGIN {
    node_t stack[int];
    int depth = 0;

    void traverse(node_t n, edge_t e) {
      stack[depth++] = n;

      if (n.label == "ncurses-libs-6.4_2") {
        int i;
        for (i = 0; i < depth; i++) {
          printf("%s", stack[i].label);
          if (i < depth-1)
            printf(" -> ");
        }
        printf("\n");
      }

      e = fstout(n);
      while (e != NULL) {
        traverse(e.head, NULL);
        if (e == NULL)
          break;
        e = nxtout(e);
      }

      depth--;
    }
  }
  BEG_G {
    traverse(node($,"31"), NULL);
  }
'

@Anachron
Copy link
Author

Nice, that one is quite fast.

If you could now manage to show all dependencies in a tree I guess we can use that one instead of mine.

@leahneukirchen
Copy link
Owner

Here is one with one or two arguments: https://l2.re/gmGaDF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants