From 4eb636f3d82b25ff9cdfcda9fe053a1341105934 Mon Sep 17 00:00:00 2001 From: Jerome Lacoste Date: Thu, 14 Dec 2023 14:04:20 +0100 Subject: [PATCH] [fastlane_core] add support to Ruby 3.3 (#21683) * Relax regular expression that captures compilation error to be compatible with ruby 3.3 * Relax regular expression that captures compilation error to be compatible with ruby 3.3 * Change the way we build the test and its expected results to accomodate for internal changes in ruby 3.3 evaluation of __FILE__ within the eval() call * Update fastlane/spec/plugins_specs/plugin_generator_spec.rb Co-authored-by: Roger Oba --------- Co-authored-by: Roger Oba --- fastlane/spec/plugins_specs/plugin_generator_spec.rb | 9 +++++++-- .../fastlane_core/configuration/configuration_file.rb | 2 +- frameit/spec/strings_parser_spec.rb | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fastlane/spec/plugins_specs/plugin_generator_spec.rb b/fastlane/spec/plugins_specs/plugin_generator_spec.rb index 4a4dda0a582..b7b57dcfab9 100644 --- a/fastlane/spec/plugins_specs/plugin_generator_spec.rb +++ b/fastlane/spec/plugins_specs/plugin_generator_spec.rb @@ -111,7 +111,9 @@ end it "creates a plugin.rb file for the plugin" do - plugin_rb_file = File.join(tmp_dir, gem_name, 'lib', 'fastlane', 'plugin', "#{plugin_name}.rb") + relative_path = File.join('lib', 'fastlane', 'plugin', "#{plugin_name}.rb") + plugin_rb_file = File.join(tmp_dir, gem_name, relative_path) + expect(File.exist?(plugin_rb_file)).to be(true) plugin_rb_contents = File.read(plugin_rb_file) @@ -122,7 +124,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) # rubocop:disable Security/Eval - eval(plugin_rb_contents) + # Starting with Ruby 3.3, we must pass the __FILE__ of the actual file location for the all_class method implementation to work. + # Also, we expand the relative_path within Dir.chdir, as Dir.chdir on macOS will make it so tmp paths will always be under /private, + # while expand_path called from outside of Dir.chdir will not be prefixed by /private + eval(plugin_rb_contents, binding, File.expand_path(relative_path), __LINE__) # rubocop:enable Security/Eval # If we evaluate the contents of the generated plugin.rb file, diff --git a/fastlane_core/lib/fastlane_core/configuration/configuration_file.rb b/fastlane_core/lib/fastlane_core/configuration/configuration_file.rb index 3ffc0a0ecce..e447b630884 100644 --- a/fastlane_core/lib/fastlane_core/configuration/configuration_file.rb +++ b/fastlane_core/lib/fastlane_core/configuration/configuration_file.rb @@ -48,7 +48,7 @@ def initialize(config, path, block_for_missing, skip_printing_values = false) print_resulting_config_values unless skip_printing_values # only on success rescue SyntaxError => ex - line = ex.to_s.match(/\(eval\):(\d+)/)[1] + line = ex.to_s.match(/\(eval.*\):(\d+)/)[1] UI.error("Error in your #{File.basename(path)} at line #{line}") UI.content_error(content, line) UI.user_error!("Syntax error in your configuration file '#{path}' on line #{line}: #{ex}") diff --git a/frameit/spec/strings_parser_spec.rb b/frameit/spec/strings_parser_spec.rb index 548512789ed..4c13f91fd51 100644 --- a/frameit/spec/strings_parser_spec.rb +++ b/frameit/spec/strings_parser_spec.rb @@ -48,7 +48,7 @@ describe "failure parsing" do it "logs a helpful message on a bad file" do expect(Frameit::UI).to receive(:error).with(/.*translations.bad.strings line 2:/) - expect(Frameit::UI).to receive(:verbose).with(/undefined method .\[\]. for nil:NilClass/) + expect(Frameit::UI).to receive(:verbose).with(/undefined method .\[\]. for nil/) expect(Frameit::UI).to receive(:error).with(/Empty parsing result for .*translations.bad.strings/) translations = Frameit::StringsParser.parse("./frameit/spec/fixtures/translations.bad.strings")