はじめに
cweagans/composer-patchesを使って依存関係にパッチを当てるとき、何故かMacOSだと失敗してしまいます。
数十秒フリーズしたのち、エラーが流れます。
composer i
....
- Applying patches for composer/ca-bundle
patches/cloudflare-ca.patch (0)
- Applying patches for hoa/exception
patches/Idle.patch (0)
- Applying patches for hoa/consistency
patches/Consistency.patch (0)
- Applying patches for hoa/protocol
patches/Node.patch (0)
Could not apply patch! Skipping. The error was: The process "patch '-p1' --no-backup-if-mismatch -d '/Users/xxxx/src/github.com/malsuke/phpstan-src/vendor/hoa/protocol' < '/Users/xxxx/src/github.com/malsuke/phpstan-src/patches/Node.patch'" exceeded the timeout of 300 seconds.
In Patches.php line 331:
Cannot apply patch 0 (patches/Node.patch)!
理由
これはMacOSに搭載されているpatchコマンドがBSD系統のものであるからです。
composer-patchesはGNU系統のpatchコマンドを基本として作られている(?)ようなので、通常のMacOSで実行するとオプション周りが合わないために失敗します。
解決方法
GNU系統のpatchコマンドでデフォルトで入っているpatchコマンドを上書きします。
# brewでgpatchをインストール brew install gpatch # シンボリックリンクを貼って置き換える sudo ln -sf $(which gpatch) /usr/local/bin/patch
再度composer iを実行すると、うまくいきました
$ composer i Gathering patches for root package. Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Nothing to install, update or remove Package hoa/compiler is abandoned, you should avoid using it. No replacement was suggested. Package hoa/consistency is abandoned, you should avoid using it. No replacement was suggested. Package hoa/event is abandoned, you should avoid using it. No replacement was suggested. Package hoa/exception is abandoned, you should avoid using it. No replacement was suggested. Package hoa/file is abandoned, you should avoid using it. No replacement was suggested. Package hoa/iterator is abandoned, you should avoid using it. No replacement was suggested. Package hoa/math is abandoned, you should avoid using it. No replacement was suggested. Package hoa/protocol is abandoned, you should avoid using it. No replacement was suggested. Package hoa/regex is abandoned, you should avoid using it. No replacement was suggested. Package hoa/stream is abandoned, you should avoid using it. No replacement was suggested. Package hoa/ustring is abandoned, you should avoid using it. No replacement was suggested. Package hoa/visitor is abandoned, you should avoid using it. No replacement was suggested. Package hoa/zformat is abandoned, you should avoid using it. No replacement was suggested. Generating autoload files 54 packages you are using are looking for funding. Use the `composer fund` command to find out more!