diff options
author | Homu <homu@barosl.com> | 2016-02-25 16:45:24 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-02-25 16:45:24 +0900 |
commit | 4552992885035a4a22f49fc0dc7f55681463a194 (patch) | |
tree | fd1799d1e6782278238b32d5f25be8a4c42418c1 | |
parent | 64e8b55515ac3e090f9a2a39091e398f5b750672 (diff) | |
parent | 2d5b5c443aa5765f8755e2453a0ded43b71565db (diff) | |
download | bundler-4552992885035a4a22f49fc0dc7f55681463a194.tar.gz |
Auto merge of #4320 - bundler:seg-with-rubygems, r=segiddins
Add helper script for running with particular rubygems versions
\c @indirect
-rwxr-xr-x | bin/rake | 6 | ||||
-rwxr-xr-x | bin/rspec | 6 | ||||
-rwxr-xr-x | bin/rubocop | 6 | ||||
-rwxr-xr-x | bin/with_rubygems | 39 |
4 files changed, 48 insertions, 9 deletions
@@ -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") @@ -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..d16c289822 --- /dev/null +++ b/bin/with_rubygems @@ -0,0 +1,39 @@ +#!/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 + +rubygems_lib = rubygems_path + "lib" +ENV["RUBYOPT"] = %(-I#{rubygems_lib} #{ENV["RUBYOPT"]}) + +if $0 != __FILE__ + ARGV.unshift($0) +elsif 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) |