Skip to content

macOS: rebranding#964

Closed
JLHwung wants to merge 27 commits intoHomebrew:masterfrom
JLHwung:macOS_rebranding
Closed

macOS: rebranding#964
JLHwung wants to merge 27 commits intoHomebrew:masterfrom
JLHwung:macOS_rebranding

Conversation

@JLHwung
Copy link
Copy Markdown

@JLHwung JLHwung commented Sep 15, 2016

This PR is a revived version of #359. It replace all OS X reference to #{MacOS.os_name} except that

  • The files in the vendor folder
  • The files in the cask folder
  • The files without a .rb extension
  • Reference of a specific version e.g. OS X 10.8.2, OS X Yosemite

It also replace all OS X reference to macOS on all comments except for reference of a specific version.

This PR fixes #961.

There are 2 OS X references in brew.sh. The tricky part is that even /usr/bin/sw_ver -productName returns Mac OS X on macOS 10.12, so I don't know a safe way (except if-else on productVersion) to replace OS X string in shell scripts.

  • 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?
    There is similar pull request macOS: rebranding #359, this PR covers the works on macOS: rebranding #359.
  • 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 tests with your changes locally?

Comment thread Library/Homebrew/os/mac.rb Outdated
version < "10.9"
end

def os_name
Copy link
Copy Markdown
Contributor

@DomT4 DomT4 Sep 15, 2016

Choose a reason for hiding this comment

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

You'll need to pick up the changes I suggested here. Plain version comparisons like this don't work especially well, you get situations where 10.10 is correctly reported as OS X but 10.7 is flagged as macOS.

The proposed change in the linked issue also allows you to fix the situation where Requirements have their own @version we shouldn't be ignoring. My proposed fix in the other issue isn't perfect, and will need some additional testing & tweaking, but it's closer.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'd better write a test for that.

Comment thread Library/Homebrew/formula_support.rb Outdated

def to_s
return @explanation unless @explanation.empty?
os_name = OS.mac? ? MacOS.os_name : 'macOS'
Copy link
Copy Markdown
Member

@reitermarkus reitermarkus Sep 15, 2016

Choose a reason for hiding this comment

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

Is this doing what it's supposed to be doing? If OS.mac? is false, how can it be 'macOS'?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I use MacOS.os_name before but CI complains that MacOS is uninitialized constant. Test always pass locally. So I thought may be it's the case when OS.mac is false?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems arbitrary that this is the only place where this is happening.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's because you need to not use MacOS (or OS.mac?) outside of Library/Homebrew/os or Library/Homebrew/extend/os/. Instead, have an OS.name method which uses subclasses in Library/Homebrew/extend/os/mac to set the right macOS name.

Alternatively, edit brew.sh to set a HOMEBREW_OS_NAME (like HOMEBREW_OS_VERSION currently) which uses the correct version and then OS.name can just use ENV["HOMEBREW_OS_NAME"]

Shout if you need more help with this!

Copy link
Copy Markdown
Author

@JLHwung JLHwung Sep 15, 2016

Choose a reason for hiding this comment

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

@MikeMcQuaid I think why CI complains is that when ENV["HOMEBREW_TEST_GENERIC_OS"] is set, MacOS is not initialized but we can use OS::Mac.os_name(ENV["HOMEBREW_OSX_VERSION"]) here so that both CI and macOS should be happy.

Instead, have an OS.name method which uses subclasses in Library/Homebrew/extend/os/mac to set the right macOS name.

It would be confused if there is a os.os_name method that returns macOS even in Linux because we implicitly assume that it is called under macOS, if not TEST_GENERIC_OS, only.
Test failed because under TEST_GENERIC_OS, os/mac is not loaded so we cannot call the method in formula_support. Although formula_support is agnostic of os/mac, but obviously all the error messages defined there are only meaningful when running on os/mac. So I suggest:

  • requiring os/mac on test_formula_support
  • supply version to mimic the real behaviour on different macOS versions.

Alternatively, edit brew.sh to set a HOMEBREW_OS_NAME (like HOMEBREW_OS_VERSION currently) which uses the correct version and then OS.name can just use ENV["HOMEBREW_OS_NAME"]

It think this is over complicated. Basically I aim to adding the pedantry in a single place so that when macOS 10.14 is released we don't have to search everywhere to remove multiple methods and their usage.

Comment thread Library/Homebrew/os/mac.rb Outdated

def os_name(version = @version)
# TODO: replace os_name by constant string "macOS" when macOS 10.14 is released
if Version.create(version) >= Version.create("10.12")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you could just use version >= "10.12" here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Like @DomT4 said before, plain version comparison doesn't work well as "10.7" > "10.12" in the plain string comparison.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

version = Version(version) unless version.is_a? Version
version >= "10.12"

will work

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid version >= "10.12" will fail because ArgumentError: comparison of Version with String failed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check the methods above; if you create a version the same as them (probably with .new) then you should be able to compare the same as them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or you may need to use/try > rather than >=

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid Thank you! Version.new LGTM, I'd better add more test to ensure it does not break.

version < "10.9"
end

