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

Returns a new instance of ValgrindHelper.



138
139
140
141
# File 'lib/hoe/debugging.rb', line 138

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.



136
137
138
# File 'lib/hoe/debugging.rb', line 136

def directory
  @directory
end

#project_nameObject

Returns the value of attribute project_name.



136
137
138
# File 'lib/hoe/debugging.rb', line 136

def project_name
  @project_name
end

Instance Method Details

#formatted_ruby_versionObject



143
144
145
146
147
148
149
150
# File 'lib/hoe/debugging.rb', line 143

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



191
192
193
194
195
196
197
# File 'lib/hoe/debugging.rb', line 191

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



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/hoe/debugging.rb', line 160

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 = String.new "{\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



183
184
185
186
187
188
189
# File 'lib/hoe/debugging.rb', line 183

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

#valgrindObject



199
200
201
202
203
# File 'lib/hoe/debugging.rb', line 199

def valgrind
  # note that valgrind will generally crap out on rubies >= 2.1
  # unless we increase the max stack size beyond the default
  "ulimit -s unlimited && valgrind"
end

#version_matchesObject



152
153
154
155
156
157
158
# File 'lib/hoe/debugging.rb', line 152

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