Class: ToolExecutor
Instance Method Summary collapse
- #build_command_line(tool_config, extra_params, *args) ⇒ Object
-
#exec(command, args = []) ⇒ Object
shell out, execute command, and return response.
Instance Method Details
#build_command_line(tool_config, extra_params, *args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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( (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 |
#exec(command, args = []) ⇒ Object
shell out, execute command, and return response
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ceedling/tool_executor.rb', line 51 def exec(command, args=[]) = command[:options] [:boom] = true if ([:boom].nil?) [:stderr_redirect] = StdErrRedirect::NONE if ([:stderr_redirect].nil?) # Build command line command_line = [ command[:line].strip, args, @tool_executor_helper.stderr_redirect_cmdline_append( ), ].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:[: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. ) # 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 [:boom]) raise ShellException.new( shell_result:shell_result, name:pretty_tool_name( command ) ) end return shell_result end |