def os_name(version = @version)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this maybe just be called name?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid I think name is a bit too general to use as a method name 😄. Well to tell you the truth I just find it cumbersome to rewrite all the commit messages from "use os_name" to "use name".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In that case you can avoid making version a Version if it already is one and 10.12 doesn't need to be a Version.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid use Version here because

  • we need to pass Version to os_name on macos_requirement
  • "10.7" > "10.12" so plain string comparison is not sufficient

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

version = Version(version) unless version.is_a? Version

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid Ahh, this time I get your point. Thank you.

Comment thread Library/Homebrew/formula_support.rb Outdated

def to_s
return @explanation unless @explanation.empty?
os_name = OS.mac? ? MacOS.os_name : 'macOS'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's because you need to not use MacOS (or OS.mac?) outside of Library/Homebrew/os or Library/Homebrew/extend/os/. Instead, have an OS.name method which uses subclasses in Library/Homebrew/extend/os/mac to set the right macOS name.

Alternatively, edit brew.sh to set a HOMEBREW_OS_NAME (like HOMEBREW_OS_VERSION currently) which uses the correct version and then OS.name can just use ENV["HOMEBREW_OS_NAME"]

Shout if you need more help with this!

version < "10.9"
end

def os_name(version = @version)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In that case you can avoid making version a Version if it already is one and 10.12 doesn't need to be a Version.

Comment thread Library/Homebrew/formula_support.rb Outdated

def to_s
return @explanation unless @explanation.empty?
os_name = OS::Mac.os_name(ENV["HOMEBREW_OSX_VERSION"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, this needs to use ENV["HOMEBREW_OS_VERSION"] (not OSX_VERSION) and be in the OS class so it works on non-OS X platforms. Alternatively, all the OS X references in code need to be moved into extend/os.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think I'd better revert this change to use MacOS.os_name unconditionally, and require os/mac on test_formula_support. Apparently the error message is meaningless on a Linux, isn't it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep, ideally we'd not have any user-facing messages that say "OS X" outside of Library/Homebrew/os/mac/ or Library/Homebrew/extend/os/mac.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

So I think when test_formula_support makes assertions on the user-facing messages, it should require os/mac otherwise it does not simulate the real cases.
Apparently we are facing same os/mac loading problem if we write a test for KegOnlyReason::valid method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

os/mac should not be used/needed outside of those two directories.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid Yep, I mean requiring os/mac on test_formula_support, just like what we do in test_os_mac_language.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid How about I move Class KegOnlyReason in formula_support to /extend/os/mac (as we do for formula_cellar_checks) ? As the whole class is macOS-only and ideally we should not have it outside Library/Homebrew/os/mac, right? I am wondering how to specify that this method is macOnly and instruct the test should go into the macOs-only branch.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid If necessary I can also move other OS X referencing user-facing messages to /extend/os/mac.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JLHwung That'd be good, thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@MikeMcQuaid CI complains that KegOnlyReason is uninitialized on linuxbrew because I move to os/mac. How would this class be used on Linux?

@UniqMartin
Copy link
Copy Markdown
Contributor

As mentioned in #961 (comment) by now I'm strongly in favor of maximum simplicity and using “macOS” everywhere as soon as 10.12 is released. However, if we really wanted to be serious about adapting our output, the distinction will need to be three-fold (“Mac OS X” for 10.0-10.6, “OS X” for 10.7-10.11, and “macOS” for 10.12+).

@MikeMcQuaid
Copy link
Copy Markdown
Member

As mentioned in #961 (comment):
The API reference at https://developer.apple.com/reference/ only ever speaks of “macOS” when talking about when an API was introduced, even if it's “macOS 10.0+”.

This is by far the strongest argument for me so I'm 👍 with just using macOS all over.

@JLHwung I'm so sorry to send you on such a wild chase for this, my apologies. I hope you've learnt some stuff through doing so and will continue to contribute to Homebrew. Let me know if you'd rather doing the mass-macOS replacement or if you'd rather we did. Thanks so much for your contributions.

@JLHwung
Copy link
Copy Markdown
Author

JLHwung commented Sep 18, 2016

@MikeMcQuaid Sorry for late reply as I am in vacation now. I've learnt a lot more than it appears at the beginning, and thank you for your review. I cannot spare time on replacing before 20th so it'd better assigned to other people.

As I am working on this pr, I find many macOS-dependent code does not locate in os/mac or extend/os/mac, shall we split the platform-dependent codes or just let it be?

@JLHwung JLHwung closed this Sep 18, 2016
@UniqMartin
Copy link
Copy Markdown
Contributor

Thanks you for your work here!

As I am working on this pr, I find many macOS-dependent code does not locate in os/mac or extend/os/mac, shall we split the platform-dependent codes or just let it be?

This is an ongoing process and we started it fairly recently in an attempt to make Homebrew truly platform-agnostic (to the extent it makes sense) and to help move back code from Linuxbrew into Homebrew with proper abstractions and cleaner code structure. If that's a topic that interests you, we're more than happy to have someone help us with this endeavor.

@Homebrew Homebrew locked and limited conversation to collaborators May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adapt to macOS/OS X naming convention in diagnostics

5 participants