1
0
mirror of https://github.com/php/pie.git synced 2026-03-23 23:12:17 +01:00

436: detect bsdlibc on OSX

This commit is contained in:
James Titcumb
2026-01-16 16:52:43 +00:00
parent 97cd6c9def
commit 53c4c570af
4 changed files with 31 additions and 1 deletions

View File

@@ -252,7 +252,7 @@ string may be used.
* `{Version}` the version of your extension, e.g. `1.20.1`
* `{Arch}` the architecture of the binary, one of `x86`, `x86_64`, `arm64`
* `{OS}` the operating system, one of `windows`, `darwin`, `linux`, `bsd`, `solaris`, `unknown`
* `{Libc}` the libc flavour, one of `glibc`, `musl`
* `{Libc}` the libc flavour, one of `glibc`, `musl`, `bsdlibc`
* `{Debug}` the debug mode, one of `debug`, `nodebug` (or omitted)
* `{TSMode}` the thread safety mode, one of `zts`, `nts` (or omitted)
* `{Format}` the archive format, one of `zip`, `tgz`

View File

@@ -15,11 +15,17 @@ enum LibcFlavour: string
{
case Gnu = 'glibc';
case Musl = 'musl';
case Bsd = 'bsdlibc';
public static function detect(): self
{
$executableFinder = new ExecutableFinder();
$otool = $executableFinder->find('otool');
if ($otool !== null) {
return self::Bsd;
}
$lddPath = $executableFinder->find('ldd');
$lsPath = $executableFinder->find('ls');

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
echo "/bin/ls:
/usr/lib/libutil.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)"

View File

@@ -20,6 +20,7 @@ final class LibcFlavourTest extends TestCase
{
private const GLIBC_PATH = __DIR__ . '/../../assets/fake-ldd/glibc';
private const MUSL_PATH = __DIR__ . '/../../assets/fake-ldd/musl';
private const BSD_PATH = __DIR__ . '/../../assets/fake-ldd/bsdlibc';
#[RequiresOperatingSystemFamily('Linux')]
public function testGlibcFlavourIsDetected(): void
@@ -42,4 +43,21 @@ final class LibcFlavourTest extends TestCase
putenv('PATH=' . $oldPath);
}
#[RequiresOperatingSystemFamily('Linux')]
public function testBsdlibcFlavourIsDetected(): void
{
$oldPath = getenv('PATH');
putenv('PATH=' . realpath(self::BSD_PATH) . PATH_SEPARATOR . $oldPath);
self::assertSame(LibcFlavour::Bsd, LibcFlavour::detect());
putenv('PATH=' . $oldPath);
}
#[RequiresOperatingSystemFamily('Darwin')]
public function testBsdlibcFlavourIsDetectedOnRealOsx(): void
{
self::assertSame(LibcFlavour::Bsd, LibcFlavour::detect());
}
}