File: call-graph.sh

package info (click to toggle)
debci 3.13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,656 kB
  • sloc: ruby: 6,516; sh: 2,437; javascript: 100; makefile: 92; perl: 11
file content (64 lines) | stat: -rwxr-xr-x 1,393 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

set -eu

if [ $# -eq 0 ]; then
  programs=$(find bin/ -type f -name 'debci-*' | xargs -n 1 basename)
  functions_file=lib/functions.sh
else
  programs=""
  functions_file="$@"
fi

the_functions=$(sed -e '/^\S\+()/!d; s/().*//' "$functions_file")

echo "digraph \"debci call graph\" {"

# declare function nodes
echo "  subgraph cluster_functions {"
for func in $the_functions; do
  echo "    \"${func}\" [shape=ellipse];"
done
echo "    label=\"$functions_file\";"
echo "    graph[style=dashed];"
echo "  }"

# declare program nodes
for program in $programs; do
  echo "  \"${program}\" [shape=box,style=filled,bgcolor=yellow];"
done

# calls from programs
for caller in $programs; do
  for callee in $programs $the_functions; do
    if [ "$caller" != "$callee" ] && grep -q "$callee" bin/"$caller"; then
      echo "  \"${caller}\" -> \"${callee}\";"
    fi
  done
done

# calls from functions
while read line; do
  case "$line" in
    \#*)
      continue
      ;;
  esac
  if echo "$line" | grep -q '^\S*()'; then
    func=$(echo "$line" | sed -e 's/().*//')
  else
    if echo "$line" | grep -q '^}$'; then
      func=
    else
      if [ -n "$func" ]; then
        for f in $the_functions; do
          if echo "$line" | grep -q "\b$f[^=]\|$f\$"; then
            echo "  \"$func\" -> \"${f}\";"
          fi
        done
      fi
    fi
  fi
done < "$functions_file"

echo "}"