Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detect_clang_version version extraction #13335

Conversation

imrehorvath
Copy link

@imrehorvath imrehorvath commented May 27, 2022

The current pattern matching /clang-(\d+\.\d+\.\d+(\.\d+)?)/, 1 in the detect_clang_version method fails to fully match the new clang version string "1316.0.21.2.5" introduced with CLT 13.4, which lead to a false report of outdated CLT.

With this rewritten regex /clang-(\d+(\.\d+)+)/, 1, we have a more robust pattern matching enabled.

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

The previous implementation was depending on a fix number of version number segments. Apple has introduced one more tag for the latest CLT version 13.4, which broke the check, leading to a false warning. With this rewritten regex we have a more robust version detection.
@imrehorvath
Copy link
Author

% /Library/Developer/CommandLineTools/usr/bin/clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

irb(main):001:0> MacOS::CLT.outdated?
=> true
irb(main):002:0> MacOS::CLT.detect_clang_version
=> "1316.0.21.2"
irb(main):003:0> MacOS::CLT.latest_clang_version
=> "1316.0.21.2.5"

irb(main):009:0> Utils.popen_read("/Library/Developer/CommandLineTools/usr/bin/clang", "--version")[/clang-(\d+(\.\d+)+)/, 1]
=> "1316.0.21.2.5"
irb(main):010:0> Utils.popen_read("/Library/Developer/CommandLineTools/usr/bin/clang", "--version")[/clang-(\d+(\.\d+)+)/, 1].sub(/^(\d+)0(\d)\./, "\\1.\\2.")
=> "1316.0.21.2.5"
irb(main):011:0> 

Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

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

Thanks!

@carlocab carlocab merged commit 512f885 into Homebrew:master May 27, 2022
@imrehorvath imrehorvath deleted the imrehorvath-macos-clt-detect-clang-version-fix branch May 27, 2022 18:41
@github-actions github-actions bot added the outdated PR was locked due to age label Jun 27, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants