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 test_package
() # $1=pkgname
81 [ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
82 die
"Package name \"$pkg\" contains illegal characters"
84 for conf
in `grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'`; do
85 grep "$conf=" .config
> /dev
/null
&& SELECTED
=1 && break
87 local STAMP_SUCCESS
="$STAMP_DIR_SUCCESS/$pkg"
88 local STAMP_FAILED
="$STAMP_DIR_FAILED/$pkg"
89 local STAMP_BLACKLIST
="$STAMP_DIR_BLACKLIST/$pkg"
91 [ -e "$STAMP_SUCCESS" -a $force -eq 0 ] && return
92 rm -f "$STAMP_SUCCESS"
93 [ -n "$SELECTED" ] ||
{
94 echo "Package $pkg is not selected"
97 [ -e "$STAMP_BLACKLIST" -a $force -eq 0 ] && {
98 echo "Package $pkg is blacklisted"
101 echo "Testing package $pkg..."
102 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST"
103 mkdir
-p "$STAGING_DIR"
104 cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
105 [ $lean_test -eq 0 ] && {
106 rm -rf "$BUILD_DIR" "$BUILD_DIR_HOST"
107 clean_kernel_build_dir
109 mkdir
-p "$BUILD_DIR" "$BUILD_DIR_HOST"
110 local logfile
="$(basename $pkg).log"
111 deptest_make
"package/$pkg/compile" "$logfile"
112 if [ $?
-eq 0 ]; then
113 ( cd "$STAMP_DIR_SUCCESS"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
115 ( cd "$STAMP_DIR_FAILED"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
116 echo "Building package $pkg FAILED"
120 # parse commandline options
125 while [ $# -ne 0 ]; do
138 if [ -n "${1:2}" ]; then
146 packages
="$packages $1"
152 [ -f "$BASEDIR/include/toplevel.mk" ] || \
153 die
"Error: Could not find buildsystem base directory"
154 [ -f "$BASEDIR/.config" ] || \
155 die
"The buildsystem is not configured. Please run make menuconfig."
156 cd "$BASEDIR" || die
"Failed to enter base directory"
158 mkdir
-p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" \
159 "$BIN_DIR" "$LOG_DIR"
161 bootstrap_deptest_make
()
165 local logfile
="bootstrap-deptest-$(echo "$target" | tr / -).log"
166 echo "deptest-make $target"
167 deptest_make
"$target" "$logfile" "$@" || \
168 die
"make $target failed, please check $logfile"
171 bootstrap_native_make
()
175 local logfile
="bootstrap-native-$(echo "$target" | tr / -).log"
177 make -j$nrjobs "$target" \
178 V
=99 "$@" >"$LOG_DIR/$logfile" 2>&1 || \
179 die
"make $target failed, please check $logfile"
182 [ -d "$STAGING_DIR_HOST_TMPL" ] ||
{
183 echo "Bootstrapping build environment..."
184 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
185 mkdir
-p "$STAGING_DIR" "$STAGING_DIR_HOST" \
186 "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
187 bootstrap_native_make tools
/install
188 bootstrap_native_make toolchain
/install
189 bootstrap_deptest_make tools
/install
190 bootstrap_deptest_make target
/linux
/install
191 cp -al "$STAGING_DIR_HOST" "$STAGING_DIR_HOST_TMPL"
192 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST"
193 echo "Build environment OK."
196 if [ -z "$packages" ]; then
197 # iterate over all packages
198 for pkg
in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
202 # only check the specified packages
203 for pkg
in $packages; do