1
0

deptest.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/usr/bin/env bash
  2. #
  3. # Automated libreCMC 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. stamp_exists() # $1=stamp
  72. {
  73. [ -e "$1" -o -L "$1" ]
  74. }
  75. test_package() # $1=pkgname
  76. {
  77. local pkg="$1"
  78. [ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
  79. die "Package name \"$pkg\" contains illegal characters"
  80. local SELECTED=
  81. for conf in `grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'`; do
  82. grep "$conf=" .config > /dev/null && SELECTED=1 && break
  83. done
  84. local STAMP_SUCCESS="$STAMP_DIR_SUCCESS/$pkg"
  85. local STAMP_FAILED="$STAMP_DIR_FAILED/$pkg"
  86. local STAMP_BLACKLIST="$STAMP_DIR_BLACKLIST/$pkg"
  87. rm -f "$STAMP_FAILED"
  88. stamp_exists "$STAMP_SUCCESS" && [ $force -eq 0 ] && return
  89. rm -f "$STAMP_SUCCESS"
  90. [ -n "$SELECTED" ] || {
  91. echo "Package $pkg is not selected"
  92. return
  93. }
  94. stamp_exists "$STAMP_BLACKLIST" && [ $force -eq 0 ] && {
  95. echo "Package $pkg is blacklisted"
  96. return
  97. }
  98. echo "Testing package $pkg..."
  99. rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST"
  100. mkdir -p "$STAGING_DIR"
  101. cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
  102. [ $lean_test -eq 0 ] && {
  103. rm -rf "$BUILD_DIR" "$BUILD_DIR_HOST"
  104. clean_kernel_build_dir
  105. }
  106. mkdir -p "$BUILD_DIR" "$BUILD_DIR_HOST"
  107. local logfile="$(basename $pkg).log"
  108. deptest_make "package/$pkg/compile" "$logfile"
  109. if [ $? -eq 0 ]; then
  110. ( cd "$STAMP_DIR_SUCCESS"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
  111. else
  112. ( cd "$STAMP_DIR_FAILED"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
  113. echo "Building package $pkg FAILED"
  114. fi
  115. }
  116. # parse commandline options
  117. packages=
  118. lean_test=0
  119. force=0
  120. nrjobs=1
  121. while [ $# -ne 0 ]; do
  122. case "$1" in
  123. --help|-h)
  124. usage
  125. exit 0
  126. ;;
  127. --lean)
  128. lean_test=1
  129. ;;
  130. --force)
  131. force=1
  132. ;;
  133. -j*)
  134. if [ -n "${1:2}" ]; then
  135. nrjobs="${1:2}"
  136. else
  137. shift
  138. nrjobs="$1"
  139. fi
  140. ;;
  141. *)
  142. packages="$packages $1"
  143. ;;
  144. esac
  145. shift
  146. done
  147. [ -f "$BASEDIR/include/toplevel.mk" ] || \
  148. die "Error: Could not find buildsystem base directory"
  149. [ -f "$BASEDIR/.config" ] || \
  150. die "The buildsystem is not configured. Please run make menuconfig."
  151. cd "$BASEDIR" || die "Failed to enter base directory"
  152. mkdir -p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" \
  153. "$BIN_DIR" "$LOG_DIR"
  154. bootstrap_deptest_make()
  155. {
  156. local target="$1"
  157. shift
  158. local logfile="bootstrap-deptest-$(echo "$target" | tr / -).log"
  159. echo "deptest-make $target"
  160. deptest_make "$target" "$logfile" "$@" || \
  161. die "make $target failed, please check $logfile"
  162. }
  163. bootstrap_native_make()
  164. {
  165. local target="$1"
  166. shift
  167. local logfile="bootstrap-native-$(echo "$target" | tr / -).log"
  168. echo "make $target"
  169. make -j$nrjobs "$target" \
  170. V=99 "$@" >"$LOG_DIR/$logfile" 2>&1 || \
  171. die "make $target failed, please check $logfile"
  172. }
  173. [ -d "$STAGING_DIR_HOST_TMPL" ] || {
  174. echo "Bootstrapping build environment..."
  175. rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
  176. mkdir -p "$STAGING_DIR" "$STAGING_DIR_HOST" \
  177. "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
  178. bootstrap_native_make tools/install
  179. bootstrap_native_make toolchain/install
  180. bootstrap_deptest_make tools/install
  181. bootstrap_deptest_make target/linux/install
  182. cp -al "$STAGING_DIR_HOST" "$STAGING_DIR_HOST_TMPL"
  183. rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST"
  184. echo "Build environment OK."
  185. }
  186. if [ -z "$packages" ]; then
  187. # iterate over all packages
  188. for pkg in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
  189. test_package "$pkg"
  190. done
  191. else
  192. # only check the specified packages
  193. for pkg in $packages; do
  194. test_package "$pkg"
  195. done
  196. fi