Skip to content

Commit ff9c659

Browse files
authored
Merge pull request #7588 from ruby/deprecate-default-option
Deprecate `--default` option from install command
2 parents 673e16c + c3cc38c commit ff9c659

File tree

10 files changed

+74
-167
lines changed

10 files changed

+74
-167
lines changed

Manifest.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ lib/rubygems/gemcutter_utilities/webauthn_listener.rb
428428
lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb
429429
lib/rubygems/gemcutter_utilities/webauthn_poller.rb
430430
lib/rubygems/gemspec_helpers.rb
431-
lib/rubygems/install_default_message.rb
432431
lib/rubygems/install_message.rb
433432
lib/rubygems/install_update_options.rb
434433
lib/rubygems/installer.rb

bundler/spec/support/helpers.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,20 @@ def install_gem(path, install_dir, default = false)
333333
raise "OMG `#{path}` does not exist!" unless File.exist?(path)
334334

335335
args = "--no-document --ignore-dependencies --verbose --local --install-dir #{install_dir}"
336-
args += " --default" if default
337336

338337
gem_command "install #{args} '#{path}'"
338+
339+
if default
340+
gem = Pathname.new(path).basename.to_s.match(/(.*)\.gem/)[1]
341+
342+
# Revert Gem::Installer#write_spec and apply Gem::Installer#write_default_spec
343+
FileUtils.mkdir_p File.join(install_dir, "specifications", "default")
344+
File.rename File.join(install_dir, "specifications", gem + ".gemspec"),
345+
File.join(install_dir, "specifications", "default", gem + ".gemspec")
346+
347+
# Revert Gem::Installer#write_cache_file
348+
File.delete File.join(install_dir, "cache", gem + ".gem")
349+
end
339350
end
340351

341352
def with_built_bundler(version = nil, opts = {}, &block)

lib/rubygems/commands/install_command.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,7 @@ def install_gems # :nodoc:
239239
# Loads post-install hooks
240240

241241
def load_hooks # :nodoc:
242-
if options[:install_as_default]
243-
require_relative "../install_default_message"
244-
else
245-
require_relative "../install_message"
246-
end
242+
require_relative "../install_message"
247243
require_relative "../rdoc"
248244
end
249245

lib/rubygems/commands/setup_command.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,18 @@ def install_default_bundler_gem(bin_dir)
393393
Dir.chdir("bundler") do
394394
built_gem = Gem::Package.build(new_bundler_spec)
395395
begin
396-
Gem::Installer.at(
396+
installer = Gem::Installer.at(
397397
built_gem,
398398
env_shebang: options[:env_shebang],
399399
format_executable: options[:format_executable],
400400
force: options[:force],
401-
install_as_default: true,
402401
bin_dir: bin_dir,
403402
install_dir: default_dir,
404403
wrappers: true
405-
).install
404+
)
405+
installer.install
406+
File.delete installer.spec_file
407+
installer.write_default_spec
406408
ensure
407409
FileUtils.rm_f built_gem
408410
end

lib/rubygems/dependency_installer.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Gem::DependencyInstaller
2828
wrappers: true,
2929
build_args: nil,
3030
build_docs_in_background: false,
31-
install_as_default: false,
3231
}.freeze
3332

3433
##
@@ -87,7 +86,6 @@ def initialize(options = {})
8786
@wrappers = options[:wrappers]
8887
@build_args = options[:build_args]
8988
@build_docs_in_background = options[:build_docs_in_background]
90-
@install_as_default = options[:install_as_default]
9189
@dir_mode = options[:dir_mode]
9290
@data_mode = options[:data_mode]
9391
@prog_mode = options[:prog_mode]
@@ -240,7 +238,6 @@ def install(dep_or_name, version = Gem::Requirement.default)
240238
user_install: @user_install,
241239
wrappers: @wrappers,
242240
build_root: @build_root,
243-
install_as_default: @install_as_default,
244241
dir_mode: @dir_mode,
245242
data_mode: @data_mode,
246243
prog_mode: @prog_mode,

lib/rubygems/install_default_message.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/rubygems/install_update_options.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,9 @@ def add_install_update_options
158158
options[:without_groups].concat v.map(&:intern)
159159
end
160160

