Class: Hoe::Debugging::ValgrindHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/hoe/debugging.rb

Constant Summary collapse

DEFAULT_DIRECTORY_NAME =
"suppressions"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_name, options = {}) ⇒ ValgrindHelper



113
114
115
116
# File 'lib/hoe/debugging.rb', line 113

def initialize project_name, options={}
  @project_name = project_name
  @directory    = options[:directory] || DEFAULT_DIRECTORY_NAME
end

Instance Attribute Details

#directoryObject

Returns the value of attribute directory.



111
112
113
# File 'lib/hoe/debugging.rb', line 111

def directory
  @directory
end

#project_nameObject

Returns the value of attribute project_name.



111
112
113
# File 'lib/hoe/debugging.rb', line 111

def project_name
  @project_name
end

Instance Method Details

#formatted_ruby_versionObject



118
119
120
121
122
123
124
125
# File 'lib/hoe/debugging.rb', line 118

def formatted_ruby_version
  engine = if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Ruby Enterprise Edition/
             "ree"
           else
             defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
           end
  %Q{#{engine}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}}
end

#matching_suppression_fileObject



165
166
167
168
169
170
171
# File 'lib/hoe/debugging.rb', line 165

def matching_suppression_file
  version_matches.each do |version_string|
    matches = Dir[File.join(directory, "#{project_name}_#{version_string}*.supp")]
    return matches[0] if matches[0]
  end
  nil
end

#parse_suppressions_from(logfile_name) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/hoe/debugging.rb', line 134

def parse_suppressions_from logfile_name
  suppressions = []
  File.open logfile_name do |logfile|
    suppression = nil
    while ! logfile.eof? do
      line = logfile.readline
      if suppression.nil?
        if line =~ /\<insert_a_suppression_name_here\>/
          suppression = "{\n"
          suppression << line
        end
      else
        suppression << line
        if line =~ /^\}$/
          suppressions << suppression
          suppression = nil
        end
      end
    end
  end
  suppressions.uniq.join
end

#save_suppressions_from(logfile, options = {}) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/hoe/debugging.rb', line 157

def save_suppressions_from logfile, options={}
  ensure_directory_exists
  suppressions = parse_suppressions_from logfile
  filename = File.join directory, "#{project_name}_#{formatted_ruby_version}.supp"
  File.open(filename, "w") { |out| out.write suppressions }
  filename
end

#valgrind(command, options = {}) ⇒ Object



173
174
175
# File 'lib/hoe/debugging.rb', line 173

def valgrind command, options={}
  sh "valgrind #{vopts.join ' '} #{hoe_debugging_ruby} #{hoe_debugging_make_test_cmd}"
end

#version_matchesObject



127
128
129
130
131
132
# File 'lib/hoe/debugging.rb', line 127

def version_matches
  matches = [formatted_ruby_version]
  matches << formatted_ruby_version.split(".")[0,3].join(".")
  matches << formatted_ruby_version.split(".")[0,2].join(".")
  matches
end