Class: ToolExecutorHelper

Inherits:
Object show all
Defined in:
lib/ceedling/tool_executor_helper.rb

Overview

Helper functions for the tool executor

Instance Method Summary collapse

Instance Method Details

#log_results(command_str, shell_result) ⇒ Object

Logs tool execution results

Attributes

  • command_str: The command ran.

  • shell_results: The outputs of the command including exit code and output.



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
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ceedling/tool_executor_helper.rb', line 65

def log_results(command_str, shell_result)
  # No logging unless we're at least at Obnoxious
  return if !@verbosinator.should_output?( Verbosity::OBNOXIOUS )

  output =      "> Shell executed command:\n"
  output +=     "`#{command_str}`\n"

  if !shell_result.empty?
    # Detailed debug logging
    if @verbosinator.should_output?( Verbosity::DEBUG )
      output +=   "> With $stdout: "
      output += shell_result[:stdout].empty? ? "<empty>\n" : "\n#{shell_result[:stdout].strip()}\n"

      output +=   "> With $stderr: "
      output += shell_result[:stderr].empty? ? "<empty>\n" : "\n#{shell_result[:stderr].strip()}\n"

      output +=   "> And terminated with status: #{shell_result[:status]}\n"

      @loginator.log( '', Verbosity::DEBUG )
      @loginator.log( output, Verbosity::DEBUG )
      @loginator.log( '', Verbosity::DEBUG )

      return # Bail out
    end

    # Slightly less verbose obnoxious logging
    if !shell_result[:output].empty?
      output += "> Produced output: "
      output += shell_result[:output].strip().empty? ? "<empty>\n" : "\n#{shell_result[:output].strip()}\n"
    end

    if !shell_result[:exit_code].nil?
      output += "> And terminated with exit code: [#{shell_result[:exit_code]}]\n"
    else
      output += "> And exited prematurely\n"      
    end
  end

  @loginator.log( '', Verbosity::OBNOXIOUS )
  @loginator.log( output, Verbosity::OBNOXIOUS )
  @loginator.log( '', Verbosity::OBNOXIOUS )
end

#osify_path_separators(executable) ⇒ Object

Modifies an executables path based on platform.

Attributes

  • executable: The executable’s path.



22
23
24
25
# File 'lib/ceedling/tool_executor_helper.rb', line 22

def osify_path_separators(executable)
  return executable.gsub(/\//, '\\') if (@system_wrapper.windows?)
  return executable
end

#stderr_redirect_cmdline_append(tool_config) ⇒ Object

Returns the stderr redirect append based on the config.

Attributes

  • tool_config: A hash containing config information.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ceedling/tool_executor_helper.rb', line 33

def stderr_redirect_cmdline_append(tool_config)
  return nil if (tool_config.nil? || tool_config[:stderr_redirect].nil?)

  config_redirect = tool_config[:stderr_redirect]
  redirect        = StdErrRedirect::NONE

  if (config_redirect == StdErrRedirect::AUTO)
     if (@system_wrapper.windows?)
       redirect = StdErrRedirect::WIN
     elsif (@system_utils.tcsh_shell?)
       redirect = StdErrRedirect::TCSH
     else
       redirect = StdErrRedirect::UNIX
     end
  end

  case redirect
    when StdErrRedirect::NONE then nil
    when StdErrRedirect::WIN  then '2>&1'
    when StdErrRedirect::UNIX then '2>&1'
    when StdErrRedirect::TCSH then '|&'
    else redirect.to_s
  end
end