Skip to content

Commit

Permalink
Use top-level OS instead
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Sep 18, 2024
1 parent 3a57f77 commit 32a62e3
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 232 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/attestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.enabled?
return false if Homebrew::EnvConfig.no_verify_attestations?
return true if Homebrew::EnvConfig.verify_attestations?
return false if ENV.fetch("CI", false)
return false if ::OS.unsupported_configuration?
return false if OS.unsupported_configuration?

# Always check credentials last to avoid unnecessary credential extraction.
(Homebrew::EnvConfig.developer? || Homebrew::EnvConfig.devcmdrun?) && GitHub::API.credentials.present?
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ def formula_ignores(formula)
# On Linux, GCC installation can be moved so long as the whole directory tree is moved together:
# https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed.
when Version.formula_optionally_versioned_regex(:gcc)
Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if ::OS.linux?
Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if OS.linux?
# binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451.
when Version.formula_optionally_versioned_regex(:binutils)
%r{#{cellar_regex}/binutils} if ::OS.linux?
%r{#{cellar_regex}/binutils} if OS.linux?
end
# rubocop:enable Homebrew/MoveToExtendOS

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def run

# TODO: Refactor and move to extend/os
# rubocop:disable Homebrew/MoveToExtendOS
unless ::OS.mac?
unless OS.mac?
bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask"
files = files.grep_v(%r{^test/(os/mac|cask)(/.*|_spec\.rb)$})
end

unless ::OS.linux?
unless OS.linux?
bundle_args << "--tag" << "~needs_linux"
files = files.grep_v(%r{^test/os/linux(/.*|_spec\.rb)$})
end
Expand Down
34 changes: 16 additions & 18 deletions Library/Homebrew/extend/os/linux/cleanup.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module Linux
module Cleanup
extend T::Helpers
module OS
module Linux
module Cleanup
extend T::Helpers

requires_ancestor { Homebrew::Cleanup }
requires_ancestor { Homebrew::Cleanup }

sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?
sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?

rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact
system_ruby = Pathname.new("/usr/bin/ruby")
rubies << system_ruby if system_ruby.exist?
rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact
system_ruby = Pathname.new("/usr/bin/ruby")

Check warning on line 16 in Library/Homebrew/extend/os/linux/cleanup.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/cleanup.rb#L15-L16

Added lines #L15 - L16 were not covered by tests
rubies << system_ruby if system_ruby.exist?

check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb"
rubies.uniq.any? do |ruby|
quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt",
check_ruby_version, RUBY_VERSION
end
check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb"
rubies.uniq.any? do |ruby|
quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt",

Check warning on line 21 in Library/Homebrew/extend/os/linux/cleanup.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/cleanup.rb#L19-L21

Added lines #L19 - L21 were not covered by tests
check_ruby_version, RUBY_VERSION
end
end
end
end
end

Homebrew::Cleanup.prepend(Homebrew::OS::Linux::Cleanup)
Homebrew::Cleanup.prepend(OS::Linux::Cleanup)
38 changes: 18 additions & 20 deletions Library/Homebrew/extend/os/linux/cli/parser.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module Linux
module CLI
module Parser
extend T::Helpers
module OS
module Linux
module CLI
module Parser
extend T::Helpers

requires_ancestor { Homebrew::CLI::Parser }
requires_ancestor { Homebrew::CLI::Parser }

sig { void }
def set_default_options
args["formula?"] = true if args.respond_to?(:formula?)
end
sig { void }
def set_default_options
args["formula?"] = true if args.respond_to?(:formula?)
end

sig { void }
def validate_options
return unless args.respond_to?(:cask?)
return unless args.cask?
sig { void }
def validate_options
return unless args.respond_to?(:cask?)
return unless args.cask?

# NOTE: We don't raise an error here because we don't want
# to print the help page or a stack trace.
odie "Invalid `--cask` usage: Casks do not work on Linux"
end
# NOTE: We don't raise an error here because we don't want
# to print the help page or a stack trace.
odie "Invalid `--cask` usage: Casks do not work on Linux"
end
end
end
end
end

Homebrew::CLI::Parser.prepend(Homebrew::OS::Linux::CLI::Parser)
Homebrew::CLI::Parser.prepend(OS::Linux::CLI::Parser)
88 changes: 43 additions & 45 deletions Library/Homebrew/extend/os/linux/formula.rb
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# frozen_string_literal: true

module Homebrew
module OS
module Linux
module Formula
extend T::Helpers

requires_ancestor { ::Formula }

sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) }
def shared_library(name, version = nil)
suffix = if version == "*" || (name == "*" && version.blank?)
"{,.*}"
elsif version.present?
".#{version}"
end
"#{name}.so#{suffix}"
module OS
module Linux
module Formula
extend T::Helpers

requires_ancestor { ::Formula }

sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) }
def shared_library(name, version = nil)
suffix = if version == "*" || (name == "*" && version.blank?)
"{,.*}"
elsif version.present?
".#{version}"
end
"#{name}.so#{suffix}"
end

