aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/.rubocop.yml19
-rw-r--r--Library/.rubocop_audit.yml (renamed from Library/.auditcops.yml)0
-rw-r--r--Library/Homebrew/.rubocop.yml14
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/dmg.rb24
-rw-r--r--Library/Homebrew/cask/lib/hbc/system_command.rb61
-rw-r--r--Library/Homebrew/cmd/style.rb2
-rw-r--r--Library/Homebrew/compat/formula.rb5
-rw-r--r--Library/Homebrew/extend/fileutils.rb5
-rw-r--r--Library/Homebrew/test/cmd/style_spec.rb4
9 files changed, 78 insertions, 56 deletions
diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml
index dd6e039b0..7b3bdaeb6 100644
--- a/Library/.rubocop.yml
+++ b/Library/.rubocop.yml
@@ -63,26 +63,26 @@ Metrics/AbcSize:
Max: 250
Metrics/BlockLength:
- Max: 1250
+ Max: 144
Metrics/ClassLength:
- Max: 1500
+ Max: 589
Metrics/CyclomaticComplexity:
Max: 75
Metrics/LineLength:
- Max: 400
+ Max: 324
Metrics/MethodLength:
- Max: 250
+ Max: 222
Metrics/ModuleLength:
CountComments: false
- Exclude:
- - '**/bin/**/*'
- - '**/cmd/**/*'
- - '**/lib/**/*'
+ Max: 367
+
+Metrics/ParameterLists:
+ CountKeywordArgs: false
Metrics/PerceivedComplexity:
Max: 100
@@ -94,6 +94,9 @@ Performance/Caller:
Style/Alias:
EnforcedStyle: prefer_alias
+Style/AsciiComments:
+ Enabled: false
+
Style/AutoResourceCleanup:
Enabled: true
diff --git a/Library/.auditcops.yml b/Library/.rubocop_audit.yml
index b5b7a8b58..b5b7a8b58 100644
--- a/Library/.auditcops.yml
+++ b/Library/.rubocop_audit.yml
diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml
index 143468643..0e1fb2d04 100644
--- a/Library/Homebrew/.rubocop.yml
+++ b/Library/Homebrew/.rubocop.yml
@@ -25,14 +25,20 @@ Lint/NestedMethodDefinition:
Lint/ParenthesesAsGroupedExpression:
Enabled: true
+Metrics/BlockLength:
+ Max: 1250
+
Metrics/BlockNesting:
Max: 5
-Metrics/ModuleLength:
- Max: 360
+Metrics/ClassLength:
+ Max: 1226
+
+Metrics/LineLength:
+ Max: 244
-Metrics/ParameterLists:
- CountKeywordArgs: false
+Metrics/MethodLength:
+ Max: 195
# we won't change backward compatible method names
Naming/MethodName:
diff --git a/Library/Homebrew/cask/lib/hbc/container/dmg.rb b/Library/Homebrew/cask/lib/hbc/container/dmg.rb
index 1d172a4b7..c0e43f68a 100644
--- a/Library/Homebrew/cask/lib/hbc/container/dmg.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/dmg.rb
@@ -88,7 +88,7 @@ module Hbc
bomfile.close
Tempfile.open(["", ".list"]) do |filelist|
- filelist.write(bom_filelist_from_path(mount))
+ filelist.puts(bom_filelist_from_path(mount))
filelist.close
@command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path])
@@ -98,16 +98,17 @@ module Hbc
end
def bom_filelist_from_path(mount)
- Dir.chdir(mount) do
- Dir.glob("**/*", File::FNM_DOTMATCH).map do |path|
- next if skip_path?(Pathname(path))
- (path == ".") ? path : path.prepend("./")
- end.compact.join("\n").concat("\n")
- end
+ # We need to use `find` here instead of Ruby in order to properly handle
+ # file names containing special characters, such as โ€œeโ€ + โ€œยดโ€ vs. โ€œรฉโ€.
+ @command.run("/usr/bin/find", args: [".", "-print0"], chdir: mount, print_stderr: false).stdout
+ .split("\0")
+ .reject { |path| skip_path?(mount, path) }
+ .join("\n")
end
- def skip_path?(path)
- dmg_metadata?(path) || system_dir_symlink?(path)
+ def skip_path?(mount, path)
+ path = Pathname(path.sub(%r{^\./}, ""))
+ dmg_metadata?(path) || system_dir_symlink?(mount, path)
end
# unnecessary DMG metadata
@@ -130,9 +131,10 @@ module Hbc
DMG_METADATA_FILES.include?(relative_root.basename.to_s)
end
- def system_dir_symlink?(path)
+ def system_dir_symlink?(mount, path)
+ full_path = Pathname(mount).join(path)
# symlinks to system directories (commonly to /Applications)
- path.symlink? && MacOS.system_dir?(path.readlink)
+ full_path.symlink? && MacOS.system_dir?(full_path.readlink)
end
def mounts_from_plist(plist)
diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb
index be083c29e..9ce3de907 100644
--- a/Library/Homebrew/cask/lib/hbc/system_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/system_command.rb
@@ -8,14 +8,14 @@ require "hbc/utils/hash_validator"
module Hbc
class SystemCommand
- attr_reader :command
+ extend Predicable
- def self.run(executable, options = {})
- new(executable, options).run!
+ def self.run(executable, **options)
+ new(executable, **options).run!
end
- def self.run!(command, options = {})
- run(command, options.merge(must_succeed: true))
+ def self.run!(command, **options)
+ run(command, **options, must_succeed: true)
end
def run!
@@ -26,38 +26,49 @@ module Hbc
case type
when :stdout
processed_output[:stdout] << line
- ohai line.chomp if options[:print_stdout]
+ ohai line.chomp if print_stdout?
when :stderr
processed_output[:stderr] << line
- ohai line.chomp if options[:print_stderr]
+ ohai line.chomp if print_stderr?
end
end
- assert_success if options[:must_succeed]
+ assert_success if must_succeed?
result
end
- def initialize(executable, options)
+ def initialize(executable, args: [], sudo: false, input: [], print_stdout: false, print_stderr: true, must_succeed: false, **options)
+ executable, *args = Shellwords.shellescape(executable) if args.empty?
+
@executable = executable
+ @args = args
+ @sudo = sudo
+ @input = input
+ @print_stdout = print_stdout
+ @print_stderr = print_stderr
+ @must_succeed = must_succeed
+ options.extend(HashValidator).assert_valid_keys(:chdir)
@options = options
- process_options!
+ end
+
+ def command
+ @command ||= [
+ *sudo_prefix,
+ executable,
+ *args,
+ ].freeze
end
private
- attr_reader :executable, :options, :processed_output, :processed_status
-
- def process_options!
- options.extend(HashValidator)
- .assert_valid_keys :input, :print_stdout, :print_stderr, :args, :must_succeed, :sudo
- sudo_prefix = %w[/usr/bin/sudo -E --]
- sudo_prefix = sudo_prefix.insert(1, "-A") unless ENV["SUDO_ASKPASS"].nil?
- @command = [executable]
- options[:print_stderr] = true unless options.key?(:print_stderr)
- @command.unshift(*sudo_prefix) if options[:sudo]
- @command.concat(options[:args]) if options.key?(:args) && !options[:args].empty?
- @command[0] = Shellwords.shellescape(@command[0]) if @command.size == 1
- nil
+ attr_reader :executable, :args, :input, :options, :processed_output, :processed_status
+
+ attr_predicate :sudo?, :print_stdout?, :print_stderr?, :must_succeed?
+
+ def sudo_prefix
+ return [] unless sudo?
+ askpass_flags = ENV.key?("SUDO_ASKPASS") ? ["-A"] : []
+ ["/usr/bin/sudo", *askpass_flags, "-E", "--"]
end
def assert_success
@@ -77,7 +88,7 @@ module Hbc
def each_output_line(&b)
raw_stdin, raw_stdout, raw_stderr, raw_wait_thr =
- Open3.popen3(*expanded_command)
+ Open3.popen3(*expanded_command, **options)
write_input_to(raw_stdin)
raw_stdin.close_write
@@ -87,7 +98,7 @@ module Hbc
end
def write_input_to(raw_stdin)
- [*options[:input]].each { |line| raw_stdin.print line }
+ [*input].each(&raw_stdin.method(:print))
end
def each_line_from(sources)
diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb
index 58f430a27..89484d67d 100644
--- a/Library/Homebrew/cmd/style.rb
+++ b/Library/Homebrew/cmd/style.rb
@@ -109,7 +109,7 @@ module Homebrew
args << "--config" << HOMEBREW_LIBRARY_PATH/".rubocop.yml"
args << HOMEBREW_LIBRARY_PATH
else
- args << "--config" << HOMEBREW_LIBRARY/".auditcops.yml"
+ args << "--config" << HOMEBREW_LIBRARY/".rubocop_audit.yml"
args += files
end
diff --git a/Library/Homebrew/compat/formula.rb b/Library/Homebrew/compat/formula.rb
index 853a38706..57ab84a76 100644
--- a/Library/Homebrew/compat/formula.rb
+++ b/Library/Homebrew/compat/formula.rb
@@ -78,4 +78,9 @@ class Formula
def startup_plist
odeprecated "Formula#startup_plist", "Formula#plist"
end
+
+ def rake(*args)
+ # odeprecated "FileUtils#rake", "system \"rake\""
+ system "rake", *args
+ end
end
diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb
index ed5bfe6c3..34ef3869f 100644
--- a/Library/Homebrew/extend/fileutils.rb
+++ b/Library/Homebrew/extend/fileutils.rb
@@ -101,11 +101,6 @@ module FileUtils
system Formulary.factory("scons").opt_bin/"scons", *args
end
- # Run the `rake` from the `ruby` Homebrew is using rather than whatever is in the `PATH`.
- def rake(*args)
- system RUBY_BIN/"rake", *args
- end
-
# Run `make` 3.81 or newer.
# Uses the system make on Leopard and newer, and the
# path to the actually-installed make on Tiger or older.
diff --git a/Library/Homebrew/test/cmd/style_spec.rb b/Library/Homebrew/test/cmd/style_spec.rb
index 4701036f1..9bc8fcab1 100644
--- a/Library/Homebrew/test/cmd/style_spec.rb
+++ b/Library/Homebrew/test/cmd/style_spec.rb
@@ -4,12 +4,12 @@ describe "brew style" do
around(:each) do |example|
begin
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
- FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".auditcops.yml"
+ FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml"
example.run
ensure
FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
- FileUtils.rm_f HOMEBREW_LIBRARY/".auditcops.yml"
+ FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml"
end
end