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 101
101:     def call_hook(name, *args)
102:       @hooks[name].each do |hook|
103:         if hook.arity == 0 || args.length == 0
104:           hook.call
105:         else
106:           hook.call(*args)
107:         end
108:       end
109:     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 74
74:     def compile
75:       return false if @compile_mutex.locked?
76: 
77:       @compile_mutex.synchronize do
78:         logger.info "Compile Start"
79:         call_hook :compile_start
80:         out = nil
81:         if @compile_id
82:           out = process_sync_exec "compile #{@compile_id}"
83:         else
84:           out = process_sync_exec mxmlc_cmd
85:           if m = out.match(FCSH_RESULT_RE)
86:             @compile_id = m[1]
87:           else
88:             raise "Can't get Compile ID\n" + out.to_s
89:           end
90:         end
91:         logger.info out
92:         if out.match(/bytes\)/)
93:           call_hook :compile_success, out
94:         else
95:           call_hook :compile_error, out
96:         end
97:         call_hook :compile_finish
98:       end
99:     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:         orig_java_options = ENV['_JAVA_OPTIONS']
66:         ENV['_JAVA_OPTIONS'] = orig_java_options.to_s + ' -Duser.language=en'
67:         @process = IO.popen(@config[:fcsh_cmd] + ' 2>&1', 'r+') unless @process
68:         ENV['LANG'] = orig_lang
69:         ENV['_JAVA_OPTIONS'] = orig_java_options
70:       end
71:       @process
72:     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 111
111:     def read_result(process)
112:       unless @not_first_read 
113:         # first_time, FIXME uncool...
114:         begin
115:           process.expect(FCSH_WAIT_RE)
116:         rescue NoMethodError => e
117:           warn 'mxmlc not found. (check PATH)'
118:           raise e
119:         end
120:         @not_first_read = true
121:       end
122:       
123:       process.expect(FCSH_WAIT_RE).first.sub(FCSH_WAIT_RE, '')
124:     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]