Skip to content

Commit

Permalink
Support casks in readall
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Jun 18, 2020
1 parent b37520c commit 3f6d3e5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Library/Homebrew/cmd/readall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def readall_args
usage_banner <<~EOS
`readall` [<options>] [<tap>]
Import all formulae 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
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 items when making
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
switch "--aliases",
description: "Verify any alias symlinks in each tap."
Expand All @@ -30,7 +30,7 @@ def readall

if args.syntax?
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)
end
Expand Down
9 changes: 9 additions & 0 deletions Library/Homebrew/extend/os/linux/readall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Readall
class << self
def valid_casks?(*)
true
end
end
end
3 changes: 3 additions & 0 deletions Library/Homebrew/extend/os/readall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require "extend/os/linux/readall" if OS.linux?
34 changes: 26 additions & 8 deletions Library/Homebrew/readall.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "formula"
require "cask/cask_loader"

module Readall
class << self
Expand Down Expand Up @@ -35,28 +36,43 @@ def valid_aliases?(alias_dir, formula_dir)
end

def valid_formulae?(formulae)
failed = false
success = true
formulae.each do |file|
Formulary.factory(file)
rescue Interrupt
raise
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "Invalid formula: #{file}"
puts e
failed = true
$stderr.puts e
success = false
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

def valid_tap?(tap, options = {})
failed = false
success = true
if options[:aliases]
valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir)
failed = true unless valid_aliases
success = false unless valid_aliases
end
valid_formulae = valid_formulae?(tap.formula_files)
failed = true unless valid_formulae
!failed
valid_casks = valid_casks?(tap.cask_files)
success = false if !valid_formulae || !valid_casks
success
end

private
Expand All @@ -79,3 +95,5 @@ def syntax_errors_or_warnings?(rb)
end
end
end

require "extend/os/readall"
8 changes: 4 additions & 4 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ Rerun the post-install steps for *`formula`*.

### `readall` [*`options`*] [*`tap`*]

Import all formulae 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 significant changes to `formula.rb`, testing the performance of loading
all formulae or checking if any current formulae have Ruby issues.
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 items when making
significant changes to `formula.rb`, testing the performance of loading all
items or checking if any current formulae/casks have Ruby issues.

* `--aliases`:
Verify any alias symlinks in each tap.
Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ Pin the specified \fIformula\fR, preventing them from being upgraded when issuin
Rerun the post\-install steps for \fIformula\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
\fB\-\-aliases\fR
Expand Down

0 comments on commit 3f6d3e5

Please sign in to comment.