From 0048b394d486b96271255c86452dece5128028f8 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Fri, 24 Mar 2023 22:02:00 -0700 Subject: [PATCH] readall: fix no simulate This wasn't working with casks because the bottle tag would be nil here. It was refactored to not use the bottle tag because casks don't have bottles. I also moved the valid_casks? method to extend/os/mac because casks only run on macOS and the generic OS tests were failing before. --- Library/Homebrew/extend/os/linux/readall.rb | 10 ------ Library/Homebrew/extend/os/mac/readall.rb | 37 +++++++++++++++++++++ Library/Homebrew/extend/os/readall.rb | 2 +- Library/Homebrew/readall.rb | 26 ++------------- 4 files changed, 41 insertions(+), 34 deletions(-) delete mode 100644 Library/Homebrew/extend/os/linux/readall.rb create mode 100644 Library/Homebrew/extend/os/mac/readall.rb diff --git a/Library/Homebrew/extend/os/linux/readall.rb b/Library/Homebrew/extend/os/linux/readall.rb deleted file mode 100644 index bc2366b642..0000000000 --- a/Library/Homebrew/extend/os/linux/readall.rb +++ /dev/null @@ -1,10 +0,0 @@ -# typed: true -# frozen_string_literal: true - -module Readall - class << self - def valid_casks?(_casks, bottle_tag: nil) - true - end - end -end diff --git a/Library/Homebrew/extend/os/mac/readall.rb b/Library/Homebrew/extend/os/mac/readall.rb new file mode 100644 index 0000000000..adb0ad26ab --- /dev/null +++ b/Library/Homebrew/extend/os/mac/readall.rb @@ -0,0 +1,37 @@ +# typed: true +# frozen_string_literal: true + +module Readall + class << self + def valid_casks?(casks, os_name: nil, arch: Hardware::CPU.type) + return true if os_name == :linux + + current_macos_version = if os_name.is_a?(Symbol) + MacOS::Version.from_symbol(os_name) + else + MacOS.version + end + + success = T.let(true, T::Boolean) + casks.each do |file| + cask = Cask::CaskLoader.load(file) + + # Fine to have missing URLs for unsupported macOS + macos_req = cask.depends_on.macos + next if macos_req&.version && Array(macos_req.version).none? do |macos_version| + current_macos_version.public_send(macos_req.comparator, macos_version) + end + + raise "Missing URL" if cask.url.nil? + rescue Interrupt + raise + rescue Exception => e # rubocop:disable Lint/RescueException + os_and_arch = "macOS #{current_macos_version} on #{arch}" + onoe "Invalid cask (#{os_and_arch}): #{file}" + $stderr.puts e + success = false + end + success + end + end +end diff --git a/Library/Homebrew/extend/os/readall.rb b/Library/Homebrew/extend/os/readall.rb index af407f1c44..132f0062e0 100644 --- a/Library/Homebrew/extend/os/readall.rb +++ b/Library/Homebrew/extend/os/readall.rb @@ -1,4 +1,4 @@ # typed: strict # frozen_string_literal: true -require "extend/os/linux/readall" if OS.linux? +require "extend/os/mac/readall" if OS.mac? diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index 881a74f099..3a777ffe37 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -62,28 +62,8 @@ module Readall success end - def valid_casks?(casks, bottle_tag: nil) - return true if bottle_tag.present? && bottle_tag.system == :linux - - success = T.let(true, T::Boolean) - casks.each do |file| - cask = Cask::CaskLoader.load(file) - - # Fine to have missing URLs for unsupported macOS - macos_req = cask.depends_on.macos - next if macos_req&.version && Array(macos_req.version).none? do |macos_version| - bottle_tag.to_macos_version.public_send(macos_req.comparator, macos_version) - end - - raise "Missing URL" if cask.url.nil? - rescue Interrupt - raise - rescue Exception => e # rubocop:disable Lint/RescueException - onoe "Invalid cask (#{bottle_tag}): #{file}" - $stderr.puts e - success = false - end - success + def valid_casks?(_casks, os_name: nil, arch: nil) + true end def valid_tap?(tap, options = {}) @@ -108,7 +88,7 @@ module Readall 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, bottle_tag: bottle_tag) + success = false unless valid_casks?(tap.cask_files, os_name: os_name, arch: arch) ensure Homebrew::SimulateSystem.clear end