Class: MRuby::Command::Mrbc

Inherits:
MRuby::Command show all
Defined in:
ext/enterprise_script_service/mruby/lib/mruby/build/command.rb

Instance Attribute Summary collapse

Attributes inherited from MRuby::Command

#build, #command

Instance Method Summary collapse

Methods inherited from MRuby::Command

#clone, #shellquote

Constructor Details

#initialize(build) ⇒ Mrbc

Returns a new instance of Mrbc.



325
326
327
328
329
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 325

def initialize(build)
  super
  @command = nil
  @compile_options = "-B%{funcname} -o-"
end

Instance Attribute Details

#compile_optionsObject

Returns the value of attribute compile_options.



323
324
325
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 323

def compile_options
  @compile_options
end

Instance Method Details

#run(out, infiles, funcname, cdump = true) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 331

def run(out, infiles, funcname, cdump = true)
  @command ||= @build.mrbcfile
  infiles = [infiles].flatten
  infiles.each_with_index do |f, i|
    _pp i == 0 ? "MRBC" : "", f.relative_path, indent: 2
  end
  cmd = %Q["#{filename @command}" #{cdump ? "-S" : ""} #{@compile_options % {:funcname => funcname}} #{filename(infiles).map{|f| %Q["#{f}"]}.join(' ')}]
  puts cmd if Rake.verbose
  IO.popen(cmd, 'r+') do |io|
    out.puts io.read
  end
  # if mrbc execution fail, drop the file
  unless $?.success?
    rm_f out.path
    fail "Command failed with status (#{$?.exitstatus}): [#{cmd[0,42]}...]"
  end
end