class ToolExecutor

Public Instance Methods

build_command_line(tool_config, extra_params, *args) click to toggle source

@param extra_params is an array of parameters to append to executable

# File lib/ceedling/tool_executor.rb, line 23
def build_command_line(tool_config, extra_params, *args)
  @tool_name  = tool_config[:name]
  @executable = tool_config[:executable]

  command = {}

  # basic premise is to iterate top to bottom through arguments using '$' as
  #  a string replacement indicator to expand globals or inline yaml arrays
  #  into command line arguments via substitution strings
  # executable must be quoted if it includes spaces (common on windows)
  executable = @tool_executor_helper.osify_path_separators( expandify_element(@executable, *args) )
  executable = "\"#{executable}\"" if executable.include?(' ')
  command[:line] = [
    executable,
    extra_params.join(' ').strip,
    build_arguments(tool_config[:arguments], *args),
    ].reject{|s| s.nil? || s.empty?}.join(' ').strip

  command[:options] = {
    :stderr_redirect => @tool_executor_helper.stderr_redirection(tool_config, @configurator.project_logging),
    :background_exec => tool_config[:background_exec]
    }

  return command
end
exec(command, options={}, args=[]) click to toggle source

shell out, execute command, and return response

# File lib/ceedling/tool_executor.rb, line 51
def exec(command, options={}, args=[])
  options[:boom] = true if (options[:boom].nil?)
  options[:stderr_redirect] = StdErrRedirect::NONE if (options[:stderr_redirect].nil?)
  options[:background_exec] = BackgroundExec::NONE if (options[:background_exec].nil?)
  # build command line
  command_line = [
    @tool_executor_helper.background_exec_cmdline_prepend( options ),
    command.strip,
    args,
    @tool_executor_helper.stderr_redirect_cmdline_append( options ),
    @tool_executor_helper.background_exec_cmdline_append( options ),
    ].flatten.compact.join(' ')

  @streaminator.stderr_puts("Verbose: #{__method__.to_s}(): #{command_line}", Verbosity::DEBUG)

  shell_result = {}

  # depending on background exec option, we shell out differently
  time = Benchmark.realtime do
    if (options[:background_exec] != BackgroundExec::NONE)
      shell_result = @system_wrapper.shell_system( command_line, options[:boom] )
    else
      shell_result = @system_wrapper.shell_backticks( command_line, options[:boom] )
    end
  end
  shell_result[:time] = time

  #scrub the string for illegal output
  unless shell_result[:output].nil?
    shell_result[:output] = shell_result[:output].scrub if "".respond_to?(:scrub)
    shell_result[:output].gsub!(/\033\[\d\dm/,'')
  end

  @tool_executor_helper.print_happy_results( command_line, shell_result, options[:boom] )
  @tool_executor_helper.print_error_results( command_line, shell_result, options[:boom] )

  # go boom if exit code isn't 0 (but in some cases we don't want a non-0 exit code to raise)
  raise ShellExecutionException.new(shell_result) if ((shell_result[:exit_code] != 0) and options[:boom])

  return shell_result
end
setup() click to toggle source
# File lib/ceedling/tool_executor.rb, line 15
def setup
  @tool_name  = ''
  @executable = ''
end