|
| 1 | +platform :osx, '10.11' |
| 2 | + |
| 3 | +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. |
| 4 | +ENV['COCOAPODS_DISABLE_STATS'] = 'true' |
| 5 | + |
| 6 | +project 'Runner', { |
| 7 | + 'Debug' => :debug, |
| 8 | + 'Profile' => :release, |
| 9 | + 'Release' => :release, |
| 10 | +} |
| 11 | + |
| 12 | +def parse_KV_file(file, separator='=') |
| 13 | + file_abs_path = File.expand_path(file) |
| 14 | + if !File.exists? file_abs_path |
| 15 | + return []; |
| 16 | + end |
| 17 | + pods_ary = [] |
| 18 | + skip_line_start_symbols = ["#", "/"] |
| 19 | + File.foreach(file_abs_path) { |line| |
| 20 | + next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } |
| 21 | + plugin = line.split(pattern=separator) |
| 22 | + if plugin.length == 2 |
| 23 | + podname = plugin[0].strip() |
| 24 | + path = plugin[1].strip() |
| 25 | + podpath = File.expand_path("#{path}", file_abs_path) |
| 26 | + pods_ary.push({:name => podname, :path => podpath}); |
| 27 | + else |
| 28 | + puts "Invalid plugin specification: #{line}" |
| 29 | + end |
| 30 | + } |
| 31 | + return pods_ary |
| 32 | +end |
| 33 | + |
| 34 | +def pubspec_supports_macos(file) |
| 35 | + file_abs_path = File.expand_path(file) |
| 36 | + if !File.exists? file_abs_path |
| 37 | + return false; |
| 38 | + end |
| 39 | + File.foreach(file_abs_path) { |line| |
| 40 | + return true if line =~ /^\s*macos:/ |
| 41 | + } |
| 42 | + return false |
| 43 | +end |
| 44 | + |
| 45 | +target 'Runner' do |
| 46 | + use_frameworks! |
| 47 | + use_modular_headers! |
| 48 | + |
| 49 | + # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock |
| 50 | + # referring to absolute paths on developers' machines. |
| 51 | + ephemeral_dir = File.join('Flutter', 'ephemeral') |
| 52 | + symlink_dir = File.join(ephemeral_dir, '.symlinks') |
| 53 | + symlink_plugins_dir = File.join(symlink_dir, 'plugins') |
| 54 | + system("rm -rf #{symlink_dir}") |
| 55 | + system("mkdir -p #{symlink_plugins_dir}") |
| 56 | + |
| 57 | + # Flutter Pods |
| 58 | + generated_xcconfig = parse_KV_file(File.join(ephemeral_dir, 'Flutter-Generated.xcconfig')) |
| 59 | + if generated_xcconfig.empty? |
| 60 | + puts "Flutter-Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first." |
| 61 | + end |
| 62 | + generated_xcconfig.map { |p| |
| 63 | + if p[:name] == 'FLUTTER_FRAMEWORK_DIR' |
| 64 | + symlink = File.join(symlink_dir, 'flutter') |
| 65 | + File.symlink(File.dirname(p[:path]), symlink) |
| 66 | + pod 'FlutterMacOS', :path => File.join(symlink, File.basename(p[:path])) |
| 67 | + end |
| 68 | + } |
| 69 | + |
| 70 | + # Plugin Pods |
| 71 | + plugin_pods = parse_KV_file('../.flutter-plugins') |
| 72 | + plugin_pods.map { |p| |
| 73 | + symlink = File.join(symlink_plugins_dir, p[:name]) |
| 74 | + File.symlink(p[:path], symlink) |
| 75 | + if pubspec_supports_macos(File.join(symlink, 'pubspec.yaml')) |
| 76 | + pod p[:name], :path => File.join(symlink, 'macos') |
| 77 | + end |
| 78 | + } |
| 79 | +end |
| 80 | + |
| 81 | +# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system. |
| 82 | +install! 'cocoapods', :disable_input_output_paths => true |
0 commit comments