lib/barista/compiler.rb in barista-0.4.3 vs lib/barista/compiler.rb in barista-0.5.0
- old
+ new
@@ -1,6 +1,7 @@
require 'digest/sha2'
+require 'open4'
module Barista
class Compiler
class << self; attr_accessor :bin_path; end
@@ -51,22 +52,30 @@
end.join(" ")
end
def invoke_coffee(path)
command = "#{self.class.bin_path} #{coffee_options} '#{path}'".squeeze(' ')
- result = %x(#{command}).to_s
- if !$?.success?
+ Barista.invoke_hook :before_compilation, path
+ pid, stdin, stdout, stderr = Open4.popen4(command)
+ stdin.close
+ _, status = Process.waitpid2(pid)
+ out = stdout.read.strip
+ err = stderr.read.strip
+ if status.success?
+ if err.blank?
+ Barista.invoke_hook :compiled, path
+ else
+ Barista.invoke_hook :compiled_with_warning, path, err
+ end
+ else
+ Barista.invoke_hook :compilation_failed, path, err
if Barista.exception_on_error? && !@options[:silence]
raise CompilationError, "\"#{command}\" exited with a non-zero status."
else
- result = nil
+ out = nil
end
end
- result
- end
-
- def content_hash
- @content_hash ||= Digest::SHA256.hexdigest(@content)
+ out
end
end
end