@@ -9,74 +9,63 @@ project 'Runner', {
9
9
'Release' => :release ,
10
10
}
11
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 [ ] ;
12
+ def flutter_root
13
+ generated_xcode_build_settings_path = File . expand_path ( File . join ( '..' , 'Flutter' , 'ephemeral' , 'Flutter-Generated.xcconfig' ) , __FILE__ )
14
+ unless File . exist? ( generated_xcode_build_settings_path )
15
+ raise " #{ generated_xcode_build_settings_path } must exist. If you're running pod install manually, make sure \" flutter pub get \" is executed first"
16
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
17
34
- def pubspec_supports_macos ( file )
35
- file_abs_path = File . expand_path ( file )
36
- if !File . exists? file_abs_path
37
- return false ;
18
+ File . foreach ( generated_xcode_build_settings_path ) do |line |
19
+ matches = line . match ( /FLUTTER_ROOT\= (.*)/ )
20
+ return matches [ 1 ] . strip if matches
38
21
end
39
- File . foreach ( file_abs_path ) { |line |
40
- return true if line =~ /^\s *macos:/
41
- }
42
- return false
22
+ raise "FLUTTER_ROOT not found in #{ generated_xcode_build_settings_path } . Try deleting Flutter-Generated.xcconfig, then run \" flutter pub get\" "
43
23
end
44
24
45
- target 'Runner' do
46
- use_frameworks!
47
- use_modular_headers!
25
+ require File . expand_path ( File . join ( 'packages' , 'flutter_tools' , 'bin' , 'podhelper' ) , flutter_root )
26
+
27
+ flutter_macos_podfile_setup
28
+
29
+ def install_plugin_pods ( application_path = nil , relative_symlink_dir , platform )
30
+ # defined_in_file is set by CocoaPods and is a Pathname to the Podfile.
31
+ application_path ||= File . dirname ( defined_in_file . realpath ) if self . respond_to? ( :defined_in_file )
32
+ raise 'Could not find application path' unless application_path
48
33
49
34
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
50
35
# 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
36
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
- }
37
+ symlink_dir = File . expand_path ( relative_symlink_dir , application_path )
38
+ system ( 'rm' , '-rf' , symlink_dir ) # Avoid the complication of dependencies like FileUtils.
39
+
40
+ symlink_plugins_dir = File . expand_path ( 'plugins' , symlink_dir )
41
+ system ( 'mkdir' , '-p' , symlink_plugins_dir )
69
42
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' )
43
+ plugins_file = File . join ( application_path , '..' , '.flutter-plugins-dependencies' )
44
+ plugin_pods = flutter_parse_plugins_file ( plugins_file , platform )
45
+ plugin_pods . each do |plugin_hash |
46
+ plugin_name = plugin_hash [ 'name' ]
47
+ plugin_path = plugin_hash [ 'path' ]
48
+ # iOS and macOS code can be shared in "darwin" directory, otherwise
49
+ # respectively in "ios" or "macos" directories.
50
+ shared_darwin_source = plugin_hash . fetch ( 'shared_darwin_source' , false )
51
+ platform_directory = shared_darwin_source ? 'darwin' : platform
52
+ if ( plugin_name && plugin_path )
53
+ specPath = "#{ plugin_path } /#{ platform_directory } /#{ plugin_name } .podspec"
54
+ pod plugin_name , :path => specPath
77
55
end
78
- }
56
+ end
79
57
end
80
58
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
59
+ target 'Runner' do
60
+ use_frameworks!
61
+ use_modular_headers!
62
+
63
+ flutter_install_macos_engine_pod ( File . dirname ( File . realpath ( __FILE__ ) ) )
64
+ install_plugin_pods ( File . dirname ( File . realpath ( __FILE__ ) ) , '.symlinks' , 'macos' )
65
+ end
66
+
67
+ post_install do |installer |
68
+ installer . pods_project . targets . each do |target |
69
+ flutter_additional_macos_build_settings ( target )
70
+ end
71
+ end
0 commit comments