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"
36 echo "deptest.sh [OPTIONS] [PACKAGES]"
39 echo " --lean Run a lean test. Do not clean the build directory for each"
41 echo " --force Force a test, even if a success/blacklist stamp is available"
42 echo " -j X Number of make jobs"
44 echo "PACKAGES are packages to test. If not specified, all installed packages"
45 echo "will be tested."
54 make -j$nrjobs "$target" \
55 BUILD_DIR
="$BUILD_DIR" \
56 BUILD_DIR_HOST
="$BUILD_DIR_HOST" \
57 KERNEL_BUILD_DIR
="$KERNEL_BUILD_DIR" \
59 STAGING_DIR
="$STAGING_DIR" \
60 STAGING_DIR_HOST
="$STAGING_DIR_HOST" \
61 FORCE_HOST_INSTALL
=1 \
62 V
=99 "$@" >"$LOG_DIR/$logfile" 2>&1
65 clean_kernel_build_dir
()
67 # delete everything, except the kernel build dir "linux-X.X.X"
69 cd "$KERNEL_BUILD_DIR" || die
"Failed to enter kernel build dir"
71 [ -z "$(echo "$entry" | egrep -e '^linux-*.*.*$')" ] ||
continue
72 rm -rf "$entry" || die
"Failed to clean kernel build dir"
77 test_package
() # $1=pkgname
80 [ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
81 die
"Package name \"$pkg\" contains illegal characters"
83 for conf
in `grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'`; do
84 grep "$conf=" .config
> /dev
/null
&& SELECTED
=1 && break
86 local STAMP_SUCCESS
="$STAMP_DIR_SUCCESS/$pkg"
87 local STAMP_FAILED
="$STAMP_DIR_FAILED/$pkg"
88 local STAMP_BLACKLIST
="$STAMP_DIR_BLACKLIST/$pkg"
90 [ -f "$STAMP_SUCCESS" -a $force -eq 0 ] && return
91 rm -f "$STAMP_SUCCESS"
92 [ -n "$SELECTED" ] ||
{
93 echo "Package $pkg is not selected"
96 [ -f "$STAMP_BLACKLIST" -a $force -eq 0 ] && {
97 echo "Package $pkg is blacklisted"
100 echo "Testing package $pkg..."
101 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST"
102 mkdir
-p "$STAGING_DIR"
103 cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
104 [ $lean_test -eq 0 ] && {
105 rm -rf "$BUILD_DIR" "$BUILD_DIR_HOST"
106 clean_kernel_build_dir
108 mkdir
-p "$BUILD_DIR" "$BUILD_DIR_HOST"
109 deptest_make
"package/$pkg/compile" "$(basename $pkg).log"
110 if [ $?
-eq 0 ]; then
111 touch "$STAMP_SUCCESS"
113 touch "$STAMP_FAILED"
114 echo "Building package $pkg FAILED"
118 # parse commandline options
123 while [ $# -ne 0 ]; do
136 if [ -n "${1:2}" ]; then
144 packages
="$packages $1"
150 [ -f "$BASEDIR/include/toplevel.mk" ] || \
151 die
"Error: Could not find buildsystem base directory"
152 [ -f "$BASEDIR/.config" ] || \
153 die
"The buildsystem is not configured. Please run make menuconfig."
154 cd "$BASEDIR" || die
"Failed to enter base directory"
156 mkdir
-p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" \
157 "$BIN_DIR" "$LOG_DIR"
159 bootstrap_deptest_make
()
163 local logfile
="bootstrap-deptest-$(echo "$target" | tr / -).log"
164 echo "deptest-make $target"
165 deptest_make
"$target" "$logfile" "$@" || \
166 die
"make $target failed, please check $logfile"
169 bootstrap_native_make
()
173 local logfile
="bootstrap-native-$(echo "$target" | tr / -).log"
175 make -j$nrjobs "$target" \
176 V
=99 "$@" >"$LOG_DIR/$logfile" 2>&1 || \
177 die
"make $target failed, please check $logfile"
180 [ -d "$STAGING_DIR_HOST_TMPL" ] ||
{
181 echo "Bootstrapping build environment..."
182 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
183 mkdir
-p "$STAGING_DIR" "$STAGING_DIR_HOST" \
184 "$BUILD_DIR" "$BUILD_DIR_HOST" "$KERNEL_BUILD_DIR"
185 bootstrap_native_make tools
/install
186 bootstrap_native_make toolchain
/install
187 bootstrap_deptest_make tools
/install
188 bootstrap_deptest_make target
/linux
/install
189 cp -al "$STAGING_DIR_HOST" "$STAGING_DIR_HOST_TMPL"
190 rm -rf "$STAGING_DIR" "$STAGING_DIR_HOST" "$BUILD_DIR" "$BUILD_DIR_HOST"
191 echo "Build environment OK."
194 if [ -z "$packages" ]; then
195 # iterate over all packages
196 for pkg
in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
200 # only check the specified packages
201 for pkg
in $packages; do