os: add kernel_version#8381
Conversation
Library/Homebrew/os.rb
Outdated
There was a problem hiding this comment.
Maybe call this kernel_version?
Any new utility methods that are used by formulae should be used by at least 3 (ideally a lot more than that) before we add them. I'm not sure I see the advantage here; it's not even actually shorter in this case? |
About 17 formulae use
Hehe, you might have a point 😆 It's longer but I think it's more clear |
|
I'm not convinced the |
527fd35 to
1c3c382
Compare
|
Slightly off-topic, latest GNU |
You've changed my mind: I like these. |
Library/Homebrew/os.rb
Outdated
There was a problem hiding this comment.
- What if
uname -rfails? (should probablyraise) Utils.popen_readmight be a nicer fit here.
There was a problem hiding this comment.
Also: could this get a unit test.
I'm not certain, but after checking in |
Library/Homebrew/os.rb
Outdated
There was a problem hiding this comment.
Doesn't Version.create return Version::NULL?
There was a problem hiding this comment.
That would be Version.parse but that might be excessive in this case since uname -r already returns a valid version string
Library/Homebrew/os.rb
Outdated
There was a problem hiding this comment.
| @kernel_version ||= if output = Utils.popen_read("uname", "-r").chomp.presence | |
| @kernel_version ||= if output = Utils.safe_popen_read("uname", "-r").chomp.presence |
I don't think this should be able to fail, right?
There was a problem hiding this comment.
Whoops, I forgot about that. I was just preserving the functionality of OS::Linux::Kernel.version since that's where this came from
We probably won't need the if since safe_popen_read raises an error anyways
Library/Homebrew/os/linux/kernel.rb
Outdated
There was a problem hiding this comment.
I'm not sure if we want to preserve this or not
There was a problem hiding this comment.
I think so unless you can verify it's unused in e.g. linuxbrew-core in which case: 🔥 it.
There was a problem hiding this comment.
Looks like this is only used in brew in extend/os/linux/diagnostic (including below_minimum_version?):
% cd $(brew --repo)
% grep -r 'Linux::Kernel' *
Library/Homebrew/test/os/linux/diagnostic_spec.rb: allow(OS::Linux::Kernel).to receive(:below_minimum_version?).and_return(true)
Library/Homebrew/extend/os/linux/diagnostic.rb: return unless OS::Linux::Kernel.below_minimum_version?
Library/Homebrew/extend/os/linux/diagnostic.rb: Your Linux kernel #{OS::Linux::Kernel.version} is too old.
Library/Homebrew/extend/os/linux/diagnostic.rb: We only support kernel #{OS::Linux::Kernel.minimum_version} or later.% cd $(brew --repo homebrew/core)
% git remote get-url origin
https://github.com/Homebrew/linuxbrew-core
% grep 'Linux::Kernel' Formula/*
% grep 'Linux::' Formula/*
Formula/clang-format.rb: if Formula["glibc"].any_version_installed? || OS::Linux::Glibc.system_version < Formula["glibc"].version
Formula/glibc.rb: Glibc.version >= OS::Linux::Glibc.system_version
Formula/glibc.rb: Your system's glibc version is #{OS::Linux::Glibc.system_version}, and Homebrew's glibc version is #{Glibc.version}.
Formula/llvm@7.rb: if Formula["glibc"].any_version_installed? || OS::Linux::Glibc.system_version < Formula["glibc"].version
Formula/llvm@8.rb: if Formula["glibc"].any_version_installed? || OS::Linux::Glibc.system_version < Formula["glibc"].version
Formula/llvm@9.rb: if Formula["glibc"].any_version_installed? || OS::Linux::Glibc.system_version < Formula["glibc"].version
Formula/llvm.rb: if Formula["glibc"].any_version_installed? || OS::Linux::Glibc.system_version < Formula["glibc"].versionThere was a problem hiding this comment.
Cool! I think you can 🔥 then.
There was a problem hiding this comment.
So uh, what does 🔥 mean in this context? 😅
There was a problem hiding this comment.
Sorry: burn it down (i.e. delete it)
Library/Homebrew/os.rb
Outdated
460f1d9 to
3379e3b
Compare
brew stylewith your changes locally?brew testswith your changes locally?This allows for e.g.
`uname -r`.split(".").firstinhomebrew/core/gccto be replaced withOS.kernel_version.majorUses:
`uname -r`.split(".").first→OS.kernel_version.major`uname -r`.to_i→OS.kernel_version.major`uname -r`.chomp→OS.kernel_versionshell_output("uname -r").strip→OS.kernel_versionUtils.safe_popen_read("uname", "-r").chomp→OS.kernel_version