Opened 5 years ago

Closed 4 years ago

#60051 closed defect (fixed)

gildas @202002a: sort: invalid option -- V

Reported by: ryandesign (Ryan Carsten Schmidt) Owned by: bardeau
Priority: Normal Milestone:
Component: ports Version: 2.6.2
Keywords: Cc:
Port: gildas

Description

https://build.macports.org/builders/ports-10.8_x86_64-builder/builds/15383/steps/install-port/logs/stdio

The first thing printed in the build phase is:

sort: invalid option -- V
Try `sort --help' for more information.
sort: invalid option -- V
Try `sort --help' for more information.
sort: invalid option -- V
Try `sort --help' for more information.
sort: invalid option -- V
Try `sort --help' for more information.

Change History (6)

comment:1 Changed 5 years ago by bardeau

This comes from an attempt to create a shell utility which is able to indicate if a program version is lower than some reference version. Namely:

    verle() {
        # Return 0 if first argument is "lower or equal" the second argument
        # NB: the line return in echo below is more portable than echo -e "\n"
        [  "$1" = "`echo "$1
$2" | sort -V | head -n1`" ]
    }
    verlt() {
        # Return 0 if first argument is "lower than" second argument
        [ "$1" = "$2" ] && return 1 || verle $1 $2
    }

used as e.g. with some plain numbers:

if verlt "4.8.0" "4.7.0"; then
...

In the past we used the syntax

if [ "4.8.0" "<" "4.7.0" ]; then

"<" provides lexicographical comparison, which is valid up to versions 9.9.9. Unfortunately, zsh does not behave correctly with the later syntax. Note that zsh is now the default user shell under macOS. Choice has been made to use the functions shown on top, which make use of "sort -V" (sort by version number). My tests have shown a good support on a variety of OS, including Catalina 10.15.2, but it seems it is not as portable as I expected.

Last but not least, I need a syntax compatible with bash, dash, and zsh. For the time being I have no good solution.

Last edited 5 years ago by bardeau (previous) (diff)

comment:2 Changed 4 years ago by ryandesign (Ryan Carsten Schmidt)

macOS sort has a -V option on High Sierra and newer but not on El Capitan and older. I didn't test Sierra. I'm told busybox's sort also doesn't have -V. So it's not portable to use that.

If you don't care about portability, you can add a dependency on port:coreutils and use ${prefix}/bin/gsort instead of sort. It does support -V.

There are many other potential solutions to this problem of varying portability and correctness. I haven't tried them myself but maybe you'll see a method in there that you like.

comment:3 in reply to:  2 ; Changed 4 years ago by bardeau

Replying to ryandesign:

If you don't care about portability, you can add a dependency on port:coreutils and use ${prefix}/bin/gsort instead of sort. It does support -V.

What is the proper way to to invoke gsort from my shell script? Is ${prefix} supposed to be a valid environment variable? It does not seem:

/opt/local/var/macports/build/_opt_local_var_macports_sources_github.com_macports_macports-ports_science_gildas/gildas/work/gildas-src-jun20b/admin/define-system.sh: line 28: /bin/gsort: No such file or directory

Isn't there a configure.* keyword I could use for reinplacement?

There are many other potential solutions to this problem of varying portability and correctness. I haven't tried them myself but maybe you'll see a method in there that you like.

I precisely used one of the method proposed on this page (verle-verlt). A lot of methods contain bashisms which are not portable (in particular to dash or zsh). The verlt-verle is the softest solution I could find, at the cost of depending on a sort -V implementation.

comment:4 in reply to:  3 Changed 4 years ago by ryandesign (Ryan Carsten Schmidt)

Replying to bardeau:

Replying to ryandesign:

If you don't care about portability, you can add a dependency on port:coreutils and use ${prefix}/bin/gsort instead of sort. It does support -V.

What is the proper way to to invoke gsort from my shell script? Is ${prefix} supposed to be a valid environment variable? It does not seem:

/opt/local/var/macports/build/_opt_local_var_macports_sources_github.com_macports_macports-ports_science_gildas/gildas/work/gildas-src-jun20b/admin/define-system.sh: line 28: /bin/gsort: No such file or directory

Isn't there a configure.* keyword I could use for reinplacement?

prefix is a Tcl variable. If you need it outside of Tcl, for example in a source code file, you add a patchfile that puts a @PREFIX@ placeholder into the file in the right place, and then you replace the placeholder with the variable's value like this:

post-patch {
    reinplace -W ${worksrcpath} "s|@PREFIX@|${prefix}|g" somefile.sh someotherfile.sh
}

There are many other potential solutions to this problem of varying portability and correctness. I haven't tried them myself but maybe you'll see a method in there that you like.

I precisely used one of the method proposed on this page (verle-verlt). A lot of methods contain bashisms which are not portable (in particular to dash or zsh). The verlt-verle is the softest solution I could find, at the cost of depending on a sort -V implementation.

As I said, the proposals are of varying portability. :) sort -V isn't portable.

comment:5 Changed 4 years ago by bardeau

I have made a bug fix and a pull request to solve this issue.

comment:6 Changed 4 years ago by bardeau

Resolution: fixed
Status: assignedclosed

In 4ac1b00a24652290706e06c3267e09c3ffa79f91/macports-ports (master):

Gildas: fixed support for El Capitan and older.

Closes: #60051
Closes: #60639

Note: See TracTickets for help on using tickets.