macOS に capybara-webkit をインストールする
Catalina に capybara-webkit をインストールしようとして手間取りました。
こちらを参考に解決しました。
Installing Qt and compiling capybara webkit · thoughtbot/capybara-webkit Wiki
capybara-webkit のビルドに必要な QtWebKit が Qt 5.6 で削除されてしまったため、 Qt 5.5 をインストールする必要があるのですが、brew のパッケージ qt@5.5 もすでに削除されているため、brew のリポジトリの過去の歴史を紐解いて qt@5.5 を無理やりインストールする、ていう荒業を使います。
Catalina, High Sierra, Sierra, El Capitan, Yosemite で同じ手順で出来るようです。 Mojave だけ手順が違うようですので、上記リンク先を参照下さい。
環境
$ uname -a Darwin MonBP.local 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64 $ brew -v Homebrew 2.2.2 Homebrew/homebrew-core (git revision 47102; last commit 2019-12-23) Homebrew/homebrew-cask (git revision 4f1da; last commit 2019-12-24)
手順
brew のリポジトリの qt@5.5 が削除される直前のコミットから Formula/qt@5.5.rb
というファイルをサルベージします。
$ brew update $ cd $( brew --prefix )/Homebrew/Library/Taps/homebrew/homebrew-core $ git checkout 9ba3d6ef8891e5c15dbdc9333f857b13711d4e97 Formula/qt@5.5.rb fatal: reference is not a tree: 9ba3d6ef8891e5c15dbdc9333f857b13711d4e97
fatal: reference is not a tree
というエラーが出たかもしれません。これは brew がリポジトリを shallow clone しているためです。git の全履歴を取得します。
$ git fetch --unshallow remote: Enumerating objects: 664813, done. remote: Counting objects: 100% (660680/660680), done. remote: Compressing objects: 100% (226471/226471), done. remote: Total 655516 (delta 431659), reused 650038 (delta 426185), pack-reused 0 Receiving objects: 100% (655516/655516), 261.95 MiB | 5.65 MiB/s, done. Resolving deltas: 100% (431659/431659), completed with 3945 local objects.
もう一度サルベージ実行。
$ git checkout 9ba3d6ef8891e5c15dbdc9333f857b13711d4e97 Formula/qt@5.5.rb Updated 1 path from 741af0285f
無事取得出来たようです。では qt@5.5
をインストールしてみます。
$ brew install qt@5.5 Error: qt@5.5: unknown version :mountain_lion
上記のようなエラーが出て失敗した場合は、サルベージした Formula/qt@5.5.rb
の25行目をコメントアウトします。
$ vi Formula/qt@5.5.rb # OS X 10.7 Lion is still supported in Qt 5.5, but is no longer a reference # configuration and thus untested in practice. Builds on OS X 10.7 have been # reported to fail: <https://github.com/Homebrew/homebrew/issues/45284>. depends_on :macos => :mountain_lion ↓ # OS X 10.7 Lion is still supported in Qt 5.5, but is no longer a reference # configuration and thus untested in practice. Builds on OS X 10.7 have been # reported to fail: <https://github.com/Homebrew/homebrew/issues/45284>. #depends_on :macos => :mountain_lion # この行をコメントアウト
再度インストール。
$ brew install qt@5.5 Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/cask). No changes to formulae. ==> Downloading https://homebrew.bintray.com/bottles/qt@5.5-5.5.1_1.high_sierra.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/30/30c5a19c4c18737d40ab072d27a1b5220e746eb7a549812ceb1799eb07cfd58f?__gd ######################################################################## 100.0% ==> Pouring qt@5.5-5.5.1_1.high_sierra.bottle.tar.gz ==> Caveats We agreed to the Qt opensource license for you. If this is unacceptable you should uninstall. qt@5.5 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula. If you need to have qt@5.5 first in your PATH run: echo 'export PATH="/usr/local/opt/qt@5.5/bin:$PATH"' >> ~/.zshrc For compilers to find qt@5.5 you may need to set: export LDFLAGS="-L/usr/local/opt/qt@5.5/lib" export CPPFLAGS="-I/usr/local/opt/qt@5.5/include" For pkg-config to find qt@5.5 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/qt@5.5/lib/pkgconfig" ==> Summary 🍺 /usr/local/Cellar/qt@5.5/5.5.1_1: 7,330 files, 329.7MB
インストール出来ました。
qt@5.5 は keg オンリーパッケージなので、パッケージ中の qmake などのファイルが /usr/local
以下にリンクされておらずそのままでは使えません。強制的にリンクします。
brew link --force qt@5.5
リンクされてるかどうかチェックします。
$ which qmake /usr/local/bin/qmake $ ls -l /usr/local/bin/qmake lrwxr-xr-x 1 monmon admin 34 12 24 15:56 /usr/local/bin/qmake -> ../Cellar/qt@5.5/5.5.1_1/bin/qmake
サルベージしたファイルは削除しちゃいましょう。
$ git reset Formula/qt@5.5.rb $ rm Formula/qt@5.5.rb
これで capybara-webkit がインストール出来るはずです。
$ bundle install -j4 --without production --path vendor/bundle (略) Installing capybara-webkit 1.15.1 with native extensions Bundle complete! 72 Gemfile dependencies, 185 gems now installed. Gems in the group production were not installed. Bundled gems are installed into `./vendor/bundle`
やったね。