[brcm63xx] Remove patch 140-new_bcm96348gw_leds because it is really the GW6200 leds...
[openwrt.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
11 SCRIPTDIR="$(dirname "$0")"
12 [ "${SCRIPTDIR:0:1}" = "/" ] || SCRIPTDIR="$PWD/$SCRIPTDIR"
13 BASEDIR="$SCRIPTDIR/.."
14
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"
26 LOG_DIR_NAME="logs"
27 LOG_DIR="$DIR/$LOG_DIR_NAME"
28
29 die()
30 {
31 echo "$@"
32 exit 1
33 }
34
35 usage()
36 {
37 echo "deptest.sh [OPTIONS] [PACKAGES]"
38 echo
39 echo "OPTIONS:"
40 echo " --lean Run a lean test. Do not clean the build directory for each"
41 echo " package test."
42 echo " --force Force a test, even if a success/blacklist stamp is available"
43 echo " -j X Number of make jobs"
44 echo
45 echo "PACKAGES are packages to test. If not specified, all installed packages"
46 echo "will be tested."
47 }
48
49 deptest_make()
50 {
51 local target="$1"
52 shift
53 local logfile="$1"
54 shift
55 make -j$nrjobs "$target" \
56 BUILD_DIR="$BUILD_DIR" \
57 BUILD_DIR_HOST="$BUILD_DIR_HOST" \
58 KERNEL_BUILD_DIR="$KERNEL_BUILD_DIR" \
59 BIN_DIR="$BIN_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
64 }
65
66 clean_kernel_build_dir()
67 {
68 # delete everything, except the kernel build dir "linux-X.X.X"
69 (
70 cd "$KERNEL_BUILD_DIR" || die "Failed to enter kernel build dir"
71 for entry in *; do
72 [ -z "$(echo "$entry" | egrep -e '^linux-*.*.*$')" ] || continue
73 rm -rf "$entry" || die "Failed to clean kernel build dir"
74 done
75 )
76 }
77
78 test_package() # $1=pkgname
79 {
80 local pkg="$1"
81 [ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
82 die "Package name \"$pkg\" contains illegal characters"
83 local SELECTED=
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
86 done
87 local STAMP_SUCCESS="$STAMP_DIR_SUCCESS/$pkg"
88 local STAMP_FAILED="$STAMP_DIR_FAILED/$pkg"
89 local STAMP_BLACKLIST="$STAMP_DIR_BLACKLIST/$pkg"
90 rm -f "$STAMP_FAILED"
91 [ -e "$STAMP_SUCCESS" -a $force -eq 0 ] && return
92 rm -f "$STAMP_SUCCESS"
93 [ -n "$SELECTED" ] || {
94 echo "Package $pkg is not selected"
95 return
96 }
97 [ -e "$STAMP_BLACKLIST" -a $force -eq 0 ] && {
98 echo "Package $pkg is blacklisted"
99 return
100 }
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
108 }
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" )
114 else
115 ( cd "$STAMP_DIR_FAILED"; ln -s "../$LOG_DIR_NAME/$logfile" "./$pkg" )
116 echo "Building package $pkg FAILED"
117 fi
118 }
119
120 # parse commandline options
121 packages=
122 lean_test=0
123 force=0
124 nrjobs=1
125 while [ $# -ne 0 ]; do
126 case "$1" in
127 --help|-h)
128 usage
129 exit 0
130 ;;
131 --lean)
132 lean_test=1
133 ;;
134 --force)
135 force=1
136 ;;
137 -j*)
138 if [ -n "${1:2}" ]; then
139 nrjobs="${1:2}"
140 else
141 shift
142 nrjobs="$1"
143 fi
144 ;;
145 *)
146 packages="$packages $1"
147 ;;
148 esac
149 shift
150 done
151
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"
157
158 mkdir -p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" \
159 "$BIN_DIR" "$LOG_DIR"
160
161 bootstrap_deptest_make()
162 {
163 local target="$1"
164 shift
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"
169 }
170
171 bootstrap_native_make()
172 {
173 local target="$1"
174 shift
175 local logfile="bootstrap-native-$(echo "$target" | tr / -).log"
176 echo "make $target"
177 make -j$nrjobs "$target" \
178 V=99 "$@" >"$LOG_DIR/$logfile" 2>&1 || \
179 die "make $target failed, please check $logfile"
180 }
181
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."
194 }
195
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
199 test_package "$pkg"
200 done
201 else
202 # only check the specified packages
203 for pkg in $packages; do
204 test_package "$pkg"
205 done
206 fi
This page took 0.058127 seconds and 5 git commands to generate.