ひだまりソケットは壊れない

ソフトウェア開発に関する話を書きます。 最近は主に Android アプリ、Windows アプリ (UWP アプリ)、Java 関係です。

まじめなことを書くつもりでやっています。 適当なことは 「一角獣は夜に啼く」 に書いています。

古い RubyGems と Bundler 2.1.1 の組み合わせでは bundle exec 環境下で bundler を見つけられない??

CircleCI の macOS ビルドコンテナで fastlane を使って iOS プロジェクトのビルドをしているのだが、以下のようなエラーが出るようになってしまった。 根本的な原因はわかってないけど、とりあえずメモとして残しておく。

bundle exec fastlane tests

[⠦] 🚀 bundler: failed to load command: fastlane (/Users/distiller/project/vendor/bundle/ruby/2.3.0/bin/fastlane)
LoadError: cannot load such file -- bundler
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane/plugins/plugin_manager.rb:5:in `require'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane/plugins/plugin_manager.rb:5:in `<class:PluginManager>'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane/plugins/plugin_manager.rb:4:in `<module:Fastlane>'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane/plugins/plugin_manager.rb:3:in `<top (required)>'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane/plugins/plugins.rb:9:in `require'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane/plugins/plugins.rb:9:in `<top (required)>'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane.rb:27:in `require'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane.rb:27:in `<top (required)>'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane/cli_tools_distributor.rb:41:in `require'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/fastlane/lib/fastlane/cli_tools_distributor.rb:41:in `take_off'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/gems/fastlane-2.128.1/bin/fastlane:23:in `<top (required)>'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/bin/fastlane:22:in `load'
  /Users/distiller/project/vendor/bundle/ruby/2.3.0/bin/fastlane:22:in `<top (required)>'

エラー詳細と状況

fastlane の中の require 'bundler' している箇所で 「LoadError: cannot load such file -- bundler」 というエラーが発生している。

このエラーが発生したのは Bundler のバージョン 2.1.1 を使用している時で、Bundler 2.0.2 を使用している時には問題は起こらなかった。 RubyRubyGems のバージョンは次の通り。

$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]

$ gem --version
2.5.2.3

調査

とりあえず Bundler のバージョンによって挙動が違うっぽいので Bundler のバージョンを変えながら挙動を確認してみた。

# 両方の Bundler をインストール
$ sudo gem install bundler -v 2.1.1
Fetching: bundler-2.1.1.gem (100%)
Successfully installed bundler-2.1.1
1 gem installed

$ sudo gem install bundler -v 2.0.2
Successfully installed bundler-2.0.2
1 gem installed

# Bundler 2.1.1 で require 'bundler' した場合はエラー
$ bundle _2.1.1_ exec irb
irb(main):001:0> require 'bundler'
LoadError: cannot load such file -- bundler
	from (irb):1:in `require'
	from (irb):1
	from /usr/bin/irb:11:in `<top (required)>'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:63:in `load'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:63:in `kernel_load'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:28:in `run'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:476:in `exec'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:30:in `dispatch'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:24:in `start'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/exe/bundle:46:in `block in <top (required)>'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
	from /Library/Ruby/Gems/2.3.0/gems/bundler-2.1.1/exe/bundle:34:in `<top (required)>'
	from /usr/local/bin/bundle:22:in `load'
	from /usr/local/bin/bundle:22:in `<main>'
irb(main):002:0> exit

# Bundler 2.0.2 だと問題なし
$ bundle _2.0.2_ exec irb
irb(main):001:0> require 'bundler'
=> false
irb(main):002:0> exit

RubyRubyGems のバージョンを上げると起こらない

ちなみに RubyRubyGems のバージョンを上げると、Bundler 2.1.1 を使ってもこの問題は起こらなかった。

$ ruby --version
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17]

$ gem --version
3.1.1

$ bundle exec irb 
irb(main):001:0> require 'bundler'
=> false

CircleCI の macOS ビルドコンテナだと chruby コマンドを使って Ruby の新しいバージョンを使えるっぽいので (Xcode 10.1 のコンテナで確認)、対応策としては新しいバージョンの Ruby を使うようにするのが良さそう。