Skip to content

Commit dce82f7

Browse files
authored
Remove deprecated Ruby File.exists? in helper script (#109428)
1 parent a624cb7 commit dce82f7

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

packages/flutter_tools/bin/podhelper.rb

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
# target 'Runner' do
1515
# ...
1616
# end
17-
def flutter_ios_podfile_setup
18-
end
17+
def flutter_ios_podfile_setup; end
1918

2019
# Same as flutter_ios_podfile_setup for macOS.
21-
def flutter_macos_podfile_setup
22-
end
20+
def flutter_macos_podfile_setup; end
2321

2422
# Add iOS build settings to pod targets.
2523
#
@@ -60,13 +58,12 @@ def flutter_additional_ios_build_settings(target)
6058
# Profile can't be derived from the CocoaPods build configuration. Use release framework (for linking only).
6159
configuration_engine_dir = build_configuration.type == :debug ? debug_framework_dir : release_framework_dir
6260
Dir.new(configuration_engine_dir).each_child do |xcframework_file|
63-
next if xcframework_file.start_with?(".") # Hidden file, possibly on external disk.
64-
if xcframework_file.end_with?("-simulator") # ios-arm64_x86_64-simulator
61+
next if xcframework_file.start_with?('.') # Hidden file, possibly on external disk.
62+
if xcframework_file.end_with?('-simulator') # ios-arm64_x86_64-simulator
6563
build_configuration.build_settings['FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]'] = "\"#{configuration_engine_dir}/#{xcframework_file}\" $(inherited)"
66-
elsif xcframework_file.start_with?("ios-") # ios-arm64
64+
elsif xcframework_file.start_with?('ios-') # ios-arm64
6765
build_configuration.build_settings['FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]'] = "\"#{configuration_engine_dir}/#{xcframework_file}\" $(inherited)"
68-
else
69-
# Info.plist or another platform.
66+
# else Info.plist or another platform.
7067
end
7168
end
7269
build_configuration.build_settings['OTHER_LDFLAGS'] = '$(inherited) -framework Flutter'
@@ -158,7 +155,7 @@ def flutter_install_all_macos_pods(macos_application_path = nil)
158155
# Optional, defaults to the Podfile directory.
159156
def flutter_install_ios_engine_pod(ios_application_path = nil)
160157
# defined_in_file is set by CocoaPods and is a Pathname to the Podfile.
161-
ios_application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
158+
ios_application_path ||= File.dirname(defined_in_file.realpath) if respond_to?(:defined_in_file)
162159
raise 'Could not find iOS application path' unless ios_application_path
163160

164161
podspec_directory = File.join(ios_application_path, 'Flutter')
@@ -167,7 +164,7 @@ def flutter_install_ios_engine_pod(ios_application_path = nil)
167164
# Generate a fake podspec to represent the Flutter framework.
168165
# This is only necessary because plugin podspecs contain `s.dependency 'Flutter'`, and if this Podfile
169166
# does not add a `pod 'Flutter'` CocoaPods will try to download it from the CocoaPods trunk.
170-
File.open(copied_podspec_path, 'w') { |podspec|
167+
File.open(copied_podspec_path, 'w') do |podspec|
171168
podspec.write <<~EOF
172169
#
173170
# NOTE: This podspec is NOT to be published. It is only used as a local source!
@@ -188,24 +185,24 @@ def flutter_install_ios_engine_pod(ios_application_path = nil)
188185
s.vendored_frameworks = 'path/to/nothing'
189186
end
190187
EOF
191-
}
188+
end
192189

193190
# Keep pod path relative so it can be checked into Podfile.lock.
194-
pod 'Flutter', :path => flutter_relative_path_from_podfile(podspec_directory)
191+
pod 'Flutter', path: flutter_relative_path_from_podfile(podspec_directory)
195192
end
196193

197194
# Same as flutter_install_ios_engine_pod for macOS.
198195
def flutter_install_macos_engine_pod(mac_application_path = nil)
199196
# defined_in_file is set by CocoaPods and is a Pathname to the Podfile.
200-
mac_application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
197+
mac_application_path ||= File.dirname(defined_in_file.realpath) if respond_to?(:defined_in_file)
201198
raise 'Could not find macOS application path' unless mac_application_path
202199

203200
copied_podspec_path = File.expand_path('FlutterMacOS.podspec', File.join(mac_application_path, 'Flutter', 'ephemeral'))
204201

205202
# Generate a fake podspec to represent the FlutterMacOS framework.
206203
# This is only necessary because plugin podspecs contain `s.dependency 'FlutterMacOS'`, and if this Podfile
207204
# does not add a `pod 'FlutterMacOS'` CocoaPods will try to download it from the CocoaPods trunk.
208-
File.open(copied_podspec_path, 'w') { |podspec|
205+
File.open(copied_podspec_path, 'w') do |podspec|
209206
podspec.write <<~EOF
210207
#
211208
# NOTE: This podspec is NOT to be published. It is only used as a local source!
@@ -226,10 +223,10 @@ def flutter_install_macos_engine_pod(mac_application_path = nil)
226223
s.vendored_frameworks = 'path/to/nothing'
227224
end
228225
EOF
229-
}
226+
end
230227

231228
# Keep pod path relative so it can be checked into Podfile.lock.
232-
pod 'FlutterMacOS', :path => File.join('Flutter', 'ephemeral')
229+
pod 'FlutterMacOS', path: File.join('Flutter', 'ephemeral')
233230
end
234231

235232
# Install Flutter plugin pods.
@@ -238,7 +235,7 @@ def flutter_install_macos_engine_pod(mac_application_path = nil)
238235
# Optional, defaults to the Podfile directory.
239236
def flutter_install_plugin_pods(application_path = nil, relative_symlink_dir, platform)
240237
# defined_in_file is set by CocoaPods and is a Pathname to the Podfile.
241-
application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
238+
application_path ||= File.dirname(defined_in_file.realpath) if respond_to?(:defined_in_file)
242239
raise 'Could not find application path' unless application_path
243240

244241
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
@@ -256,23 +253,22 @@ def flutter_install_plugin_pods(application_path = nil, relative_symlink_dir, pl
256253
plugin_name = plugin_hash['name']
257254
plugin_path = plugin_hash['path']
258255
has_native_build = plugin_hash.fetch('native_build', true)
259-
if (plugin_name && plugin_path && has_native_build)
260-
symlink = File.join(symlink_plugins_dir, plugin_name)
261-
File.symlink(plugin_path, symlink)
256+
next unless plugin_name && plugin_path && has_native_build
257+
symlink = File.join(symlink_plugins_dir, plugin_name)
258+
File.symlink(plugin_path, symlink)
262259

263-
# Keep pod path relative so it can be checked into Podfile.lock.
264-
relative = flutter_relative_path_from_podfile(symlink)
260+
# Keep pod path relative so it can be checked into Podfile.lock.
261+
relative = flutter_relative_path_from_podfile(symlink)
265262

266-
pod plugin_name, :path => File.join(relative, platform)
267-
end
263+
pod plugin_name, path: File.join(relative, platform)
268264
end
269265
end
270266

271267
# .flutter-plugins-dependencies format documented at
272268
# https://flutter.dev/go/plugins-list-migration
273269
def flutter_parse_plugins_file(file, platform)
274270
file_path = File.expand_path(file)
275-
return [] unless File.exists? file_path
271+
return [] unless File.exist? file_path
276272

277273
dependencies_file = File.read(file)
278274
dependencies_hash = JSON.parse(dependencies_file)

packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def install_flutter_plugin_pods(flutter_application_path)
6767

6868
# Keep pod path relative so it can be checked into Podfile.lock.
6969
relative = flutter_relative_path_from_podfile(ios_application_path)
70-
pod 'FlutterPluginRegistrant', :path => File.join(relative, 'Flutter', 'FlutterPluginRegistrant'), :inhibit_warnings => true
70+
pod 'FlutterPluginRegistrant', path: File.join(relative, 'Flutter', 'FlutterPluginRegistrant'), inhibit_warnings: true
7171
end
7272

7373
# Install Flutter application pod.
@@ -87,27 +87,25 @@ def install_flutter_application_pod(flutter_application_path)
8787
# Keep script phase paths relative so they can be checked into source control.
8888
relative = flutter_relative_path_from_podfile(export_script_directory)
8989

90-
flutter_export_environment_path = File.join('${SRCROOT}', relative, 'flutter_export_environment.sh');
90+
flutter_export_environment_path = File.join('${SRCROOT}', relative, 'flutter_export_environment.sh')
9191

9292
# Compile App.framework and move it and Flutter.framework to "BUILT_PRODUCTS_DIR"
93-
script_phase :name => 'Run Flutter Build {{projectName}} Script',
94-
:script => "set -e\nset -u\nsource \"#{flutter_export_environment_path}\"\nexport VERBOSE_SCRIPT_LOGGING=1 && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh build",
95-
:execution_position => :before_compile
93+
script_phase name: 'Run Flutter Build {{projectName}} Script',
94+
script: "set -e\nset -u\nsource \"#{flutter_export_environment_path}\"\nexport VERBOSE_SCRIPT_LOGGING=1 && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh build",
95+
execution_position: :before_compile
9696

9797
# Embed App.framework AND Flutter.framework.
98-
script_phase :name => 'Embed Flutter Build {{projectName}} Script',
99-
:script => "set -e\nset -u\nsource \"#{flutter_export_environment_path}\"\nexport VERBOSE_SCRIPT_LOGGING=1 && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh embed_and_thin",
100-
:execution_position => :after_compile
98+
script_phase name: 'Embed Flutter Build {{projectName}} Script',
99+
script: "set -e\nset -u\nsource \"#{flutter_export_environment_path}\"\nexport VERBOSE_SCRIPT_LOGGING=1 && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh embed_and_thin",
100+
execution_position: :after_compile
101101
end
102102

103103
def flutter_root
104104
generated_xcode_build_settings_path = File.expand_path(File.join('..', '..', 'Flutter', 'Generated.xcconfig'), __FILE__)
105-
unless File.exist?(generated_xcode_build_settings_path)
106-
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
107-
end
105+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" unless File.exist?(generated_xcode_build_settings_path)
108106

109107
File.foreach(generated_xcode_build_settings_path) do |line|
110-
matches = line.match(/FLUTTER_ROOT\=(.*)/)
108+
matches = line.match(/FLUTTER_ROOT=(.*)/)
111109
return matches[1].strip if matches
112110
end
113111
# This should never happen...
@@ -127,7 +125,7 @@ def flutter_post_install(installer, skip: false)
127125
return if skip
128126

129127
installer.pods_project.targets.each do |target|
130-
target.build_configurations.each do |build_configuration|
128+
target.build_configurations.each do |_build_configuration|
131129
# flutter_additional_ios_build_settings is in Flutter root podhelper.rb
132130
flutter_additional_ios_build_settings(target)
133131
end

0 commit comments

Comments
 (0)