cookutils rev 932

Add modules/deps: check package's dependencies; cook: make/update split.db and files.list; modules/compressor: use static (i.e. unbreakable) versions of pngquant and optipng.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Jun 17 23:56:37 2017 +0300 (2017-06-17)
parents 253b4ffeef27
children 9b8a08ce85c9
files Makefile cook modules/compressor modules/deps
line diff
     1.1 --- a/Makefile	Fri Jun 16 16:40:34 2017 +0300
     1.2 +++ b/Makefile	Sat Jun 17 23:56:37 2017 +0300
     1.3 @@ -28,7 +28,9 @@
     1.4  	install -m 0755 cooker           $(DESTDIR)$(PREFIX)/bin
     1.5  	install -m 0755 cookiso          $(DESTDIR)$(PREFIX)/bin
     1.6  	install -m 0755 cooklinux        $(DESTDIR)$(PREFIX)/bin
     1.7 -	install -m 0755 modules/pkgdb modules/compressor \
     1.8 +	install -m 0755 modules/pkgdb \
     1.9 +					modules/compressor \
    1.10 +					modules/deps \
    1.11  									 $(DESTDIR)$(PREFIX)/libexec/cookutils
    1.12  	install -m 0644 cook.conf        $(DESTDIR)/etc/slitaz
    1.13  	install -m 0644 cook.site        $(DESTDIR)/etc/slitaz
     2.1 --- a/cook	Fri Jun 16 16:40:34 2017 +0300
     2.2 +++ b/cook	Sat Jun 17 23:56:37 2017 +0300
     2.3 @@ -63,6 +63,7 @@
     2.4      --forced           $(_ 'force reinstall of chroot packages.')
     2.5  cook pkgdb
     2.6      --flavors          $(_ 'create up-to-date flavors files.')
     2.7 +cook splitdb           $(_ 'create up-to-date split.db file.')
     2.8  
     2.9  EOT
    2.10  	exit 0
    2.11 @@ -1034,7 +1035,7 @@
    2.12  	tazpkg=$(ls *.tazpkg)
    2.13  	packit_quality
    2.14  	footer "$(_ 'Package "%s" created' "$tazpkg")"
    2.15 -	update_packages_info
    2.16 +	update_packages_db
    2.17  }
    2.18  
    2.19  
    2.20 @@ -1404,18 +1405,53 @@
    2.21  }
    2.22  
    2.23  
    2.24 -# Update packages.info every time after successful build
    2.25 +# Update packages database every time after successful build
    2.26  
    2.27 -update_packages_info() {
    2.28 -	sed -i "/^$PACKAGE\t/d" $PKGS/packages.info
    2.29 +update_packages_db() {
    2.30 +	# packages.info (unsorted, located near to packages)
    2.31 +	local pi="$PKGS/packages.info"
    2.32 +	sed -i "/^$PACKAGE\t/d" $pi
    2.33  	unset_receipt; . $pack/receipt
    2.34  	SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
    2.35  	DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
    2.36  	MD5="$(md5sum "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" | awk '{print $1}')"
    2.37 -	cat >> $PKGS/packages.info <<EOT
    2.38 +	cat >> $pi <<EOT
    2.39  $PACKAGE	$VERSION$EXTRAVERSION	$CATEGORY	$SHORT_DESC	$WEB_SITE	$TAGS	$SIZES	$DEPENDS	$MD5	$PROVIDE
    2.40  EOT
    2.41  
    2.42 +	# files.list (uncompressed, unsorted, located in $cache)
    2.43 +	local fl="$cache/files.list"
    2.44 +	touch $fl
    2.45 +	sed -i "/^$PACKAGE: /d" $fl
    2.46 +	sed  "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
    2.47 +}
    2.48 +
    2.49 +
    2.50 +# Update split.db once for receipt
    2.51 +
    2.52 +update_split_db() {
    2.53 +	local db="$cache/split.db"
    2.54 +	touch $db
    2.55 +	sed -i "/^$pkg\t/d" $db
    2.56 +	echo -e "$pkg\t$(all_names)" >> $db
    2.57 +}
    2.58 +
    2.59 +
    2.60 +# Recreate whole split.db from scratch
    2.61 +
    2.62 +recreate_split_db() {
    2.63 +	# Clean
    2.64 +	local db="$cache/split.db"
    2.65 +	touch $db
    2.66 +	> $db
    2.67 +
    2.68 +	cd $WOK
    2.69 +	for i in *; do
    2.70 +		[ -f "$WOK/$i/receipt" ] || continue
    2.71 +		unset PACKAGE SPLIT
    2.72 +		. $WOK/$i/receipt
    2.73 +		echo -e "$PACKAGE\t$(all_names)" >> $db
    2.74 +	done
    2.75  }
    2.76  
    2.77  
    2.78 @@ -1425,6 +1461,10 @@
    2.79  # Commands
    2.80  #
    2.81  
    2.82 +# cook <package> --deps
    2.83 +[ -n "$deps" ] && { @@PREFIX@@/libexec/cookutils/deps $1; exit 0; }
    2.84 +
    2.85 +
    2.86  case "$1" in
    2.87  	usage|help|-u|-h)
    2.88  		 usage ;;
    2.89 @@ -1718,6 +1758,11 @@
    2.90  		@@PREFIX@@/libexec/cookutils/pkgdb "$2"
    2.91  		;;
    2.92  
    2.93 +	splitdb)
    2.94 +		# File split.db is useful for searching for split packages.
    2.95 +		recreate_split_db
    2.96 +		;;
    2.97 +
    2.98  	*)
    2.99  		# Just cook and generate a package.
   2.100  		check_root
   2.101 @@ -1792,6 +1837,8 @@
   2.102  		trap '_ "\n\nCook stopped: control-C\n\n" | \
   2.103  			tee -a $LOGS/$pkg.log' INT
   2.104  
   2.105 +		update_split_db
   2.106 +
   2.107  		# Handle --options
   2.108  		case "$2" in
   2.109  			--clean|-c)
   2.110 @@ -1833,9 +1880,6 @@
   2.111  				sed -i '$ s|$| [ Done ]|' $activity
   2.112  				rm -f $command
   2.113  				exit 0 ;;
   2.114 -
   2.115 -			--cdeps)
   2.116 -				@@PREFIX@@/libexec/cookutils/cdeps $pkg
   2.117  		esac
   2.118  
   2.119  		# Rotate log
     3.1 --- a/modules/compressor	Fri Jun 16 16:40:34 2017 +0300
     3.2 +++ b/modules/compressor	Sat Jun 17 23:56:37 2017 +0300
     3.3 @@ -194,8 +194,8 @@
     3.4  	use_op=true
     3.5  	[ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
     3.6  	[ "${COOKOPTS/!optipng/}"  != "$COOKOPTS" ] && use_op=false
     3.7 -	$use_pq && tpi pngquant
     3.8 -	$use_op && tpi optipng
     3.9 +	$use_pq && tpi pngquant-static
    3.10 +	$use_op && tpi optipng-static
    3.11  
    3.12  	action 'Compressing png images...'
    3.13  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/modules/deps	Sat Jun 17 23:56:37 2017 +0300
     4.3 @@ -0,0 +1,239 @@
     4.4 +#!/bin/sh
     4.5 +#
     4.6 +# deps - module of the SliTaz Cook
     4.7 +# Copyright (C) SliTaz GNU/Linux - GNU GPL v3
     4.8 +#
     4.9 +
    4.10 +. /usr/lib/slitaz/libcook.sh
    4.11 +
    4.12 +
    4.13 +# Maintain databases
    4.14 +
    4.15 +fl="$cache/tp.files.db"		# combined list of all files
    4.16 +db_so="$cache/tp.so.db"		# database with *.so files
    4.17 +db_a="$cache/tp.a.db"		# database with *.a files
    4.18 +db_la="$cache/tp.la.db"		# database with *.la files
    4.19 +db_pc="$cache/tp.pc.db"		# database with *.pc files
    4.20 +
    4.21 +fl_mirrorz='/var/lib/tazpkg/files.list.lzma'	# mirror files list
    4.22 +fl_local='/home/slitaz/cache/files.list'		# local files list
    4.23 +
    4.24 +# recreate "combined list of all files" in the cases:
    4.25 +#   * it absent
    4.26 +#   * mirror files list has been updated
    4.27 +#   * local files list has been updated
    4.28 +
    4.29 +if [ ! -s $fl   -o   $fl_mirrorz -nt $fl   -o   $fl_local -nt $fl ]; then
    4.30 +	# unpack mirror files list
    4.31 +	fl_mirror="$(mktemp)"
    4.32 +	lzcat $fl_mirrorz > $fl_mirror
    4.33 +
    4.34 +	# remove packages that exist in local list
    4.35 +	cut -d: -f1 $fl_local | uniq | \
    4.36 +	while read package; do
    4.37 +		sed -i "/^$package: /d" $fl_mirror
    4.38 +	done
    4.39 +
    4.40 +	# combine lists
    4.41 +	cat $fl_mirror $fl_local > $fl
    4.42 +
    4.43 +	# clean
    4.44 +	rm $fl_mirror
    4.45 +fi
    4.46 +
    4.47 +# recreate "database with *.so files" in the cases:
    4.48 +#   * it absent
    4.49 +#   * combined list of all files has been updated
    4.50 +
    4.51 +if [ ! -s $db_so   -o   $fl -nt $db_so ]; then
    4.52 +	fgrep '/lib/' $fl | fgrep '.so' | \
    4.53 +	sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
    4.54 +	awk -F$'\t' '{if ($2 !~ "uclibc") print}' | \
    4.55 +	sort > $db_so
    4.56 +fi
    4.57 +
    4.58 +# recreate "database with *.a files" in the cases:
    4.59 +#   * it absent
    4.60 +#   * combined list of all files has been updated
    4.61 +
    4.62 +if [ ! -s $db_a -o $fl -nt $db_a ]; then
    4.63 +	fgrep '/usr/lib/lib' $fl | fgrep '.a' | \
    4.64 +	sed 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' | \
    4.65 +	sort > $db_a
    4.66 +fi
    4.67 +
    4.68 +# recreate "database with *.la files" in the cases:
    4.69 +#   * it absent
    4.70 +#   * combined list of all files has been updated
    4.71 +
    4.72 +if [ ! -s $db_la -o $fl -nt $db_la ]; then
    4.73 +	fgrep '/usr/lib/' $fl | fgrep '.la' | \
    4.74 +	sed 's|^\([^:]*\): \(.*\)$|\2\t\1|' | \
    4.75 +	sort > $db_la
    4.76 +fi
    4.77 +
    4.78 +# recreate "database with *.pc files" in the cases:
    4.79 +#   * it absent
    4.80 +#   * combined list of all files has been updated
    4.81 +
    4.82 +if [ ! -s $db_pc -o $fl -nt $db_pc ]; then
    4.83 +	grep '\.pc$' $fl | \
    4.84 +	sed -e 's|^\([^:]*\):.*/\([^/]*\)$|\2\t\1|' -e '/\tbuildroot$/d' | \
    4.85 +	sort > $db_pc
    4.86 +fi
    4.87 +
    4.88 +
    4.89 +
    4.90 +
    4.91 +# Auxiliary function that deal with "not found" packages as well as with "repeatedly found" packages
    4.92 +
    4.93 +outpkg() {
    4.94 +	pkgs="$1"
    4.95 +	case $pkgs in
    4.96 +		*ld-linux.so*);;
    4.97 +		*linux-gate.so*);;
    4.98 +		*)
    4.99 +			echo "$pkgs" | awk '
   4.100 +			# if both packages exist in list, return the first one only
   4.101 +			function s(pkg1, pkg2) {
   4.102 +				if (index(" "$0" ", " "pkg1" ") && index(" "$0" ", " " pkg2 " "))
   4.103 +					$0 = pkg1;
   4.104 +			}
   4.105 +			{
   4.106 +				s("wine",         "wine-rt");
   4.107 +				s("samba",        "samba-pam");
   4.108 +				s("mesa",         "mesa-wayland");
   4.109 +				s("mysql",        "mariadb");
   4.110 +				s("perl",         "perl-thread");
   4.111 +				s("xorg-server",  "xorg-server-light");
   4.112 +				s("cairo",        "cairo-gl");
   4.113 +				s("freetype",     "freetype-infinality");
   4.114 +				s("freetype",     "freetype-without-harfbuzz");
   4.115 +				s("harfbuzz",     "harfbuzz-icu");
   4.116 +				s("openbox",      "openbox-imlib2");
   4.117 +				s("gcc-lib-base", "gcc49-lib-base"); # also gcc54-lib-base and gcc61-lib-base
   4.118 +				s("polkit",       "polkit-pam");
   4.119 +				s("libgudev",     "eudev"); # also systemd
   4.120 +				s("xz-dev",       "liblzma-dev");
   4.121 +
   4.122 +				if (! index($0, "glibc-base") &&
   4.123 +					! index($0, "gcc-lib-base") &&
   4.124 +					! index($0, "glibc-dev") &&
   4.125 +					$0 != "gcc")
   4.126 +						print gensub(" ", "|", "g");
   4.127 +			}';;
   4.128 +	esac >>$tmptmp
   4.129 +}
   4.130 +
   4.131 +
   4.132 +# Search for item $1 in db $2
   4.133 +
   4.134 +indb() {
   4.135 +	local res="$(awk -vi="$1" '
   4.136 +		{
   4.137 +			if ($1 == i)
   4.138 +				{ print $2; found = 1; }
   4.139 +		}
   4.140 +		END {
   4.141 +			if (found != 1) {
   4.142 +				if (index(i, "statically linked"))
   4.143 +					print gensub(" ", "_", "g", i);
   4.144 +				else
   4.145 +					printf("[%s]\n", i);
   4.146 +			}
   4.147 +		}
   4.148 +	' $2 | tr '\n' ' ')"
   4.149 +	outpkg "${res% }"
   4.150 +}
   4.151 +
   4.152 +
   4.153 +# Like `ldd` function but returns packages names where dependency exists.
   4.154 +# Also can process some development files
   4.155 +
   4.156 +tp_ldd() {
   4.157 +	unset IFS
   4.158 +	tmptmp=$(mktemp)
   4.159 +
   4.160 +	case $1 in
   4.161 +		*.la)
   4.162 +			# found dependencies in the *.la files
   4.163 +			libs=$(. $1; echo $dependency_libs)
   4.164 +			for i in $libs; do
   4.165 +				case $i in
   4.166 +					-l*)  indb "lib${i#-l}.so" $db_so;; # FIXME: I'm not sure it's about a *.so, but *.a often absent
   4.167 +					*.la) indb "$i" $db_la;;
   4.168 +				esac
   4.169 +			done
   4.170 +			;;
   4.171 +		*.pc)
   4.172 +			# found dependencies in the *.pc files
   4.173 +			# Syntax examples:
   4.174 +			# Requires: glib-2.0 gobject-2.0
   4.175 +			# Requires.private: gmodule-no-export-2.0
   4.176 +			# Requires: gobject-2.0,gio-2.0
   4.177 +			pcs=$(grep '^Requires' $1 | cut -d: -f2 | tr ',' ' ' | tr '\n' ' ')
   4.178 +			for i in $pcs; do
   4.179 +				indb "$i.pc" $db_pc
   4.180 +			done
   4.181 +			# Syntax examples:
   4.182 +			# Libs: -L${libdir} -lgio-2.0
   4.183 +			# Libs.private: -lz -lresolv    
   4.184 +			libs=$(grep '^Libs' $1 | cut -d: -f2 | tr '\n' ' ')
   4.185 +			for i in $libs; do
   4.186 +				case $i in
   4.187 +					-l*) indb "lib${i#-l}.so" $db_so;;
   4.188 +				esac
   4.189 +			done
   4.190 +			;;
   4.191 +		*/lib/modules/*)
   4.192 +			echo 'linux'
   4.193 +			;;
   4.194 +		*.pl|*.pm)
   4.195 +			echo 'perl'
   4.196 +			;;
   4.197 +		*.py)
   4.198 +			echo 'python'
   4.199 +			;;
   4.200 +		*)
   4.201 +			LD_PRELOAD= LD_TRACE_LOADED_OBJECTS=1 /lib/ld-linux* "$1" 2>/dev/null | \
   4.202 +			sed 's| =>.*||; s| (.*||; s|\t||' | \
   4.203 +			while read i; do
   4.204 +				indb "$i" $db_so
   4.205 +			done
   4.206 +			;;
   4.207 +	esac
   4.208 +
   4.209 +	sort -u $tmptmp
   4.210 +	rm $tmptmp
   4.211 +}
   4.212 +
   4.213 +
   4.214 +# Return all the names of packages bundled in this receipt
   4.215 +
   4.216 +all_names() {
   4.217 +	local split=" $SPLIT "
   4.218 +	if [ "${split/ $PACKAGE /}" != "$split" ]; then
   4.219 +		# $PACKAGE included somewhere in $SPLIT (probably in the end).
   4.220 +		# We should build packages in the order defined in the $SPLIT.
   4.221 +		echo $SPLIT
   4.222 +	else
   4.223 +		# We'll build the $PACKAGE, then all defined in the $SPLIT.
   4.224 +		echo $PACKAGE $SPLIT
   4.225 +	fi
   4.226 +}
   4.227 +
   4.228 +
   4.229 +
   4.230 +
   4.231 +unset IFS
   4.232 +. $WOK/$1/receipt
   4.233 +
   4.234 +for pkg in $(all_names); do
   4.235 +	title 'Dependencies for "%s"' "$pkg"
   4.236 +	IFS=$'\n'
   4.237 +	while read file; do
   4.238 +		tp_ldd "$WOK/$1/taz/$pkg-$VERSION/fs$file"
   4.239 +	done < $WOK/$1/taz/$pkg-$VERSION/files.list | sort -u | grep -v "^$pkg$"
   4.240 +done
   4.241 +
   4.242 +newline