class Hoe::Debugging::ValgrindHelper

Constants

DEFAULT_DIRECTORY_NAME

Attributes

directory[RW]
project_name[RW]

Public Class Methods

new(project_name, options={}) click to toggle source
# File lib/hoe/debugging.rb, line 139
def initialize project_name, options={}
  @project_name = project_name
  @directory    = options[:directory] || DEFAULT_DIRECTORY_NAME
end

Public Instance Methods

formatted_ruby_version() click to toggle source
# File lib/hoe/debugging.rb, line 144
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_files() click to toggle source
# File lib/hoe/debugging.rb, line 192
def matching_suppression_files
  matching_files = []
  version_matches.each do |version_string|
    matching_files += Dir[File.join(directory, "#{project_name}_#{version_string}.supp")]
    matching_files += Dir[File.join(directory, "#{project_name}_#{version_string}_*.supp")]
  end
  matching_files
end
parse_suppressions_from(logfile_name) click to toggle source
# File lib/hoe/debugging.rb, line 161
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={}) click to toggle source
# File lib/hoe/debugging.rb, line 184
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() click to toggle source
# File lib/hoe/debugging.rb, line 201
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_matches() click to toggle source
# File lib/hoe/debugging.rb, line 153
def version_matches
  matches = [formatted_ruby_version]                          # e.g. "ruby-2.5.1.57"
  matches << formatted_ruby_version.split(".")[0,3].join(".") # e.g. "ruby-2.5.1"
  matches << formatted_ruby_version.split(".")[0,2].join(".") # e.g. "ruby-2.5"
  matches << formatted_ruby_version.split(".")[0,1].join(".") # e.g. "ruby-2"
  matches
end

Private Instance Methods

ensure_directory_exists() click to toggle source
# File lib/hoe/debugging.rb, line 209
def ensure_directory_exists
  return if File.directory? directory
  FileUtils.mkdir_p directory
  File.open(File.join(directory, "README.txt"), "w") do |readme|
    readme.puts "This directory contains valgrind suppression files generated by the hoe-debugging gem."
  end
end