From 8a06ca5f6e96636e9349617851dd1b0eb8af1bd8 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Wed, 24 Feb 2016 20:23:44 -0600 Subject: Add helper script for running with particular rubygems versions --- bin/rake | 6 +++--- bin/rspec | 6 +++--- bin/rubocop | 6 +++--- bin/with_rubygems | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 9 deletions(-) create mode 100755 bin/with_rubygems (limited to 'bin') diff --git a/bin/rake b/bin/rake index ccf7cbeedc..29b6d6f4aa 100755 --- a/bin/rake +++ b/bin/rake @@ -1,6 +1,8 @@ #!/usr/bin/env ruby # frozen_string_literal: true +load File.expand_path("../with_rubygems", __FILE__) if ENV["RGV"] + require "rubygems" bundler_spec = Gem::Specification.load(File.expand_path("../../bundler.gemspec", __FILE__)) @@ -12,8 +14,6 @@ bundler_spec.dependencies.each do |dep| end end -Gem::Specification.unresolved_deps.each do |_name, dep| - gem dep.name, *dep.requirement -end +Gem.finish_resolve if Gem.respond_to?(:finish_resolve) load Gem.bin_path("rake", "rake") diff --git a/bin/rspec b/bin/rspec index 404da15056..388fe57382 100755 --- a/bin/rspec +++ b/bin/rspec @@ -1,6 +1,8 @@ #!/usr/bin/env ruby # frozen_string_literal: true +load File.expand_path("../with_rubygems", __FILE__) if ENV["RGV"] + require "rubygems" bundler_spec = Gem::Specification.load(File.expand_path("../../bundler.gemspec", __FILE__)) @@ -8,8 +10,6 @@ bundler_spec.dependencies.each do |dep| gem dep.name, dep.requirement.to_s end -Gem::Specification.unresolved_deps.each do |_name, dep| - gem dep.name, *dep.requirement -end +Gem.finish_resolve if Gem.respond_to?(:finish_resolve) load Gem.bin_path("rspec-core", "rspec") diff --git a/bin/rubocop b/bin/rubocop index bc81f5cc88..01840861cc 100755 --- a/bin/rubocop +++ b/bin/rubocop @@ -1,6 +1,8 @@ #!/usr/bin/env ruby # frozen_string_literal: true +load File.expand_path("../with_rubygems", __FILE__) if ENV["RGV"] + require "rubygems" bundler_spec = Gem::Specification.load(File.expand_path("../../bundler.gemspec", __FILE__)) @@ -10,8 +12,6 @@ end gem "rubocop", "= 0.37.1" -Gem::Specification.unresolved_deps.each do |_name, dep| - gem dep.name, *dep.requirement -end +Gem.finish_resolve if Gem.respond_to?(:finish_resolve) load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/with_rubygems b/bin/with_rubygems new file mode 100755 index 0000000000..666467b1e5 --- /dev/null +++ b/bin/with_rubygems @@ -0,0 +1,35 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "pathname" + +def run(*cmd) + return if system(*cmd) + raise "Running `#{cmd.join(" ")}` failed" +end + +version = ENV.delete("RGV") +rubygems_path = Pathname.new(__FILE__).join("../../tmp/rubygems").expand_path +unless rubygems_path.directory? + rubygems_path.parent.mkpath unless rubygems_path.directory? + run("git", "clone", "https://github.com/rubygems/rubygems.git", rubygems_path.to_s) +end +Dir.chdir(rubygems_path) do + version = "v#{version}" if version =~ /\A\d/ + run("git", "checkout", version, "--quiet") +end if version + +ENV["RUBYOPT"] = %(-I#{rubygems_path + "lib"} #{ENV["RUBYOPT"]}) +if cmd = ARGV.first + possible_dirs = [ + Pathname.new(__FILE__) + "..", + Pathname.new(__FILE__) + "../../exe", + rubygems_path + "bin", + ] + cmd = possible_dirs.map do |dir| + dir.join(cmd).expand_path + end.find(&:file?) + ARGV[0] = cmd.to_s if cmd +end + +exec(*ARGV) if $0 == __FILE__ -- cgit v1.2.1