aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/readall.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb
index 339819f0d..f95b7be74 100644
--- a/Library/Homebrew/cmd/readall.rb
+++ b/Library/Homebrew/cmd/readall.rb
@@ -22,7 +22,8 @@ module Homebrew
Thread.new do
begin
while rb = ruby_files.pop(true)
- failed = true unless system RUBY_PATH, "-c", "-w", rb
+ # As a side effect, print syntax errors/warnings to `$stderr`.
+ failed = true if syntax_errors_or_warnings?(rb)
end
rescue ThreadError # ignore empty queue error
end
@@ -69,4 +70,17 @@ module Homebrew
end
end
end
+
+ private
+
+ def syntax_errors_or_warnings?(rb)
+ # Retrieve messages about syntax errors/warnings printed to `$stderr`, but
+ # discard a `Syntax OK` printed to `$stdout` (in absence of syntax errors).
+ messages = Utils.popen_read("#{RUBY_PATH} -c -w #{rb} 2>&1 >/dev/null")
+ $stderr.print messages
+
+ # Only syntax errors result in a non-zero status code. To detect syntax
+ # warnings we also need to inspect the output to `$stderr`.
+ !$?.success? || !messages.chomp.empty?
+ end
end