Mike McQuaid c5dbd3ca24
Rearrange requires
This improves the load time of most brew commands. For an example of
one of the simplest commands this speeds up:

Without Bootsnap:
```
$ hyperfine 'git checkout master; brew help' 'git checkout optimise_requires; brew help'
Benchmark 1: git checkout master; brew help
  Time (mean ± σ):     525.0 ms ±  35.8 ms    [User: 229.9 ms, System: 113.1 ms]
  Range (min … max):   465.3 ms … 576.6 ms    10 runs

Benchmark 2: git checkout optimise_requires; brew help
  Time (mean ± σ):     383.3 ms ±  25.1 ms    [User: 133.0 ms, System: 72.1 ms]
  Range (min … max):   353.0 ms … 443.6 ms    10 runs

Summary
  git checkout optimise_requires; brew help ran
    1.37 ± 0.13 times faster than git checkout master; brew help
```

With Bootsnap:
```
$ hyperfine 'git checkout master; brew help' 'git checkout optimise_requires; brew help'
Benchmark 1: git checkout master; brew help
  Time (mean ± σ):     386.0 ms ±  30.9 ms    [User: 130.2 ms, System: 93.8 ms]
  Range (min … max):   359.5 ms … 469.3 ms    10 runs

Benchmark 2: git checkout optimise_requires; brew help
  Time (mean ± σ):     330.2 ms ±  32.4 ms    [User: 93.4 ms, System: 73.0 ms]
  Range (min … max):   302.9 ms … 413.9 ms    10 runs

Summary
  git checkout optimise_requires; brew help ran
    1.17 ± 0.15 times faster than git checkout master; brew help
```
2024-07-14 08:49:39 -04:00

83 lines
2.2 KiB
Ruby

# typed: true
# frozen_string_literal: true
require "version"
# Helper functions for querying operating system information.
module OS
# Check whether the operating system is macOS.
#
# @api public
sig { returns(T::Boolean) }
def self.mac?
return false if ENV["HOMEBREW_TEST_GENERIC_OS"]
RbConfig::CONFIG["host_os"].include? "darwin"
end
# Check whether the operating system is Linux.
#
# @api public
sig { returns(T::Boolean) }
def self.linux?
return false if ENV["HOMEBREW_TEST_GENERIC_OS"]
RbConfig::CONFIG["host_os"].include? "linux"
end
# Get the kernel version.
#
# @api public
sig { returns(Version) }
def self.kernel_version
require "utils/popen"
@kernel_version ||= Version.new(Utils.safe_popen_read("uname", "-r").chomp)
end
# Get the kernel name.
#
# @api public
sig { returns(String) }
def self.kernel_name
require "utils/popen"
@kernel_name ||= Utils.safe_popen_read("uname", "-s").chomp
end
::OS_VERSION = ENV.fetch("HOMEBREW_OS_VERSION").freeze
# See Linux-CI.md
LINUX_CI_OS_VERSION = "Ubuntu 22.04"
LINUX_GLIBC_CI_VERSION = "2.35"
LINUX_GLIBC_NEXT_CI_VERSION = "2.35"
LINUX_GCC_CI_VERSION = "11.0"
LINUX_PREFERRED_GCC_COMPILER_FORMULA = "gcc@11" # https://packages.ubuntu.com/jammy/gcc
LINUX_PREFERRED_GCC_RUNTIME_FORMULA = "gcc"
if OS.mac?
require "os/mac"
require "hardware"
# Don't tell people to report issues on unsupported configurations.
if !OS::Mac.version.prerelease? &&
!OS::Mac.version.outdated_release? &&
ARGV.none? { |v| v.start_with?("--cc=") } &&
(HOMEBREW_PREFIX.to_s == HOMEBREW_DEFAULT_PREFIX ||
(HOMEBREW_PREFIX.to_s == HOMEBREW_MACOS_ARM_DEFAULT_PREFIX && Hardware::CPU.arm?))
ISSUES_URL = "https://docs.brew.sh/Troubleshooting"
end
PATH_OPEN = "/usr/bin/open"
elsif OS.linux?
require "os/linux"
ISSUES_URL = "https://docs.brew.sh/Troubleshooting"
PATH_OPEN = if OS::Linux.wsl? && (wslview = which("wslview").presence)
wslview.to_s
else
"xdg-open"
end.freeze
end
sig { returns(T::Boolean) }
def self.unsupported_configuration?
!defined?(OS::ISSUES_URL)
end
end