Class: Calasmash::Compiler

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

Overview

The calamsash compiler will compiles the Xcode project with the scheme it’s told to compile with.

Author:

  • alexfish

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheme) ⇒ Compiler

Returns a new instance of Compiler.



16
17
18
# File 'lib/calasmash/compiler.rb', line 16

def initialize(scheme)
  @scheme = scheme
end

Instance Attribute Details

#schemeObject

Public: the Scheme the compiler is compiling



14
15
16
# File 'lib/calasmash/compiler.rb', line 14

def scheme
  @scheme
end

Instance Method Details

#compile(&complete) ⇒ Object

The compiler’s heart, executes the compiling with xcodebuild

@param &complete Compleition block

Returns nothing because it completes with a complete block



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/calasmash/compiler.rb', line 26

def compile(&complete)
  started
  status = nil
  output = ""

  Open3.popen3 command do |stdin, out, err, wait_thr|
    [out, err].each do |stream|
      Thread.new do
        until (line = stream.gets).nil? do
          print "."
          output << line
        end
      end
    end
    wait_thr.join
    status = wait_thr.value.exitstatus
  end

  if status != 0
    puts "\nCompilation failed: \n\n #{output}"
    exit status
  else
    completed
    complete.call(true) if complete
  end
end