summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2018-10-17 17:38:54 +0000
committerBundlerbot <bot@bundler.io>2018-10-17 17:38:54 +0000
commit18369b8a0999f11515e28603676f99ca376d7d93 (patch)
tree456cc07a39f12d2ba9734a04bca13323d081b6d2
parenta144e72484ee16fb57a13fb1ba1a54ebefaf5b2e (diff)
parent4e60117ece710fe99396d4a3f02d6430f7346fa3 (diff)
downloadbundler-18369b8a0999f11515e28603676f99ca376d7d93.tar.gz
Merge #6738
6738: Make RakeTask spec:deps OS agnostic r=segiddins a=leoarnold @segiddins encouraged contributions towards support for Windows https://github.com/bundler/bundler/issues/5992#issuecomment-326809543 As a first step towards this goal this commit introduces safe and OS agnostic directory traversal in the first pieces of Ruby code called when setting up a test environment. ### What was the end-user problem that led to this PR? See #5992. ### What was your diagnosis of the problem? File path concatenation explicitly used UNIX style file system separators. ### What is your fix for the problem, implemented in this PR? Use `File.join` and `Pathname.join` instead. Define null device explicitly since Ruby 1.8.7 does not know `File::NULL`. Co-authored-by: Leo Arnold <github@leoarnold.de>
-rw-r--r--Rakefile3
-rw-r--r--spec/support/path.rb8
-rw-r--r--spec/support/rubygems_ext.rb12
3 files changed, 12 insertions, 11 deletions
diff --git a/Rakefile b/Rakefile
index a4e4b19db2..625e6630bf 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,7 +5,8 @@ $:.unshift File.expand_path("../lib", __FILE__)
require "shellwords"
require "benchmark"
-RUBYGEMS_REPO = if `cd .. && git remote --verbose 2>/dev/null` =~ /rubygems/i
+NULL_DEVICE = (Gem.win_platform? ? "NUL" : "/dev/null")
+RUBYGEMS_REPO = if `git -C "#{File.expand_path("..")}" remote --verbose 2> #{NULL_DEVICE}` =~ /rubygems/i
File.expand_path("..")
else
File.expand_path("tmp/rubygems")
diff --git a/spec/support/path.rb b/spec/support/path.rb
index b24ac16d5b..8dd8f5a277 100644
--- a/spec/support/path.rb
+++ b/spec/support/path.rb
@@ -9,15 +9,15 @@ module Spec
end
def gemspec
- @gemspec ||= Pathname.new(File.expand_path(root.join("bundler.gemspec"), __FILE__))
+ @gemspec ||= root.join("bundler.gemspec")
end
def bindir
- @bindir ||= Pathname.new(File.expand_path(root.join("exe"), __FILE__))
+ @bindir ||= root.join("exe")
end
def spec_dir
- @spec_dir ||= Pathname.new(File.expand_path(root.join("spec"), __FILE__))
+ @spec_dir ||= root.join("spec")
end
def tmp(*path)
@@ -95,7 +95,7 @@ module Spec
end
def bundler_path
- Pathname.new(File.expand_path(root.join("lib"), __FILE__))
+ root.join("lib")
end
def global_plugin_gem(*args)
diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb
index c18f7650fc..eff142118f 100644
--- a/spec/support/rubygems_ext.rb
+++ b/spec/support/rubygems_ext.rb
@@ -33,17 +33,17 @@ module Spec
ENV["BUNDLE_PATH"] = nil
ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s
- ENV["PATH"] = [Path.bindir, "#{Path.system_gem_path}/bin", ENV["PATH"]].join(File::PATH_SEPARATOR)
+ ENV["PATH"] = [Path.bindir, Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
manifest = DEPS.to_a.sort_by(&:first).map {|k, v| "#{k} => #{v}\n" }
- manifest_path = "#{Path.base_system_gems}/manifest.txt"
+ manifest_path = Path.base_system_gems.join("manifest.txt")
# it's OK if there are extra gems
- if !File.exist?(manifest_path) || !(manifest - File.readlines(manifest_path)).empty?
+ if !manifest_path.file? || !(manifest - manifest_path.readlines).empty?
FileUtils.rm_rf(Path.base_system_gems)
FileUtils.mkdir_p(Path.base_system_gems)
puts "installing gems for the tests to use..."
install_gems(DEPS)
- File.open(manifest_path, "w") {|f| f << manifest.join }
+ manifest_path.open("w") {|f| f << manifest.join }
end
ENV["HOME"] = Path.home.to_s
@@ -60,9 +60,9 @@ module Spec
reqs.map! {|name, req| "'#{name}:#{req}'" }
deps = reqs.concat(no_reqs).join(" ")
cmd = if Gem::VERSION < "2.0.0"
- "gem install #{deps} --no-rdoc --no-ri --conservative"
+ "#{Gem.ruby} -S gem install #{deps} --no-rdoc --no-ri --conservative"
else
- "gem install #{deps} --no-document --conservative"
+ "#{Gem.ruby} -S gem install #{deps} --no-document --conservative"
end
puts cmd
system(cmd) || raise("Installing gems #{deps} for the tests to use failed!")