Merge pull request #13451 from Rylan12/cask-on-condition
Add `on_{system}` blocks to formula and cask DSL
This commit is contained in:
commit
74e933caa3
@ -6,6 +6,7 @@ require "cask/config"
|
|||||||
require "cask/dsl"
|
require "cask/dsl"
|
||||||
require "cask/metadata"
|
require "cask/metadata"
|
||||||
require "searchable"
|
require "searchable"
|
||||||
|
require "utils/bottles"
|
||||||
|
|
||||||
module Cask
|
module Cask
|
||||||
# An instance of a cask.
|
# An instance of a cask.
|
||||||
@ -58,6 +59,10 @@ module Cask
|
|||||||
def config=(config)
|
def config=(config)
|
||||||
@config = config
|
@config = config
|
||||||
|
|
||||||
|
refresh
|
||||||
|
end
|
||||||
|
|
||||||
|
def refresh
|
||||||
@dsl = DSL.new(self)
|
@dsl = DSL.new(self)
|
||||||
return unless @block
|
return unless @block
|
||||||
|
|
||||||
@ -89,7 +94,7 @@ module Cask
|
|||||||
version_os_hash = {}
|
version_os_hash = {}
|
||||||
actual_version = MacOS.full_version.to_s
|
actual_version = MacOS.full_version.to_s
|
||||||
|
|
||||||
MacOS::Version::SYMBOLS.each do |os_name, os_version|
|
MacOSVersions::SYMBOLS.each do |os_name, os_version|
|
||||||
MacOS.full_version = os_version
|
MacOS.full_version = os_version
|
||||||
cask = CaskLoader.load(token)
|
cask = CaskLoader.load(token)
|
||||||
version_os_hash[os_name] = cask.version if cask.version != version
|
version_os_hash[os_name] = cask.version if cask.version != version
|
||||||
@ -214,7 +219,7 @@ module Cask
|
|||||||
end
|
end
|
||||||
alias == eql?
|
alias == eql?
|
||||||
|
|
||||||
def to_h
|
def to_hash
|
||||||
{
|
{
|
||||||
"token" => token,
|
"token" => token,
|
||||||
"full_token" => full_name,
|
"full_token" => full_name,
|
||||||
@ -238,6 +243,42 @@ module Cask
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_h
|
||||||
|
hash = to_hash
|
||||||
|
variations = {}
|
||||||
|
|
||||||
|
hash_keys_to_skip = %w[outdated installed versions]
|
||||||
|
|
||||||
|
if @dsl.on_system_blocks_exist?
|
||||||
|
[:arm, :intel].each do |arch|
|
||||||
|
MacOSVersions::SYMBOLS.each_key do |os_name|
|
||||||
|
# Big Sur is the first version of macOS that supports arm
|
||||||
|
next if arch == :arm && MacOS::Version.from_symbol(os_name) < MacOS::Version.from_symbol(:big_sur)
|
||||||
|
|
||||||
|
Homebrew::SimulateSystem.os = os_name
|
||||||
|
Homebrew::SimulateSystem.arch = arch
|
||||||
|
|
||||||
|
refresh
|
||||||
|
|
||||||
|
bottle_tag = ::Utils::Bottles::Tag.new(system: os_name, arch: arch).to_sym
|
||||||
|
to_hash.each do |key, value|
|
||||||
|
next if hash_keys_to_skip.include? key
|
||||||
|
next if value.to_s == hash[key].to_s
|
||||||
|
|
||||||
|
variations[bottle_tag] ||= {}
|
||||||
|
variations[bottle_tag][key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Homebrew::SimulateSystem.clear
|
||||||
|
refresh
|
||||||
|
|
||||||
|
hash["variations"] = variations
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def to_h_string_gsubs(string)
|
def to_h_string_gsubs(string)
|
||||||
|
|||||||
@ -25,6 +25,8 @@ require "cask/dsl/version"
|
|||||||
require "cask/url"
|
require "cask/url"
|
||||||
require "cask/utils"
|
require "cask/utils"
|
||||||
|
|
||||||
|
require "extend/on_system"
|
||||||
|
|
||||||
module Cask
|
module Cask
|
||||||
# Class representing the domain-specific language used for casks.
|
# Class representing the domain-specific language used for casks.
|
||||||
#
|
#
|
||||||
@ -89,8 +91,13 @@ module Cask
|
|||||||
*ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] },
|
*ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] },
|
||||||
]).freeze
|
]).freeze
|
||||||
|
|
||||||
|
extend Predicable
|
||||||
|
include OnSystem
|
||||||
|
|
||||||
attr_reader :cask, :token
|
attr_reader :cask, :token
|
||||||
|
|
||||||
|
attr_predicate :on_system_blocks_exist?
|
||||||
|
|
||||||
def initialize(cask)
|
def initialize(cask)
|
||||||
@cask = cask
|
@cask = cask
|
||||||
@token = cask.token
|
@token = cask.token
|
||||||
@ -112,10 +119,17 @@ module Cask
|
|||||||
def set_unique_stanza(stanza, should_return)
|
def set_unique_stanza(stanza, should_return)
|
||||||
return instance_variable_get("@#{stanza}") if should_return
|
return instance_variable_get("@#{stanza}") if should_return
|
||||||
|
|
||||||
if !@cask.allow_reassignment && instance_variable_defined?("@#{stanza}")
|
unless @cask.allow_reassignment
|
||||||
raise CaskInvalidError.new(cask, "'#{stanza}' stanza may only appear once.")
|
if instance_variable_defined?("@#{stanza}") && !@called_in_on_system_block
|
||||||
|
raise CaskInvalidError.new(cask, "'#{stanza}' stanza may only appear once.")
|
||||||
|
end
|
||||||
|
|
||||||
|
if instance_variable_defined?("@#{stanza}_set_in_block") && @called_in_on_system_block
|
||||||
|
raise CaskInvalidError.new(cask, "'#{stanza}' stanza may only be overridden once.")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
instance_variable_set("@#{stanza}_set_in_block", true) if @called_in_on_system_block
|
||||||
instance_variable_set("@#{stanza}", yield)
|
instance_variable_set("@#{stanza}", yield)
|
||||||
rescue CaskInvalidError
|
rescue CaskInvalidError
|
||||||
raise
|
raise
|
||||||
|
|||||||
@ -55,7 +55,7 @@ module Cask
|
|||||||
begin
|
begin
|
||||||
@macos = if args.count > 1
|
@macos = if args.count > 1
|
||||||
MacOSRequirement.new([args], comparator: "==")
|
MacOSRequirement.new([args], comparator: "==")
|
||||||
elsif MacOS::Version::SYMBOLS.key?(args.first)
|
elsif MacOSVersions::SYMBOLS.key?(args.first)
|
||||||
MacOSRequirement.new([args.first], comparator: "==")
|
MacOSRequirement.new([args.first], comparator: "==")
|
||||||
elsif /^\s*(?<comparator><|>|[=<>]=)\s*:(?<version>\S+)\s*$/ =~ args.first
|
elsif /^\s*(?<comparator><|>|[=<>]=)\s*:(?<version>\S+)\s*$/ =~ args.first
|
||||||
MacOSRequirement.new([version.to_sym], comparator: comparator)
|
MacOSRequirement.new([version.to_sym], comparator: comparator)
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module OnOS
|
|
||||||
extend T::Sig
|
|
||||||
|
|
||||||
# Block only executed on macOS. No-op on Linux.
|
|
||||||
# <pre>on_macos do
|
|
||||||
# # Do something Mac-specific
|
|
||||||
# end</pre>
|
|
||||||
sig { params(block: T.proc.void).void }
|
|
||||||
def on_macos(&block)
|
|
||||||
raise "No block content defined for 'on_macos' block" unless T.unsafe(block)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Block only executed on Linux. No-op on macOS.
|
|
||||||
# <pre>on_linux do
|
|
||||||
# # Do something Linux-specific
|
|
||||||
# end</pre>
|
|
||||||
sig { params(block: T.proc.void).void }
|
|
||||||
def on_linux(&block)
|
|
||||||
raise "No block content defined for 'on_linux' block" unless T.unsafe(block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
require "extend/os/on_os"
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module OnOS
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
103
Library/Homebrew/extend/on_system.rb
Normal file
103
Library/Homebrew/extend/on_system.rb
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "simulate_system"
|
||||||
|
|
||||||
|
module OnSystem
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
|
ARCH_OPTIONS = [:intel, :arm].freeze
|
||||||
|
BASE_OS_OPTIONS = [:macos, :linux].freeze
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
|
sig { params(arch: Symbol).returns(T::Boolean) }
|
||||||
|
def arch_condition_met?(arch)
|
||||||
|
raise ArgumentError, "Invalid arch condition: #{arch.inspect}" if ARCH_OPTIONS.exclude?(arch)
|
||||||
|
|
||||||
|
current_arch = Homebrew::SimulateSystem.arch || Hardware::CPU.type
|
||||||
|
arch == current_arch
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(os_name: Symbol, or_condition: T.nilable(Symbol)).returns(T::Boolean) }
|
||||||
|
def os_condition_met?(os_name, or_condition = nil)
|
||||||
|
if Homebrew::EnvConfig.simulate_macos_on_linux?
|
||||||
|
return false if os_name == :linux
|
||||||
|
return true if [:macos, *MacOSVersions::SYMBOLS.keys].include?(os_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
if BASE_OS_OPTIONS.include?(os_name)
|
||||||
|
if Homebrew::SimulateSystem.none?
|
||||||
|
return OS.linux? if os_name == :linux
|
||||||
|
return OS.mac? if os_name == :macos
|
||||||
|
end
|
||||||
|
|
||||||
|
return Homebrew::SimulateSystem.send("#{os_name}?")
|
||||||
|
end
|
||||||
|
|
||||||
|
raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name)
|
||||||
|
|
||||||
|
if or_condition.present? && [:or_newer, :or_older].exclude?(or_condition)
|
||||||
|
raise ArgumentError, "Invalid OS `or_*` condition: #{or_condition.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
base_os = MacOS::Version.from_symbol(os_name)
|
||||||
|
current_os = MacOS::Version.from_symbol(Homebrew::SimulateSystem.os || MacOS.version.to_sym)
|
||||||
|
|
||||||
|
return current_os >= base_os if or_condition == :or_newer
|
||||||
|
return current_os <= base_os if or_condition == :or_older
|
||||||
|
|
||||||
|
current_os == base_os
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(method_name: Symbol).returns(Symbol) }
|
||||||
|
def condition_from_method_name(method_name)
|
||||||
|
method_name.to_s.sub(/^on_/, "").to_sym
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(base: Class).void }
|
||||||
|
def self.included(base)
|
||||||
|
ARCH_OPTIONS.each do |arch|
|
||||||
|
base.define_method("on_#{arch}") do |&block|
|
||||||
|
@on_system_blocks_exist = true
|
||||||
|
|
||||||
|
return unless OnSystem.arch_condition_met? OnSystem.condition_from_method_name(__method__)
|
||||||
|
|
||||||
|
@called_in_on_system_block = true
|
||||||
|
result = block.call
|
||||||
|
@called_in_on_system_block = false
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
BASE_OS_OPTIONS.each do |base_os|
|
||||||
|
base.define_method("on_#{base_os}") do |&block|
|
||||||
|
@on_system_blocks_exist = true
|
||||||
|
|
||||||
|
return unless OnSystem.os_condition_met? OnSystem.condition_from_method_name(__method__)
|
||||||
|
|
||||||
|
@called_in_on_system_block = true
|
||||||
|
result = block.call
|
||||||
|
@called_in_on_system_block = false
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
MacOSVersions::SYMBOLS.each_key do |os_name|
|
||||||
|
base.define_method("on_#{os_name}") do |or_condition = nil, &block|
|
||||||
|
@on_system_blocks_exist = true
|
||||||
|
|
||||||
|
os_condition = OnSystem.condition_from_method_name __method__
|
||||||
|
return unless OnSystem.os_condition_met? os_condition, or_condition
|
||||||
|
|
||||||
|
@called_in_on_system_block = true
|
||||||
|
result = block.call
|
||||||
|
@called_in_on_system_block = false
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,10 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module OnOS
|
|
||||||
def on_linux(&block)
|
|
||||||
raise "No block content defined for 'on_linux' block" unless T.unsafe(block)
|
|
||||||
|
|
||||||
yield
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module OnOS
|
|
||||||
def on_macos(&block)
|
|
||||||
raise "No block content defined for 'on_macos' block" unless T.unsafe(block)
|
|
||||||
|
|
||||||
yield
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
if OS.mac? || Homebrew::EnvConfig.simulate_macos_on_linux?
|
|
||||||
require "extend/os/mac/on_os"
|
|
||||||
elsif OS.linux?
|
|
||||||
require "extend/os/linux/on_os"
|
|
||||||
end
|
|
||||||
@ -28,7 +28,7 @@ require "tab"
|
|||||||
require "mktemp"
|
require "mktemp"
|
||||||
require "find"
|
require "find"
|
||||||
require "utils/spdx"
|
require "utils/spdx"
|
||||||
require "extend/on_os"
|
require "extend/on_system"
|
||||||
require "api"
|
require "api"
|
||||||
|
|
||||||
# A formula provides instructions and metadata for Homebrew to install a piece
|
# A formula provides instructions and metadata for Homebrew to install a piece
|
||||||
@ -64,7 +64,7 @@ class Formula
|
|||||||
include Utils::Shebang
|
include Utils::Shebang
|
||||||
include Utils::Shell
|
include Utils::Shell
|
||||||
include Context
|
include Context
|
||||||
include OnOS
|
include OnSystem
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
extend Cachable
|
extend Cachable
|
||||||
extend Predicable
|
extend Predicable
|
||||||
@ -2470,7 +2470,7 @@ class Formula
|
|||||||
# The methods below define the formula DSL.
|
# The methods below define the formula DSL.
|
||||||
class << self
|
class << self
|
||||||
include BuildEnvironment::DSL
|
include BuildEnvironment::DSL
|
||||||
include OnOS
|
include OnSystem
|
||||||
|
|
||||||
def method_added(method)
|
def method_added(method)
|
||||||
super
|
super
|
||||||
|
|||||||
@ -48,4 +48,7 @@ class Formula
|
|||||||
|
|
||||||
def env; end
|
def env; end
|
||||||
def conflicts; end
|
def conflicts; end
|
||||||
|
|
||||||
|
# This method is included by `OnSystem`
|
||||||
|
def self.on_macos(&block); end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -72,6 +72,7 @@ HOMEBREW_BOTTLES_EXTNAME_REGEX = /\.([a-z0-9_]+)\.bottle\.(?:(\d+)\.)?tar\.gz$/.
|
|||||||
|
|
||||||
require "env_config"
|
require "env_config"
|
||||||
require "compat/early" unless Homebrew::EnvConfig.no_compat?
|
require "compat/early" unless Homebrew::EnvConfig.no_compat?
|
||||||
|
require "macos_versions"
|
||||||
require "os"
|
require "os"
|
||||||
require "messages"
|
require "messages"
|
||||||
require "default_prefix"
|
require "default_prefix"
|
||||||
|
|||||||
20
Library/Homebrew/macos_versions.rb
Normal file
20
Library/Homebrew/macos_versions.rb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# typed: true
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Helper functions for querying operating system information.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
module MacOSVersions
|
||||||
|
# TODO: when removing symbols here, ensure that they are added to
|
||||||
|
# DEPRECATED_MACOS_VERSIONS in MacOSRequirement.
|
||||||
|
SYMBOLS = {
|
||||||
|
ventura: "13",
|
||||||
|
monterey: "12",
|
||||||
|
big_sur: "11",
|
||||||
|
catalina: "10.15",
|
||||||
|
mojave: "10.14",
|
||||||
|
high_sierra: "10.13",
|
||||||
|
sierra: "10.12",
|
||||||
|
el_capitan: "10.11",
|
||||||
|
}.freeze
|
||||||
|
end
|
||||||
@ -31,11 +31,7 @@ module OS
|
|||||||
module Mac
|
module Mac
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# rubocop:disable Naming/ConstantName
|
|
||||||
# rubocop:disable Style/MutableConstant
|
|
||||||
::MacOS = OS::Mac
|
::MacOS = OS::Mac
|
||||||
# rubocop:enable Naming/ConstantName
|
|
||||||
# rubocop:enable Style/MutableConstant
|
|
||||||
|
|
||||||
raise "Loaded OS::Linux on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
raise "Loaded OS::Linux on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
||||||
|
|
||||||
|
|||||||
@ -13,11 +13,7 @@ module OS
|
|||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
# rubocop:disable Naming/ConstantName
|
|
||||||
# rubocop:disable Style/MutableConstant
|
|
||||||
::MacOS = OS::Mac
|
::MacOS = OS::Mac
|
||||||
# rubocop:enable Naming/ConstantName
|
|
||||||
# rubocop:enable Style/MutableConstant
|
|
||||||
|
|
||||||
raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
||||||
|
|
||||||
|
|||||||
@ -13,22 +13,10 @@ module OS
|
|||||||
class Version < ::Version
|
class Version < ::Version
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
# TODO: when removing symbols here, ensure that they are added to
|
|
||||||
# DEPRECATED_MACOS_VERSIONS in MacOSRequirement.
|
|
||||||
SYMBOLS = {
|
|
||||||
ventura: "13",
|
|
||||||
monterey: "12",
|
|
||||||
big_sur: "11",
|
|
||||||
catalina: "10.15",
|
|
||||||
mojave: "10.14",
|
|
||||||
high_sierra: "10.13",
|
|
||||||
sierra: "10.12",
|
|
||||||
el_capitan: "10.11",
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
# TODO: bump version when new macOS is released or announced
|
# TODO: bump version when new macOS is released or announced
|
||||||
# and also update references in docs/Installation.md and
|
# and also update references in docs/Installation.md,
|
||||||
# https://github.com/Homebrew/install/blob/HEAD/install.sh
|
# https://github.com/Homebrew/install/blob/HEAD/install.sh and
|
||||||
|
# MacOSVersions::SYMBOLS
|
||||||
NEWEST_UNSUPPORTED = "13"
|
NEWEST_UNSUPPORTED = "13"
|
||||||
private_constant :NEWEST_UNSUPPORTED
|
private_constant :NEWEST_UNSUPPORTED
|
||||||
|
|
||||||
@ -42,7 +30,7 @@ module OS
|
|||||||
|
|
||||||
sig { params(version: Symbol).returns(T.attached_class) }
|
sig { params(version: Symbol).returns(T.attached_class) }
|
||||||
def self.from_symbol(version)
|
def self.from_symbol(version)
|
||||||
str = SYMBOLS.fetch(version) { raise MacOSVersionError, version }
|
str = MacOSVersions::SYMBOLS.fetch(version) { raise MacOSVersionError, version }
|
||||||
new(str)
|
new(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,10 +48,10 @@ module OS
|
|||||||
sig { override.params(other: T.untyped).returns(T.nilable(Integer)) }
|
sig { override.params(other: T.untyped).returns(T.nilable(Integer)) }
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
@comparison_cache.fetch(other) do
|
@comparison_cache.fetch(other) do
|
||||||
if SYMBOLS.key?(other) && to_sym == other
|
if MacOSVersions::SYMBOLS.key?(other) && to_sym == other
|
||||||
0
|
0
|
||||||
else
|
else
|
||||||
v = SYMBOLS.fetch(other) { other.to_s }
|
v = MacOSVersions::SYMBOLS.fetch(other) { other.to_s }
|
||||||
@comparison_cache[other] = super(::Version.new(v))
|
@comparison_cache[other] = super(::Version.new(v))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -81,7 +69,7 @@ module OS
|
|||||||
|
|
||||||
sig { returns(Symbol) }
|
sig { returns(Symbol) }
|
||||||
def to_sym
|
def to_sym
|
||||||
@to_sym ||= SYMBOLS.invert.fetch(strip_patch.to_s, :dunno)
|
@to_sym ||= MacOSVersions::SYMBOLS.invert.fetch(strip_patch.to_s, :dunno)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
|
|||||||
@ -5,7 +5,7 @@ require "download_strategy"
|
|||||||
require "checksum"
|
require "checksum"
|
||||||
require "version"
|
require "version"
|
||||||
require "mktemp"
|
require "mktemp"
|
||||||
require "extend/on_os"
|
require "extend/on_system"
|
||||||
|
|
||||||
# Resource is the fundamental representation of an external resource. The
|
# Resource is the fundamental representation of an external resource. The
|
||||||
# primary formula download, along with other declared resources, are instances
|
# primary formula download, along with other declared resources, are instances
|
||||||
@ -17,7 +17,7 @@ class Resource
|
|||||||
|
|
||||||
include Context
|
include Context
|
||||||
include FileUtils
|
include FileUtils
|
||||||
include OnOS
|
include OnSystem
|
||||||
|
|
||||||
attr_reader :mirrors, :specs, :using, :source_modified_time, :patches, :owner
|
attr_reader :mirrors, :specs, :using, :source_modified_time, :patches, :owner
|
||||||
attr_writer :version
|
attr_writer :version
|
||||||
|
|||||||
50
Library/Homebrew/simulate_system.rb
Normal file
50
Library/Homebrew/simulate_system.rb
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# typed: true
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Homebrew
|
||||||
|
# Helper module for simulating different system condfigurations.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
class SimulateSystem
|
||||||
|
class << self
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
|
attr_reader :os, :arch
|
||||||
|
|
||||||
|
sig { params(new_os: Symbol).void }
|
||||||
|
def os=(new_os)
|
||||||
|
os_options = [:macos, :linux, *MacOSVersions::SYMBOLS.keys]
|
||||||
|
raise "Unknown OS: #{new_os}" unless os_options.include?(new_os)
|
||||||
|
|
||||||
|
@os = new_os
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(new_arch: Symbol).void }
|
||||||
|
def arch=(new_arch)
|
||||||
|
raise "New arch must be :arm or :intel" unless [:arm, :intel].include?(new_arch)
|
||||||
|
|
||||||
|
@arch = new_arch
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
|
def clear
|
||||||
|
@os = @arch = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def none?
|
||||||
|
@os.nil? && @arch.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def macos?
|
||||||
|
[:macos, *MacOSVersions::SYMBOLS.keys].include?(@os)
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def linux?
|
||||||
|
@os == :linux
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -12,13 +12,13 @@ require "utils/bottles"
|
|||||||
require "patch"
|
require "patch"
|
||||||
require "compilers"
|
require "compilers"
|
||||||
require "os/mac/version"
|
require "os/mac/version"
|
||||||
require "extend/on_os"
|
require "extend/on_system"
|
||||||
|
|
||||||
class SoftwareSpec
|
class SoftwareSpec
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
include OnOS
|
include OnSystem
|
||||||
|
|
||||||
PREDEFINED_OPTIONS = {
|
PREDEFINED_OPTIONS = {
|
||||||
universal: Option.new("universal", "Build a universal binary"),
|
universal: Option.new("universal", "Build a universal binary"),
|
||||||
@ -583,7 +583,7 @@ class BottleSpecification
|
|||||||
end
|
end
|
||||||
|
|
||||||
class PourBottleCheck
|
class PourBottleCheck
|
||||||
include OnOS
|
include OnSystem
|
||||||
|
|
||||||
def initialize(formula)
|
def initialize(formula)
|
||||||
@formula = formula
|
@formula = formula
|
||||||
|
|||||||
@ -120,7 +120,9 @@ describe Cask::Cmd::List, :cask do
|
|||||||
},
|
},
|
||||||
"conflicts_with": null,
|
"conflicts_with": null,
|
||||||
"container": null,
|
"container": null,
|
||||||
"auto_updates": null
|
"auto_updates": null,
|
||||||
|
"variations": {
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "local-transmission",
|
"token": "local-transmission",
|
||||||
@ -149,7 +151,9 @@ describe Cask::Cmd::List, :cask do
|
|||||||
},
|
},
|
||||||
"conflicts_with": null,
|
"conflicts_with": null,
|
||||||
"container": null,
|
"container": null,
|
||||||
"auto_updates": null
|
"auto_updates": null,
|
||||||
|
"variations": {
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "multiple-versions",
|
"token": "multiple-versions",
|
||||||
@ -160,11 +164,13 @@ describe Cask::Cmd::List, :cask do
|
|||||||
],
|
],
|
||||||
"desc": null,
|
"desc": null,
|
||||||
"homepage": "https://brew.sh/",
|
"homepage": "https://brew.sh/",
|
||||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip",
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.3/arm.zip",
|
||||||
"appcast": null,
|
"appcast": null,
|
||||||
"version": "1.2.3",
|
"version": "1.2.3",
|
||||||
"versions": {
|
"versions": {
|
||||||
"test_os": "1.2.0"
|
"big_sur": "1.2.0",
|
||||||
|
"catalina": "1.0.0",
|
||||||
|
"mojave": "1.0.0"
|
||||||
},
|
},
|
||||||
"installed": "1.2.3",
|
"installed": "1.2.3",
|
||||||
"outdated": false,
|
"outdated": false,
|
||||||
@ -179,7 +185,32 @@ describe Cask::Cmd::List, :cask do
|
|||||||
},
|
},
|
||||||
"conflicts_with": null,
|
"conflicts_with": null,
|
||||||
"container": null,
|
"container": null,
|
||||||
"auto_updates": null
|
"auto_updates": null,
|
||||||
|
"variations": {
|
||||||
|
"arm_big_sur": {
|
||||||
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/arm.zip",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
|
},
|
||||||
|
"intel_monterey": {
|
||||||
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.3/intel.zip"
|
||||||
|
},
|
||||||
|
"intel_big_sur": {
|
||||||
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/intel.zip",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
|
},
|
||||||
|
"intel_catalina": {
|
||||||
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
|
||||||
|
},
|
||||||
|
"intel_mojave": {
|
||||||
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "third-party-cask",
|
"token": "third-party-cask",
|
||||||
@ -208,19 +239,34 @@ describe Cask::Cmd::List, :cask do
|
|||||||
},
|
},
|
||||||
"conflicts_with": null,
|
"conflicts_with": null,
|
||||||
"container": null,
|
"container": null,
|
||||||
"auto_updates": null
|
"auto_updates": null,
|
||||||
|
"variations": {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
let(:original_macos_version) { MacOS.full_version.to_s }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
casks.map(&Cask::CaskLoader.method(:load)).each(&InstallHelper.method(:install_with_caskfile))
|
# Use a more limited symbols list to shorten the variations hash
|
||||||
|
symbols = {
|
||||||
|
monterey: "12",
|
||||||
|
big_sur: "11",
|
||||||
|
catalina: "10.15",
|
||||||
|
mojave: "10.14",
|
||||||
|
}
|
||||||
|
stub_const("MacOSVersions::SYMBOLS", symbols)
|
||||||
|
|
||||||
# Add a test OS to ensure that all cask versions are listed regardless of OS.
|
# For consistency, always run on Monterey and ARM
|
||||||
symbols = MacOS::Version::SYMBOLS.dup
|
MacOS.full_version = "12"
|
||||||
symbols[:test_os] = "10.9"
|
allow(Hardware::CPU).to receive(:type).and_return(:arm)
|
||||||
stub_const("MacOS::Version::SYMBOLS", symbols)
|
|
||||||
|
casks.map(&Cask::CaskLoader.method(:load)).each(&InstallHelper.method(:install_with_caskfile))
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
MacOS.full_version = original_macos_version
|
||||||
end
|
end
|
||||||
|
|
||||||
it "of all installed Casks" do
|
it "of all installed Casks" do
|
||||||
|
|||||||
@ -1580,4 +1580,117 @@ describe Formula do
|
|||||||
expect(f.test).to eq(2)
|
expect(f.test).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "on_{os_version} blocks", :needs_macos do
|
||||||
|
before do
|
||||||
|
Homebrew::SimulateSystem.os = :monterey
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
Homebrew::SimulateSystem.clear
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:f) do
|
||||||
|
Class.new(Testball) do
|
||||||
|
@test = 0
|
||||||
|
attr_reader :test
|
||||||
|
|
||||||
|
def install
|
||||||
|
on_monterey :or_newer do
|
||||||
|
@test = 1
|
||||||
|
end
|
||||||
|
on_big_sur do
|
||||||
|
@test = 2
|
||||||
|
end
|
||||||
|
on_catalina :or_older do
|
||||||
|
@test = 3
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end.new
|
||||||
|
end
|
||||||
|
|
||||||
|
it "only calls code within `on_monterey`" do
|
||||||
|
Homebrew::SimulateSystem.os = :monterey
|
||||||
|
f.brew { f.install }
|
||||||
|
expect(f.test).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "only calls code within `on_monterey :or_newer`" do
|
||||||
|
Homebrew::SimulateSystem.os = :ventura
|
||||||
|
f.brew { f.install }
|
||||||
|
expect(f.test).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "only calls code within `on_big_sur`" do
|
||||||
|
Homebrew::SimulateSystem.os = :big_sur
|
||||||
|
f.brew { f.install }
|
||||||
|
expect(f.test).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "only calls code within `on_catalina`" do
|
||||||
|
Homebrew::SimulateSystem.os = :catalina
|
||||||
|
f.brew { f.install }
|
||||||
|
expect(f.test).to eq(3)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "only calls code within `on_catalina :or_older`" do
|
||||||
|
Homebrew::SimulateSystem.os = :mojave
|
||||||
|
f.brew { f.install }
|
||||||
|
expect(f.test).to eq(3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#on_arm" do
|
||||||
|
before do
|
||||||
|
allow(Hardware::CPU).to receive(:type).and_return(:arm)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:f) do
|
||||||
|
Class.new(Testball) do
|
||||||
|
@test = 0
|
||||||
|
attr_reader :test
|
||||||
|
|
||||||
|
def install
|
||||||
|
on_arm do
|
||||||
|
@test = 1
|
||||||
|
end
|
||||||
|
on_intel do
|
||||||
|
@test = 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end.new
|
||||||
|
end
|
||||||
|
|
||||||
|
it "only calls code within on_arm" do
|
||||||
|
f.brew { f.install }
|
||||||
|
expect(f.test).to eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#on_intel" do
|
||||||
|
before do
|
||||||
|
allow(Hardware::CPU).to receive(:type).and_return(:intel)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:f) do
|
||||||
|
Class.new(Testball) do
|
||||||
|
@test = 0
|
||||||
|
attr_reader :test
|
||||||
|
|
||||||
|
def install
|
||||||
|
on_arm do
|
||||||
|
@test = 1
|
||||||
|
end
|
||||||
|
on_intel do
|
||||||
|
@test = 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end.new
|
||||||
|
end
|
||||||
|
|
||||||
|
it "only calls code within on_intel" do
|
||||||
|
f.brew { f.install }
|
||||||
|
expect(f.test).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,12 +1,23 @@
|
|||||||
cask "multiple-versions" do
|
cask "multiple-versions" do
|
||||||
if MacOS.version == :test_os
|
arch = "arm"
|
||||||
version "1.2.0"
|
version "1.2.3"
|
||||||
else
|
|
||||||
version "1.2.3"
|
|
||||||
end
|
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
|
||||||
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
|
on_intel do
|
||||||
|
arch = "intel"
|
||||||
|
end
|
||||||
|
|
||||||
|
on_big_sur do
|
||||||
|
version "1.2.0"
|
||||||
|
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
|
end
|
||||||
|
|
||||||
|
on_catalina :or_older do
|
||||||
|
version "1.0.0"
|
||||||
|
sha256 "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
|
||||||
|
end
|
||||||
|
|
||||||
|
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine/#{version}/#{arch}.zip"
|
||||||
homepage "https://brew.sh/"
|
homepage "https://brew.sh/"
|
||||||
|
|
||||||
app "Caffeine.app"
|
app "Caffeine.app"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user