diff options
| author | David Rodriguez <deivid.rodriguez@riseup.net> | 2023-09-22 22:22:29 +0200 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-09-25 07:13:21 +0000 |
| commit | 0e808183eea91b610a17a941e4592b494e445203 (patch) | |
| tree | 163eddc2a76f49a1ec50c3d3cb4641e06e64a004 | |
| parent | 7816307b30189ec7d71d6ce704a9aebd0395d447 (diff) | |
[rubygems/rubygems] Allow standalone mode to work on a Windows edge case
If a gem is located in a different drive than the Gemfile, standalone
mode will fail to generate the `bundler/setup` script, failing with an
error like
```
ArgumentError: different prefix: "C:/" and "D:/a/rubygems/rubygems/bundler/tmp/2/bundled_app/bundle/bundler"
C:/hostedtoolcache/windows/Ruby/3.0.5/x64/lib/ruby/3.0.0/pathname.rb:528:in `relative_path_from'
D:/a/rubygems/rubygems/bundler/tmp/2/gems/system/gems/bundler-2.4.20/lib/bundler/installer/standalone.rb:58:in `gem_path'
D:/a/rubygems/rubygems/bundler/tmp/2/gems/system/gems/bundler-2.4.20/lib/bundler/installer/standalone.rb:33:in `block (2 levels) in paths'
D:/a/rubygems/rubygems/bundler/tmp/2/gems/system/gems/bundler-2.4.20/lib/bundler/installer/standalone.rb:32:in `map'
D:/a/rubygems/rubygems/bundler/tmp/2/gems/system/gems/bundler-2.4.20/lib/bundler/installer/standalone.rb:32:in `block in paths'
```
I'm fixing this by falling back to using a full path in this case.
This was caught by a failing spec, so I'm not adding new specs.
https://github.com/rubygems/rubygems/commit/3cb9b9ab7a
| -rw-r--r-- | lib/bundler/installer/standalone.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index a019fbd3b8..2145e846f7 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -55,13 +55,20 @@ module Bundler if spec.source.instance_of?(Source::Path) && spec.source.path.absolute? full_path else - Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s + relative_path_from(Bundler.root.join(bundler_path), :to => full_path) || full_path end rescue TypeError error_message = "#{spec.name} #{spec.version} has an invalid gemspec" raise Gem::InvalidSpecificationException.new(error_message) end + def relative_path_from(source, to:) + Pathname.new(to).relative_path_from(source).to_s + rescue ArgumentError + # on Windows, if source and destination are on different drivers, there's no relative path from one to the other + nil + end + def define_path_helpers <<~'END' unless defined?(Gem) |
