From c90e63b2998312e4c9aa029599df2c0b184faaa6 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 9 Sep 2021 22:39:35 +0800 Subject: [PATCH 1/3] os: add `uname` method This will allow us to replace code like os = if OS.mac? "Darwin" else "Linux" end with a call to `OS.uname`. Doing rg '= (if )?OS\.(mac|linux)\?' returns about 70 matches, so there are probably at least a handful of formulae that could be simplified by this. --- Library/Homebrew/os.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Library/Homebrew/os.rb b/Library/Homebrew/os.rb index ca2924c97f..17e9076dca 100644 --- a/Library/Homebrew/os.rb +++ b/Library/Homebrew/os.rb @@ -35,6 +35,14 @@ module OS @kernel_version ||= Version.new(Utils.safe_popen_read("uname", "-r").chomp) end + # Get the kernel name. + # + # @api public + sig { returns(String) } + def self.uname + @uname ||= Utils.safe_popen_read("uname").chomp + end + ::OS_VERSION = ENV["HOMEBREW_OS_VERSION"] CI_GLIBC_VERSION = "2.23" From b0668f4e312c4890972768915233a56fc395e691 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Fri, 10 Sep 2021 21:24:05 +0800 Subject: [PATCH 2/3] Use `-s` flag in `uname` call Co-authored-by: Mike McQuaid --- Library/Homebrew/os.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/os.rb b/Library/Homebrew/os.rb index 17e9076dca..34c0db2286 100644 --- a/Library/Homebrew/os.rb +++ b/Library/Homebrew/os.rb @@ -40,7 +40,7 @@ module OS # @api public sig { returns(String) } def self.uname - @uname ||= Utils.safe_popen_read("uname").chomp + @uname ||= Utils.safe_popen_read("uname", "-s").chomp end ::OS_VERSION = ENV["HOMEBREW_OS_VERSION"] From 85580e74591eab9b9132b222a1746a783d20b631 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Fri, 10 Sep 2021 21:25:38 +0800 Subject: [PATCH 3/3] Use `kernel_name` instead of `uname` as the method name --- Library/Homebrew/os.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/os.rb b/Library/Homebrew/os.rb index 34c0db2286..4f015bd66e 100644 --- a/Library/Homebrew/os.rb +++ b/Library/Homebrew/os.rb @@ -39,8 +39,8 @@ module OS # # @api public sig { returns(String) } - def self.uname - @uname ||= Utils.safe_popen_read("uname", "-s").chomp + def self.kernel_name + @kernel_name ||= Utils.safe_popen_read("uname", "-s").chomp end ::OS_VERSION = ENV["HOMEBREW_OS_VERSION"]