ごらくらいふ

プログラミングしたりゲームしたり

DeployGateのコマンドラインツールから Commands::Deploy Error: NoMethodError と怒られる件

環境

  • ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
  • deploygate-cli v0.6.4
  • Xcode 9.4.1

現象

dg deployを実行すると、適切にBundle Identifierを指定しているにも関わらず、Bundle Identifierの入力を求められたのち、 下記のエラーが発生する。

Status
deploygate-cli ver 0.6.4

Error message
undefined method `build_configuration_list' for nil:NilClass

Backtrace
/path/to/gemroot/gems/deploygate-0.6.4/lib/deploygate/xcode/analyze.rb:145:in `target_build_configration'
/path/to/gemroot/gems/deploygate-0.6.4/lib/deploygate/xcode/analyze.rb:91:in `target_xcode_setting_provisioning_profile_uuid'
/path/to/gemroot/gems/deploygate-0.6.4/lib/deploygate/commands/deploy/build.rb:50:in `ios'
/path/to/gemroot/gems/deploygate-0.6.4/lib/deploygate/commands/deploy/build.rb:22:in `run'
/path/to/gemroot/gems/deploygate-0.6.4/lib/deploygate/commands/deploy.rb:16:in `run'
/path/to/gemroot/gems/deploygate-0.6.4/lib/deploygate/command_builder.rb:70:in `block (2 levels) in run'
/path/to/gemroot/gems/commander-4.4.5/lib/commander/command.rb:182:in `call'
/path/to/gemroot/gems/commander-4.4.5/lib/commander/command.rb:153:in `run'
/path/to/gemroot/gems/commander-4.4.5/lib/commander/runner.rb:446:in `run_active_command'
/path/to/gemroot/gems/fastlane-2.57.2/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:64:in `run!'
/path/to/gemroot/gems/commander-4.4.5/lib/commander/delegates.rb:15:in `run!'
/path/to/gemroot/gems/deploygate-0.6.4/lib/deploygate/command_builder.rb:128:in `run'
/path/to/gemroot/gems/deploygate-0.6.4/bin/dg:6:in `<top (required)>'
/path/to/gemroot/bin/dg:23:in `load'
/path/to/gemroot/bin/dg:23:in `<main>'
/path/to/gemroot/bin/ruby_executable_hooks:15:in `eval'
/path/to/gemroot/bin/ruby_executable_hooks:15:in `<main>'

解消方法

Xcodeのメニューバーから、[Product]> [Scheme]> [Manage Schemes ...] を開き、閉じる。

原因

  • lib/deploygate/xcode/analyze.rbが必要とする、*.xcschemeが存在しないため

調査記録

なんだか業務issue感さえ漂うので、何を調べたのか書き残す。余談。

Backtraceいわく、target_build_configrationの処理中に問題が発生したことがわかる。

def target_build_configration
  target_project_setting.build_configuration_list.build_configurations.reject{|conf| conf.name != @build_configuration}.first
end

https://github.com/DeployGate/deploygate-cli/blob/v0.6.4/lib/deploygate/xcode/analyze.rb#L145

undefined method 'build_configuration_list' for nil:NilClassということから、target_project_settingの結果がnilであることが直接の問題であるとわかる。

def target_project_setting
  scheme_file = find_xcschemes
  xs = Xcodeproj::XCScheme.new(scheme_file)
  target_name = xs.profile_action.buildable_product_runnable.buildable_reference.target_name


  target_project.native_targets.reject{|target| target.name != target_name}.first
end

https://github.com/DeployGate/deploygate-cli/blob/v0.6.4/lib/deploygate/xcode/analyze.rb#L153-L155

ではtarget_project_settingの中身で何が起きているのか確認するため、scheme_file, xs, target_nameをprintしてみたところ、すべてnilであることが確認できた。

この時点で、まずfind_xcschemesが怪しいと直感を得た。(悪い癖)

native_targets.reject{|target| target.name != target_name}を見て、「ああ、target_nameがnilになっちゃって正しいtargetも捨てちゃってるんだな」という認識を挟むのが正しい怪しみ方だろう。

def find_xcschemes
  shared_schemes = Dir[File.join(@xcodeproj, 'xcshareddata', 'xcschemes', '*.xcscheme')].reject do |scheme|
    @scheme != File.basename(scheme, '.xcscheme')
  end
  user_schemes = Dir[File.join(@xcodeproj, 'xcuserdata', '*.xcuserdatad', 'xcschemes', '*.xcscheme')].reject do |scheme|
    @scheme != File.basename(scheme, '.xcscheme')
  end


  shared_schemes.concat(user_schemes).first
end

https://github.com/DeployGate/deploygate-cli/blob/v0.6.4/lib/deploygate/xcode/analyze.rb#L165-L170

で、find_xcschemesの中にあるshared_schemes, user_schemesもprintしてみればこっちもnilだと確認した。 というかブロックの中に入っていなかった。

File.joinで組んでいるパターンをターミナルからも確かめた結果、*.xcschemeが生成されていないことがわかった。 おそらくこれが原因だろうと、schemeを作る手段を求めて上記解消方法を試したところ、*.xcschemeが生成されたことを確認できた。

関連リンク

解消手順を報告させてもらったissue