Module: BenchmarkDriver::Rvm

Defined in:
lib/benchmark_driver/rvm.rb

Class Method Summary collapse

Class Method Details

.parse_spec(full_spec) ⇒ Object

Parameters:

  • full_spec (String)
    • “2.5.0”, “2.5.0 –jit”, “JIT::2.5.0 –jit”, etc.



39
40
41
42
43
44
45
46
47
# File 'lib/benchmark_driver/rvm.rb', line 39

def self.parse_spec(full_spec)
  name, spec = full_spec.split('::', 2)
  spec ||= name # if `::` is not given, regard whole string as spec
  version, *args = spec.shellsplit
  BenchmarkDriver::Config::Executable.new(
    name: name,
    command: [BenchmarkDriver::Rvm.ruby_path(version), *args],
  )
end

.ruby_path(version) ⇒ Object

Parameters:

  • version (String)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/benchmark_driver/rvm.rb', line 20

def self.ruby_path(version)
  path = if version == 'system'
    system_ruby_path
  else
    rubies = Pathname.new("#{ENV['rvm_path']}/rubies")
    abort "Rubies path '#{rubies}' not found" unless rubies.exist?
    ruby_list = rubies.children.select { |path| path.directory? && path.basename.to_s.match(version) }
    ruby_root = ruby_list.detect { |path| path.basename.to_s == version } || ruby_list[0]
    abort "Version '#{version}' not found" unless ruby_root
    "#{ruby_root}/bin/ruby"
  end

  unless File.exist?(path)
    abort "Binary '#{path}' not found"
  end
  path
end

.system_ruby_pathObject

Execute “which -a ruby” command to get a list of Ruby versions from $PATH.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/benchmark_driver/rvm.rb', line 7

def self.system_ruby_path
  env_rubies = `which -a ruby`
  abort "Failed to execute 'which -a ruby'" unless $?.success?

  env_rubies.each_line do |line|
    if !line.match(ENV['rvm_path'])
      return line.rstrip
    end
  end
  abort "System ruby not found"
end