Merge pull request #7752 from SMillerDev/cask/readall

Support casks in readall
This commit is contained in:
Mike McQuaid 2020-07-01 12:19:30 +01:00 committed by GitHub
commit 4e10341277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 19 deletions

View File

@ -11,10 +11,10 @@ module Homebrew
usage_banner <<~EOS usage_banner <<~EOS
`readall` [<options>] [<tap>] `readall` [<options>] [<tap>]
Import all formulae from the specified <tap>, or from all installed taps if none is provided. Import all items from the specified <tap>, or from all installed taps if none is provided.
This can be useful for debugging issues across all formulae when making This can be useful for debugging issues across all items when making
significant changes to `formula.rb`, testing the performance of loading significant changes to `formula.rb`, testing the performance of loading
all formulae or checking if any current formulae have Ruby issues. all items or checking if any current formulae/casks have Ruby issues.
EOS EOS
switch "--aliases", switch "--aliases",
description: "Verify any alias symlinks in each tap." description: "Verify any alias symlinks in each tap."
@ -30,7 +30,7 @@ module Homebrew
if args.syntax? if args.syntax?
scan_files = "#{HOMEBREW_LIBRARY_PATH}/**/*.rb" scan_files = "#{HOMEBREW_LIBRARY_PATH}/**/*.rb"
ruby_files = Dir.glob(scan_files).reject { |file| file =~ %r{/(vendor|cask)/} } ruby_files = Dir.glob(scan_files).reject { |file| file =~ %r{/(vendor)/} }
Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files) Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files)
end end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
module Readall
class << self
def valid_casks?(*)
true
end
end
end

View File

@ -0,0 +1,3 @@
# frozen_string_literal: true
require "extend/os/linux/readall" if OS.linux?

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "formula" require "formula"
require "cask/cask_loader"
module Readall module Readall
class << self class << self
@ -35,28 +36,43 @@ module Readall
end end
def valid_formulae?(formulae) def valid_formulae?(formulae)
failed = false success = true
formulae.each do |file| formulae.each do |file|
Formulary.factory(file) Formulary.factory(file)
rescue Interrupt rescue Interrupt
raise raise
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "Invalid formula: #{file}" onoe "Invalid formula: #{file}"
puts e $stderr.puts e
failed = true success = false
end end
!failed success
end
def valid_casks?(casks)
success = true
casks.each do |file|
Cask::CaskLoader.load(file)
rescue Interrupt
raise
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "Invalid cask: #{file}"
$stderr.puts e
success = false
end
success
end end
def valid_tap?(tap, options = {}) def valid_tap?(tap, options = {})
failed = false success = true
if options[:aliases] if options[:aliases]
valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir) valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir)
failed = true unless valid_aliases success = false unless valid_aliases
end end
valid_formulae = valid_formulae?(tap.formula_files) valid_formulae = valid_formulae?(tap.formula_files)
failed = true unless valid_formulae valid_casks = valid_casks?(tap.cask_files)
!failed success = false if !valid_formulae || !valid_casks
success
end end
private private
@ -79,3 +95,5 @@ module Readall
end end
end end
end end
require "extend/os/readall"

View File

@ -8,7 +8,7 @@ describe "Homebrew.search_args" do
end end
describe "brew search", :integration_test do describe "brew search", :integration_test do
it "falls back to a GitHub tap search when no formula is found", :needs_network do it "falls back to a GitHub tap search when no formula is found", :needs_macos, :needs_network do
setup_test_formula "testball" setup_test_formula "testball"
setup_remote_tap "homebrew/cask" setup_remote_tap "homebrew/cask"
@ -16,4 +16,13 @@ describe "brew search", :integration_test do
.to output(/firefox/).to_stdout .to output(/firefox/).to_stdout
.and be_a_success .and be_a_success
end end
# doesn't actually need Linux but only want one integration test per-OS.
it "finds formula in search", :need_linux do
setup_test_formula "testball"
expect { brew "search", "testball" }
.to output(/testball/).to_stdout
.and be_a_success
end
end end

View File

@ -46,7 +46,7 @@ RSpec.shared_context "integration test" do
example.run example.run
ensure ensure
FileUtils.rm_r HOMEBREW_PREFIX/"bin" FileUtils.rm_rf HOMEBREW_PREFIX/"bin"
end end
# Generate unique ID to be able to # Generate unique ID to be able to

View File

@ -369,10 +369,10 @@ Rerun the post-install steps for *`formula`*.
### `readall` [*`options`*] [*`tap`*] ### `readall` [*`options`*] [*`tap`*]
Import all formulae from the specified *`tap`*, or from all installed taps if none Import all items from the specified *`tap`*, or from all installed taps if none is
is provided. This can be useful for debugging issues across all formulae when provided. This can be useful for debugging issues across all items when making
making significant changes to `formula.rb`, testing the performance of loading significant changes to `formula.rb`, testing the performance of loading all
all formulae or checking if any current formulae have Ruby issues. items or checking if any current formulae/casks have Ruby issues.
* `--aliases`: * `--aliases`:
Verify any alias symlinks in each tap. Verify any alias symlinks in each tap.

View File

@ -486,7 +486,7 @@ Pin the specified \fIformula\fR, preventing them from being upgraded when issuin
Rerun the post\-install steps for \fIformula\fR\. Rerun the post\-install steps for \fIformula\fR\.
. .
.SS "\fBreadall\fR [\fIoptions\fR] [\fItap\fR]" .SS "\fBreadall\fR [\fIoptions\fR] [\fItap\fR]"
Import all formulae from the specified \fItap\fR, or from all installed taps if none is provided\. This can be useful for debugging issues across all formulae when making significant changes to \fBformula\.rb\fR, testing the performance of loading all formulae or checking if any current formulae have Ruby issues\. Import all items from the specified \fItap\fR, or from all installed taps if none is provided\. This can be useful for debugging issues across all items when making significant changes to \fBformula\.rb\fR, testing the performance of loading all items or checking if any current formulae/casks have Ruby issues\.
. .
.TP .TP
\fB\-\-aliases\fR \fB\-\-aliases\fR