class ToolExecutor
Public Instance Methods
Source
# File lib/ceedling/tool_executor.rb, line 19 def build_command_line(tool_config, extra_params, *args) command = {} command[:name] = tool_config[:name] command[:executable] = tool_config[:executable] command[:options] = {} # Blank to hold options set before `exec()` processes # 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 = @tool_executor_helper.osify_path_separators( expandify_element(tool_config[:name], tool_config[:executable], *args) ) command[:line] = [ executable, extra_params.join(' ').strip, build_arguments(tool_config[:name], tool_config[:arguments], *args), ].reject{|s| s.nil? || s.empty?}.join(' ').strip # Log command as is @loginator.log( "Command: #{command}", Verbosity::DEBUG ) # Update executable after any expansion command[:executable] = executable return command end
@param extra_params is an array of parameters to append to executable (prepend to rest of command line)
Source
# File lib/ceedling/tool_executor.rb, line 51 def exec(command, args=[]) options = command[:options] options[:boom] = true if (options[:boom].nil?) options[:stderr_redirect] = StdErrRedirect::NONE if (options[:stderr_redirect].nil?) # Build command line command_line = [ command[:line].strip, args, @tool_executor_helper.stderr_redirect_cmdline_append( options ), ].flatten.compact.join(' ') shell_result = {} # Wrap system level tool execution in exception handling begin time = Benchmark.realtime do shell_result = @system_wrapper.shell_capture3( command:command_line, boom:options[:boom] ) end shell_result[:time] = time # Ultimately, re-raise the exception as ShellException populated with the exception message rescue => error raise ShellException.new( name:pretty_tool_name( command ), message: error.message ) # Be sure to log what we can ensure # 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.log_results( command_line, shell_result ) end # Go boom if exit code is not 0 and that code means a fatal error # (Sometimes we don't want a non-0 exit code to cause an exception as the exit code may not mean a build-ending failure) if ((shell_result[:exit_code] != 0) and options[:boom]) raise ShellException.new( shell_result:shell_result, name:pretty_tool_name( command ) ) end return shell_result end
shell out, execute command, and return response