macOS: rebranding#964
Conversation
I don't use os_name for :provided_pre_{mountain_lion|mavericks|el_capitan} as before these versions, the os_name was OS X.
I leave behind line 1985 as Mac OS Lion is the system name of 10.7
Note that we cannot use MacOS.os_name here as OS.mac might not be true. Use the recent OS name here should be fine.
| version < "10.9" | ||
| end | ||
|
|
||
| def os_name |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'd better write a test for that.
|
|
||
| def to_s | ||
| return @explanation unless @explanation.empty? | ||
| os_name = OS.mac? ? MacOS.os_name : 'macOS' |
There was a problem hiding this comment.
Is this doing what it's supposed to be doing? If OS.mac? is false, how can it be 'macOS'?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Seems arbitrary that this is the only place where this is happening.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
@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/macontest_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.
|
|
||
| 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") |
There was a problem hiding this comment.
I think you could just use version >= "10.12" here.
There was a problem hiding this comment.
Like @DomT4 said before, plain version comparison doesn't work well as "10.7" > "10.12" in the plain string comparison.
There was a problem hiding this comment.
version = Version(version) unless version.is_a? Version
version >= "10.12"will work
There was a problem hiding this comment.
@MikeMcQuaid version >= "10.12" will fail because ArgumentError: comparison of Version with String failed
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Or you may need to use/try > rather than >=
There was a problem hiding this comment.
@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) |
There was a problem hiding this comment.
Could this maybe just be called name?
There was a problem hiding this comment.
@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".
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@MikeMcQuaid use Version here because
- we need to pass
Versiontoos_nameonmacos_requirement "10.7" > "10.12"so plain string comparison is not sufficient
There was a problem hiding this comment.
version = Version(version) unless version.is_a? VersionThere was a problem hiding this comment.
@MikeMcQuaid Ahh, this time I get your point. Thank you.
|
|
||
| def to_s | ||
| return @explanation unless @explanation.empty? | ||
| os_name = OS.mac? ? MacOS.os_name : 'macOS' |
There was a problem hiding this comment.
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!
…REW_OSX_VERSION"]
| version < "10.9" | ||
| end | ||
|
|
||
| def os_name(version = @version) |
There was a problem hiding this comment.
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.
|
|
||
| def to_s | ||
| return @explanation unless @explanation.empty? | ||
| os_name = OS::Mac.os_name(ENV["HOMEBREW_OSX_VERSION"]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
os/mac should not be used/needed outside of those two directories.
There was a problem hiding this comment.
@MikeMcQuaid Yep, I mean requiring os/mac on test_formula_support, just like what we do in test_os_mac_language.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
@MikeMcQuaid If necessary I can also move other OS X referencing user-facing messages to /extend/os/mac.
There was a problem hiding this comment.
@MikeMcQuaid CI complains that KegOnlyReason is uninitialized on linuxbrew because I move to os/mac. How would this class be used on Linux?
d36f386 to
0db155f
Compare
Ideally on non-macOS platform we should do nothing on keg_only except we expand its concept
8f0d1e7 to
fb255d8
Compare
|
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+). |
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- |
|
@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? |
|
Thanks you for your work here!
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. |
This PR is a revived version of #359. It replace all
OS Xreference to#{MacOS.os_name}except thatvendorfoldercaskfolder.rbextensionOS X 10.8.2,OS X YosemiteIt also replace all
OS Xreference tomacOSon all comments except for reference of a specific version.This PR fixes #961.
There are 2
OS Xreferences inbrew.sh. The tricky part is that even/usr/bin/sw_ver -productNamereturnsMac OS Xon macOS 10.12, so I don't know a safe way (except if-else on productVersion) to replaceOS Xstring in shell scripts.There is similar pull request macOS: rebranding #359, this PR covers the works on macOS: rebranding #359.
brew testswith your changes locally?