cookutils diff cook @ rev 9
Add command test and improve Quality Assurance
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed May 04 04:30:28 2011 +0200 (2011-05-04) |
parents | b222a2ef4b1a |
children | b543222cb3e0 |
line diff
1.1 --- a/cook Tue May 03 23:09:59 2011 +0200 1.2 +++ b/cook Wed May 04 04:30:28 2011 +0200 1.3 @@ -10,6 +10,9 @@ 1.4 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf 1.5 [ -f "cook.conf" ] && . ./cook.conf 1.6 1.7 +# Share activity with the Cooker. 1.8 +activity="$CACHE/activity" 1.9 + 1.10 # 1.11 # Functions 1.12 # 1.13 @@ -23,6 +26,7 @@ 1.14 usage|help $(gettext "Display this short usage.") 1.15 list-wok $(gettext "List packages in the wok.") 1.16 setup $(gettext "Setup your build environment.") 1.17 + test $(gettext "Test environment and cook a package.") 1.18 new $(gettext "Create a new package with receipt".) 1.19 list $(gettext "Cook a list of packages.") 1.20 clean-wok $(gettext "Clean-up all packages files.") 1.21 @@ -57,15 +61,18 @@ 1.22 echo -e "\\033[0;39m ]" 1.23 } 1.24 1.25 +# Log activities. 1.26 +log() { 1.27 + grep ^[a-zA-Z0-9] | \ 1.28 + sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity 1.29 +} 1.30 + 1.31 +# We dont want those escape in web interface. 1.32 clean_log() { 1.33 sed -i -e s'|\[70G\[ \[1;32m| |' \ 1.34 -e s'|\[0;39m \]||' $LOGS/$pkg.log 1.35 } 1.36 1.37 -unset_receipt() { 1.38 - unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE 1.39 -} 1.40 - 1.41 # Be sure package exist in wok. 1.42 check_pkg_in_wok() { 1.43 if [ ! -d "$WOK/$pkg" ]; then 1.44 @@ -74,6 +81,53 @@ 1.45 fi 1.46 } 1.47 1.48 +if_empty_value() { 1.49 + if [ -z "$value" ]; then 1.50 + gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n" 1.51 + exit 1 1.52 + fi 1.53 +} 1.54 + 1.55 +# QA: check a receip consistency befor building. 1.56 +receipt_quality() { 1.57 + gettext -e "QA: checking package receipt...\n" 1.58 + unset online 1.59 + if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then 1.60 + online="online" 1.61 + fi 1.62 + for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE 1.63 + do 1.64 + unset value 1.65 + value=$(grep ^$var= receipt | cut -d \" -f 2) 1.66 + case "$var" in 1.67 + PACKAGE|VERSION|SHORT_DESC) 1.68 + if_empty_value ;; 1.69 + CATEGORY) 1.70 + [ -z "$value" ] && value="empty" 1.71 + valid="base-system x-window utilities network graphics \ 1.72 + multimedia office development system-tools security games \ 1.73 + misc meta non-free" 1.74 + if ! echo "$valid" | grep -q -w "$value"; then 1.75 + gettext "QA: unknow category:"; echo -e " $value\n" 1.76 + exit 1 1.77 + fi ;; 1.78 + WEB_SITE) 1.79 + # We dont check WGET_URL since if dl is needed it will fail. 1.80 + # Break also if we not online. Here error is not fatal. 1.81 + if_empty_value 1.82 + [ -z "$online" ] || break 1.83 + if ! busybox wget -s $value 2>/dev/null; then 1.84 + gettext "QA: Unable to reach:"; echo -e " $value\n" 1.85 + fi ;; 1.86 + esac 1.87 + done 1.88 +} 1.89 + 1.90 +# Executed before sourcing a receipt. 1.91 +unset_receipt() { 1.92 + unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL 1.93 +} 1.94 + 1.95 # Path's used in receipt and by cook itself. 1.96 set_paths() { 1.97 pkgdir=$WOK/$PACKAGE 1.98 @@ -86,16 +140,45 @@ 1.99 src=$WOK/$WANTED/source/$WANTED-$VERSION 1.100 install=$WOK/$WANTED/install 1.101 fi 1.102 - # Old way compatibility 1.103 + # Old way compatibility. 1.104 _pkg=$install 1.105 } 1.106 1.107 -# Get package source 1.108 +# Get package source. 1.109 get_source() { 1.110 - wget -P $SRC $WGET_URL 1.111 + case "$WGET_URL" in 1.112 + http://*|ftp://*) 1.113 + # Busybox Wget is better! 1.114 + busybox wget -c -P $SRC $WGET_URL ;; 1.115 + hg*|mercurial*) 1.116 + # We are in cache so clone here and create a tarball 1.117 + pwd=$(pwd) 1.118 + if $(echo "$WGET_URL" | fgrep -q hg); then 1.119 + url=${WGET_URL#hg|} 1.120 + else 1.121 + url=${WGET_URL#mercurial|} 1.122 + fi 1.123 + pkgsrc=$PACKAGE-$VERSION 1.124 + [ "$SOURCE" ] && pkgsrc=$SOURCE-$VERSION 1.125 + tarball=$pkgsrc.tar.bz2 1.126 + gettext "Getting source from Hg: "; echo $url 1.127 + gettext "Cloning to: "; echo "$pwd/$pkgsrc" 1.128 + hg clone $url $pkgsrc || exit 1 1.129 + gettext "Creating tarball: "; echo "$tarball" 1.130 + tar cjf $tarball $pkgsrc || exit 1 1.131 + mv $tarball $SRC && rm -rf $pkgsrc ;; 1.132 + git*) 1.133 + echo "TODO: git implementation in cook" && exit 1 ;; 1.134 + svn*) 1.135 + echo "TODO: svn implementation in cook" && exit 1 ;; 1.136 + *) 1.137 + gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \ 1.138 + tee -a $LOGS/$PACKAGE.log 1.139 + exit 1 ;; 1.140 + esac 1.141 } 1.142 1.143 -# Extract source package 1.144 +# Extract source package. 1.145 extract_source() { 1.146 gettext "Extracting:"; echo " $TARBALL" 1.147 case "$TARBALL" in 1.148 @@ -106,7 +189,7 @@ 1.149 esac 1.150 } 1.151 1.152 -# Display cooked package summary 1.153 +# Display cooked package summary. 1.154 summary() { 1.155 cd $WOK/$pkg 1.156 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null) 1.157 @@ -119,8 +202,8 @@ 1.158 cat << EOT 1.159 Packed : $fs 1.160 Compressed : $size 1.161 +Cook time : ${time}s 1.162 Files : $files 1.163 -Cook time : ${time}s 1.164 $(separator) 1.165 1.166 EOT 1.167 @@ -194,8 +277,9 @@ 1.168 # Remove installed deps. 1.169 remove_deps() { 1.170 # Now remove installed build deps. 1.171 - deps=$(cat $CACHE/installed.diff | grep ^+[a-zA-Z0-9] | sed s/^+//) 1.172 - nb=$(echo $deps | wc -l) 1.173 + diff="$CACHE/installed.diff" 1.174 + deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//) 1.175 + nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l) 1.176 if [ -s "$CACHE/installed.diff" ]; then 1.177 gettext "Build dependencies to remove:"; echo " $nb" 1.178 gettext "Removing:" 1.179 @@ -211,10 +295,11 @@ 1.180 1.181 # The main cook function. 1.182 cookit() { 1.183 + echo "Cooking: $PACKAGE $VERSION" 1.184 + echo "Cooking: $PACKAGE $VERSION" | log 1.185 + separator 1.186 set_paths 1.187 - unset error 1.188 - echo "Cooking: $PACKAGE $VERSION" 1.189 - separator 1.190 + [ "$QA" ] && receipt_quality 1.191 rm -rf install taz source $CACHE/error 1.192 1.193 # Disable -pipe if less than 512Mb free RAM. 1.194 @@ -264,18 +349,25 @@ 1.195 get_source || exit 1 1.196 fi 1.197 fi 1.198 - if [ ! "$WANTED" ] && [ ! -d "$src" ]; then 1.199 + if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then 1.200 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp 1.201 extract_source || exit 1 1.202 mv * ../$PACKAGE-$VERSION 1.203 cd .. && rm -rf tmp 1.204 fi 1.205 1.206 - # Execute receipt rules and stay compatible with _pkg. 1.207 + # Execute receipt rules. 1.208 if grep -q ^compile_rules $pkgdir/receipt; then 1.209 gettext -e "Executing: compile_rules\n" 1.210 - cd $src && compile_rules || exit 1 1.211 + [ -d "$src" ] && cd $src 1.212 + compile_rules || exit 1 1.213 + # QA: compile_rules success so valid. 1.214 + mkdir -p $install 1.215 + # Stay compatible with _pkg 1.216 [ -d $src/_pkg ] && mv $src/_pkg $install 1.217 + else 1.218 + # QA: No compile_rules so no error, valid. 1.219 + mkdir -p $install 1.220 fi 1.221 if grep -q ^genpkg_rules $pkgdir/receipt; then 1.222 gettext -e "Executing: genpkg_rules\n" 1.223 @@ -288,13 +380,13 @@ 1.224 1.225 # Cook quality assurance. 1.226 cookit_quality() { 1.227 + if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then 1.228 + echo -e "\nERROR: cook failed\n" | tee -a $LOGS/$pkg.log 1.229 + fi 1.230 + # ERROR can be echoed any time in cookit() 1.231 if grep -q ^ERROR $LOGS/$pkg.log; then 1.232 exit 1 1.233 fi 1.234 - if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then 1.235 - echo -e "\nERROR: cook failed\n" | \ 1.236 - tee -a $LOGS/$pkg.log && exit 1 1.237 - fi 1.238 } 1.239 1.240 # Create the package. 1.241 @@ -375,6 +467,12 @@ 1.242 chmod -R g+w $SLITAZ 1.243 separator 1.244 gettext -e "All done, ready to cook packages :-)\n\n" ;; 1.245 + test) 1.246 + # Test a cook environment. 1.247 + echo "TODO: Use $DATA/cooktest \$(cp cooktest \$WOK and cook)" 1.248 + [ ! -d "$WOK" ] && exit 1 1.249 + [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK 1.250 + cook cooktest ;; 1.251 new) 1.252 # Create the package folder and an empty receipt. 1.253 pkg="$2" 1.254 @@ -502,7 +600,8 @@ 1.255 exit 1 1.256 fi 1.257 fi 1.258 - # Finally we may want to build the *-dev package 1.259 + # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg" 1.260 + # You automation: use the Cooker Build Bot. 1.261 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev 1.262 ;; 1.263 esac