Class Rascut::FcshWrapper
In: lib/rascut/fcsh_wrapper.rb
Parent: Object

Methods

Constants

FCSH_RESULT_RE = /fcsh: Assigned (\d+) as the compile target id/
FCSH_WAIT_RE = /^\(fcsh\)\s*$/

Attributes

config  [RW] 
files  [RW] 
hooks  [RW] 
original_files  [RW] 
target_script  [RW] 

Public Class methods

[Source]

    # File lib/rascut/fcsh_wrapper.rb, line 16
16:     def initialize(target_script, config)
17:       @target_script = target_script
18:       @config = config
19:       @hooks = Hash.new {|h, k| h[k] = []}
20:       @mutex = Mutex.new
21:       @compile_mutex = Mutex.new
22:       @compile_id = nil
23:       @process = nil
24:       @not_first_read = nil
25:     end

Public Instance methods

[Source]

     # File lib/rascut/fcsh_wrapper.rb, line 97
 97:     def call_hook(name, *args)
 98:       @hooks[name].each do |hook|
 99:         if hook.arity == 0 || args.length == 0
100:           hook.call
101:         else
102:           hook.call(*args)
103:         end
104:       end
105:     end

[Source]

    # File lib/rascut/fcsh_wrapper.rb, line 44
44:     def close
45:       if process
46:         process.close
47:         call_hook :close
48:       end
49:     end

[Source]

    # File lib/rascut/fcsh_wrapper.rb, line 71
71:     def compile
72:       return false if @compile_mutex.locked?
73: 
74:       @compile_mutex.synchronize do
75:         logger.info "Compile Start"
76:         out = nil
77:         if @compile_id
78:           out = process_sync_exec "compile #{@compile_id}"
79:         else
80:           out = process_sync_exec mxmlc_cmd
81:           if m = out.match(FCSH_RESULT_RE)
82:             @compile_id = m[1]
83:           else
84:             raise "Can't get Compile ID\n" + out.to_s
85:           end
86:         end
87:         logger.info out
88:         if out.match(/bytes\)/)
89:           call_hook :compile_success, out
90:         else
91:           call_hook :compile_error, out
92:         end
93:         call_hook :compile, out
94:       end
95:     end

[Source]

    # File lib/rascut/fcsh_wrapper.rb, line 51
51:     def logger
52:       @config[:logger]
53:     end

[Source]

    # File lib/rascut/fcsh_wrapper.rb, line 55
55:     def mxmlc_cmd
56:       cmd = ['mxmlc', @config[:compile_config], @target_script].join(' ')
57:       logger.debug cmd
58:       cmd
59:     end

[Source]

    # File lib/rascut/fcsh_wrapper.rb, line 61
61:     def process
62:       unless @process
63:         orig_lang = ENV['LANG']
64:         ENV['LANG'] = 'C' # for flex3 sdk beta locale
65:         @process = IO.popen(@config[:fcsh_cmd] + ' 2>&1', 'r+') unless @process
66:         ENV['LANG'] = orig_lang
67:       end
68:       @process
69:     end

[Source]

    # File lib/rascut/fcsh_wrapper.rb, line 35
35:     def process_sync_exec(str, result_get = true)
36:       res = nil
37:       @mutex.synchronize do
38:         process.puts str
39:         res = read_result(process) if result_get
40:       end
41:       res
42:     end

[Source]

     # File lib/rascut/fcsh_wrapper.rb, line 107
107:     def read_result(process)
108:       unless @not_first_read 
109:         # first_time, FIXME uncool...
110:         process.expect(FCSH_WAIT_RE)
111:         @not_first_read = true
112:       end
113:       
114:       process.expect(FCSH_WAIT_RE).first.sub(FCSH_WAIT_RE, '')
115:     end

[Source]

    # File lib/rascut/fcsh_wrapper.rb, line 27
27:     def reload!
28:       if @compile_id
29:         process_sync_exec("clear #{@compile_id}")
30:         @compile_id = nil
31:       end
32:       call_hook :reload, @compile_id
33:     end

[Validate]