platform :ios, '12.0'

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true

flutter_application_path = 'flutterapp/'
framework_dir = File.join(flutter_application_path, '.ios', 'Flutter')

engine_dir = File.join(framework_dir, 'engine')
if !File.exist?(engine_dir)
  # Copy the debug engine to have something to link against if the xcode backend script has not run yet.
  debug_framework_dir = File.join(flutter_root(flutter_application_path), 'bin', 'cache', 'artifacts', 'engine', 'ios')
  FileUtils.mkdir_p(engine_dir)
  FileUtils.cp_r(File.join(debug_framework_dir, 'Flutter.framework'), engine_dir)
  FileUtils.cp(File.join(debug_framework_dir, 'Flutter.podspec'), engine_dir)
end

target 'ios_add2app' do
  eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
end

target 'ios_add2appTests' do
  pod 'Flutter', :path => engine_dir
  inherit! :search_paths
  pod 'EarlGrey'
end
