From 80260df699d0a3caca40bcae58fb7bf0d91d72ca Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Tue, 31 May 2016 14:10:16 -0700 Subject: [PATCH] remove mkmf as a dependency. --- lib/elm/compiler.rb | 24 ++++++++++++------------ spec/elm/compiler_spec.rb | 3 +-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/elm/compiler.rb b/lib/elm/compiler.rb index 561079f..905c625 100644 --- a/lib/elm/compiler.rb +++ b/lib/elm/compiler.rb @@ -1,37 +1,37 @@ require 'elm/compiler/exceptions' require 'open3' require 'tempfile' -require 'mkmf' module Elm class Compiler class << self - def compile(elm_files, output_path: nil, elm_make_path: nil) - elm_executable = elm_make_path || find_executable0("elm-make") - fail ExecutableNotFound unless elm_executable_exists?(elm_executable) + def compile(elm_files, output_path: nil, elm_make_path: "elm-make") + fail ExecutableNotFound unless elm_executable_exists?(elm_make_path) if output_path - elm_make(elm_executable, elm_files, output_path) + elm_make(elm_make_path, elm_files, output_path) else - compile_to_string(elm_executable, elm_files) + compile_to_string(elm_make_path, elm_files) end end private - def elm_executable_exists?(elm_executable) - File.executable?(elm_executable) + def elm_executable_exists?(elm_make_path) + Open3.popen2(elm_make_path){}.nil? + rescue Errno::ENOENT, Errno::EACCES + false end - def compile_to_string(elm_executable, elm_files) + def compile_to_string(elm_make_path, elm_files) Tempfile.open(['elm', '.js']) do |tempfile| - elm_make(elm_executable, elm_files, tempfile.path) + elm_make(elm_make_path, elm_files, tempfile.path) return File.read tempfile.path end end - def elm_make(elm_executable, elm_files, output_path) - Open3.popen3({"LANG" => "en_US.UTF8" }, elm_executable, *elm_files, '--yes', '--output', output_path) do |_stdin, _stdout, stderr, wait_thr| + def elm_make(elm_make_path, elm_files, output_path) + Open3.popen3({"LANG" => "en_US.UTF8" }, elm_make_path, *elm_files, '--yes', '--output', output_path) do |_stdin, _stdout, stderr, wait_thr| fail CompileError, stderr.gets(nil) if wait_thr.value.exitstatus != 0 end end diff --git a/spec/elm/compiler_spec.rb b/spec/elm/compiler_spec.rb index ea182f3..9cd3aa9 100644 --- a/spec/elm/compiler_spec.rb +++ b/spec/elm/compiler_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'mkmf' describe Elm::Compiler do let(:test_file) { 'spec/fixtures/Test.elm' } @@ -58,7 +57,7 @@ end it 'should work if path is good' do - output = Elm::Compiler.compile(test_file, elm_make_path: find_executable0('elm-make')) + output = Elm::Compiler.compile(test_file, elm_make_path: 'elm-make') expect(output).to be_instance_of(String) expect(output.empty?).to be(false) end