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

os/{mac,mac/sdk}: refactor out sdk_version #10150

Merged
merged 2 commits into from
Dec 29, 2020
Merged

os/{mac,mac/sdk}: refactor out sdk_version #10150

merged 2 commits into from
Dec 29, 2020

Conversation

carlocab
Copy link
Member

@carlocab carlocab commented Dec 26, 2020

  • 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.
    • Looking into this, but it seems to already be tested elsewhere.
  • 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?
  • Have you successfully run brew man locally and committed any changes?

The changes here rely on #10129. Merge that PR before this one. (Tests will pass when that is done.)

This PR:

  1. Removes sdk_version, as it is no longer in use (cf. os/mac/pkgconfig: merge pc files for 11.1 and 11.0 #10129 (comment))
  2. Combines the logic in
    return sdk if OS::Mac.version >= :big_sur && sdk.version.major == OS::Mac.version.major
    and
    sdk_path = File.join(sdk_prefix, "MacOSX.sdk")
    if OS::Mac.version >= :big_sur && File.directory?(sdk_path)
    sdk_settings = File.join(sdk_path, "SDKSettings.json")
    version = JSON.parse(File.read(sdk_settings))["Version"] if File.exist?(sdk_settings)
    paths[OS::Mac::Version.new(version)] = sdk_path if version.present?
    end
    using the behaviour of OS::Mac.version in Big Sur.

Since OS::Mac.version returns only the major version in Big Sur, we use that to populate the sdk_paths hash with the key-value pair OS::Mac.version.major => /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk.

This alleviates the concern expressed here: #10112 (comment)

This also allows you to request for the versioned SDK path if required:

❯ brew ruby -e 'puts MacOS.sdk_path_if_needed'
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
❯ brew ruby -e 'puts MacOS.sdk_path_if_needed(OS::Mac::Version.new("11.1"))'
/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk
❯ brew ruby -e 'puts MacOS.sdk_path_if_needed(OS::Mac::Version.new("10.15"))'
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk

Finer-grained control over the exact SDK path could prove useful when macOS 12 hits.

@carlocab carlocab requested a review from mistydemeo December 26, 2020 01:40
@BrewTestBot
Copy link
Member

Review period will end on 2020-12-29 at 00:00:00 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 26, 2020
@carlocab
Copy link
Member Author

One limitation of this is that latest_sdk

https://github.com/Homebrew/brew/blob/3a7de2275ef2477e1ee141c0d0b8f37925d145df/Library/Homebrew/os/mac/sdk.rb#L34-L39

still returns a path to MacOSX11.x.sdk. latest_sdk is used in

https://github.com/Homebrew/brew/blob/3a7de2275ef2477e1ee141c0d0b8f37925d145df/Library/Homebrew/os/mac/sdk.rb#L45-L54

I can fix that if that's not desirable, but I currently only have ugly hacks in mind.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Nice work here so far @carlocab!

Library/Homebrew/os/mac/sdk.rb Outdated Show resolved Hide resolved
Library/Homebrew/os/mac/sdk.rb Outdated Show resolved Hide resolved
Library/Homebrew/os/mac/sdk.rb Outdated Show resolved Hide resolved
@carlocab
Copy link
Member Author

carlocab commented Dec 28, 2020

I don't think I actually need the if sdk_settings.exist? block (I can inline the if statement to the JSON.parseline), but I think writing it that way also makes it easier to read.

@MikeMcQuaid
Copy link
Member

still returns a path to MacOSX11.x.sdk.

Might be worth making it private as a result?

@carlocab
Copy link
Member Author

Well, BaseSDKLocator is already private (at least, I think that's what private_constant does), so it actually takes a minute to figure out how to get to latest_sdk and then make it give you the attribute you want.

It doesn't hurt, however. Updated commits will be up when brew tests finishes running.

@MikeMcQuaid
Copy link
Member

Looks good, thanks again @carlocab!

@carlocab
Copy link
Member Author

Cheers @MikeMcQuaid. Thanks for bearing with my glaring lack of familiarity with Ruby.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 29, 2020
@BrewTestBot
Copy link
Member

Review period ended.

@carlocab
Copy link
Member Author

carlocab commented Dec 29, 2020

Weird, there look to be two "CI / test everything (macOS)" runs, but the first failed because it never really started. [1] Going to rebase and force push to try to restart the tests.

[1] https://github.com/Homebrew/brew/runs/1618013201

@MikeMcQuaid MikeMcQuaid merged commit b3902eb into Homebrew:master Dec 29, 2020
@carlocab carlocab deleted the sdk-version-refactor branch December 29, 2020 14:11
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Jan 28, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Jan 28, 2021
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.

3 participants