sig { returns(String) }
def loader_path
"$ORIGIN"
end
sig { returns(String) }
def loader_path
"$ORIGIN"

Check warning on line 23 in Library/Homebrew/extend/os/linux/formula.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/formula.rb#L23

Added line #L23 was not covered by tests
end

sig { params(targets: T.nilable(T.any(Pathname, String))).void }
def deuniversalize_machos(*targets); end

sig { params(spec: SoftwareSpec).void }
def add_global_deps_to_spec(spec)
return unless DevelopmentTools.needs_build_formulae?

@global_deps ||= begin
dependency_collector = spec.dependency_collector
related_formula_names = Set.new([
name,
*aliases,
*versioned_formulae_names,
])
[
dependency_collector.gcc_dep_if_needed(related_formula_names),
dependency_collector.glibc_dep_if_needed(related_formula_names),
].compact.freeze
end
@global_deps.each { |dep| spec.dependency_collector.add(dep) }
sig { params(targets: T.nilable(T.any(Pathname, String))).void }
def deuniversalize_machos(*targets); end

sig { params(spec: SoftwareSpec).void }
def add_global_deps_to_spec(spec)
return unless DevelopmentTools.needs_build_formulae?

@global_deps ||= begin
dependency_collector = spec.dependency_collector
related_formula_names = Set.new([

Check warning on line 35 in Library/Homebrew/extend/os/linux/formula.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/formula.rb#L33-L35

Added lines #L33 - L35 were not covered by tests
name,
*aliases,
*versioned_formulae_names,
])
[
dependency_collector.gcc_dep_if_needed(related_formula_names),

Check warning on line 41 in Library/Homebrew/extend/os/linux/formula.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/formula.rb#L41

Added line #L41 was not covered by tests
dependency_collector.glibc_dep_if_needed(related_formula_names),
].compact.freeze
end
@global_deps.each { |dep| spec.dependency_collector.add(dep) }

Check warning on line 45 in Library/Homebrew/extend/os/linux/formula.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/formula.rb#L45

Added line #L45 was not covered by tests
end

sig { returns(T::Boolean) }
def valid_platform?
requirements.none?(MacOSRequirement)
end
sig { returns(T::Boolean) }
def valid_platform?
requirements.none?(MacOSRequirement)
end
end
end
end

Formula.prepend(Homebrew::OS::Linux::Formula)
Formula.prepend(OS::Linux::Formula)
18 changes: 8 additions & 10 deletions Library/Homebrew/extend/os/mac/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module MacOS
module Cleaner
private
module OS
module Mac
module Cleaner
private

sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.mach_o_executable? || path.text_executable?
end
sig { params(path: Pathname).returns(T::Boolean) }
def executable_path?(path)
path.mach_o_executable? || path.text_executable?
end
end
end
end

Cleaner.prepend(Homebrew::OS::MacOS::Cleaner)
Cleaner.prepend(OS::Mac::Cleaner)
18 changes: 8 additions & 10 deletions Library/Homebrew/extend/os/mac/cleanup.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module MacOS
module Cleanup
sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?
module OS
module Mac
module Cleanup
sig { returns(T::Boolean) }
def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby?

Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present?
end
Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present?

Check warning on line 11 in Library/Homebrew/extend/os/mac/cleanup.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/mac/cleanup.rb#L11

Added line #L11 was not covered by tests
end
end
end
end

Homebrew::Cleanup.prepend(Homebrew::OS::MacOS::Cleanup)
Homebrew::Cleanup.prepend(OS::Mac::Cleanup)
32 changes: 15 additions & 17 deletions Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# typed: strict
# frozen_string_literal: true

module Homebrew
module OS
module MacOS
module DevCmd
module Bottle
sig { returns(T::Array[String]) }
def tar_args
if ::MacOS.version >= :catalina
["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze
else
[].freeze
end
module OS
module Mac
module DevCmd
module Bottle
sig { returns(T::Array[String]) }
def tar_args
if ::MacOS.version >= :catalina

Check warning on line 10 in Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb#L10

Added line #L10 was not covered by tests
["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze
else
[].freeze
end
end

sig { params(gnu_tar_formula: Formula).returns(String) }
def gnu_tar(gnu_tar_formula)
"#{gnu_tar_formula.opt_bin}/gtar"
end
sig { params(gnu_tar_formula: Formula).returns(String) }
def gnu_tar(gnu_tar_formula)
"#{gnu_tar_formula.opt_bin}/gtar"

Check warning on line 19 in Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb#L19

Added line #L19 was not covered by tests
end
end
end
end
end

Homebrew::DevCmd::Bottle.prepend(Homebrew::OS::MacOS::DevCmd::Bottle)
Homebrew::DevCmd::Bottle.prepend(OS::Mac::DevCmd::Bottle)
Loading

0 comments on commit 32a62e3

Please sign in to comment.