deptest: Add sanity check to avoid trouble with illegal package names
[openwrt/svn-archive/archive.git] / scripts / deptest.sh
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 # Usage:
11 # No commandline arguments => check dependencies of all installed packages
12 # Package name(s) as arguments => only test the specified packages
13 #
14
15 SCRIPTDIR="$(dirname "$0")"
16 [ "${SCRIPTDIR:0:1}" = "/" ] || SCRIPTDIR="$PWD/$SCRIPTDIR"
17 BASEDIR="$SCRIPTDIR/.."
18
19 DIR="$BASEDIR/tmp/deptest"
20 STAMP_DIR_SUCCESS="$DIR/stamp-success"
21 STAMP_DIR_FAILED="$DIR/stamp-failed"
22 STAMP_DIR_BLACKLIST="$DIR/stamp-blacklist"
23 BUILD_DIR="$DIR/build_dir/target"
24 BUILD_DIR_HOST="$DIR/build_dir/host"
25 STAGING_DIR="$DIR/staging_dir"
26 STAGING_DIR_HOST="$DIR/staging_dir_host"
27 STAGING_DIR_HOST_TMPL="$DIR/staging_dir_host_tmpl"
28 LOG_DIR="$DIR/logs"
29
30 die()
31 {
32 echo "$@"
33 exit 1
34 }
35
36 test_package() # $1=pkgname
37 {
38 local pkg="$1"
39 [ -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
40 die "Package name \"$pkg\" contains illegal characters"
41 local SELECTED=
42 for conf in `grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'`; do
43 grep "$conf=" .config > /dev/null && SELECTED=1 && break
44 done
45 local STAMP_SUCCESS="$STAMP_DIR_SUCCESS/$pkg"
46 local STAMP_FAILED="$STAMP_DIR_FAILED/$pkg"
47 local STAMP_BLACKLIST="$STAMP_DIR_BLACKLIST/$pkg"
48 rm -f "$STAMP_FAILED"
49 [ -f "$STAMP_SUCCESS" ] && return
50 [ -n "$SELECTED" ] || {
51 echo "Package $pkg is not selected"
52 return
53 }
54 [ -f "$STAMP_BLACKLIST" ] && {
55 echo "Package $pkg is blacklisted"
56 return
57 }
58 echo "Testing package $pkg..."
59 rm -rf "$STAGING_DIR"
60 mkdir -p "$STAGING_DIR"
61 rm -rf "$STAGING_DIR_HOST"
62 cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
63 make package/$pkg/compile \
64 BUILD_DIR="$BUILD_DIR" \
65 BUILD_DIR_HOST="$BUILD_DIR_HOST" \
66 STAGING_DIR="$STAGING_DIR" \
67 STAGING_DIR_HOST="$STAGING_DIR_HOST" \
68 V=99 >"$LOG_DIR/$(basename $pkg).log" 2>&1
69 if [ $? -eq 0 ]; then
70 touch "$STAMP_SUCCESS"
71 else
72 touch "$STAMP_FAILED"
73 echo "Building package $pkg failed!"
74 fi
75 }
76
77 [ -f "$BASEDIR/include/toplevel.mk" ] || \
78 die "Error: Could not find buildsystem base directory"
79 [ -f "$BASEDIR/.config" ] || \
80 die "The buildsystem is not configured. Please run make menuconfig."
81 cd "$BASEDIR" || die "Failed to enter base directory"
82
83 mkdir -p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" \
84 "$BUILD_DIR" "$BUILD_DIR_HOST" "$LOG_DIR"
85
86 [ -d "$STAGING_DIR_HOST_TMPL" ] || {
87 rm -rf staging_dir/host
88 make tools/install V=99 || die "make tools/install failed, please check"
89 cp -al staging_dir/host "$STAGING_DIR_HOST_TMPL"
90 make toolchain/install V=99 || die "make toolchain/install failed, please check"
91 make target/linux/install V=99 || die "make target/linux/install failed, please check"
92 }
93
94 if [ $# -eq 0 ]; then
95 # iterate over all packages
96 for pkg in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
97 test_package "$pkg"
98 done
99 else
100 # Only check the specified packages
101 while [ $# -ne 0 ]; do
102 test_package "$1"
103 shift
104 done
105 fi