Podfile-macos 2.77 KB
Newer Older
1 2 3
# Using a CDN with CocoaPods 1.7.2 or later can save a lot of time on pod installation, but it's experimental rather than the default.
# source 'https://cdn.cocoapods.org/'

4
platform :osx, '10.11'
5

6 7 8
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

9 10
project 'Runner', {
  'Debug' => :debug,
11 12
  # TODO: Add Profile support to projects.
  #'Profile' => :release,
13 14 15
  'Release' => :release,
}

16
def parse_KV_file(file, separator='=')
17 18 19 20 21
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  pods_ary = []
22
  skip_line_start_symbols = ["#", "/"]
23
  File.foreach(file_abs_path) { |line|
24
      next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
25
      plugin = line.split(pattern=separator)
26
      if plugin.length == 2
27
        podname = plugin[0].strip()
28
        path = plugin[1].strip()
29
        podpath = File.expand_path("#{path}", file_abs_path)
30
        pods_ary.push({:name => podname, :path => podpath});
31 32 33
      else
        puts "Invalid plugin specification: #{line}"
      end
34 35 36 37
  }
  return pods_ary
end

38 39 40 41 42 43
def pubspec_supports_macos(file)
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return false;
  end
  File.foreach(file_abs_path) { |line|
44
    return true if line =~ /^\s*macos:/
45 46 47 48
  }
  return false
end

49
target 'Runner' do
50 51
  use_frameworks!

52 53
  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
54 55 56 57 58
  ephemeral_dir = File.join('Flutter', 'ephemeral')
  symlink_dir = File.join(ephemeral_dir, '.symlinks')
  symlink_plugins_dir = File.join(symlink_dir, 'plugins')
  system("rm -rf #{symlink_dir}")
  system("mkdir -p #{symlink_plugins_dir}")
59

60
  # Flutter Pods
61 62 63
  generated_xcconfig = parse_KV_file(File.join(ephemeral_dir, 'Flutter-Generated.xcconfig'))
  if generated_xcconfig.empty?
    puts "Flutter-Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
64
  end
65
  generated_xcconfig.map { |p|
66
    if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
67
      symlink = File.join(symlink_dir, 'flutter')
68
      File.symlink(File.dirname(p[:path]), symlink)
69
      pod 'FlutterMacOS', :path => File.join(symlink, File.basename(p[:path]))
70 71 72 73
    end
  }

  # Plugin Pods
74 75
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.map { |p|
76
    symlink = File.join(symlink_plugins_dir, p[:name])
77
    File.symlink(p[:path], symlink)
78 79
    if pubspec_supports_macos(File.join(symlink, 'pubspec.yaml'))
      pod p[:name], :path => File.join(symlink, 'macos')
80
    end
81
  }
82
end
83 84 85

# 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