Don't use conf-which for detecting if a depext CLI tool is installed
Hi!
I just noticed that some packages use conf-which to detect if a depext CLI tool is installed. However, that isn't portable on platforms where there's no which tool (e.g., Windows). For instance the package conf-git does a which git to detect the presence of git, but a simpler git --version could do just fine.
Useful suggestion by @UnixJunkie using command -v: https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script#677212
If we know that the program has a particular switch such as --version or --help and has a fast exit path when using that switch, I think it's better to use it instead of launching a shell just to test command -v, as it's a shell builtin.
We don't have a "meta" package conf-command, we're creating packages for each program we may need, so that's more-or-less doable.
I agree, I added the link here as reference for the future for the packages where we cannot do that
Apparently, svm-train -h has an exit code of 1, so I did not want to use it. I guess that the exit code must be 0 so that opam will consider the command was found and is working. Hence, I used command -v, a bash shell builtin, since it is judged less evil than which, according to experts.
On Sat, Oct 9, 2021 at 12:26 AM Marcello Seri @.***> wrote:
I agree, I added the link here as reference for the future for the packages where we cannot do that
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ocaml/opam-repository/issues/18452#issuecomment-938730593, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFUFAEB7ANUJ2PLPNVYQG3UF4ETNANCNFSM42OO5ZCQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Must be the Season of the Which! (Debian is deprecating the which command, and in general Windows doesn't have it either (nor an unix shell)).
If we know that the program has a particular switch such as --version or --help and has a fast exit path when using that switch, I think it's better to use it instead of launching a shell just to test command -v, as it's a shell builtin.
I've just noticed that for conf-pkg-config.2 we're doing
build: [
["pkg-config" "--help"] {os != "openbsd"}
["/usr/local/bin/pkgconf" "--help"] {os = "openbsd"}
]
but that generates some noisy output! (the help text). I don't think there's a nice way to silence this (because Windows wouldn't like > /dev/null, or how would we know what shell is used?) so we should prefer --version over --help to have less noise.