Sha256: d8aa083fd2790d83c1c54eb9761c64ad2c78ab3c380e7057dd0772cbfaadd82e

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

require 'benchmark'
require 'open3'

module Jeka
  module Compiler
    class Compiler
      attr_reader :database
      
      def command(cmd)
        stdout_ = nil
        stderr_ = nil
        exit_status_ = nil
        
        b = Benchmark.measure do
          Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
            stdout_ = stdout.readlines
            stderr_ = stderr.readlines
            exit_status_ = wait_thr.value
          end
        end.to_a
        
        bench = Hash.new
        bench[:user_cpu_time] = b[1]
        bench[:system_cpu_time] = b[2]
        bench[:childrens_use_cpu_time] = b[3]
        bench[:childrens_system_cpu_time] = b[4]
        bench[:elapsed_real_time] = b[5]
        return stdout_, stderr_, exit_status_.exitstatus, bench
      end
      
      def build(&block)
        return _build_command ? command(_build_command) : [[], [], 0, 0]
      end
      
      def run(input = '')
        return command("echo '#{input}' | #{_run_command}")
      end
      
      def jekafy
        @database = Jeka::Analysis::Compiler.create(
          name: self.class.to_s,
          compiler_options: Jeka::Analysis::CompilerOption.convert(@options),
          source_files: Jeka::Analysis::SourceFile.convert(@files)
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jeka-0.2.2 lib/jeka/compilers/compiler.rb
jeka-0.2.1 lib/jeka/compilers/compiler.rb
jeka-0.2.0 lib/jeka/compilers/compiler.rb