deptest.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/bin/bash
  2. #
  3. # Automated OpenWrt package dependency checker
  4. #
  5. # Copyright (C) 2009-2010 OpenWrt.org
  6. #
  7. # This is free software, licensed under the GNU General Public License v2.
  8. # See /LICENSE for more information.
  9. #
  10. SCRIPTDIR="$(dirname "$0")"
  11. [ "${SCRIPTDIR:0:1}" = "/" ] || SCRIPTDIR="$PWD/$SCRIPTDIR"
  12. BASEDIR="$SCRIPTDIR/.."
  13. DIR="$BASEDIR/tmp/deptest"
  14. STAMP_DIR_SUCCESS="$DIR/stamp-success"
  15. STAMP_DIR_FAILED="$DIR/stamp-failed"
  16. STAMP_DIR_BLACKLIST="$DIR/stamp-blacklist"
  17. BUILD_DIR="$DIR/build_dir/target"
  18. BUILD_DIR_HOST="$DIR/build_dir/host"
  19. KERNEL_BUILD_DIR="$DIR/build_dir/linux"
  20. STAGING_DIR="$DIR/staging_dir/target"
  21. STAGING_DIR_HOST="$DIR/staging_dir/host"
  22. STAGING_DIR_HOST_TMPL="$DIR/staging_dir_host_tmpl"
  23. BIN_DIR="$DIR/staging_dir/bin_dir"
  24. LOG_DIR_NAME="logs"
  25. LOG_DIR="$DIR/$LOG_DIR_NAME"
  26. die()
  27. {
  28. echo "$@"
  29. exit 1
  30. }
  31. usage()
  32. {
  33. echo "deptest.sh [OPTIONS] [PACKAGES]"
  34. echo
  35. echo "OPTIONS:"
  36. echo " --lean Run a lean test. Do not clean the build directory for each"
  37. echo " package test."
  38. echo " --force Force a test, even if a success/blacklist stamp is available"
  39. echo " -j X Number of make jobs"
  40. echo
  41. echo "PACKAGES are packages to test. If not specified, all installed packages"
  42. echo "will be tested."
  43. }
  44. deptest_make()
  45. {
  46. local target="$1"
  47. shift
  48. local logfile="$1"
  49. shift
  50. make -j$nrjobs "$target" \
  51. BUILD_DIR="$BUILD_DIR" \
  52. BUILD_DIR_HOST="$BUILD_DIR_HOST" \
  53. KERNEL_BUILD_DIR="$KERNEL_BUILD_DIR" \
  54. BIN_DIR="$BIN_DIR" \
  55. STAGING_DIR="$STAGING_DIR" \
  56. STAGING_DIR_HOST="$STAGING_DIR_HOST" \
  57. FORCE_HOST_INSTALL=1 \
  58. V=99 "$@" >"$LOG_DIR/$logfile" 2>&1
  59. }
  60. clean_kernel_build_dir()
  61. {
  62. # delete everything, except the kernel build dir "linux-X.X.X"
  63. (
  64. cd "$KERNEL_BUILD_DIR" || die "Failed to enter kernel build dir"
  65. for entry in *; do
  66. [ -z "$(echo "$entry" | egrep -e '^linux-*.*.*$')" ] || continue
  67. rm -rf "$entry" || die "Failed to clean kernel build dir"
  68. done
  69. )
  70. }
  71. test_package() # $1=pkgname
  72. {
  73. local pkg="$1"
  74. [ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
  75. die "Package name \"$pkg\" contains illegal characters"
  76. local SELECTED=
  77. for conf in `grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'`; do
  78. grep "$conf=" .config > /dev/null && SELECTED=1 && break
  79. done
  80. local STAMP_SUCCESS="$STAMP_DIR_SUCCESS/$pkg"
  81. local STAMP_FAILED="$STAMP_DIR_FAILED/$pkg"
  82. local STAMP_BLACKLIST="$STAMP_DIR_BLACKLIST/$pkg"
  83. rm -f "$STAMP_FAILED"
  84. [ -e "$STAMP_SUCCESS" -a $force -eq 0 ] && return
  85. rm -f "$STAMP_SUCCESS"
  86. [ -n "$SELECTED" ] || {
  87. echo "Package $pkg is not selected"
  88. return
  89. }
  90. [ -e "$STAMP_BLACKLIST" -a $force -eq 0 ] && {
  91. echo "Package $pkg is blacklisted"
  92. return
  93. }
  94. echo "Testing package $pkg..."
  95. rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST"
  96. mkdir -p "$STAGING_DIR"
  97. cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
  98. [ $lean_test -eq 0 ] && {
  99. rm -rf "$BUILD_DIR" "$BUILD_DIR_HOST"
  100. clean_kernel_build_dir
  101. }
  102. mkdir -p "$BUILD_DIR" "$BUILD_DIR_HOST"
  103. local logfile="$(basename $pkg).log"
  104. deptest_make "package/$pkg/compile" "$logfile"
  105. if [ $? -eq 0 ]; then
  106. ( cd "$STAMP_DIR_SUCCESS"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
  107. else
  108. ( cd "$STAMP_DIR_FAILED"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
  109. echo "Building package $pkg FAILED"
  110. fi
  111. }
  112. # parse commandline options
  113. packages=
  114. lean_test=0
  115. force=0
  116. nrjobs=1
  117. while [ $# -ne 0 ]; do
  118. case "$1" in
  119. --help|-h)
  120. usage
  121. exit 0
  122. ;;
  123. --lean)
  124. lean_test=1
  125. ;;
  126. --force)
  127. force=1
  128. ;;
  129. -j*)
  130. if [ -n "${1:2}" ]; then
  131. nrjobs="${1:2}"
  132. else
  133. shift
  134. nrjobs="$1"
  135. fi
  136. ;;
  137. *)
  138. packages="$packages $1"
  139. ;;
  140. esac
  141. shift
  142. done
  143. [ -f "$BASEDIR/include/toplevel.mk" ] || \
  144. die "Error: Could not find buildsystem base directory"
  145. [ -f "$BASEDIR/.config" ] || \
  146. die "The buildsystem is not configured. Please run make menuconfig."
  147. cd "$BASEDIR" || die "Failed to enter base directory"
  148. mkdir -p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" \
  149. "$BIN_DIR" "$LOG_DIR"
  150. bootstrap_deptest_make()
  151. {
  152. local target="$1"
  153. shift
  154. local logfile="bootstrap-deptest-$(echo "$target" | tr / -).log"
  155. echo "deptest-make $target"
  156. deptest_make "$target" "$logfile" "$@" || \
  157. die "make $target failed, please check $logfile"
  158. }
  159. bootstrap_native_make()
  160. {
  161. local target="$1"
  162. shift
  163. local logfile="bootstrap-native-$(echo "$target" | tr / -).log"
  164. echo "make $target"
  165. make -j$nrjobs "$target" \
  166. V=99 "$@" >"$LOG_DIR/$logfile" 2>&1 || \
  167. die "make $target failed, please check $logfile"
  168. }
  169. [ -d "$STAGING_DIR_HOST_TMPL" ] || {
  170. echo "Bootstrapping build environment..."
  171. rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
  172. mkdir -p "$STAGING_DIR" "$STAGING_DIR_HOST" \
  173. "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
  174. bootstrap_native_make tools/install
  175. bootstrap_native_make toolchain/install
  176. bootstrap_deptest_make tools/install
  177. bootstrap_deptest_make target/linux/install
  178. cp -al "$STAGING_DIR_HOST" "$STAGING_DIR_HOST_TMPL"
  179. rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST"
  180. echo "Build environment OK."
  181. }
  182. if [ -z "$packages" ]; then
  183. # iterate over all packages
  184. for pkg in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
  185. test_package "$pkg"
  186. done
  187. else
  188. # only check the specified packages
  189. for pkg in $packages; do
  190. test_package "$pkg"
  191. done
  192. fi