Sha256: d2eb14f7673373ae2f9f69493ea174cfba41b031814b06a9d0711f9997466ab7

Contents?: true

Size: 1.54 KB

Versions: 16

Compression:

Stored size: 1.54 KB

Contents

require 'shellwords'
require 'pathname'

module BenchmarkDriver
  module Rvm
    # Execute "which -a ruby" command to get a list of Ruby versions from $PATH.
    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

    # @param [String] version
    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

    # @param [String] full_spec - "2.5.0", "2.5.0 --jit", "JIT::2.5.0 --jit", etc.
    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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
benchmark_driver-0.16.5 lib/benchmark_driver/rvm.rb
benchmark_driver-0.16.4 lib/benchmark_driver/rvm.rb
benchmark_driver-0.16.3 lib/benchmark_driver/rvm.rb
benchmark_driver-0.16.2 lib/benchmark_driver/rvm.rb
benchmark_driver-0.16.1 lib/benchmark_driver/rvm.rb
benchmark_driver-0.16.0 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.18 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.17 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.16 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.15 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.14 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.13 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.12 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.11 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.10 lib/benchmark_driver/rvm.rb
benchmark_driver-0.15.9 lib/benchmark_driver/rvm.rb