Skip to content

Commit 026ed9a

Browse files
Fix gem exec rails new foo failing on Ruby 3.2
The default version of securerandom (0.2.2) gets activated by RubyGems, but does not match Rails requirements (>= 0.3), leading to an error like this: ``` $ gem exec rails new repro /Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:2246:in `raise_if_conflicts': Unable to activate activesupport-7.2.1, because securerandom-0.2.2 conflicts with securerandom (>= 0.3) (Gem::ConflictError) from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:1383:in `activate' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:1421:in `block in activate_dependencies' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:1403:in `each' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:1403:in `activate_dependencies' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/specification.rb:1385:in `activate' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/core_ext/kernel_gem.rb:62:in `block in gem' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/core_ext/kernel_gem.rb:62:in `synchronize' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/core_ext/kernel_gem.rb:62:in `gem' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/exec_command.rb:193:in `activate!' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/commands/exec_command.rb:73:in `execute' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/command.rb:326:in `invoke_with_build_args' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/command_manager.rb:255:in `invoke_command' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/command_manager.rb:194:in `process_args' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/command_manager.rb:152:in `run' from /Users/deivid/Code/rubygems/rubygems/lib/rubygems/gem_runner.rb:56:in `run' from /Users/deivid/code/rubygems/rubygems/exe/gem:12:in `<main>' ``` Vendoring our own securerandom fixes the issue since that way we avoid activating the gem internally.
1 parent 93ab9ac commit 026ed9a

File tree

10 files changed

+508
-4
lines changed

10 files changed

+508
-4
lines changed

.github/workflows/install-rubygems.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ jobs:
8585
- name: Check bundler install didn't hit the network
8686
run: if grep -q 'GET http' output.txt; then false; else true; fi
8787
working-directory: ./bundler
88+
- name: Check gem exec can create a rails project
89+
run: gem exec rails new app --minimal
90+
if: matrix.ruby.name != 'truffleruby' && matrix.ruby.name != 'jruby'
8891
- name: Check rails can be installed
8992
run: gem install rails --verbose --backtrace
9093
timeout-minutes: 10

Manifest.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ lib/rubygems/vendor/optparse/lib/optparse/version.rb
586586
lib/rubygems/vendor/resolv/.document
587587
lib/rubygems/vendor/resolv/LICENSE.txt
588588
lib/rubygems/vendor/resolv/lib/resolv.rb
589+
lib/rubygems/vendor/securerandom/.document
590+
lib/rubygems/vendor/securerandom/LICENSE.txt
591+
lib/rubygems/vendor/securerandom/lib/random/formatter.rb
592+
lib/rubygems/vendor/securerandom/lib/securerandom.rb
589593
lib/rubygems/vendor/timeout/.document
590594
lib/rubygems/vendor/timeout/LICENSE.txt
591595
lib/rubygems/vendor/timeout/lib/timeout.rb

lib/rubygems/vendor/resolv/lib/resolv.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'io/wait'
66

77
begin
8-
require 'securerandom'
8+
require_relative '../../securerandom/lib/securerandom'
99
rescue LoadError
1010
end
1111

@@ -602,10 +602,10 @@ def extract_resources(msg, name, typeclass) # :nodoc:
602602
}
603603
end
604604

605-
if defined? SecureRandom
605+
if defined? Gem::SecureRandom
606606
def self.random(arg) # :nodoc:
607607
begin
608-
SecureRandom.random_number(arg)
608+
Gem::SecureRandom.random_number(arg)
609609
rescue NotImplementedError
610610
rand(arg)
611611
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Vendored files do not need to be documented
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions
5+
are met:
6+
1. Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
2. Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22+
SUCH DAMAGE.

0 commit comments

Comments
 (0)