Skip to content

Conversation

dokimyj
Copy link
Contributor

@dokimyj dokimyj commented Jul 25, 2024

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I see several green ci/circleci builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.
    • N/A
  • I've added or updated relevant unit tests.

Motivation and Context

Fixes error from #22147

Description

While trying run_tests with #22147 commit source,
some Xcode versions (e.g. Xcode 16 beta 2) failed due to nil-referring [] search.

trainer/lib/trainer/test_parser.rb:216:in generate_cmd_parse_xcresult': [!] undefined method []' for nil:NilClass (NoMethodError)

This PR solves the problem below:

Error details and `xcrun xcresulttool version` example of Xcode 16 beta
00:09:43 Called from Fastfile at line 58
00:09:43 ```
00:09:43     56:	  desc "Run test!"
00:09:43     57:	  lane :test do
00:09:43  => 58:	    run_tests(
00:09:43     59:	      scheme: scheme,
00:09:43     60:	      devices: [
00:09:43 ```

...

source_path/vendor/bundle/ruby/3.2.0/bundler/gems/fastlane-26104a51d25a/trainer/lib/trainer/test_parser.rb:216:in `generate_cmd_parse_xcresult': [!] undefined method `[]' for nil:NilClass (NoMethodError)
00:09:47 
00:09:47       version = match[:version]&.to_f
00:09:47                      ^^^^^^^^^^

After I have found this error, tried xcrun xcresulttool version with all Xcode 16 beta versions and here's the result:

$ DEVELOPER_DIR=/Applications/Xcode_16_beta.app xcrun xcresulttool version
xcresulttool version 23019.2, format version 3.53 (current)

$ DEVELOPER_DIR=/Applications/Xcode_16_beta_2.app xcrun xcresulttool version
xcresulttool version 23019.2, format version 3.53 (current)

$ DEVELOPER_DIR=/Applications/Xcode_16_beta_3.app xcrun xcresulttool version
xcresulttool version 23021, format version 3.53 (current)

$ DEVELOPER_DIR=/Applications/Xcode/Xcode_16_beta_4.app xcrun xcresulttool version
xcresulttool version 23024, format version 3.53 (current)

Testing Steps

Installed fastlane gem with the source of this branch, executed run_tests with Xcode 15.4, Xcode 16 beta 2, and beta 4.

  • Xcode 15.4
20:22:39 +-------------------------------------------------------------------------------------------------------------------------------+
20:22:39 |                                                   Summary for scan 2.221.1                                                    |
20:22:39 +------------------------------------------------+------------------------------------------------------------------------------+
...
20:22:39 | xcode_path                                     | /Applications/Xcode/Xcode_15.4.app                                           |
20:22:39 +------------------------------------------------+------------------------------------------------------------------------------+

...

20:25:58 ▸ Test Succeeded
20:26:01 Skipping HTML... only available with `xcodebuild_formatter: 'xcpretty'` right now
20:26:01 Your 'xcodebuild_formatter' doesn't support these 'output_types'. Change your 'output_types' to prevent these warnings from showing...
20:26:02 +------------------------+
20:26:02 |      Test Results      |
20:26:02 +--------------------+---+
20:26:02 | Number of tests    | 6 |
20:26:02 | Number of failures | 0 |
20:26:02 +--------------------+---+
  • Xcode 16 beta 4
20:13:29 +-------------------------------------------------------------------------------------------------------------------------------+
20:13:29 |                                                   Summary for scan 2.221.1                                                    |
20:13:29 +------------------------------------------------+------------------------------------------------------------------------------+
...
20:13:29 | xcode_path                                     | /Applications/Xcode/Xcode_16_beta_4.app                                      |
20:13:29 +------------------------------------------------+------------------------------------------------------------------------------+

...

20:15:15 ▸ Test Succeeded
20:15:19 Skipping HTML... only available with `xcodebuild_formatter: 'xcpretty'` right now
20:15:19 Your 'xcodebuild_formatter' doesn't support these 'output_types'. Change your 'output_types' to prevent these warnings from showing...
20:15:19 +------------------------+
20:15:19 |      Test Results      |
20:15:19 +--------------------+---+
20:15:19 | Number of tests    | 6 |
20:15:19 | Number of failures | 0 |
20:15:19 +--------------------+---+

  • Xcode 16 beta 2 (Problematic on master branch)
20:07:18 +-------------------------------------------------------------------------------------------------------------------------------+
20:07:18 |                                                   Summary for scan 2.221.1                                                    |
20:07:18 +------------------------------------------------+------------------------------------------------------------------------------+
...
20:07:18 | xcode_path                                     | /Applications/Xcode/Xcode_16_beta_2.app                                      |
20:07:18 +------------------------------------------------+------------------------------------------------------------------------------+

...

20:10:00 ▸ Test Succeeded
20:10:04 Skipping HTML... only available with `xcodebuild_formatter: 'xcpretty'` right now
20:10:04 Your 'xcodebuild_formatter' doesn't support these 'output_types'. Change your 'output_types' to prevent these warnings from showing...
20:10:05 +------------------------+
20:10:05 |      Test Results      |
20:10:05 +--------------------+---+
20:10:05 | Number of tests    | 6 |
20:10:05 | Number of failures | 0 |
20:10:05 +--------------------+---+

match = `xcrun xcresulttool version`.match(/xcresulttool version (?<version>\d+),/)
version = match[:version]&.to_f
xcresulttool_cmd << '--legacy' if version >= 23_021.0
match = `xcrun xcresulttool version`.match(/xcresulttool version (?<version>[\d.]+)/)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omitted , at the end because the code below this line would fail if the version includes any kind of alphabets([a-Z]).

  • with , at the end of regex
irb(main):005:0> match = 'xcresulttool version 22222.5.1-beta, Format Version 34'.match(/xcresulttool version (?<version>[\d.]+),/)
=> nil
  • without , at the end of regex
irb(main):004:0> match = 'xcresulttool version 22222.5.1-beta, Format Version 34'.match(/xcresulttool version (?<version>[\d.]+)/)
=> #<MatchData "xcresulttool version 22222.5.1" version:"22222.5.1">

@dokimyj dokimyj marked this pull request as ready for review July 25, 2024 11:48
@dokimyj dokimyj changed the title [scan][trainer] hotfix for float-type version acquisition fails [scan][trainer] hotfix for float-type version acquisition of xcresulttool version fails Jul 25, 2024
@giginet giginet self-requested a review July 25, 2024 12:46
Copy link
Collaborator

@giginet giginet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@giginet giginet merged commit 9bc8429 into fastlane:master Jul 25, 2024
@dokimyj dokimyj deleted the dokimyj-patch-2 branch July 26, 2024 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants