diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-30 16:24:31 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-30 16:41:10 +0900 |
| commit | dfd9e72b1786597db643d50c7a55d1fcbadf7802 (patch) | |
| tree | 0d01d8547e4ddc372931b3a07d2467a0a5847c61 /scripts/linters/src/Linters | |
| parent | 2f6689c3c1476c40a7c722491c1fcd5763e7d55f (diff) | |
| download | php-shirabe-dfd9e72b1786597db643d50c7a55d1fcbadf7802.tar.gz php-shirabe-dfd9e72b1786597db643d50c7a55d1fcbadf7802.tar.zst php-shirabe-dfd9e72b1786597db643d50c7a55d1fcbadf7802.zip | |
build(nix): add a package output producing the binary
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'scripts/linters/src/Linters')
| -rw-r--r-- | scripts/linters/src/Linters/ComposerPin.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/linters/src/Linters/ComposerPin.php b/scripts/linters/src/Linters/ComposerPin.php new file mode 100644 index 00000000..d1db55fe --- /dev/null +++ b/scripts/linters/src/Linters/ComposerPin.php @@ -0,0 +1,63 @@ +<?php + +declare(strict_types=1); + +namespace Shirabe\Lint\Linters; + +use Shirabe\Lint\Linter; + +/** + * The Composer sources are pinned twice: as the `composer` submodule, which a `cargo` build reads, + * and as the `composer` flake input, which a `nix build` reads in its place because a flake source + * carries no submodule. Both have to name the same commit, or the two builds embed different + * Composer runtimes. + */ +final class ComposerPin implements Linter +{ + public function name(): string + { + return 'composer_pin'; + } + + public function failureIntro(): string + { + return "The `composer` submodule and the `composer` flake input name different commits.\n" + . 'Point the input at the submodule commit and run `nix flake lock`:'; + } + + public function check(string $rootDir, array $excludes): array + { + $submoduleRev = $this->submoduleRev($rootDir); + $inputRev = $this->inputRev($rootDir); + + if ($submoduleRev === $inputRev) { + return []; + } + + return [ + "submodule: {$submoduleRev}", + "flake input: {$inputRev}", + ]; + } + + private function submoduleRev(string $rootDir): string + { + $command = sprintf('git -C %s ls-tree HEAD composer', escapeshellarg($rootDir)); + exec($command, $output, $status); + if ($status !== 0 || $output === []) { + return '(unreadable: git ls-tree HEAD composer failed)'; + } + + // `<mode> commit <rev>\tcomposer` + $fields = preg_split('/\s+/', $output[0]); + + return $fields[2] ?? '(unreadable: unexpected git ls-tree output)'; + } + + private function inputRev(string $rootDir): string + { + $lock = json_decode((string) file_get_contents("{$rootDir}/flake.lock"), true); + + return $lock['nodes']['composer']['locked']['rev'] ?? '(missing from flake.lock)'; + } +} |
