[pacman-dev] [PATCH] makepkg : switch from getopt to getopts builtin
From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry
Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin
getopt is an external script for parsing and is less portable than getopts
which is a bash builtin.
The main problem is that it only supports short opts, so long opts had to be
dropped.
The benefits are a much better portability and a simpler code for the
arguments parsing.
TODO: better testing, fix man page.
Signed-off-by: Xavier Chantry
On Mon 2008-06-02 11:54, Xavier wrote:
From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry
Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin getopt is an external script for parsing and is less portable than getopts which is a bash builtin. The main problem is that it only supports short opts, so long opts had to be dropped. The benefits are a much better portability and a simpler code for the arguments parsing.
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it. Bear in mind I don't have a strong opinion about that, I was just playing devil's advocate :) -- Alessio (molok) Bolognino Please send personal email to themolok@gmail.com Public Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xFE0270FB GPG Key ID = 1024D / FE0270FB 2007-04-11 Key Fingerprint = 9AF8 9011 F271 450D 59CF 2D7D 96C9 8F2A FE02 70FB
Alessio Bolognino wrote:
On Mon 2008-06-02 11:54, Xavier wrote:
From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry
Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin getopt is an external script for parsing and is less portable than getopts which is a bash builtin. The main problem is that it only supports short opts, so long opts had to be dropped. The benefits are a much better portability and a simpler code for the arguments parsing.
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it.
Wasn't the whole point of this that getopt didn't work properly/as expected on BSD?
Bear in mind I don't have a strong opinion about that, I was just playing devil's advocate :)
Well, I am not a fan! Has anybody looked into parsing options manually? I seem to recall Xavier point out a bash implementation that could be used. makepkg does not have anything too complex (options take one arg max) so it should be fairly easy. I'd much prefer a parse_options function to be added than to lose all the long options. However, if that proves too complex a solution, I will graciously accept defeat... Allan
On Mon, Jun 2, 2008 at 11:15 AM, Allan McRae
Alessio Bolognino wrote:
On Mon 2008-06-02 11:54, Xavier wrote:
From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry
Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin getopt is an external script for parsing and is less portable than getopts which is a bash builtin. The main problem is that it only supports short opts, so long opts had to be dropped. The benefits are a much better portability and a simpler code for the arguments parsing.
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it.
Wasn't the whole point of this that getopt didn't work properly/as expected on BSD?
Bear in mind I don't have a strong opinion about that, I was just playing devil's advocate :)
Well, I am not a fan! Has anybody looked into parsing options manually? I seem to recall Xavier point out a bash implementation that could be used. makepkg does not have anything too complex (options take one arg max) so it should be fairly easy. I'd much prefer a parse_options function to be added than to lose all the long options. However, if that proves too complex a solution, I will graciously accept defeat...
I won't graciously accept it! :) I'd much rather keep longopts, so I think a parse_options() function that uses getopts in combo with some manual longopt parsing is our best bet. -Dan
On Mon, Jun 2, 2008 at 6:29 PM, Dan McGee
I won't graciously accept it! :)
I'd much rather keep longopts, so I think a parse_options() function that uses getopts in combo with some manual longopt parsing is our best bet.
Ok so let's just revert to the old way: http://www.archlinux.org/pipermail/pacman-dev/2008-May/011858.html You can see the loop was approximately twice longer because longopts and shortopts are handled separately, but it might be the best compromise.
2008/6/3 Xavier
On Mon, Jun 2, 2008 at 6:29 PM, Dan McGee
wrote: I won't graciously accept it! :)
I'd much rather keep longopts, so I think a parse_options() function that uses getopts in combo with some manual longopt parsing is our best bet.
Ok so let's just revert to the old way: http://www.archlinux.org/pipermail/pacman-dev/2008-May/011858.html
You can see the loop was approximately twice longer because longopts and shortopts are handled separately, but it might be the best compromise.
Sounds reasonable. -- Roman Kyrylych (Роман Кирилич)
On Mon, Jun 2, 2008 at 5:11 PM, Alessio Bolognino
Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it.
The reason of that patch is that the different getopt implementations are not compatible : http://www.archlinux.org/pipermail/pacman-dev/2008-May/011857.html The arguments parsing currently does not work on osx / bsd.
On Tue 2008-06-03 10:45, Xavier wrote:
On Mon, Jun 2, 2008 at 5:11 PM, Alessio Bolognino
wrote: Maybe dropping all long options is not a great idea: makepkg has a lot of options and find an alphanumeric character for each is not that easy/intuitive; Furthermore getopt is ported virtually everywhere: Mac OS X, FreeBSD, OpenBSD, NetBSD etc. and stuff like asciidoc depends upon it.
The reason of that patch is that the different getopt implementations are not compatible : http://www.archlinux.org/pipermail/pacman-dev/2008-May/011857.html The arguments parsing currently does not work on osx / bsd.
Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt". -- Alessio (molok) Bolognino Please send personal email to themolok@gmail.com Public Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xFE0270FB GPG Key ID = 1024D / FE0270FB 2007-04-11 Key Fingerprint = 9AF8 9011 F271 450D 59CF 2D7D 96C9 8F2A FE02 70FB
On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino
Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt".
Now I am confused. Do they all include a getopt in their base system, for example as /bin/getopt , and then external getopt which install as /usr/bin/getopt or something? The binary name is getopt on all except on openbsd where it is gnugetopt? Or were you just talking about the package / port name? In any cases, this is very interesting, are you able to check it to be sure it works? Or anyone else?
On Tue, Jun 3, 2008 at 9:57 AM, Xavier
On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino
wrote: Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt".
Now I am confused. Do they all include a getopt in their base system, for example as /bin/getopt , and then external getopt which install as /usr/bin/getopt or something? The binary name is getopt on all except on openbsd where it is gnugetopt? Or were you just talking about the package / port name?
In any cases, this is very interesting, are you able to check it to be sure it works? Or anyone else?
Yeah, I'm confused as well, wow. I didn't know it was this complex of a situation. I would love to see the following: 1. Where does getopt definitely work and definitely not work "out of the box"? 2. Where is (GNU) getopt available if it is installed? At first I was convinced we shouldn't use it, but now not so much. -Dan
On Tue 2008-06-03 10:22, Dan McGee wrote:
On Tue, Jun 3, 2008 at 9:57 AM, Xavier
wrote: On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino
wrote: Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt".
Now I am confused. Do they all include a getopt in their base system, for example as /bin/getopt , and then external getopt which install as /usr/bin/getopt or something? The binary name is getopt on all except on openbsd where it is gnugetopt? Or were you just talking about the package / port name?
In any cases, this is very interesting, are you able to check it to be sure it works? Or anyone else?
Yeah, I'm confused as well, wow. I didn't know it was this complex of a situation.
I would love to see the following: 1. Where does getopt definitely work and definitely not work "out of the box"?
By default GNU getopt is not installed on BSDs.
2. Where is (GNU) getopt available if it is installed?
In Mac OS X is /opt/local/bin/getopt , in OpenBSD is /usr/local/bin/gnugetopt , in FreeBSD probably is /usr/local/bin/getopt , in NetBSD is $somewhere/getopt
At first I was convinced we shouldn't use it, but now not so much.
I don't know if this is acceptable, but we could use a function in makepkg to find the *right* getopt, something like: ------------8<-------------------8<-------------------8<--------------- getopt="" for x in `echo $PATH | sed s@:@\ @g`; do for y in getopt gnugetopt; do if [[ -x $x/$y ]]; then $x/$y --version 2>&1 | grep getopt &>/dev/null if [[ $? == 0 ]] && [[ -z $getopt ]]; then getopt=$x/$y fi fi done done echo $getopt ----------->8------------------->8------------------->8---------------- (It works because GNU getopt prints "getopt (enhanced) 1.1.4" and BSD getopt prints "--") Yeah, it's ugly. -- Alessio (molok) Bolognino Please send personal email to themolok@gmail.com Public Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xFE0270FB GPG Key ID = 1024D / FE0270FB 2007-04-11 Key Fingerprint = 9AF8 9011 F271 450D 59CF 2D7D 96C9 8F2A FE02 70FB
On Tue, Jun 3, 2008 at 12:31 PM, Alessio Bolognino
On Tue 2008-06-03 10:22, Dan McGee wrote:
On Tue, Jun 3, 2008 at 9:57 AM, Xavier
wrote: On Tue, Jun 3, 2008 at 4:32 PM, Alessio Bolognino
wrote: Actually FreeBSD and NetBSD have in their port tree "getopt", which is this one: http://software.frodo.looijaard.name/getopt/ as you can see, is the same getopt in util-linux; in OpenBSD's tree is called gnugetopt, but it's still the same software. In Mac OS X it can be installed with macports, and it's called "getopt".
Now I am confused. Do they all include a getopt in their base system, for example as /bin/getopt , and then external getopt which install as /usr/bin/getopt or something? The binary name is getopt on all except on openbsd where it is gnugetopt? Or were you just talking about the package / port name?
In any cases, this is very interesting, are you able to check it to be sure it works? Or anyone else?
Yeah, I'm confused as well, wow. I didn't know it was this complex of a situation.
I would love to see the following: 1. Where does getopt definitely work and definitely not work "out of the box"?
By default GNU getopt is not installed on BSDs.
2. Where is (GNU) getopt available if it is installed?
In Mac OS X is /opt/local/bin/getopt , in OpenBSD is /usr/local/bin/gnugetopt , in FreeBSD probably is /usr/local/bin/getopt , in NetBSD is $somewhere/getopt
At first I was convinced we shouldn't use it, but now not so much.
I don't know if this is acceptable, but we could use a function in makepkg to find the *right* getopt, something like:
------------8<-------------------8<-------------------8<--------------- getopt="" for x in `echo $PATH | sed s@:@\ @g`; do for y in getopt gnugetopt; do if [[ -x $x/$y ]]; then $x/$y --version 2>&1 | grep getopt &>/dev/null if [[ $? == 0 ]] && [[ -z $getopt ]]; then getopt=$x/$y fi fi done done echo $getopt ----------->8------------------->8------------------->8----------------
(It works because GNU getopt prints "getopt (enhanced) 1.1.4" and BSD getopt prints "--")
Yeah, it's ugly.
getopt -T looks like the winner for deciding whether we have a valid getopt version installed. That doesn't solve the parsing issues though. -Dan
Dan McGee wrote:
getopt -T looks like the winner for deciding whether we have a valid getopt version installed. That doesn't solve the parsing issues though.
I am confused. which parsing issues?
Ping. Was there any decision made about this? If the getopts on the different platforms are compatible, there wouldn't be any parsing issues, would there?
On Wed, Jul 9, 2008 at 11:02 AM, Sebastian Nowicki
Ping.
Was there any decision made about this? If the getopts on the different platforms are compatible, there wouldn't be any parsing issues, would there?
I don't think so, that was the whole purpose of checking for gnu getopt. I don't even know which parsing issues Dan was talking about, parsing issues when using getopt for parsing arguments, or parsing issues inside the "gnu getopt detection" of Alessio or something else.
I just installed GNU getopt manually (not using macports) to /usr/ local on Mac OS X Leopard, and it seems to work fine. The only "problem" is that you have to modify PATH so that /usr/local is before /usr/bin so that the right one gets used. The "gnu getopt finder" code that Alessio would solve the problem (if it works properly). I haven't been able to test it on BSD yet.
participants (6)
-
Alessio Bolognino
-
Allan McRae
-
Dan McGee
-
Roman Kyrylych
-
Sebastian Nowicki
-
Xavier