161-
add_option(:"Install/Update", "--default",
161+
add_option(:Deprecated, "--default",
162162
"Add the gem's full specification to",
163163
"specifications/default and extract only its bin") do |v,_o|
164-
options[:install_as_default] = v
165164
end
166165

167166
add_option(:"Install/Update", "--explain",

lib/rubygems/installer.rb

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,7 @@ def install
274274
run_pre_install_hooks
275275

276276
# Set loaded_from to ensure extension_dir is correct
277-
if @options[:install_as_default]
278-
spec.loaded_from = default_spec_file
279-
else
280-
spec.loaded_from = spec_file
281-
end
277+
spec.loaded_from = spec_file
282278

283279
# Completely remove any previous gem files
284280
FileUtils.rm_rf gem_dir
@@ -287,24 +283,17 @@ def install
287283
dir_mode = options[:dir_mode]
288284
FileUtils.mkdir_p gem_dir, mode: dir_mode && 0o755
289285

290-
if @options[:install_as_default]
291-
extract_bin
292-
write_default_spec
293-
else
294-
extract_files
286+
extract_files
295287

296-
build_extensions
297-
write_build_info_file
298-
run_post_build_hooks
299-
end
288+
build_extensions
289+
write_build_info_file
290+
run_post_build_hooks
300291

301292
generate_bin
302293
generate_plugins
303294

304-
unless @options[:install_as_default]
305-
write_spec
306-
write_cache_file
307-
end
295+
write_spec
296+
write_cache_file
308297

309298
File.chmod(dir_mode, gem_dir) if dir_mode
310299

@@ -409,12 +398,18 @@ def spec_file
409398
File.join gem_home, "specifications", "#{spec.full_name}.gemspec"
410399
end
411400

401+
def default_spec_dir
402+
dir = File.join(gem_home, "specifications", "default")
403+
FileUtils.mkdir_p dir
404+
dir
405+
end
406+
412407
##
413408
# The location of the default spec file for default gems.
414409
#
415410

416411
def default_spec_file
417-
File.join gem_home, "specifications", "default", "#{spec.full_name}.gemspec"
412+
File.join default_spec_dir, "#{spec.full_name}.gemspec"
418413
end
419414

420415
##
@@ -889,11 +884,7 @@ def pre_install_checks
889884

890885
ensure_loadable_spec
891886

892-
if options[:install_as_default]
893-
Gem.ensure_default_gem_subdirectories gem_home
894-
else
895-
Gem.ensure_gem_subdirectories gem_home
896-
end
887+
Gem.ensure_gem_subdirectories gem_home
897888

898889
return true if @force
899890

test/rubygems/helper.rb

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,44 @@ def self.specific_extra_args_hash=(value)
6060
end
6161
end
6262

63+
class Gem::Installer
64+
# Copy from Gem::Installer#install with install_as_default option from old version
65+
def install_default_gem
66+
pre_install_checks
67+
68+
run_pre_install_hooks
69+
70+
spec.loaded_from = default_spec_file
71+
72+
FileUtils.rm_rf gem_dir
73+
FileUtils.rm_rf spec.extension_dir
74+
75+
dir_mode = options[:dir_mode]
76+
FileUtils.mkdir_p gem_dir, mode: dir_mode && 0o755
77+
78+
extract_bin
79+
write_default_spec
80+
81+
generate_bin
82+
generate_plugins
83+
84+
File.chmod(dir_mode, gem_dir) if dir_mode
85+
86+
say spec.post_install_message if options[:post_install_message] && !spec.post_install_message.nil?
87+
88+
Gem::Specification.add_spec(spec)
89+
90+
load_plugin
91+
92+
run_post_install_hooks
93+
94+
spec
95+
rescue Errno::EACCES => e
96+
# Permission denied - /path/to/foo
97+
raise Gem::FilePermissionError, e.message.split(" - ").last
98+
end
99+
end
100+
63101
##
64102
# RubyGemTestCase provides a variety of methods for testing rubygems and
65103
# gem-related behavior in a sandbox. Through RubyGemTestCase you can install
@@ -811,8 +849,8 @@ def install_specs(*specs)
811849

812850
def install_default_gems(*specs)
813851
specs.each do |spec|
814-
installer = Gem::Installer.for_spec(spec, install_as_default: true)
815-
installer.install
852+
installer = Gem::Installer.for_spec(spec)
853+
installer.install_default_gem
816854
Gem.register_default_spec(spec)
817855
end
818856
end

test/rubygems/test_gem_installer.rb

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,119 +2425,6 @@ def test_dir
24252425
assert_match %r{/gemhome/gems/a-2$}, installer.dir
24262426
end
24272427

2428-
def test_default_gem_loaded_from
2429-
spec = util_spec "a"
2430-
installer = Gem::Installer.for_spec spec, install_as_default: true
2431-
installer.install
2432-
assert_predicate spec, :default_gem?
2433-
end
2434-
2435-
def test_default_gem_without_wrappers
2436-
installer = setup_base_installer
2437-
2438-
FileUtils.rm_rf File.join(Gem.default_dir, "specifications")
2439-
2440-
installer.wrappers = false
2441-
installer.options[:install_as_default] = true
2442-
installer.gem_dir = @spec.gem_dir
2443-
2444-
use_ui @ui do
2445-
installer.install
2446-
end
2447-
2448-
assert_directory_exists File.join(@spec.gem_dir, "bin")
2449-
installed_exec = File.join @spec.gem_dir, "bin", "executable"
2450-
assert_path_exist installed_exec
2451-
2452-
assert_directory_exists File.join(Gem.default_dir, "specifications")
2453-
assert_directory_exists File.join(Gem.default_dir, "specifications", "default")
2454-
2455-
default_spec = eval File.read File.join(Gem.default_dir, "specifications", "default", "a-2.gemspec")
2456-
assert_equal Gem::Version.new("2"), default_spec.version
2457-
assert_equal ["bin/executable"], default_spec.files
2458-
2459-
assert_directory_exists util_inst_bindir
2460-
2461-
installed_exec = File.join util_inst_bindir, "executable"
2462-
assert_path_exist installed_exec
2463-
2464-
wrapper = File.read installed_exec
2465-
2466-
if symlink_supported?
2467-
refute_match(/generated by RubyGems/, wrapper)
2468-
else # when symlink not supported, it warns and fallbacks back to installing wrapper
2469-
assert_match(/Unable to use symlinks, installing wrapper/, @ui.error)
2470-
assert_match(/generated by RubyGems/, wrapper)
2471-
end
2472-
end
2473-
2474-
def test_default_gem_with_wrappers
2475-
installer = setup_base_installer
2476-
2477-
installer.wrappers = true
2478-
installer.options[:install_as_default] = true
2479-
installer.gem_dir = @spec.gem_dir
2480-
2481-
use_ui @ui do
2482-
installer.install
2483-
end
2484-
2485-
assert_directory_exists util_inst_bindir
2486-
2487-
installed_exec = File.join util_inst_bindir, "executable"
2488-
assert_path_exist installed_exec
2489-
2490-
wrapper = File.read installed_exec
2491-
assert_match(/generated by RubyGems/, wrapper)
2492-
end
2493-
2494-
def test_default_gem_with_exe_as_bindir
2495-
@spec = quick_gem "c" do |spec|
2496-
util_make_exec spec, "#!/usr/bin/ruby", "exe"
2497-
end
2498-
2499-
util_build_gem @spec
2500-
2501-
@spec.cache_file
2502-
2503-
installer = util_installer @spec, @gemhome
2504-
2505-
installer.options[:install_as_default] = true
2506-
installer.gem_dir = @spec.gem_dir
2507-
2508-
use_ui @ui do
2509-
installer.install
2510-
end
2511-
2512-
assert_directory_exists File.join(@spec.gem_dir, "exe")
2513-
installed_exec = File.join @spec.gem_dir, "exe", "executable"
2514-
assert_path_exist installed_exec
2515-
2516-
assert_directory_exists File.join(Gem.default_dir, "specifications")
2517-
assert_directory_exists File.join(Gem.default_dir, "specifications", "default")
2518-
2519-
default_spec = eval File.read File.join(Gem.default_dir, "specifications", "default", "c-2.gemspec")
2520-
assert_equal Gem::Version.new("2"), default_spec.version
2521-
assert_equal ["exe/executable"], default_spec.files
2522-
end
2523-
2524-
def test_default_gem_to_specific_install_dir
2525-
@gem = setup_base_gem
2526-
installer = util_installer @spec, "#{@gemhome}2"
2527-
installer.options[:install_as_default] = true
2528-
2529-
use_ui @ui do
2530-
installer.install
2531-
end
2532-
2533-
assert_directory_exists File.join("#{@gemhome}2", "specifications")
2534-
assert_directory_exists File.join("#{@gemhome}2", "specifications", "default")
2535-
2536-
default_spec = eval File.read File.join("#{@gemhome}2", "specifications", "default", "a-2.gemspec")
2537-
assert_equal Gem::Version.new("2"), default_spec.version
2538-
assert_equal ["bin/executable"], default_spec.files
2539-
end
2540-
25412428
def test_package_attribute
25422429
gem = quick_gem "c" do |spec|
25432430
util_make_exec spec, "#!/usr/bin/ruby", "exe"

0 commit comments

Comments
 (0)