delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/01/08/00:51:35

X-Spam-Check-By: sourceware.org
Message-ID: <459F2ABB.8010304@cwilson.fastmail.fm>
Date: Fri, 05 Jan 2007 23:51:07 -0500
From: Charles Wilson <cygwin AT cwilson DOT fastmail DOT fm>
User-Agent: Thunderbird 1.5.0.9 (Windows/20061207)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: [patch] cygport-0.2.7 custom commands
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------040906080500030602080107
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Implements an extensible method of calling custom cygport functions from 
the cygport command line, in addition to the existing prep, install, 
check, pkg ones (etc).  This is a forward port of the original patch, 
posted on 2006-12-9 here:
http://www.cygwin.com/ml/cygwin/2006-12/msg00366.html


It works this way:
    cygport cvs-1.11.22-1 custom0-cvs_check_local_known_fail
will invoke cvs_check_local_known_fail() with no additional arguments.

However,
    cygport cvs-1.11.22-1 custom3-cvs_do_one_test rcslib remote fail
will invoke cvs_do_one_test() with $1=rcslib $2=remote $3=fail.

Note that the number following 'custom' indicates how many arguments to 
consume and forward to the target command.  Variants from 0 to 9 are 
accepted.


The custom-command framework will ONLY invoke shell functions; it can't 
be used to run arbitrary commands (although, you could simply edit the 
.cygport file to define a shell function which then runs those arbitrary 
commands).

The subcommand 'custom-show' will list all shell functions defined 
within the cygport runtime envionment, including those defined in the 
cygport file.
    cygport cvs-1.11.22-1 custom-show


As you can tell from my examples, I needed this functionality to deal 
with cvs's totally braindead testsuite "system".  (During development, 
that is.  Normal cygport usage for running the cvs testsuite would be 
'cygport cvs-1.11.22-1 check' as usual).

You can test the custom-command functionality (using any old cygport 
file) by doing:
    cygport some-cygport-file custom0-dummy
    cygport some-cygport-file custom1-dummy a
    cygport some-cygport-file custom2-dummy a b
etc -- or even
    cygport some-cygport-file \
        prep \
        custom2-dummy a b \
        compile \
        custom1-dummy c \
        install \
        custom4-dummy d e f g \
        pkg


2007-01-05  Charles Wilson  <...>

	* bin/cygport.in (custom_dummy_core): new function, used to test
	custom-command framework
	(custom_dummy): ditto
	(main): add implentation for custom-show) and customN-*)

-- 
Chuck

--------------040906080500030602080107
Content-Type: text/plain;
 name="cygport-custom-cmds.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="cygport-custom-cmds.patch"

Index: bin/cygport.in
===================================================================
RCS file: /cvsroot/cygwin-ports/cygport/bin/cygport.in,v
retrieving revision 1.45
diff -u -r1.45 cygport.in
--- bin/cygport.in	4 Jan 2007 02:35:26 -0000	1.45
+++ bin/cygport.in	6 Jan 2007 04:50:07 -0000
@@ -1644,11 +1644,38 @@
 
 ################################################################################
 #
+# test target for custom command hooks
+#
+################################################################################
+custom_dummy_core() {
+	local -i my_c=0
+	local -i my_argc=$#
+
+	while (( my_c < my_argc ))
+	do
+		my_c+=1
+		echo "${my_c}: $1"
+		shift
+	done
+}
+custom_dummy() {
+	inform "custom_dummy called with $# args"
+	custom_dummy_core "$@"
+}
+export -f custom_dummy_core custom_dummy
+readonly -f custom_dummy_core custom_dummy
+
+################################################################################
+#
 # End of functions
 #
 ################################################################################
 
 declare -i arg_n=2
+declare -i custom_arg_n
+declare -i custom_argc
+declare -a custom_args
+declare -x custom_cmd
 
 while (( arg_n < argc ))
 do
@@ -1721,6 +1748,46 @@
 			finish;
 			_status=$?;
 			;;
+		custom-show)
+			for fnc in $(set | sed -n '/()/s/()//p')
+			do
+				if test "$(type -t ${fnc})" == "function"
+				then
+					echo " ${fnc}"
+				fi
+			done
+			;;
+		custom0-* | custom1-* | custom2-* | custom3-* | custom4-* | \
+		custom5-* | custom6-* | custom7-* | custom8-* | custom9-* )
+			custom_argc=${argv[${arg_n}]:6:1}
+			custom_cmd=${argv[${arg_n}]:8}
+			if [ -z "${custom_cmd}" ]
+			then
+				error "${argv[${arg_n}]}* command has no target following the 'custom${custom_argc}-'"
+			fi
+
+			# consume arguments
+			custom_arg_n=0
+			while (( custom_arg_n < custom_argc )) && (( arg_n+1 < argc ))
+			do
+				arg_n+=1
+				custom_args[${custom_arg_n}]="${argv[${arg_n}]}"
+				custom_arg_n+=1
+			done
+			if (( custom_arg_n < custom_argc ))
+			then
+				error "custom${custom_argc} command ${custom_cmd}: not enough arguments"
+			fi
+			
+			if test "$(type -t ${custom_cmd})" == "function"
+			then
+				__stage ${custom_cmd} && eval "${custom_cmd} ${custom_args[@]}"
+				_status=$?;
+			else
+				error "${custom_cmd} is not a shell function"
+			fi
+			unset custom_args
+			;;
 		help)
 			__show_help;
 			exit 0;


--------------040906080500030602080107
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--------------040906080500030602080107--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019