3 # Automated OpenWrt package dependency checker
5 # Copyright (C) 2009-2010 OpenWrt.org
7 # This is free software, licensed under the GNU General Public License v2.
8 # See /LICENSE for more information.
11 SCRIPTDIR="$(dirname "$0")"
12 [ "${SCRIPTDIR:0:1}" = "/" ] || SCRIPTDIR="$PWD/$SCRIPTDIR"
13 BASEDIR="$SCRIPTDIR/.."
15 DIR="$BASEDIR/tmp/deptest"
16 STAMP_DIR_SUCCESS="$DIR/stamp-success"
17 STAMP_DIR_FAILED="$DIR/stamp-failed"
18 STAMP_DIR_BLACKLIST="$DIR/stamp-blacklist"
19 BUILD_DIR="$DIR/build_dir/target"
20 BUILD_DIR_HOST="$DIR/build_dir/host"
21 KERNEL_BUILD_DIR="$DIR/build_dir/linux"
22 STAGING_DIR="$DIR/staging_dir/target"
23 STAGING_DIR_HOST="$DIR/staging_dir/host"
24 STAGING_DIR_HOST_TMPL="$DIR/staging_dir_host_tmpl"
25 BIN_DIR="$DIR/staging_dir/bin_dir"
27 LOG_DIR="$DIR/$LOG_DIR_NAME"
37 echo "deptest.sh [OPTIONS] [PACKAGES]"
40 echo " --lean Run a lean test. Do not clean the build directory for each"
42 echo " --force Force a test, even if a success/blacklist stamp is available"
43 echo " -j X Number of make jobs"
45 echo "PACKAGES are packages to test. If not specified, all installed packages"
46 echo "will be tested."
55 make -j$nrjobs "$target" \
56 BUILD_DIR="$BUILD_DIR" \
57 BUILD_DIR_HOST="$BUILD_DIR_HOST" \
58 KERNEL_BUILD_DIR="$KERNEL_BUILD_DIR" \
60 STAGING_DIR="$STAGING_DIR" \
61 STAGING_DIR_HOST="$STAGING_DIR_HOST" \
62 FORCE_HOST_INSTALL=1 \
63 V=99 "$@" >"$LOG_DIR/$logfile" 2>&1
66 clean_kernel_build_dir()
68 # delete everything, except the kernel build dir "linux-X.X.X"
70 cd "$KERNEL_BUILD_DIR" || die "Failed to enter kernel build dir"
72 [ -z "$(echo "$entry" | egrep -e '^linux-*.*.*$')" ] || continue
73 rm -rf "$entry" || die "Failed to clean kernel build dir"
78 stamp_exists() # $1=stamp
80 [ -e "$1" -o -L "$1" ]
83 test_package() # $1=pkgname
86 [ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
87 die "Package name \"$pkg\" contains illegal characters"
89 for conf in `grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'`; do
90 grep "$conf=" .config > /dev/null && SELECTED=1 && break
92 local STAMP_SUCCESS="$STAMP_DIR_SUCCESS/$pkg"
93 local STAMP_FAILED="$STAMP_DIR_FAILED/$pkg"
94 local STAMP_BLACKLIST="$STAMP_DIR_BLACKLIST/$pkg"
96 stamp_exists "$STAMP_SUCCESS" && [ $force -eq 0 ] && return
97 rm -f "$STAMP_SUCCESS"
98 [ -n "$SELECTED" ] || {
99 echo "Package $pkg is not selected"
102 stamp_exists "$STAMP_BLACKLIST" && [ $force -eq 0 ] && {
103 echo "Package $pkg is blacklisted"
106 echo "Testing package $pkg..."
107 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST"
108 mkdir -p "$STAGING_DIR"
109 cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
110 [ $lean_test -eq 0 ] && {
111 rm -rf "$BUILD_DIR" "$BUILD_DIR_HOST"
112 clean_kernel_build_dir
114 mkdir -p "$BUILD_DIR" "$BUILD_DIR_HOST"
115 local logfile="$(basename $pkg).log"
116 deptest_make "package/$pkg/compile" "$logfile"
117 if [ $? -eq 0 ]; then
118 ( cd "$STAMP_DIR_SUCCESS"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
120 ( cd "$STAMP_DIR_FAILED"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
121 echo "Building package $pkg FAILED"
125 # parse commandline options
130 while [ $# -ne 0 ]; do
143 if [ -n "${1:2}" ]; then
151 packages="$packages $1"
157 [ -f "$BASEDIR/include/toplevel.mk" ] || \
158 die "Error: Could not find buildsystem base directory"
159 [ -f "$BASEDIR/.config" ] || \
160 die "The buildsystem is not configured. Please run make menuconfig."
161 cd "$BASEDIR" || die "Failed to enter base directory"
163 mkdir -p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" \
164 "$BIN_DIR" "$LOG_DIR"
166 bootstrap_deptest_make()
170 local logfile="bootstrap-deptest-$(echo "$target" | tr / -).log"
171 echo "deptest-make $target"
172 deptest_make "$target" "$logfile" "$@" || \
173 die "make $target failed, please check $logfile"
176 bootstrap_native_make()
180 local logfile="bootstrap-native-$(echo "$target" | tr / -).log"
182 make -j$nrjobs "$target" \
183 V=99 "$@" >"$LOG_DIR/$logfile" 2>&1 || \
184 die "make $target failed, please check $logfile"
187 [ -d "$STAGING_DIR_HOST_TMPL" ] || {
188 echo "Bootstrapping build environment..."
189 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
190 mkdir -p "$STAGING_DIR" "$STAGING_DIR_HOST" \
191 "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
192 bootstrap_native_make tools/install
193 bootstrap_native_make toolchain/install
194 bootstrap_deptest_make tools/install
195 bootstrap_deptest_make target/linux/install
196 cp -al "$STAGING_DIR_HOST" "$STAGING_DIR_HOST_TMPL"
197 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST"
198 echo "Build environment OK."
201 if [ -z "$packages" ]; then
202 # iterate over all packages
203 for pkg in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
207 # only check the specified packages
208 for pkg in $packages; do