Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,64 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

unit-tests-freebsd:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions:
- '82'
- '83'
- '84'
- '85'
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
with:
persist-credentials: false
- name: Test in FreeBSD
uses: vmactions/freebsd-vm@5a72679103d223925653750faa878a143340fbd0 #v1.5.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
envs: 'GITHUB_TOKEN'
usesh: true
prepare: |
pkg install -y \
php${{ matrix.php-versions }} \
php${{ matrix.php-versions }}-composer \
php${{ matrix.php-versions }}-ctype \
php${{ matrix.php-versions }}-curl \
php${{ matrix.php-versions }}-dom \
php${{ matrix.php-versions }}-filter \
php${{ matrix.php-versions }}-iconv \
php${{ matrix.php-versions }}-intl \
php${{ matrix.php-versions }}-mbstring \
php${{ matrix.php-versions }}-pcntl \
php${{ matrix.php-versions }}-phar \
php${{ matrix.php-versions }}-posix \
php${{ matrix.php-versions }}-session \
php${{ matrix.php-versions }}-simplexml \
php${{ matrix.php-versions }}-sodium \
php${{ matrix.php-versions }}-tokenizer \
php${{ matrix.php-versions }}-xml \
php${{ matrix.php-versions }}-xmlwriter \
php${{ matrix.php-versions }}-zip \
autoconf \
automake \
bash \
bison \
ca_root_nss \
gmake \
pkgconf \
re2c \
sudo \
git
run: |
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
composer config --global --auth github-oauth.github.com "$GITHUB_TOKEN"
composer install
vendor/bin/phpunit

bundled-php-extension-tests:
runs-on: ${{ matrix.operating-system }}
strategy:
Expand Down
3 changes: 2 additions & 1 deletion src/Building/UnixBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\Downloading\DownloadUrlMethod;
use Php\Pie\File\BinaryFile;
use Php\Pie\Platform\MakePath;
use Php\Pie\Platform\TargetPhp\PhpizePath;
use Php\Pie\Platform\TargetPlatform;
use Php\Pie\Util\Process;
Expand Down Expand Up @@ -198,7 +199,7 @@ private function make(
IOInterface $io,
callable|null $outputCallback,
): void {
$makeCommand = ['make'];
$makeCommand = [MakePath::guess()];

if ($targetPlatform->makeParallelJobs === 1) {
$io->write('Running make without parallelization - try providing -jN to PIE where N is the number of cores you have.');
Expand Down
3 changes: 2 additions & 1 deletion src/Installing/UnixInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Php\Pie\Downloading\DownloadUrlMethod;
use Php\Pie\File\BinaryFile;
use Php\Pie\File\Sudo;
use Php\Pie\Platform\MakePath;
use Php\Pie\Platform\TargetPlatform;
use Php\Pie\Util\Process;
use RuntimeException;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function __invoke(
break;

default:
$installCommands[] = ['make', 'install'];
$installCommands[] = [MakePath::guess(), 'install'];
}

// If the target directory isn't writable, or a .so file already exists and isn't writable, try to use sudo
Expand Down
67 changes: 67 additions & 0 deletions src/Platform/MakePath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace Php\Pie\Platform;

use Symfony\Component\Process\Process;

use function assert;
use function file_exists;
use function is_executable;
use function Safe\preg_match;
use function trim;

/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
final class MakePath
{
private static function looksLikeValidGnuMake(string $makePathToCheck): bool
{
if ($makePathToCheck === '') {
return false;
}

if (! file_exists($makePathToCheck) || ! is_executable($makePathToCheck)) {
return false;
}

$makeVersionProcess = new Process([$makePathToCheck, '--version']);
if ($makeVersionProcess->run() !== 0) {
return false;
}

return preg_match('/GNU Make/i', $makeVersionProcess->getOutput()) === 1;
}

/**
* PHP extension Makefiles (generated by phpize/configure) rely on GNU
* Make syntax. On some platforms (e.g. FreeBSD, NetBSD, OpenBSD), the
* `make` found on the PATH is the native BSD make, which cannot parse
* these Makefiles; GNU Make is available there as `gmake` instead.
*
* @return non-empty-string
*/
public static function guess(): string
{
foreach (['make', 'gmake'] as $candidate) {
// Note: depends on `which` existing, which doesn't always...
$which = new Process(['which', $candidate]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it could be that it inherits the current process verbosity, in which case if used in quiet mode for example you may not have an output there when you would expect to.

I vaguely remember that problem in Box and I'm about to fix some instances I noticed in Infection, but it's not clear 100% to me when it occurs so you may not be hit by this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theofidry is that specific to FreeBSD? or just in general? I've not observed this verbosity inheritance behaviour before... 🤔

if ($which->run() !== 0) {
continue;
}

$candidatePath = trim($which->getOutput());

if (! self::looksLikeValidGnuMake($candidatePath)) {
continue;
}

assert($candidatePath !== '');

return $candidatePath;
}

// Fall back to assuming/hoping make is on the path
return 'make';
}
}
1 change: 1 addition & 0 deletions test/integration/Command/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static function phpPathProvider(): array
'/usr/bin/php-config8.1',
'/usr/bin/php-config8.0',
'/usr/bin/php-config7.4',
'/usr/local/bin/php-config',
],
static fn (string $phpConfigPath) => file_exists($phpConfigPath)
&& is_executable($phpConfigPath),
Expand Down
1 change: 1 addition & 0 deletions test/integration/Installing/UnixInstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static function phpPathProvider(): array
'/usr/bin/php-config7.4',
'/usr/bin/php-config7.3',
'/usr/bin/php-config7.2',
'/usr/local/bin/php-config',
],
static fn (string $phpConfigPath) => file_exists($phpConfigPath)
&& is_executable($phpConfigPath),
Expand Down
23 changes: 23 additions & 0 deletions test/unit/Platform/MakePathTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Php\PieUnitTest\Platform;

use Composer\Util\Platform;
use Php\Pie\Platform\MakePath;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(MakePath::class)]
final class MakePathTest extends TestCase
{
public function testGuessingFindsMakePath(): void
{
if (Platform::isWindows()) {
self::markTestSkipped('Guessing make path is not done for Windows as we are not building for Windows.');
}

self::assertNotEmpty(MakePath::guess());
}
}
Loading