diff --git a/README.md b/README.md index ec4a61c..78934db 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,11 @@ Suppose your PHP package `foo/bar` relies on an external archive file (`examplel "extra": { "downloads": { "examplelib": { - "url": "https://example.com/examplelib-{$version}-{$os}-{$architecture}.{$extension}", + "url": "https://example.com/examplelib-{$version}-{$os}-{$architecture}${$musl}.{$extension}", "path": "extern/{$id}", "version": "1.1.0", "variables": { + "{$musl}": "PHP_OS === 'Linux' && musl() === true ? '-musl' : ''", "{$os}": "strtolower(PHP_OS_FAMILY)", "{$architecture}": "strtolower(php_uname('m'))", "{$extension}": "PHP_OS_FAMILY === 'Windows' ? 'zip' : 'tar.gz'", @@ -108,6 +109,7 @@ Custom variable support these methods: * `str_starts_with` * `str_ends_with` * `matches` +* `musl` #### Constants diff --git a/src/Attribute/Validator/VariablesValidator.php b/src/Attribute/Validator/VariablesValidator.php index 224c762..e6265a5 100644 --- a/src/Attribute/Validator/VariablesValidator.php +++ b/src/Attribute/Validator/VariablesValidator.php @@ -5,6 +5,7 @@ use Composer\Package\PackageInterface; use LastCall\DownloadsPlugin\Attribute\AttributeManagerInterface; use LastCall\DownloadsPlugin\Enum\Attribute; +use LastCall\DownloadsPlugin\Helper\MuslDetector; use Le\SMPLang\Exception; use Le\SMPLang\SMPLang; @@ -27,6 +28,7 @@ public function __construct( 'str_contains' => str_contains(...), 'str_starts_with' => str_starts_with(...), 'str_ends_with' => str_ends_with(...), + 'musl' => new MuslDetector(), 'matches' => fn (string $pattern, string $subject) => 1 === preg_match($pattern, $subject), 'PHP_OS' => \PHP_OS, 'PHP_OS_FAMILY' => \PHP_OS_FAMILY, diff --git a/src/Helper/MuslDetector.php b/src/Helper/MuslDetector.php new file mode 100644 index 0000000..7242b9f --- /dev/null +++ b/src/Helper/MuslDetector.php @@ -0,0 +1,17 @@ +&1', $output, $returnCode); + if (0 !== $returnCode) { + return false; + } + $ldd = trim(implode("\n", $output)); + + return str_contains($ldd, 'musl'); + } +} diff --git a/tests/Unit/Helper/MuslDetectorTest.php b/tests/Unit/Helper/MuslDetectorTest.php new file mode 100644 index 0000000..6d572de --- /dev/null +++ b/tests/Unit/Helper/MuslDetectorTest.php @@ -0,0 +1,16 @@ +assertFalse($detector()); + } +}