summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rubygems/dependency_installer.rb4
-rw-r--r--lib/rubygems/install_update_options.rb12
-rw-r--r--lib/rubygems/installer.rb15
-rw-r--r--lib/rubygems/request_set.rb2
-rw-r--r--test/rubygems/test_gem_installer.rb52
5 files changed, 82 insertions, 3 deletions
diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb
index 6a6dfa5c20..c842714d95 100644
--- a/lib/rubygems/dependency_installer.rb
+++ b/lib/rubygems/dependency_installer.rb
@@ -88,6 +88,8 @@ class Gem::DependencyInstaller
@dir_mode = options[:dir_mode]
@data_mode = options[:data_mode]
@prog_mode = options[:prog_mode]
+ @build_extension = options[:build_extension]
+ @install_plugin = options[:install_plugin]
# Indicates that we should not try to update any deps unless
# we absolutely must.
@@ -169,6 +171,8 @@ class Gem::DependencyInstaller
dir_mode: @dir_mode,
data_mode: @data_mode,
prog_mode: @prog_mode,
+ build_extension: @build_extension,
+ install_plugin: @install_plugin,
}
options[:install_dir] = @install_dir if @only_install_dir
diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb
index 66cb5c049b..e8859cadaf 100644
--- a/lib/rubygems/install_update_options.rb
+++ b/lib/rubygems/install_update_options.rb
@@ -192,6 +192,18 @@ module Gem::InstallUpdateOptions
"rbconfig.rb for the deployment target platform") do |v, _o|
Gem.set_target_rbconfig(v)
end
+
+ add_option(:"Install/Update", "--[no-]build-extension",
+ "Build native extensions during installation.",
+ "Defaults to true") do |v, _o|
+ options[:build_extension] = v
+ end
+
+ add_option(:"Install/Update", "--[no-]install-plugin",
+ "Install plugins during installation.",
+ "Defaults to true") do |v, _o|
+ options[:install_plugin] = v
+ end
end
##
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 914e413677..730708fc33 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -282,12 +282,16 @@ class Gem::Installer
extract_files
- build_extensions
+ if options[:build_extension] == false
+ warn_skipped_extensions
+ else
+ build_extensions
+ end
write_build_info_file
run_post_build_hooks
generate_bin
- generate_plugins
+ generate_plugins unless options[:install_plugin] == false
write_spec
write_cache_file
@@ -809,6 +813,13 @@ class Gem::Installer
builder.build_extensions
end
+ def warn_skipped_extensions # :nodoc:
+ return if spec.extensions.empty?
+
+ alert_warning "#{spec.full_name} contains native extensions that were not built.\n" \
+ "To build extensions, run: gem install #{spec.name} --build-extension"
+ end
+
##
# Reads the file index and extracts each file into the gem directory.
#
diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb
index 5a855fdb10..dbebd1af0c 100644
--- a/lib/rubygems/request_set.rb
+++ b/lib/rubygems/request_set.rb
@@ -182,7 +182,7 @@ class Gem::RequestSet
# Install requested gems after they have been downloaded
sorted_requests.each do |req|
if req.installed? && @always_install.none? {|spec| spec == req.spec.spec }
- req.spec.spec.build_extensions
+ req.spec.spec.build_extensions unless options[:build_extension] == false
yield req, nil if block_given?
next
end
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index f20771c5f0..ca0a82a94e 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -2442,6 +2442,58 @@ class TestGemInstaller < Gem::InstallerTestCase
assert_kind_of(String, installer.gem)
end
+ def test_install_no_build_extension
+ installer = util_setup_installer
+
+ gemdir = File.join @gemhome, "gems", @spec.full_name
+
+ installer.options[:build_extension] = false
+
+ use_ui @ui do
+ installer.install
+ end
+
+ assert_path_exist gemdir
+ assert_path_not_exist File.join(@spec.extension_dir, "gem.build_complete")
+ assert_match "contains native extensions that were not built", @ui.error
+ end
+
+ def test_install_no_build_extension_without_extensions
+ spec = quick_gem "b", 2
+
+ util_build_gem spec
+
+ installer = util_installer spec, @gemhome
+ installer.options[:build_extension] = false
+
+ use_ui @ui do
+ installer.install
+ end
+
+ refute_match "contains native extensions", @ui.error
+ end
+
+ def test_install_no_install_plugin
+ installer = util_setup_installer do |spec|
+ write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
+ io.write "# do nothing"
+ end
+
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end
+
+ installer.options[:install_plugin] = false
+
+ build_rake_in do
+ use_ui @ui do
+ installer.install
+ end
+ end
+
+ plugin_path = File.join Gem.plugindir, "a_plugin.rb"
+ refute File.exist?(plugin_path), "plugin must not be written when --no-install-plugin"
+ end
+
private
def util_execless