depends: find-like output

when dealing with package dependency woes, such as

http://cygwin.com/ml/cygwin/2014-10/msg00563.html

The current "depends" tree method fails, because it only shows the packages, not
the dependency paths. These paths are necessary to solve the "shortest path
problem"

http://wikipedia.org/wiki/Shortest_path_problem

Now, every possible dependency path will print from the chosen package. Combined
with category search you can run searches such as

    apt-cyg category Base |
    apt-cyg depends |
    awk '/perl$/ {print length,$0}' |
    sort -n

Solving the path problem in seconds.
This commit is contained in:
Steven Penny 2014-11-11 03:15:24 -06:00
parent 2138f54544
commit e9bea37b95
1 changed files with 21 additions and 33 deletions

54
apt-cyg
View File

@ -150,8 +150,7 @@ function apt-category {
pck = $2
}
$1 == "category:" && $0 ~ query {
$1 = ""
printf "%-25s%s\n", pck, $0
print pck
}
' query="$pks" setup.ini
done
@ -213,46 +212,33 @@ function apt-depends {
check-packages
for pkg in "${pks[@]}"
do
(( sq++ )) && echo
awk '
@include "join"
$1 == "@" {
pkg = $2
apg = $2
}
$1 == "requires:" {
for (i=2; i<=NF; i++)
reqs[pkg][i-1]=$i
for (z=2; z<=NF; z++)
reqs[apg][z-1] = $z
}
END {
setMinDepth(query)
prtPkg(query)
prpg(ENVIRON["pkg"])
}
function prtPkg(pkg, req, i) {
depth++
if ( depth == mn[pkg] && !seen[pkg]++ ) {
printf "%*s%s\n", indent, "", pkg
indent += 2
if (pkg in reqs)
for (i=1; i in reqs[pkg]; i++) {
req = reqs[pkg][i]
prtPkg(req)
}
indent -= 2
}
depth--
function smartmatch(small, large, values) {
for (each in large)
values[large[each]]
return small in values
}
function setMinDepth(pkg, req, i) {
depth++
mn[pkg] = !(pkg in mn) || depth < mn[pkg] ? depth : mn[pkg]
if (depth == mn[pkg]) {
if (pkg in reqs)
for (i=1; i in reqs[pkg]; i++) {
req = reqs[pkg][i]
setMinDepth(req)
}
}
depth--
function prpg(fpg) {
if (smartmatch(fpg, spath)) return
spath[length(spath)+1] = fpg
print join(spath, 1, length(spath))
if (isarray(reqs[fpg]))
for (each in reqs[fpg])
prpg(reqs[fpg][each])
delete spath[length(spath)]
}
' query="$pkg" setup.ini
' setup.ini
done
}
@ -595,6 +581,8 @@ do
esac
done
set -a
if type -t apt-$command | grep -q function
then
apt-$command