cookutils rev 1079

Improve work with sets:
- keep natural order of the sets described in $SPLIT,
- provide new mode (COOKOPTS="instant-pack"): compile the set and then immediately pack all it's packages, so they will be available for the next set.
Allow to change $CATEGORY.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Jul 10 10:25:36 2018 +0300 (2018-07-10)
parents 1463d32f6f90
children 9583c9709f51
files cook doc/cookopts.txt lighttpd/index.cgi modules/mk_pkg_receipt
line diff
     1.1 --- a/cook	Thu Jun 21 12:57:52 2018 +0300
     1.2 +++ b/cook	Tue Jul 10 10:25:36 2018 +0300
     1.3 @@ -86,6 +86,16 @@
     1.4  }
     1.5  
     1.6  
     1.7 +# Find the package, return the receipt name where it was found
     1.8 +# for example, libpcreposix -> pcre
     1.9 +
    1.10 +find_pkg_in_wok() {
    1.11 +	awk -F$'\t' -vi="$1" '{
    1.12 +		if (index(" " $2 " ", i)) {print $1; exit}
    1.13 +	}' $cache/split.db
    1.14 +}
    1.15 +
    1.16 +
    1.17  # Initialize files used in $CACHE
    1.18  
    1.19  init_db_files() {
    1.20 @@ -629,6 +639,68 @@
    1.21  }
    1.22  
    1.23  
    1.24 +# Internal function to cook specified SET
    1.25 +
    1.26 +cook_set() {
    1.27 +	# Switch to the specified source set
    1.28 +	set_paths
    1.29 +	local suffix=''
    1.30 +	[ -n "$SET" ] && suffix="-$SET"
    1.31 +	export     src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
    1.32 +	export install="$WOK/$pkg/install$suffix"
    1.33 +	export DESTDIR="$install"
    1.34 +
    1.35 +	if [ -n "$SETS" ]; then
    1.36 +		if [ -n "$SET" ]; then
    1.37 +			title "Switching to the set '$SET'"
    1.38 +		else
    1.39 +			title "Switching to the default set"
    1.40 +		fi
    1.41 +		echo "src    : $src"
    1.42 +		echo "install: $install"
    1.43 +	fi
    1.44 +	[ -d "$src" ] && cd $src	# packages without sources exists
    1.45 +	echo
    1.46 +
    1.47 +	[ -d "$install" ] && rm -r $install
    1.48 +	#mkdir -p $install
    1.49 +
    1.50 +	compile_rules $@ || { broken; exit 1; }
    1.51 +
    1.52 +	# Stay compatible with _pkg
    1.53 +	[ -d "$src/_pkg" ] && mv $src/_pkg $install
    1.54 +
    1.55 +	copy_generic_stuff
    1.56 +
    1.57 +	timestamp job$job_counter # compiling (set '$SET')
    1.58 +
    1.59 +	# Actions to do after compiling the package
    1.60 +	# Skip all for split packages (already done in main package)
    1.61 +	if [ -z "$WANTED" ]; then
    1.62 +		footer
    1.63 +		export COOKOPTS ARCH install
    1.64 +		@@PREFIX@@/libexec/cookutils/compressor install
    1.65 +		timestamp job$(($job_counter + 1)) # compressing (set '$SET')
    1.66 +	fi
    1.67 +
    1.68 +	# Activate "instant-pack" mode
    1.69 +	if [ "${COOKOPTS/instant-pack/}" != "$COOKOPTS" ]; then
    1.70 +		echo " $SPLIT " | fgrep -q " $PACKAGE " || SPLIT="$PACKAGE $SPLIT"
    1.71 +		# determine the list of the packages belongs to the current SET...
    1.72 +		echo -n $SPLIT \
    1.73 +		| awk -vset="$SET" '
    1.74 +			BEGIN { RS = " "; FS = ":"; }
    1.75 +			{ if ($2 == set) print $1; }' \
    1.76 +		| while read SET_PKG; do
    1.77 +			# ... and then pack them
    1.78 +			packit $SET_PKG
    1.79 +		done
    1.80 +	fi
    1.81 +
    1.82 +	job_counter=$(($job_counter + 2))
    1.83 +}
    1.84 +
    1.85 +
    1.86  # The main cook function.
    1.87  
    1.88  cookit() {
    1.89 @@ -806,13 +878,14 @@
    1.90  		timestamp job4 # patching
    1.91  
    1.92  		# Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
    1.93 -		SETS=$(echo $SPLIT \
    1.94 +		# Keep natural order of the sets, don't sort them alphabetically
    1.95 +		SETS=$(echo -n $SPLIT \
    1.96  			| awk '
    1.97  				BEGIN { RS = " "; FS = ":"; }
    1.98 -				{ print $2; }' \
    1.99 -			| sort -u \
   1.100 -			| tr '\n' ' ')
   1.101 -		SETS=${SETS% }	# normalize space
   1.102 +				{
   1.103 +					if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
   1.104 +				}' \
   1.105 +			| sed 's| $||')
   1.106  		# Prepare specified source sets using patched sources
   1.107  		[ -n "$SETS" -a -d "$src" ] &&
   1.108  		for set in $SETS; do
   1.109 @@ -824,49 +897,19 @@
   1.110  		timestamp sets "$SETS"
   1.111  
   1.112  		job_counter='6'
   1.113 -		for SET in '' $SETS; do
   1.114 -			# Switch to the specified source set
   1.115 -			set_paths
   1.116 -			local suffix=''
   1.117 -			[ -n "$SET" ] && suffix="-$SET"
   1.118 -			export     src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
   1.119 -			export install="$WOK/$pkg/install$suffix"
   1.120 -			export DESTDIR="$install"
   1.121  
   1.122 -			if [ -n "$SETS" ]; then
   1.123 -				if [ -n "$SET" ]; then
   1.124 -					title "Switching to the set '$SET'"
   1.125 -				else
   1.126 -					title "Switching to the default set"
   1.127 -				fi
   1.128 -				echo "src    : $src"
   1.129 -				echo "install: $install"
   1.130 -			fi
   1.131 -			[ -d "$src" ] && cd $src	# packages without sources exists
   1.132 -			echo
   1.133 +		SET='' cook_set # first run for empty SET
   1.134  
   1.135 -			[ -d "$install" ] && rm -r $install
   1.136 -			#mkdir -p $install
   1.137 -
   1.138 -			compile_rules $@ || { broken; exit 1; }
   1.139 -
   1.140 -			# Stay compatible with _pkg
   1.141 -			[ -d "$src/_pkg" ] && mv $src/_pkg $install
   1.142 -
   1.143 -			copy_generic_stuff
   1.144 -
   1.145 -			timestamp job$job_counter # compiling (set '$SET')
   1.146 -
   1.147 -			# Actions to do after compiling the package
   1.148 -			# Skip all for split packages (already done in main package)
   1.149 -			if [ -z "$WANTED" ]; then
   1.150 -				footer
   1.151 -				export COOKOPTS ARCH install
   1.152 -				@@PREFIX@@/libexec/cookutils/compressor install
   1.153 -				timestamp job$(($job_counter + 1)) # compressing (set '$SET')
   1.154 -			fi
   1.155 -
   1.156 -			job_counter=$(($job_counter + 2))
   1.157 +		# Allow to change SETS after the first run, follow the changes
   1.158 +		SETS=$(. $receipt; echo -n $SPLIT \
   1.159 +			| awk '
   1.160 +				BEGIN { RS = " "; FS = ":"; }
   1.161 +				{
   1.162 +					if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
   1.163 +				}' \
   1.164 +			| sed 's| $||')
   1.165 +		for SET in $SETS; do
   1.166 +			cook_set
   1.167  		done
   1.168  	else
   1.169  		mkdir -p $install	# allow receipts without `compile_rules()`
   1.170 @@ -982,7 +1025,7 @@
   1.171  
   1.172  	cd $taz
   1.173  	action 'Copying "%s"...' 'receipt'
   1.174 -	export PACKAGE VERSION SHORT_DESC WEB_SITE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT CONFIG_FILES
   1.175 +	export PACKAGE VERSION CATEGORY SHORT_DESC WEB_SITE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT CONFIG_FILES
   1.176  	@@PREFIX@@/libexec/cookutils/mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
   1.177  	chown 0.0 $pack/receipt; status
   1.178  
   1.179 @@ -1182,7 +1225,7 @@
   1.180  
   1.181  all_names() {
   1.182  	# Get package names from $SPLIT variable
   1.183 -	local split=$(echo $SPLIT \
   1.184 +	local split=$(echo -n $SPLIT \
   1.185  		| awk '
   1.186  			BEGIN { RS = " "; FS = ":"; }
   1.187  			{ print $1; }' \
   1.188 @@ -2137,6 +2180,8 @@
   1.189  		fi
   1.190  
   1.191  		# Proceed only if `cookit` return code is zero-OK
   1.192 +		# If instant-pack if specified, then packages already packed in the cookit()
   1.193 +		[ "${COOKOPTS/instant-pack/}" == "$COOKOPTS" ] &&
   1.194  		packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
   1.195  		timestamp job29 # packing
   1.196  
     2.1 --- a/doc/cookopts.txt	Thu Jun 21 12:57:52 2018 +0300
     2.2 +++ b/doc/cookopts.txt	Tue Jul 10 10:25:36 2018 +0300
     2.3 @@ -164,3 +164,13 @@
     2.4      Default behaviour is to end work with error message when package contains no
     2.5      files (exception is made for packages belonging to the "meta" category).
     2.6      Presence of this option allows the package not to contain files.
     2.7 +
     2.8 +instant-pack
     2.9 +    Usual behaviour is to make the sources (when sources in the $src became
    2.10 +    files in the $install) and then pack the package (when files from $install
    2.11 +    split to one or another $fs, and then became the *.tazpkg archives).
    2.12 +    When multiple SETs used in the receipt, the default behaviour is to make
    2.13 +    all the sources for all the sets, and only then to pack all the packages.
    2.14 +    Presence of this option will pack the SET packages instantly before
    2.15 +    to switch to another SET. So, packages created in the first SET will be
    2.16 +    immediately available to use in the second SET, and so on.
     3.1 --- a/lighttpd/index.cgi	Thu Jun 21 12:57:52 2018 +0300
     3.2 +++ b/lighttpd/index.cgi	Tue Jul 10 10:25:36 2018 +0300
     3.3 @@ -571,7 +571,7 @@
     3.4  				-e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
     3.5  				-e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
     3.6  				-e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
     3.7 -				-e 's|^Switching to the set.*|<span class="switch">‣‣‣ \0</span>|' \
     3.8 +				-e 's|^Switching to the .*|<span class="switch">‣‣‣ \0</span>|' \
     3.9  				\
    3.10  				-e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
    3.11  				-e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
     4.1 --- a/modules/mk_pkg_receipt	Thu Jun 21 12:57:52 2018 +0300
     4.2 +++ b/modules/mk_pkg_receipt	Tue Jul 10 10:25:36 2018 +0300
     4.3 @@ -39,7 +39,7 @@
     4.4  PACKAGE="$PACKAGE"; DEPENDS="$(echo $DEPENDS)"; PROVIDE="$(echo $PROVIDE)"
     4.5  SUGGESTED="$(echo $SUGGESTED)"; TAZPANEL_DAEMON="$TAZPANEL_DAEMON"
     4.6  TAGS="$(echo $TAGS)"; VERSION="$VERSION"; SHORT_DESC="$SHORT_DESC"
     4.7 -WEB_SITE="$WEB_SITE"
     4.8 +WEB_SITE="$WEB_SITE"; CATEGORY="$CATEGORY"
     4.9  EOT
    4.10  unset_receipt
    4.11  . "$orig_receipt"