silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
720 stars 820 forks source link

FIX Ensure 'which' command detection across Linux distributions #11218

Closed minimalic closed 1 month ago

minimalic commented 1 month ago

Description

This pull request addresses an issue with the which command detection in the sake script, which failed to accurately detect the presence of the which command across different operating systems. The previous implementation using command -v which functioned properly on Ubuntu-like distributions but not on others like Rocky Linux/RHEL or Fedora, where it sometimes returned only a command name or a function instead of the full path to the executable.

To ensure broader compatibility, especially with non-Debian-based Linux distributions, this fix modifies the command detection logic to use type -P which.

Manual testing steps

On Linux inside Silverstripe project, run vendor/bin/sake dev/build and verify that it executes without the "which command" error.

Issues

Pull request checklist

minimalic commented 1 month ago

Yes, I thought the same on my first try on macOS, but I noticed the type command behaves differently in zsh (current default on macOS).

If you try it with bash (default environment in the sake script) you will notice that type -P which behaves the same across Unix-Like Systems.

You can test it with a simple script (don't forget to make this script itself executable with chmod u+x script.sh):

#!/usr/bin/env bash

[ -x "$(command -v which)" ] && echo "executable" || echo "no"
[ -x "$(type -P which)" ] && echo "executable" || echo "no"

I've tested it on latest macOS, Ubuntu, Rocky Linux/RHEL, Fedora. The second command worked on all systems, while the first (actual sake method) did not.

The problem with command -v which is the output of an "Alias" instead of direct path on some systems - so the check for executability fails. The type -P which method should be most compatible alternative - as long as sake uses bash shell environment.

GuySartorelli commented 1 month ago

Closed in favour of https://github.com/silverstripe/silverstripe-framework/pull/11232