C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dependency-graph.sh 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/bin/bash -e
  2. # template for bash scripts
  3. # internal use only
  4. append_msg() {
  5. if test $# -ne 0; then
  6. echo -en ":\e[0m \e[1m$*"
  7. fi
  8. echo -e "\e[0m"
  9. }
  10. # write a notice
  11. notice() {
  12. if test $# -eq 0; then
  13. return
  14. fi
  15. echo -e "\e[1m$*\e[0m" 1>&3
  16. }
  17. # write error message
  18. error() {
  19. echo -en "\e[1;31merror" 1>&2
  20. append_msg $* 1>&2
  21. }
  22. # write a warning message
  23. warning() {
  24. echo -en "\e[1;33mwarning" 1>&2
  25. append_msg $* 1>&2
  26. }
  27. # write a success message
  28. success() {
  29. echo -en "\e[1;32msuccess" 1>&2
  30. append_msg $* 1>&2
  31. }
  32. # commandline parameter evaluation
  33. files=${0%/*}/configure.ac
  34. short=0
  35. while test $# -gt 0; do
  36. case "$1" in
  37. (--short|-s) short=1;;
  38. (--help|-h) less <<EOF
  39. SYNOPSIS
  40. $0 [OPTIONS] <files>
  41. OPTIONS
  42. --help, -h show this help
  43. --short, -s short graph with no external dependencies
  44. <files> list of zero or more configure.ac files
  45. (default: ${files})
  46. DESCRIPTION
  47. Evaluates dependencies of all the given configure.ac file. By
  48. default takes the local configure.ac. Outputs a graphwiz dot file
  49. with the dependencies. Solid lines are required dependencies, dotted
  50. lines are optional dependencies.
  51. EXAMPLE
  52. Evaluate all dependencies between all local subversion and git
  53. projects, if they are in the path ~/svn and ~/git:
  54. $0 ~/svn/*/configure.ac ~/git/*/configure.ac
  55. EOF
  56. exit;;
  57. (*) files=$*; break;;
  58. esac
  59. if test $# -eq 0; then
  60. error "missing parameter, try $0 --help"; exit 1
  61. fi
  62. shift;
  63. done
  64. # run a command, print the result and abort in case of error
  65. # option: --no-check: ignore the result, continue in case of error
  66. run() {
  67. check=1
  68. while test $# -gt 0; do
  69. case "$1" in
  70. (--no-check) check=0;;
  71. (*) break;;
  72. esac
  73. shift;
  74. done
  75. echo -en "\e[1m-> running:\e[0m $* ..."
  76. result=$($* 2>&1)
  77. res=$?
  78. if test $res -ne 0; then
  79. if test $check -eq 1; then
  80. error "failed with return code: $res"
  81. if test -n "$result"; then
  82. echo "$result"
  83. fi
  84. exit 1
  85. else
  86. warning "ignored return code: $res"
  87. fi
  88. else
  89. success
  90. fi
  91. }
  92. # error handler
  93. function traperror() {
  94. set +x
  95. local err=($1) # error status
  96. local line="$2" # LINENO
  97. local linecallfunc="$3"
  98. local command="$4"
  99. local funcstack="$5"
  100. for e in ${err[@]}; do
  101. if test -n "$e" -a "$e" != "0"; then
  102. error "line $line - command '$command' exited with status: $e (${err[@]})"
  103. if [ "${funcstack}" != "main" -o "$linecallfunc" != "0" ]; then
  104. echo -n " ... error at ${funcstack} "
  105. if [ "$linecallfunc" != "" ]; then
  106. echo -n "called at line $linecallfunc"
  107. fi
  108. echo
  109. fi
  110. exit $e
  111. fi
  112. done
  113. success
  114. exit 0
  115. }
  116. # catch errors
  117. trap 'traperror "$? ${PIPESTATUS[@]}" $LINENO $BASH_LINENO "$BASH_COMMAND" "${FUNCNAME[@]}" "${FUNCTION}"' ERR SIGINT INT TERM EXIT
  118. ##########################################################################################
  119. filter() {
  120. if test $short -eq 1; then
  121. all=$(cat)
  122. allowed=$(sed -n '/"\(.*\)" \[style=solid\];/{s//\1/;H};${x;s/\n//;s/\n/\\|/gp}' <<<"${all}")
  123. sed -n '/"\('"${allowed}"'\)" -> "\('"${allowed}"'\)"/p' <<<"${all}"
  124. else
  125. cat
  126. fi
  127. }
  128. echo "digraph G {"
  129. if test $short -eq 0; then
  130. echo "node [style=dashed];"
  131. fi
  132. (
  133. for file in $files; do
  134. if ! test -e $file; then
  135. error "file $file not found"; exit 1
  136. fi
  137. sed -n '
  138. /^ *m4_define(x_package_name, */ {s//"/;s/ *).*/"/;h;s/.*/& [style=solid];/p}
  139. /^ *AX_REQUIRE_QT/ {s/.*/"qt" -> /;G;s/\n//;s/.*/&;/p}
  140. /^ *AX_PKG_REQUIRE(\[\?\([^],)]\+\)\]\?, \[\?\([^],)]\+\)\]\?.*/ {s//"\2" -> /;G;s/\n//;s/.*/&;/p}
  141. /^ *AX_PKG_REQUIRE(\[\?\([^],)]\+\)\]\?.*/ {s//"\1" -> /;G;s/\n//;s/.*/&;/p}
  142. /^ *AX_CHECK_QT/ {s/.*/"qt" -> /;G;s/\n//;s/.*/& [style=dashed];/p}
  143. /^ *AX_PKG_CHECK(\[\?\([^],)]\+\)\]\?, \[\?\([^],)]\+\)\]\?.*/ {s//"\2" -> /;G;s/\n//;s/.*/& [style=dotted];/p}
  144. /^ *AX_PKG_CHECK(\[\?\([^],)]\+\)\]\?.*/ {s//"\1" -> /;G;s/\n//;s/.*/& [style=dotted];/p}
  145. ' $file
  146. done
  147. ) | filter
  148. echo "}"