OpenSDE Framework (without history before r20070)
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.

196 lines
4.6 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/misc/AuditBuild.sh
  6. # Copyright (C) 2008 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. MATRIX=http://www.t2-project.org/packages
  17. config=default
  18. enabled='X'
  19. repositories=
  20. VERBOSE=
  21. HTMLDIR=
  22. root=
  23. show_usage() {
  24. cat<<-EOT
  25. usage: $0 [-v] [-cfg <config>] [--no-enabled-too] [-repository <repositories>]
  26. EOT
  27. }
  28. while [ $# -gt 0 ]; do
  29. case "$1" in
  30. -cfg) config="$2"; shift ;;
  31. -v) VERBOSE=1 ;;
  32. -w) HTMLDIR="$2"; shift ;;
  33. --help) show_usage; exit 1 ;;
  34. -R) root="$2"; shift ;;
  35. --no-enabled-too)
  36. enabled=. ;;
  37. -repository)
  38. shift; repositories="$*"
  39. break ;;
  40. *) show_usage; exit 2 ;;
  41. esac
  42. shift
  43. done
  44. if [ ! -f config/$config/packages ]; then
  45. echo "ERROR: '$config' is not a valid config"
  46. exit 1
  47. fi
  48. eval `grep 'SDECFG_ID=' config/$config/config 2> /dev/null`
  49. if [ "$root" ]; then
  50. LOGSDIR=$root/var/adm/logs
  51. else
  52. LOGSDIR=build/$SDECFG_ID/var/adm/logs
  53. fi
  54. if [ -z "$SDECFG_ID" -o ! -d $LOGSDIR ]; then
  55. echo "ERROR: 'build/$SDECFG_ID/' is not a valid build root (sandbox)"
  56. exit 1
  57. fi
  58. if [ "$HTMLDIR" ]; then
  59. mkdir -p $HTMLDIR/$config.$$/{diff,log}
  60. fi
  61. expand_stages() {
  62. local array="$1" stage=
  63. while [ "$array" ]; do
  64. stage=${array:0:1}
  65. array=${array:1}
  66. if [ "$stage" != "-" ]; then
  67. echo -n "$stage "
  68. fi
  69. done
  70. }
  71. audit_package() {
  72. local pkg="$1" repo="$2" ver="$3" enabled="$4"
  73. local stages= svndiff= oldver= newver= lchanges= stage=
  74. local svnst= lstatus= lbuild= file=
  75. shift 4; stages="$*"
  76. svnst=`svn st package/$repo/$pkg`
  77. if [ "$svnst" ]; then
  78. svndiff=`svn diff package/$repo/$pkg`
  79. if [ "$svndiff" ]; then
  80. lchanges="CHANGED"
  81. oldver=`echo "$svndiff" | grep '^-\[V\]' | cut -d' ' -f2`
  82. newver=`echo "$svndiff" | grep '^+\[V\]' | cut -d' ' -f2`
  83. if [ "$oldver" ]; then
  84. ver="$oldver -> $newver"
  85. lchanges="UPDATED"
  86. elif [ "$newver" ]; then
  87. lchanges="ADDED"
  88. fi
  89. fi
  90. if [ "$HTMLDIR" ]; then
  91. {
  92. echo "$svnst"
  93. echo ""
  94. echo "$svndiff"
  95. } > $HTMLDIR/$config.$$/diff/$pkg.diff.txt
  96. lchanges="<a href=\"diff/$pkg.diff.txt\">$lchanges</a>"
  97. fi
  98. fi
  99. if [ "$enabled" == "O" ]; then
  100. for stage in $stages; do
  101. lbuild="$lbuild NO($stage)"
  102. done
  103. lstatus=3
  104. else
  105. for stage in $stages; do
  106. file=`ls -1 $LOGSDIR/$stage-$pkg.{err,log,out} 2> /dev/null`
  107. lstatus=
  108. if [ "$file" ]; then
  109. case "$file" in
  110. *.log) [ "$lstatus" ] || lstatus=1
  111. lbuild="$lbuild OK($stage)" ;;
  112. *.out) [ "$lstatus" != "2" ] || lstatus=0
  113. lbuild="$lbuild NO($stage)" ;;
  114. *) lstatus=2
  115. if [ "$HTMLDIR" ]; then
  116. lbuild="$lbuild <a href=\"log/$stage-$pkg.err.txt\">ERR($stage)</a>"
  117. cp $file $HTMLDIR/$config.$$/log/$stage-$pkg.err.txt
  118. else
  119. lbuild="$lbuild ERR($stage)"
  120. fi ;;
  121. esac
  122. else
  123. lbuild="$lbuild NO($stage)"
  124. [ "$lstatus" ] || lstatus=0
  125. fi
  126. done
  127. fi
  128. case "$lstatus" in
  129. 3) lstatus=DISABLED ;;
  130. 2) lstatus=FAILED ;;
  131. 1) lstatus=SUCCESSFUL ;;
  132. *) lstatus=PENDING ;;
  133. esac
  134. if [ "$HTMLDIR" ]; then
  135. cat <<EOT
  136. <tr><td>package/$repo/<a href="$MATRIX/$pkg.html" name="$pkg">$pkg</a></td><td>$lchanges</td><td>(${ver//>/&gt;})</td><td>$lbuild</td><td>$lstatus</td></tr>
  137. EOT
  138. else
  139. echo -e "package/$repo/$pkg\t$lchanges\t($ver)\t$lbuild\t$lstatus"
  140. fi
  141. }
  142. if [ "$HTMLDIR" ]; then
  143. cat <<EOT
  144. <html>
  145. <head><title>Audit Build $config over revision $( svn info | grep Revision | cut -d' ' -f2 )</title>
  146. <body>
  147. $( [ "$repositories" ] && echo "<h3>$repositories</h3>" )
  148. <table><tr>
  149. <th>Package</th>
  150. <th>SVN Status</th>
  151. <th>Version</th>
  152. <th>Build Status</th>
  153. <th>Result</th>
  154. </tr>
  155. EOT
  156. fi
  157. if [ "$repositories" ]; then
  158. for repo in $repositories; do
  159. repo=${repo#package/}; repo=${repo%/}
  160. if [ -d package/$repo/ ]; then
  161. grep -e "^$enabled.* $repo " config/$config/packages | while \
  162. read e stages x repo pkg ver x; do
  163. audit_package $pkg $repo $ver $e `expand_stages $stages`
  164. done
  165. fi
  166. done
  167. else
  168. grep -e "^$enabled" config/$config/packages | while \
  169. read e stages x repo pkg ver x; do
  170. audit_package $pkg $repo $ver $e `expand_stages $stages`
  171. done
  172. fi
  173. if [ "$HTMLDIR" ]; then
  174. echo "<body><html>"
  175. if [ -d "$HTMLDIR/$config" ]; then
  176. mv $HTMLDIR/$config $HTMLDIR/$config.$$-old
  177. fi
  178. mv $HTMLDIR/$config.$$ $HTMLDIR/$config/
  179. rm -rf $HTMLDIR/$config.$$-old
  180. fi