Class: Jeka::Compiler::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/jeka/compilers/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



7
8
9
# File 'lib/jeka/compilers/compiler.rb', line 7

def database
  @database
end

Instance Method Details

#build(&block) ⇒ Object



31
32
33
# File 'lib/jeka/compilers/compiler.rb', line 31

def build(&block)
  return _build_command ? command(_build_command) : [[], [], 0, 0]
end

#command(cmd) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jeka/compilers/compiler.rb', line 9

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

#jekafyObject



39
40
41
42
43
44
45
# File 'lib/jeka/compilers/compiler.rb', line 39

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

#run(input = '') ⇒ Object



35
36
37
# File 'lib/jeka/compilers/compiler.rb', line 35

def run(input = '')
  return command("echo '#{input}' | #{_run_command}")
end