summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-02-24 20:23:44 -0600
committerSamuel Giddins <segiddins@segiddins.me>2016-02-24 20:23:44 -0600
commit8a06ca5f6e96636e9349617851dd1b0eb8af1bd8 (patch)
tree4dc4ab184d27a56c1139a593492436f9d5375ac0 /bin
parentc1f6b0ca96a5593e99a7b9133aff88ade1e38918 (diff)
downloadbundler-8a06ca5f6e96636e9349617851dd1b0eb8af1bd8.tar.gz
Add helper script for running with particular rubygems versions
Diffstat (limited to 'bin')
-rwxr-xr-xbin/rake6
-rwxr-xr-xbin/rspec6
-rwxr-xr-xbin/rubocop6
-rwxr-xr-xbin/with_rubygems35
4 files changed, 44 insertions, 9 deletions
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__