-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install older PHP versions via alternate tap
Fixes #1407 Homebrew's support policy now aggressively disables older versions earlier than it did previously. That is why we tap the `shivammathur/php` repository. But since Homebrew also now "keeps" those old formulae but marks them as disabled, when Valet runs `brew install [email protected]` it fails because Homebrew just aborts due to its flags in the outdated formula. (They mark it as "disabled" and/or "keg_only :versioned_formula", but don't actually delete the formula from their repository.) To override that we must use `brew install shivammathur/php/[email protected]` internally. Therefore, we need to maintain a list of which PHP Versions we wish to specifically prefix with the `shivammathur/php` tap in order to bypass Homebrew's flags. **ANNUAL MAINTENANCE** 1. This PR adds the array of `LIMITED_PHP_VERSIONS` which we will have to update annually when new PHP versions are retired as others are released. 2. We should also annually update the `LATEST_PHP_VERSION` string.
- Loading branch information
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
class Brew | ||
{ | ||
// This is the array of PHP versions that Valet will attempt to install/configure when requested | ||
const SUPPORTED_PHP_VERSIONS = [ | ||
'php', | ||
'[email protected]', | ||
|
@@ -19,9 +20,22 @@ class Brew | |
'[email protected]', | ||
]; | ||
|
||
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1'; | ||
// Update this LATEST and the following LIMITED array when PHP versions are released or retired | ||
// We specify a numbered version here even though Homebrew links its generic 'php' alias to it | ||
const LATEST_PHP_VERSION = '[email protected]'; | ||
|
||
const LATEST_PHP_VERSION = '[email protected]'; | ||
// These are the PHP versions that should be installed via the shivammathur/php tap because | ||
// Homebrew officially no longer bottles them or they're marked disabled in their formula | ||
// Cue: Homebrew reports "[email protected] has been disabled because it is a versioned formula" | ||
const LIMITED_PHP_VERSIONS = [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
]; | ||
|
||
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1'; | ||
|
||
public function __construct(public CommandLine $cli, public Filesystem $files) | ||
{ | ||
|
@@ -72,6 +86,14 @@ public function supportedPhpVersions(): Collection | |
return collect(static::SUPPORTED_PHP_VERSIONS); | ||
} | ||
|
||
/** | ||
* Get a list of disabled/limited PHP versions. | ||
*/ | ||
public function limitedPhpVersions(): Collection | ||
{ | ||
return collect(static::LIMITED_PHP_VERSIONS); | ||
} | ||
|
||
/** | ||
* Get a list of installed PHP formulae. | ||
*/ | ||
|
@@ -135,7 +157,9 @@ public function installOrFail(string $formula, array $options = [], array $taps | |
} | ||
|
||
output('<info>['.$formula.'] is not installed, installing it now via Brew...</info> 🍻'); | ||
if ($formula !== 'php' && starts_with($formula, 'php') && preg_replace('/[^\d]/', '', $formula) < '73') { | ||
|
||
if ($this->limitedPhpVersions()->contains($formula)) { | ||
$formula = 'shivammathur/php/' . $formula; | ||
warning('Note: older PHP versions may take 10+ minutes to compile from source. Please wait ...'); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,6 +203,22 @@ public function test_linked_php_throws_exception_if_unsupported_php_version_is_l | |
resolve(Brew::class)->linkedPhp(); | ||
} | ||
|
||
public function test_outdated_php_versions_use_the_alternate_tap() | ||
{ | ||
$brewMock = Mockery::mock(Brew::class, [ | ||
$cli = Mockery::mock(CommandLine::class), | ||
Mockery::mock(Filesystem::class), | ||
])->makePartial(); | ||
|
||
$brewMock->shouldReceive('limitedPhpVersions')->andReturn(collect([ | ||
'[email protected]', | ||
])); | ||
|
||
$cli->shouldReceive('runAsUser')->once()->with(Brew::BREW_DISABLE_AUTO_CLEANUP.' brew install shivammathur/php/[email protected]', Mockery::type('Closure')); | ||
|
||
$brewMock->installOrFail('[email protected]'); | ||
} | ||
|
||
public function test_install_or_fail_will_install_brew_formulae() | ||
{ | ||
$cli = Mockery::mock(CommandLine::class); | ||
|