cookutils 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 |
files | Makefile cat.list cook cook.conf data/cooktest/receipt |
line diff
1.1 --- a/Makefile Tue May 03 23:09:59 2011 +0200 1.2 +++ b/Makefile Wed May 04 04:30:28 2011 +0200 1.3 @@ -14,7 +14,7 @@ 1.4 install -m 0777 -d $(DESTDIR)/var/www/cooker 1.5 install -m 0777 -d $(DESTDIR)$(PREFIX)/share/cook 1.6 install -m 0644 web/* $(DESTDIR)/var/www/cooker 1.7 - install -m 0644 data/* $(DESTDIR)$(PREFIX)/share/cook 1.8 + cp -r data/* $(DESTDIR)$(PREFIX)/share/cook 1.9 1.10 uninstall: 1.11 rm -f \
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/cat.list Wed May 04 04:30:28 2011 +0200 2.3 @@ -0,0 +1,20 @@ 2.4 + 2.5 +[1mPackages categories[0m 2.6 +================================================================================ 2.7 +base-system 2.8 +x-window 2.9 +utilities 2.10 +network 2.11 +graphics 2.12 +multimedia 2.13 +office 2.14 +development 2.15 +system-tools 2.16 +security 2.17 +games 2.18 +misc 2.19 +meta 2.20 +non-free 2.21 +================================================================================ 2.22 +14 categories 2.23 +
3.1 --- a/cook Tue May 03 23:09:59 2011 +0200 3.2 +++ b/cook Wed May 04 04:30:28 2011 +0200 3.3 @@ -10,6 +10,9 @@ 3.4 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf 3.5 [ -f "cook.conf" ] && . ./cook.conf 3.6 3.7 +# Share activity with the Cooker. 3.8 +activity="$CACHE/activity" 3.9 + 3.10 # 3.11 # Functions 3.12 # 3.13 @@ -23,6 +26,7 @@ 3.14 usage|help $(gettext "Display this short usage.") 3.15 list-wok $(gettext "List packages in the wok.") 3.16 setup $(gettext "Setup your build environment.") 3.17 + test $(gettext "Test environment and cook a package.") 3.18 new $(gettext "Create a new package with receipt".) 3.19 list $(gettext "Cook a list of packages.") 3.20 clean-wok $(gettext "Clean-up all packages files.") 3.21 @@ -57,15 +61,18 @@ 3.22 echo -e "\\033[0;39m ]" 3.23 } 3.24 3.25 +# Log activities. 3.26 +log() { 3.27 + grep ^[a-zA-Z0-9] | \ 3.28 + sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity 3.29 +} 3.30 + 3.31 +# We dont want those escape in web interface. 3.32 clean_log() { 3.33 sed -i -e s'|\[70G\[ \[1;32m| |' \ 3.34 -e s'|\[0;39m \]||' $LOGS/$pkg.log 3.35 } 3.36 3.37 -unset_receipt() { 3.38 - unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE 3.39 -} 3.40 - 3.41 # Be sure package exist in wok. 3.42 check_pkg_in_wok() { 3.43 if [ ! -d "$WOK/$pkg" ]; then 3.44 @@ -74,6 +81,53 @@ 3.45 fi 3.46 } 3.47 3.48 +if_empty_value() { 3.49 + if [ -z "$value" ]; then 3.50 + gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n" 3.51 + exit 1 3.52 + fi 3.53 +} 3.54 + 3.55 +# QA: check a receip consistency befor building. 3.56 +receipt_quality() { 3.57 + gettext -e "QA: checking package receipt...\n" 3.58 + unset online 3.59 + if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then 3.60 + online="online" 3.61 + fi 3.62 + for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE 3.63 + do 3.64 + unset value 3.65 + value=$(grep ^$var= receipt | cut -d \" -f 2) 3.66 + case "$var" in 3.67 + PACKAGE|VERSION|SHORT_DESC) 3.68 + if_empty_value ;; 3.69 + CATEGORY) 3.70 + [ -z "$value" ] && value="empty" 3.71 + valid="base-system x-window utilities network graphics \ 3.72 + multimedia office development system-tools security games \ 3.73 + misc meta non-free" 3.74 + if ! echo "$valid" | grep -q -w "$value"; then 3.75 + gettext "QA: unknow category:"; echo -e " $value\n" 3.76 + exit 1 3.77 + fi ;; 3.78 + WEB_SITE) 3.79 + # We dont check WGET_URL since if dl is needed it will fail. 3.80 + # Break also if we not online. Here error is not fatal. 3.81 + if_empty_value 3.82 + [ -z "$online" ] || break 3.83 + if ! busybox wget -s $value 2>/dev/null; then 3.84 + gettext "QA: Unable to reach:"; echo -e " $value\n" 3.85 + fi ;; 3.86 + esac 3.87 + done 3.88 +} 3.89 + 3.90 +# Executed before sourcing a receipt. 3.91 +unset_receipt() { 3.92 + unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL 3.93 +} 3.94 + 3.95 # Path's used in receipt and by cook itself. 3.96 set_paths() { 3.97 pkgdir=$WOK/$PACKAGE 3.98 @@ -86,16 +140,45 @@ 3.99 src=$WOK/$WANTED/source/$WANTED-$VERSION 3.100 install=$WOK/$WANTED/install 3.101 fi 3.102 - # Old way compatibility 3.103 + # Old way compatibility. 3.104 _pkg=$install 3.105 } 3.106 3.107 -# Get package source 3.108 +# Get package source. 3.109 get_source() { 3.110 - wget -P $SRC $WGET_URL 3.111 + case "$WGET_URL" in 3.112 + http://*|ftp://*) 3.113 + # Busybox Wget is better! 3.114 + busybox wget -c -P $SRC $WGET_URL ;; 3.115 + hg*|mercurial*) 3.116 + # We are in cache so clone here and create a tarball 3.117 + pwd=$(pwd) 3.118 + if $(echo "$WGET_URL" | fgrep -q hg); then 3.119 + url=${WGET_URL#hg|} 3.120 + else 3.121 + url=${WGET_URL#mercurial|} 3.122 + fi 3.123 + pkgsrc=$PACKAGE-$VERSION 3.124 + [ "$SOURCE" ] && pkgsrc=$SOURCE-$VERSION 3.125 + tarball=$pkgsrc.tar.bz2 3.126 + gettext "Getting source from Hg: "; echo $url 3.127 + gettext "Cloning to: "; echo "$pwd/$pkgsrc" 3.128 + hg clone $url $pkgsrc || exit 1 3.129 + gettext "Creating tarball: "; echo "$tarball" 3.130 + tar cjf $tarball $pkgsrc || exit 1 3.131 + mv $tarball $SRC && rm -rf $pkgsrc ;; 3.132 + git*) 3.133 + echo "TODO: git implementation in cook" && exit 1 ;; 3.134 + svn*) 3.135 + echo "TODO: svn implementation in cook" && exit 1 ;; 3.136 + *) 3.137 + gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \ 3.138 + tee -a $LOGS/$PACKAGE.log 3.139 + exit 1 ;; 3.140 + esac 3.141 } 3.142 3.143 -# Extract source package 3.144 +# Extract source package. 3.145 extract_source() { 3.146 gettext "Extracting:"; echo " $TARBALL" 3.147 case "$TARBALL" in 3.148 @@ -106,7 +189,7 @@ 3.149 esac 3.150 } 3.151 3.152 -# Display cooked package summary 3.153 +# Display cooked package summary. 3.154 summary() { 3.155 cd $WOK/$pkg 3.156 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null) 3.157 @@ -119,8 +202,8 @@ 3.158 cat << EOT 3.159 Packed : $fs 3.160 Compressed : $size 3.161 +Cook time : ${time}s 3.162 Files : $files 3.163 -Cook time : ${time}s 3.164 $(separator) 3.165 3.166 EOT 3.167 @@ -194,8 +277,9 @@ 3.168 # Remove installed deps. 3.169 remove_deps() { 3.170 # Now remove installed build deps. 3.171 - deps=$(cat $CACHE/installed.diff | grep ^+[a-zA-Z0-9] | sed s/^+//) 3.172 - nb=$(echo $deps | wc -l) 3.173 + diff="$CACHE/installed.diff" 3.174 + deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//) 3.175 + nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l) 3.176 if [ -s "$CACHE/installed.diff" ]; then 3.177 gettext "Build dependencies to remove:"; echo " $nb" 3.178 gettext "Removing:" 3.179 @@ -211,10 +295,11 @@ 3.180 3.181 # The main cook function. 3.182 cookit() { 3.183 + echo "Cooking: $PACKAGE $VERSION" 3.184 + echo "Cooking: $PACKAGE $VERSION" | log 3.185 + separator 3.186 set_paths 3.187 - unset error 3.188 - echo "Cooking: $PACKAGE $VERSION" 3.189 - separator 3.190 + [ "$QA" ] && receipt_quality 3.191 rm -rf install taz source $CACHE/error 3.192 3.193 # Disable -pipe if less than 512Mb free RAM. 3.194 @@ -264,18 +349,25 @@ 3.195 get_source || exit 1 3.196 fi 3.197 fi 3.198 - if [ ! "$WANTED" ] && [ ! -d "$src" ]; then 3.199 + if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then 3.200 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp 3.201 extract_source || exit 1 3.202 mv * ../$PACKAGE-$VERSION 3.203 cd .. && rm -rf tmp 3.204 fi 3.205 3.206 - # Execute receipt rules and stay compatible with _pkg. 3.207 + # Execute receipt rules. 3.208 if grep -q ^compile_rules $pkgdir/receipt; then 3.209 gettext -e "Executing: compile_rules\n" 3.210 - cd $src && compile_rules || exit 1 3.211 + [ -d "$src" ] && cd $src 3.212 + compile_rules || exit 1 3.213 + # QA: compile_rules success so valid. 3.214 + mkdir -p $install 3.215 + # Stay compatible with _pkg 3.216 [ -d $src/_pkg ] && mv $src/_pkg $install 3.217 + else 3.218 + # QA: No compile_rules so no error, valid. 3.219 + mkdir -p $install 3.220 fi 3.221 if grep -q ^genpkg_rules $pkgdir/receipt; then 3.222 gettext -e "Executing: genpkg_rules\n" 3.223 @@ -288,13 +380,13 @@ 3.224 3.225 # Cook quality assurance. 3.226 cookit_quality() { 3.227 + if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then 3.228 + echo -e "\nERROR: cook failed\n" | tee -a $LOGS/$pkg.log 3.229 + fi 3.230 + # ERROR can be echoed any time in cookit() 3.231 if grep -q ^ERROR $LOGS/$pkg.log; then 3.232 exit 1 3.233 fi 3.234 - if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then 3.235 - echo -e "\nERROR: cook failed\n" | \ 3.236 - tee -a $LOGS/$pkg.log && exit 1 3.237 - fi 3.238 } 3.239 3.240 # Create the package. 3.241 @@ -375,6 +467,12 @@ 3.242 chmod -R g+w $SLITAZ 3.243 separator 3.244 gettext -e "All done, ready to cook packages :-)\n\n" ;; 3.245 + test) 3.246 + # Test a cook environment. 3.247 + echo "TODO: Use $DATA/cooktest \$(cp cooktest \$WOK and cook)" 3.248 + [ ! -d "$WOK" ] && exit 1 3.249 + [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK 3.250 + cook cooktest ;; 3.251 new) 3.252 # Create the package folder and an empty receipt. 3.253 pkg="$2" 3.254 @@ -502,7 +600,8 @@ 3.255 exit 1 3.256 fi 3.257 fi 3.258 - # Finally we may want to build the *-dev package 3.259 + # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg" 3.260 + # You automation: use the Cooker Build Bot. 3.261 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev 3.262 ;; 3.263 esac
4.1 --- a/cook.conf Tue May 03 23:09:59 2011 +0200 4.2 +++ b/cook.conf Wed May 04 04:30:28 2011 +0200 4.3 @@ -16,6 +16,9 @@ 4.4 DB="/var/lib/tazpkg" 4.5 INSTALLED="$DB/installed" 4.6 4.7 +# Quality Assurance (empty to disable receipt_quality). 4.8 +QA="0" 4.9 + 4.10 # Hg wok for setup and flavors URL for the Cooker. 4.11 WOK_URL="http://hg.slitaz.org/wok" 4.12 FLAVORS_URL="http://hg.slitaz.org/flavors"
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/data/cooktest/receipt Wed May 04 04:30:28 2011 +0200 5.3 @@ -0,0 +1,46 @@ 5.4 +# SliTaz package receipt. 5.5 + 5.6 +PACKAGE="cooktest" 5.7 +VERSION="1.0" 5.8 +CATEGORY="base-system" 5.9 +SHORT_DESC="SliTaz QA test package." 5.10 +MAINTAINER="devel@slitaz.org" 5.11 +WEB_SITE="http://www.slitaz.org/" 5.12 + 5.13 +DEPENDS="" 5.14 +BUILD_DEPENDS="" 5.15 + 5.16 +# Rules to configure and make the package. 5.17 +compile_rules() 5.18 +{ 5.19 + echo -e "\n./configure && make && make install" 5.20 + echo "-----------------------------------" 5.21 + echo -e " * Log file : $LOGS/$PACKAGE.log" 5.22 + 5.23 + # Test if a package is installed. 5.24 + [ -d "$INSTALLED/make" ] && echo " * Package : make is installed" 5.25 + [ ! -d "$INSTALLED/make" ] && echo " * Package : make not installed" 5.26 + 5.27 + echo "" 5.28 +} 5.29 + 5.30 +# Rules to gen a SliTaz package suitable for Tazpkg. 5.31 +genpkg_rules() 5.32 +{ 5.33 + mkdir -p $fs/tmp 5.34 + cat << EOT 5.35 +cp -a \$install/usr/bin \$fs/usr 5.36 +------------------------------ 5.37 + * \$fs : $fs" 5.38 + * \$stuff : $stuff" 5.39 + * \$install : $install" 5.40 + * \$src : $src" 5.41 + 5.42 +EOT 5.43 + # A file to have something to package. Cook fails if package is empty. 5.44 + echo "NOTE: Create, copy files from \$install or \$stuff" 5.45 + echo -n "cook-test:" > $fs/tmp/cook-test 5.46 + date >> $fs/tmp/cook-test 5.47 + echo "" 5.48 + echo -n "End of receipt: press ENTER to continue"; read i 5.49 +}