Skip to content

Commit e8880f1

Browse files
Merge pull request #8071 from rubygems/deivid-rodriguez/idea-less-warnings
Warning about PATH in `--user-install` mode is only necessary for gems with executables (cherry picked from commit 6ea020e)
1 parent 5f965db commit e8880f1

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

lib/rubygems/installer.rb

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ class Gem::Installer
6666

6767
attr_reader :package
6868

69-
@path_warning = false
70-
7169
class << self
7270
#
7371
# Changes in rubygems to lazily loading `rubygems/command` (in order to
@@ -86,11 +84,6 @@ def inherited(klass)
8684
super(klass)
8785
end
8886

89-
##
90-
# True if we've warned about PATH not including Gem.bindir
91-
92-
attr_accessor :path_warning
93-
9487
##
9588
# Overrides the executable format.
9689
#
@@ -188,15 +181,6 @@ def initialize(package, options={})
188181
@package.dir_mode = options[:dir_mode]
189182
@package.prog_mode = options[:prog_mode]
190183
@package.data_mode = options[:data_mode]
191-
192-
if @gem_home == Gem.user_dir
193-
# If we get here, then one of the following likely happened:
194-
# - `--user-install` was specified
195-
# - `Gem::PathSupport#home` fell back to `Gem.user_dir`
196-
# - GEM_HOME was manually set to `Gem.user_dir`
197-
198-
check_that_user_bin_dir_is_in_path
199-
end
200184
end
201185

202186
##
@@ -488,11 +472,21 @@ def generate_windows_script(filename, bindir)
488472
end
489473

490474
def generate_bin # :nodoc:
491-
return if spec.executables.nil? || spec.executables.empty?
475+
executables = spec.executables
476+
return if executables.nil? || executables.empty?
477+
478+
if @gem_home == Gem.user_dir
479+
# If we get here, then one of the following likely happened:
480+
# - `--user-install` was specified
481+
# - `Gem::PathSupport#home` fell back to `Gem.user_dir`
482+
# - GEM_HOME was manually set to `Gem.user_dir`
483+
484+
check_that_user_bin_dir_is_in_path(executables)
485+
end
492486

493487
ensure_writable_dir @bin_dir
494488

495-
spec.executables.each do |filename|
489+
executables.each do |filename|
496490
bin_path = File.join gem_dir, spec.bindir, filename
497491
next unless File.exist? bin_path
498492

@@ -694,9 +688,7 @@ def process_options # :nodoc:
694688
end
695689
end
696690

697-
def check_that_user_bin_dir_is_in_path # :nodoc:
698-
return if self.class.path_warning
699-
691+
def check_that_user_bin_dir_is_in_path(executables) # :nodoc:
700692
user_bin_dir = @bin_dir || Gem.bindir(gem_home)
701693
user_bin_dir = user_bin_dir.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
702694

@@ -712,8 +704,7 @@ def check_that_user_bin_dir_is_in_path # :nodoc:
712704

713705
unless path.include? user_bin_dir
714706
unless !Gem.win_platform? && (path.include? user_bin_dir.sub(ENV["HOME"], "~"))
715-
alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
716-
self.class.path_warning = true
707+
alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables (#{executables.join(", ")}) will not run."
717708
end
718709
end
719710
end

test/rubygems/installer_test_case.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ class Gem::Installer
6464
# A test case for Gem::Installer.
6565

6666
class Gem::InstallerTestCase < Gem::TestCase
67-
def setup
68-
super
69-
70-
Gem::Installer.path_warning = false
71-
end
72-
7367
##
7468
# The path where installed executables live
7569

test/rubygems/test_gem_installer.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_check_that_user_bin_dir_is_in_path
208208
ENV["PATH"] = [ENV["PATH"], bin_dir].join(File::PATH_SEPARATOR)
209209

210210
use_ui @ui do
211-
installer.check_that_user_bin_dir_is_in_path
211+
installer.check_that_user_bin_dir_is_in_path(["executable"])
212212
end
213213

214214
assert_empty @ui.error
@@ -218,7 +218,7 @@ def test_check_that_user_bin_dir_is_in_path
218218
ENV["PATH"] = [orig_path, bin_dir.tr(File::SEPARATOR, File::ALT_SEPARATOR)].join(File::PATH_SEPARATOR)
219219

220220
use_ui @ui do
221-
installer.check_that_user_bin_dir_is_in_path
221+
installer.check_that_user_bin_dir_is_in_path(["executable"])
222222
end
223223

224224
assert_empty @ui.error
@@ -236,7 +236,7 @@ def test_check_that_user_bin_dir_is_in_path_tilde
236236
installer.bin_dir.replace File.join @userhome, "bin"
237237

238238
use_ui @ui do
239-
installer.check_that_user_bin_dir_is_in_path
239+
installer.check_that_user_bin_dir_is_in_path(["executable"])
240240
end
241241

242242
assert_empty @ui.error
@@ -248,7 +248,7 @@ def test_check_that_user_bin_dir_is_in_path_not_in_path
248248
installer = setup_base_installer
249249

250250
use_ui @ui do
251-
installer.check_that_user_bin_dir_is_in_path
251+
installer.check_that_user_bin_dir_is_in_path(["executable"])
252252
end
253253

254254
expected = installer.bin_dir
@@ -258,6 +258,7 @@ def test_check_that_user_bin_dir_is_in_path_not_in_path
258258
end
259259

260260
assert_match expected, @ui.error
261+
assert_match "(executable)", @ui.error
261262
end
262263

263264
def test_ensure_dependency
@@ -358,10 +359,8 @@ def test_generate_bin_bindir_with_user_install_warning
358359

359360
inst = Gem::Installer.at "", options
360361

361-
Gem::Installer.path_warning = false
362-
363362
use_ui @ui do
364-
inst.check_that_user_bin_dir_is_in_path
363+
inst.check_that_user_bin_dir_is_in_path(["executable"])
365364
end
366365

367366
assert_equal "", @ui.error

0 commit comments

Comments
 (0)