mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Add SimulateSystem::with
.
This commit is contained in:
parent
b0dc84b117
commit
0d56b97b07
@ -313,16 +313,13 @@ module Cask
|
||||
|
||||
hash_keys_to_skip = %w[outdated installed versions]
|
||||
|
||||
begin
|
||||
if @dsl.on_system_blocks_exist?
|
||||
[:arm, :intel].each do |arch|
|
||||
MacOSVersion::SYMBOLS.each_key do |os_name|
|
||||
bottle_tag = ::Utils::Bottles::Tag.new(system: os_name, arch: arch)
|
||||
next unless bottle_tag.valid_combination?
|
||||
|
||||
Homebrew::SimulateSystem.os = os_name
|
||||
Homebrew::SimulateSystem.arch = arch
|
||||
if @dsl.on_system_blocks_exist?
|
||||
begin
|
||||
MacOSVersion::SYMBOLS.keys.product(OnSystem::ARCH_OPTIONS).each do |os, arch|
|
||||
bottle_tag = ::Utils::Bottles::Tag.new(system: os, arch: arch)
|
||||
next unless bottle_tag.valid_combination?
|
||||
|
||||
Homebrew::SimulateSystem.with os: os, arch: arch do
|
||||
refresh
|
||||
|
||||
to_h.each do |key, value|
|
||||
@ -334,13 +331,11 @@ module Cask
|
||||
end
|
||||
end
|
||||
end
|
||||
ensure
|
||||
refresh
|
||||
end
|
||||
ensure
|
||||
Homebrew::SimulateSystem.clear
|
||||
end
|
||||
|
||||
refresh
|
||||
|
||||
hash["variations"] = variations
|
||||
hash
|
||||
end
|
||||
|
@ -148,30 +148,28 @@ module Homebrew
|
||||
tmp_cask = Cask::CaskLoader.load(tmp_contents)
|
||||
tmp_config = tmp_cask.config
|
||||
|
||||
[:arm, :intel].each do |arch|
|
||||
Homebrew::SimulateSystem.arch = arch
|
||||
OnSystem::ARCH_OPTIONS.each do |arch|
|
||||
SimulateSystem.with arch: arch do
|
||||
languages = cask.languages
|
||||
languages = [nil] if languages.empty?
|
||||
languages.each do |language|
|
||||
new_hash_config = if language.blank?
|
||||
tmp_config
|
||||
else
|
||||
tmp_config.merge(Cask::Config.new(explicit: { languages: [language] }))
|
||||
end
|
||||
|
||||
languages = cask.languages
|
||||
languages = [nil] if languages.empty?
|
||||
languages.each do |language|
|
||||
new_hash_config = if language.blank?
|
||||
tmp_config
|
||||
else
|
||||
tmp_config.merge(Cask::Config.new(explicit: { languages: [language] }))
|
||||
new_hash_cask = Cask::CaskLoader.load(tmp_contents)
|
||||
new_hash_cask.config = new_hash_config
|
||||
old_hash = new_hash_cask.sha256.to_s
|
||||
|
||||
cask_download = Cask::Download.new(new_hash_cask, quarantine: true)
|
||||
download = cask_download.fetch(verify_download_integrity: false)
|
||||
Utils::Tar.validate_file(download)
|
||||
|
||||
replacement_pairs << [new_hash_cask.sha256.to_s, download.sha256]
|
||||
end
|
||||
|
||||
new_hash_cask = Cask::CaskLoader.load(tmp_contents)
|
||||
new_hash_cask.config = new_hash_config
|
||||
old_hash = new_hash_cask.sha256.to_s
|
||||
|
||||
cask_download = Cask::Download.new(new_hash_cask, quarantine: true)
|
||||
download = cask_download.fetch(verify_download_integrity: false)
|
||||
Utils::Tar.validate_file(download)
|
||||
|
||||
replacement_pairs << [new_hash_cask.sha256.to_s, download.sha256]
|
||||
end
|
||||
ensure
|
||||
Homebrew::SimulateSystem.clear
|
||||
end
|
||||
elsif new_hash
|
||||
opoo "Cask contains multiple hashes; only updating hash for current arch." if cask.on_system_blocks_exist?
|
||||
|
@ -43,8 +43,8 @@ module Homebrew
|
||||
Utils::Bottles.tag
|
||||
end
|
||||
|
||||
Homebrew::SimulateSystem.os = @bottle_tag.system
|
||||
Homebrew::SimulateSystem.arch = if Hardware::CPU::INTEL_ARCHS.include?(@bottle_tag.arch)
|
||||
os = @bottle_tag.system
|
||||
arch = if Hardware::CPU::INTEL_ARCHS.include?(@bottle_tag.arch)
|
||||
:intel
|
||||
elsif Hardware::CPU::ARM_ARCHS.include?(@bottle_tag.arch)
|
||||
:arm
|
||||
@ -52,46 +52,46 @@ module Homebrew
|
||||
raise "Unknown arch #{@bottle_tag.arch}."
|
||||
end
|
||||
|
||||
all = args.eval_all?
|
||||
if args.total?
|
||||
if !all && !Homebrew::EnvConfig.eval_all?
|
||||
odisabled "brew unbottled --total", "brew unbottled --total --eval-all or HOMEBREW_EVAL_ALL"
|
||||
Homebrew::SimulateSystem.with os: os, arch: arch do
|
||||
all = args.eval_all?
|
||||
if args.total?
|
||||
if !all && !Homebrew::EnvConfig.eval_all?
|
||||
odisabled "brew unbottled --total", "brew unbottled --total --eval-all or HOMEBREW_EVAL_ALL"
|
||||
end
|
||||
all = true
|
||||
end
|
||||
all = true
|
||||
|
||||
if args.named.blank?
|
||||
ohai "Getting formulae..."
|
||||
elsif all
|
||||
raise UsageError, "Cannot specify formulae when using `--eval-all`/`--total`."
|
||||
end
|
||||
|
||||
formulae, all_formulae, formula_installs =
|
||||
formulae_all_installs_from_args(args, all)
|
||||
deps_hash, uses_hash = deps_uses_from_formulae(all_formulae)
|
||||
|
||||
if args.dependents?
|
||||
formula_dependents = {}
|
||||
formulae = formulae.sort_by do |f|
|
||||
dependents = uses_hash[f.name]&.length || 0
|
||||
formula_dependents[f.name] ||= dependents
|
||||
end.reverse
|
||||
elsif all
|
||||
output_total(formulae)
|
||||
return
|
||||
end
|
||||
|
||||
noun, hash = if args.named.present?
|
||||
[nil, {}]
|
||||
elsif args.dependents?
|
||||
["dependents", formula_dependents]
|
||||
else
|
||||
["installs", formula_installs]
|
||||
end
|
||||
|
||||
output_unbottled(formulae, deps_hash, noun, hash, args.named.present?)
|
||||
end
|
||||
|
||||
if args.named.blank?
|
||||
ohai "Getting formulae..."
|
||||
elsif all
|
||||
raise UsageError, "Cannot specify formulae when using `--eval-all`/`--total`."
|
||||
end
|
||||
|
||||
formulae, all_formulae, formula_installs =
|
||||
formulae_all_installs_from_args(args, all)
|
||||
deps_hash, uses_hash = deps_uses_from_formulae(all_formulae)
|
||||
|
||||
if args.dependents?
|
||||
formula_dependents = {}
|
||||
formulae = formulae.sort_by do |f|
|
||||
dependents = uses_hash[f.name]&.length || 0
|
||||
formula_dependents[f.name] ||= dependents
|
||||
end.reverse
|
||||
elsif all
|
||||
output_total(formulae)
|
||||
return
|
||||
end
|
||||
|
||||
noun, hash = if args.named.present?
|
||||
[nil, {}]
|
||||
elsif args.dependents?
|
||||
["dependents", formula_dependents]
|
||||
else
|
||||
["installs", formula_installs]
|
||||
end
|
||||
|
||||
output_unbottled(formulae, deps_hash, noun, hash, args.named.present?)
|
||||
ensure
|
||||
Homebrew::SimulateSystem.clear
|
||||
end
|
||||
|
||||
def formulae_all_installs_from_args(args, all)
|
||||
|
@ -2251,34 +2251,27 @@ class Formula
|
||||
|
||||
os_versions = [*MacOSVersion::SYMBOLS.keys, :linux]
|
||||
|
||||
begin
|
||||
if path.exist? && self.class.on_system_blocks_exist?
|
||||
formula_contents = path.read
|
||||
[:arm, :intel].each do |arch|
|
||||
os_versions.each do |os_name|
|
||||
bottle_tag = Utils::Bottles::Tag.new(system: os_name, arch: arch)
|
||||
next unless bottle_tag.valid_combination?
|
||||
if path.exist? && self.class.on_system_blocks_exist?
|
||||
formula_contents = path.read
|
||||
os_versions.product(OnSystem::ARCH_OPTIONS).each do |os, arch|
|
||||
bottle_tag = Utils::Bottles::Tag.new(system: os, arch: arch)
|
||||
next unless bottle_tag.valid_combination?
|
||||
|
||||
Homebrew::SimulateSystem.os = os_name
|
||||
Homebrew::SimulateSystem.arch = arch
|
||||
Homebrew::SimulateSystem.with os: os, arch: arch do
|
||||
variations_namespace = Formulary.class_s("Variations#{bottle_tag.to_sym.capitalize}")
|
||||
variations_formula_class = Formulary.load_formula(name, path, formula_contents, variations_namespace,
|
||||
flags: self.class.build_flags, ignore_errors: true)
|
||||
variations_formula = variations_formula_class.new(name, path, :stable,
|
||||
alias_path: alias_path, force_bottle: force_bottle)
|
||||
|
||||
variations_namespace = Formulary.class_s("Variations#{bottle_tag.to_sym.capitalize}")
|
||||
variations_formula_class = Formulary.load_formula(name, path, formula_contents, variations_namespace,
|
||||
flags: self.class.build_flags, ignore_errors: true)
|
||||
variations_formula = variations_formula_class.new(name, path, :stable,
|
||||
alias_path: alias_path, force_bottle: force_bottle)
|
||||
variations_formula.to_hash.each do |key, value|
|
||||
next if value.to_s == hash[key].to_s
|
||||
|
||||
variations_formula.to_hash.each do |key, value|
|
||||
next if value.to_s == hash[key].to_s
|
||||
|
||||
variations[bottle_tag.to_sym] ||= {}
|
||||
variations[bottle_tag.to_sym][key] = value
|
||||
end
|
||||
variations[bottle_tag.to_sym] ||= {}
|
||||
variations[bottle_tag.to_sym][key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
ensure
|
||||
Homebrew::SimulateSystem.clear
|
||||
end
|
||||
|
||||
hash["variations"] = variations
|
||||
|
@ -893,21 +893,19 @@ module Homebrew
|
||||
# The formula has no variations, so all OS-version-arch triples depend on GCC.
|
||||
return false if variations.blank?
|
||||
|
||||
MacOSVersion::SYMBOLS.each_key do |macos_version|
|
||||
[:arm, :intel].each do |arch|
|
||||
bottle_tag = Utils::Bottles::Tag.new(system: macos_version, arch: arch)
|
||||
next unless bottle_tag.valid_combination?
|
||||
MacOSVersion::SYMBOLS.keys.product(OnSystem::ARCH_OPTIONS).each do |os, arch|
|
||||
bottle_tag = Utils::Bottles::Tag.new(system: os, arch: arch)
|
||||
next unless bottle_tag.valid_combination?
|
||||
|
||||
variation_dependencies = variations.dig(bottle_tag.to_sym, "dependencies")
|
||||
# This variation either:
|
||||
# 1. does not exist
|
||||
# 2. has no variation-specific dependencies
|
||||
# In either case, it matches Linux. We must check for `nil` because an empty
|
||||
# array indicates that this variation does not depend on GCC.
|
||||
return false if variation_dependencies.nil?
|
||||
# We found a non-Linux variation that depends on GCC.
|
||||
return false if variation_dependencies.include?("gcc")
|
||||
end
|
||||
variation_dependencies = variations.dig(bottle_tag.to_sym, "dependencies")
|
||||
# This variation either:
|
||||
# 1. does not exist
|
||||
# 2. has no variation-specific dependencies
|
||||
# In either case, it matches Linux. We must check for `nil` because an empty
|
||||
# array indicates that this variation does not depend on GCC.
|
||||
return false if variation_dependencies.nil?
|
||||
# We found a non-Linux variation that depends on GCC.
|
||||
return false if variation_dependencies.include?("gcc")
|
||||
end
|
||||
|
||||
true
|
||||
|
@ -68,6 +68,7 @@ module Readall
|
||||
|
||||
def valid_tap?(tap, options = {})
|
||||
success = true
|
||||
|
||||
if options[:aliases]
|
||||
valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir)
|
||||
success = false unless valid_aliases
|
||||
@ -76,25 +77,18 @@ module Readall
|
||||
success = false unless valid_formulae?(tap.formula_files)
|
||||
success = false unless valid_casks?(tap.cask_files)
|
||||
else
|
||||
arches = [:arm, :intel]
|
||||
os_names = [*MacOSVersion::SYMBOLS.keys, :linux]
|
||||
arches.each do |arch|
|
||||
os_names.each do |os_name|
|
||||
bottle_tag = Utils::Bottles::Tag.new(system: os_name, arch: arch)
|
||||
next unless bottle_tag.valid_combination?
|
||||
os_names.product(OnSystem::ARCH_OPTIONS).each do |os, arch|
|
||||
bottle_tag = Utils::Bottles::Tag.new(system: os, arch: arch)
|
||||
next unless bottle_tag.valid_combination?
|
||||
|
||||
begin
|
||||
Homebrew::SimulateSystem.arch = arch
|
||||
Homebrew::SimulateSystem.os = os_name
|
||||
|
||||
success = false unless valid_formulae?(tap.formula_files, bottle_tag: bottle_tag)
|
||||
success = false unless valid_casks?(tap.cask_files, os_name: os_name, arch: arch)
|
||||
ensure
|
||||
Homebrew::SimulateSystem.clear
|
||||
end
|
||||
Homebrew::SimulateSystem.with os: os, arch: arch do
|
||||
success = false unless valid_formulae?(tap.formula_files, bottle_tag: bottle_tag)
|
||||
success = false unless valid_casks?(tap.cask_files, os_name: os, arch: arch)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
success
|
||||
end
|
||||
|
||||
|
@ -9,6 +9,31 @@ module Homebrew
|
||||
class << self
|
||||
attr_reader :arch, :os
|
||||
|
||||
sig {
|
||||
type_parameters(:U).params(
|
||||
os: Symbol,
|
||||
arch: Symbol,
|
||||
_block: T.proc.returns(T.type_parameter(:U)),
|
||||
).returns(T.type_parameter(:U))
|
||||
}
|
||||
def with(os: T.unsafe(nil), arch: T.unsafe(nil), &_block)
|
||||
raise ArgumentError, "At least one of `os` or `arch` must be specified." if !os && !arch
|
||||
|
||||
if self.os || self.arch
|
||||
raise "Cannot simulate#{os&.inspect&.prepend(" ")}#{arch&.inspect&.prepend(" ")} while already " \
|
||||
"simulating#{self.os&.inspect&.prepend(" ")}#{self.arch&.inspect&.prepend(" ")}."
|
||||
end
|
||||
|
||||
begin
|
||||
self.os = os if os
|
||||
self.arch = arch if arch
|
||||
|
||||
yield
|
||||
ensure
|
||||
clear
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(new_os: Symbol).void }
|
||||
def os=(new_os)
|
||||
os_options = [:macos, :linux, *MacOSVersion::SYMBOLS.keys]
|
||||
@ -19,7 +44,7 @@ module Homebrew
|
||||
|
||||
sig { params(new_arch: Symbol).void }
|
||||
def arch=(new_arch)
|
||||
raise "New arch must be :arm or :intel" unless [:arm, :intel].include?(new_arch)
|
||||
raise "New arch must be :arm or :intel" unless OnSystem::ARCH_OPTIONS.include?(new_arch)
|
||||
|
||||
@arch = new_arch
|
||||
end
|
||||
|
@ -247,11 +247,6 @@ describe Cask::Cask, :cask do
|
||||
let(:expected_versions_variations) do
|
||||
<<~JSON
|
||||
{
|
||||
"arm64_big_sur": {
|
||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin-arm64/1.2.0/arm.zip",
|
||||
"version": "1.2.0",
|
||||
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||
},
|
||||
"monterey": {
|
||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin/1.2.3/intel.zip"
|
||||
},
|
||||
@ -260,6 +255,11 @@ describe Cask::Cask, :cask do
|
||||
"version": "1.2.0",
|
||||
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||
},
|
||||
"arm64_big_sur": {
|
||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin-arm64/1.2.0/arm.zip",
|
||||
"version": "1.2.0",
|
||||
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||
},
|
||||
"catalina": {
|
||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin/1.0.0/intel.zip",
|
||||
"version": "1.0.0",
|
||||
|
@ -932,11 +932,6 @@ describe Formula do
|
||||
let(:expected_variations) do
|
||||
<<~JSON
|
||||
{
|
||||
"arm64_big_sur": {
|
||||
"dependencies": [
|
||||
"big-sur-formula"
|
||||
]
|
||||
},
|
||||
"monterey": {
|
||||
"dependencies": [
|
||||
"intel-formula"
|
||||
@ -948,6 +943,11 @@ describe Formula do
|
||||
"big-sur-formula"
|
||||
]
|
||||
},
|
||||
"arm64_big_sur": {
|
||||
"dependencies": [
|
||||
"big-sur-formula"
|
||||
]
|
||||
},
|
||||
"catalina": {
|
||||
"dependencies": [
|
||||
"intel-formula",
|
||||
@ -1656,10 +1656,6 @@ describe Formula do
|
||||
end
|
||||
|
||||
describe "#on_system" do
|
||||
after do
|
||||
Homebrew::SimulateSystem.clear
|
||||
end
|
||||
|
||||
let(:f) do
|
||||
Class.new(Testball) do
|
||||
attr_reader :foo
|
||||
@ -1679,50 +1675,47 @@ describe Formula do
|
||||
end
|
||||
|
||||
it "doesn't call code on Ventura", :needs_macos do
|
||||
Homebrew::SimulateSystem.os = :ventura
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(0)
|
||||
expect(f.bar).to eq(0)
|
||||
Homebrew::SimulateSystem.with os: :ventura do
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(0)
|
||||
expect(f.bar).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
it "calls code on Linux", :needs_linux do
|
||||
Homebrew::SimulateSystem.os = :linux
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(1)
|
||||
expect(f.bar).to eq(1)
|
||||
Homebrew::SimulateSystem.with os: :linux do
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(1)
|
||||
expect(f.bar).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
it "calls code within `on_system :linux, macos: :monterey` on Monterey", :needs_macos do
|
||||
Homebrew::SimulateSystem.os = :monterey
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(1)
|
||||
expect(f.bar).to eq(0)
|
||||
Homebrew::SimulateSystem.with os: :monterey do
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(1)
|
||||
expect(f.bar).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
it "calls code within `on_system :linux, macos: :big_sur_or_older` on Big Sur", :needs_macos do
|
||||
Homebrew::SimulateSystem.os = :big_sur
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(0)
|
||||
expect(f.bar).to eq(1)
|
||||
Homebrew::SimulateSystem.with os: :big_sur do
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(0)
|
||||
expect(f.bar).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
it "calls code within `on_system :linux, macos: :big_sur_or_older` on Catalina", :needs_macos do
|
||||
Homebrew::SimulateSystem.os = :catalina
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(0)
|
||||
expect(f.bar).to eq(1)
|
||||
Homebrew::SimulateSystem.with os: :catalina do
|
||||
f.brew { f.install }
|
||||
expect(f.foo).to eq(0)
|
||||
expect(f.bar).to eq(1)
|
||||
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
|
||||
attr_reader :test
|
||||
@ -1743,33 +1736,38 @@ describe Formula do
|
||||
end
|
||||
|
||||
it "only calls code within `on_monterey`" do
|
||||
Homebrew::SimulateSystem.os = :monterey
|
||||
f.brew { f.install }
|
||||
expect(f.test).to eq(1)
|
||||
Homebrew::SimulateSystem.with os: :monterey do
|
||||
f.brew { f.install }
|
||||
expect(f.test).to eq(1)
|
||||
end
|
||||
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)
|
||||
Homebrew::SimulateSystem.with os: :ventura do
|
||||
f.brew { f.install }
|
||||
expect(f.test).to eq(1)
|
||||
end
|
||||
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)
|
||||
Homebrew::SimulateSystem.with os: :big_sur do
|
||||
f.brew { f.install }
|
||||
expect(f.test).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
it "only calls code within `on_catalina`" do
|
||||
Homebrew::SimulateSystem.os = :catalina
|
||||
f.brew { f.install }
|
||||
expect(f.test).to eq(3)
|
||||
Homebrew::SimulateSystem.with os: :catalina do
|
||||
f.brew { f.install }
|
||||
expect(f.test).to eq(3)
|
||||
end
|
||||
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)
|
||||
Homebrew::SimulateSystem.with os: :mojave do
|
||||
f.brew { f.install }
|
||||
expect(f.test).to eq(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -302,9 +302,6 @@ describe TestRunnerFormula do
|
||||
expect(described_class.new(old_non_portable_software).dependents(current_system)).to eq([])
|
||||
expect(described_class.new(fancy_new_software).dependents(current_system)).to eq([])
|
||||
expect(described_class.new(needs_modern_compiler).dependents(current_system)).to eq([])
|
||||
|
||||
expect(Homebrew::SimulateSystem.os).to be_nil
|
||||
expect(Homebrew::SimulateSystem.arch).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -322,9 +319,6 @@ describe TestRunnerFormula do
|
||||
expect(
|
||||
described_class.new(testball_user, eval_all: true).dependents(current_system).map(&:name),
|
||||
).to eq(["recursive_testball_dependent"])
|
||||
|
||||
expect(Homebrew::SimulateSystem.os).to be_nil
|
||||
expect(Homebrew::SimulateSystem.arch).to be_nil
|
||||
end
|
||||
|
||||
context "when called with arguments" do
|
||||
@ -347,102 +341,62 @@ describe TestRunnerFormula do
|
||||
end
|
||||
|
||||
context "when given { platform: :linux, arch: :x86_64 }" do
|
||||
before do
|
||||
Homebrew::SimulateSystem.os = :linux
|
||||
Homebrew::SimulateSystem.arch = :intel
|
||||
end
|
||||
|
||||
it "returns only the dependents for the requested platform and architecture" do
|
||||
allow(Formula).to receive(:all).and_return(testball_and_dependents)
|
||||
allow(Formula).to receive(:all).and_wrap_original { testball_and_dependents }
|
||||
|
||||
expect(
|
||||
described_class.new(testball, eval_all: true).dependents(
|
||||
platform: :linux, arch: :x86_64, macos_version: nil,
|
||||
).map(&:name).sort,
|
||||
).to eq(["testball_user", "testball_user-intel", "testball_user-linux"].sort)
|
||||
|
||||
expect(Homebrew::SimulateSystem.os).to be_nil
|
||||
expect(Homebrew::SimulateSystem.arch).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when given { platform: :macos, arch: :x86_64 }" do
|
||||
before do
|
||||
Homebrew::SimulateSystem.os = :macos
|
||||
Homebrew::SimulateSystem.arch = :intel
|
||||
end
|
||||
|
||||
it "returns only the dependents for the requested platform and architecture" do
|
||||
allow(Formula).to receive(:all).and_return(testball_and_dependents)
|
||||
allow(Formula).to receive(:all).and_wrap_original { testball_and_dependents }
|
||||
|
||||
expect(
|
||||
described_class.new(testball, eval_all: true).dependents(
|
||||
platform: :macos, arch: :x86_64, macos_version: nil,
|
||||
).map(&:name).sort,
|
||||
).to eq(["testball_user", "testball_user-intel", "testball_user-macos"].sort)
|
||||
|
||||
expect(Homebrew::SimulateSystem.os).to be_nil
|
||||
expect(Homebrew::SimulateSystem.arch).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when given `{ platform: :macos, arch: :arm64 }`" do
|
||||
before do
|
||||
Homebrew::SimulateSystem.os = :macos
|
||||
Homebrew::SimulateSystem.arch = :arm
|
||||
end
|
||||
|
||||
it "returns only the dependents for the requested platform and architecture" do
|
||||
allow(Formula).to receive(:all).and_return(testball_and_dependents)
|
||||
allow(Formula).to receive(:all).and_wrap_original { testball_and_dependents }
|
||||
|
||||
expect(
|
||||
described_class.new(testball, eval_all: true).dependents(
|
||||
platform: :macos, arch: :arm64, macos_version: nil,
|
||||
).map(&:name).sort,
|
||||
).to eq(["testball_user", "testball_user-arm", "testball_user-macos"].sort)
|
||||
|
||||
expect(Homebrew::SimulateSystem.os).to be_nil
|
||||
expect(Homebrew::SimulateSystem.arch).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when given `{ platform: :macos, arch: :x86_64, macos_version: :mojave }`" do
|
||||
before do
|
||||
Homebrew::SimulateSystem.os = :mojave
|
||||
Homebrew::SimulateSystem.arch = :intel
|
||||
end
|
||||
|
||||
it "returns only the dependents for the requested platform and architecture" do
|
||||
allow(Formula).to receive(:all).and_return(testball_and_dependents)
|
||||
allow(Formula).to receive(:all).and_wrap_original { testball_and_dependents }
|
||||
|
||||
expect(
|
||||
described_class.new(testball, eval_all: true).dependents(
|
||||
platform: :macos, arch: :x86_64, macos_version: :mojave,
|
||||
).map(&:name).sort,
|
||||
).to eq(["testball_user", "testball_user-intel", "testball_user-macos"].sort)
|
||||
|
||||
expect(Homebrew::SimulateSystem.os).to be_nil
|
||||
expect(Homebrew::SimulateSystem.arch).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when given `{ platform: :macos, arch: :arm64, macos_version: :ventura }`" do
|
||||
before do
|
||||
Homebrew::SimulateSystem.os = :ventura
|
||||
Homebrew::SimulateSystem.arch = :arm
|
||||
end
|
||||
|
||||
it "returns only the dependents for the requested platform and architecture" do
|
||||
allow(Formula).to receive(:all).and_return(testball_and_dependents)
|
||||
allow(Formula).to receive(:all).and_wrap_original { testball_and_dependents }
|
||||
|
||||
expect(
|
||||
described_class.new(testball, eval_all: true).dependents(
|
||||
platform: :macos, arch: :arm64, macos_version: :ventura,
|
||||
).map(&:name).sort,
|
||||
).to eq(%w[testball_user testball_user-arm testball_user-macos testball_user-ventura].sort)
|
||||
|
||||
expect(Homebrew::SimulateSystem.os).to be_nil
|
||||
expect(Homebrew::SimulateSystem.arch).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -90,8 +90,7 @@ class TestRunnerFormula
|
||||
cache_key = :"#{platform}_#{arch}_#{macos_version}"
|
||||
|
||||
@dependent_hash[cache_key] ||= begin
|
||||
all = eval_all || Homebrew::EnvConfig.eval_all?
|
||||
formula_selector, eval_all_env = if all
|
||||
formula_selector, eval_all_env = if eval_all
|
||||
[:all, "1"]
|
||||
else
|
||||
[:installed, nil]
|
||||
@ -99,15 +98,16 @@ class TestRunnerFormula
|
||||
|
||||
with_env(HOMEBREW_EVAL_ALL: eval_all_env) do
|
||||
Formulary.clear_cache
|
||||
Homebrew::SimulateSystem.arch = SIMULATE_SYSTEM_SYMBOLS.fetch(arch)
|
||||
Homebrew::SimulateSystem.os = macos_version || platform
|
||||
|
||||
Formula.public_send(formula_selector)
|
||||
.select { |candidate_f| candidate_f.deps.map(&:name).include?(name) }
|
||||
.map { |f| TestRunnerFormula.new(f, eval_all: all) }
|
||||
.freeze
|
||||
ensure
|
||||
Homebrew::SimulateSystem.clear
|
||||
os = macos_version || platform
|
||||
arch = SIMULATE_SYSTEM_SYMBOLS.fetch(arch)
|
||||
|
||||
Homebrew::SimulateSystem.with os: os, arch: arch do
|
||||
Formula.public_send(formula_selector)
|
||||
.select { |candidate_f| candidate_f.deps.map(&:name).include?(name) }
|
||||
.map { |f| TestRunnerFormula.new(f, eval_all: eval_all) }
|
||||
.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user