Skip to content

Commit

Permalink
contrib: depdot: use processed package info
Browse files Browse the repository at this point in the history
Instead of poorly parsing Makefiles using grep, use OpenWrt's processed
package info files. This fixes handling of DEPENDS fields spanning
multiple lines and adds support for source packages building multiple
binary packages.

Closes freifunk-gluon#2814
  • Loading branch information
neocturne committed Sep 10, 2023
1 parent 8c48f20 commit 57a95b0
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions contrib/depdot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Script to output the dependency graph of Gluon's packages
# Limitations:
# * Works only if directory names and package names are the same (true for all Gluon packages)
# * Doesn't show dependencies through virtual packages correctly

set -e
Expand All @@ -16,27 +15,42 @@ escape_name() {
echo -n "_$1" | tr -c '[:alnum:]' _
}

print_node () {
print_node() {
echo "$(escape_name "$1") [label=\"$1\", shape=box];"
}

print_dep() {
echo "$(escape_name "$1") -> $(escape_name "$2");"
}

echo 'digraph G {'

for makefile in ./package/*/Makefile; do
dir="$(dirname "$makefile")"
package="$(basename "$dir")"

deps=$(grep -w DEPENDS "$makefile" | cut -d= -f2 | tr -d +)
print_package() {
local package="$1" depends="$2"
# shellcheck disable=SC2086
set -- $depends

print_node "$package"
for dep in $deps; do
for dep in "$@"; do
print_node "$dep"
print_dep "$package" "$dep"
done
}

make -C openwrt -s prepare-tmpinfo

echo 'digraph G {'

cat ./openwrt/tmp/info/.packageinfo-feeds_gluon_base_* | while read -r key value; do
case "$key" in
'Package:')
package="$value"
;;
'Depends:')
depends="${value//+/}"
;;
'@@')
print_package "$package" "$depends"
;;
esac
done | sort -u

popd >/dev/null
Expand Down

0 comments on commit 57a95b0

Please sign in to comment.