summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2024-09-12 19:24:46 +0200
committerHiroshi SHIBATA <[email protected]>2024-09-17 14:39:06 +0900
commit80e934c29c5bd8b7955e26f8683ac6644d69a200 (patch)
tree84300d13361276f377fdf53fb78d16e5d7c8d95a
parent335d630903c53c4c6665d739f620834f1b57c1de (diff)
[rubygems/rubygems] Fix `--local` hitting the network when default gems are included
https://github.com/rubygems/rubygems/commit/b9a2d4d539
-rw-r--r--lib/bundler/installer.rb3
-rw-r--r--lib/bundler/installer/gem_installer.rb6
-rw-r--r--lib/bundler/installer/parallel_installer.rb5
-rw-r--r--lib/bundler/source/rubygems.rb6
-rw-r--r--spec/bundler/bundler/installer/gem_installer_spec.rb7
-rw-r--r--spec/bundler/cache/gems_spec.rb5
6 files changed, 21 insertions, 11 deletions
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 6c07d2328b..b65546a10a 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -196,8 +196,9 @@ module Bundler
def install(options)
standalone = options[:standalone]
force = options[:force]
+ local = options[:local]
jobs = installation_parallelization(options)
- spec_installations = ParallelInstaller.call(self, @definition.specs, jobs, standalone, force)
+ spec_installations = ParallelInstaller.call(self, @definition.specs, jobs, standalone, force, local: local)
spec_installations.each do |installation|
post_install_messages[installation.name] = installation.post_install_message if installation.has_post_install_message?
end
diff --git a/lib/bundler/installer/gem_installer.rb b/lib/bundler/installer/gem_installer.rb
index a7770eb7e0..1da91857bd 100644
--- a/lib/bundler/installer/gem_installer.rb
+++ b/lib/bundler/installer/gem_installer.rb
@@ -2,14 +2,15 @@
module Bundler
class GemInstaller
- attr_reader :spec, :standalone, :worker, :force, :installer
+ attr_reader :spec, :standalone, :worker, :force, :local, :installer
- def initialize(spec, installer, standalone = false, worker = 0, force = false)
+ def initialize(spec, installer, standalone = false, worker = 0, force = false, local = false)
@spec = spec
@installer = installer
@standalone = standalone
@worker = worker
@force = force
+ @local = local
end
def install_from_spec
@@ -54,6 +55,7 @@ module Bundler
spec.source.install(
spec,
force: force,
+ local: local,
build_args: Array(spec_settings),
previous_spec: previous_spec,
)
diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb
index e745088f81..d10e5ec924 100644
--- a/lib/bundler/installer/parallel_installer.rb
+++ b/lib/bundler/installer/parallel_installer.rb
@@ -68,11 +68,12 @@ module Bundler
attr_reader :size
- def initialize(installer, all_specs, size, standalone, force, skip: nil)
+ def initialize(installer, all_specs, size, standalone, force, local: false, skip: nil)
@installer = installer
@size = size
@standalone = standalone
@force = force
+ @local = local
@specs = all_specs.map {|s| SpecInstallation.new(s) }
@specs.each do |spec_install|
spec_install.state = :installed if skip.include?(spec_install.name)
@@ -127,7 +128,7 @@ module Bundler
def do_install(spec_install, worker_num)
Plugin.hook(Plugin::Events::GEM_BEFORE_INSTALL, spec_install)
gem_installer = Bundler::GemInstaller.new(
- spec_install.spec, @installer, @standalone, worker_num, @force
+ spec_install.spec, @installer, @standalone, worker_num, @force, @local
)
success, message = gem_installer.install_from_spec
if success
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index 31815ea63a..3b6ef8bd58 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -148,7 +148,7 @@ module Bundler
end
def install(spec, options = {})
- if (spec.default_gem? && !cached_built_in_gem(spec)) || (installed?(spec) && !options[:force])
+ if (spec.default_gem? && !cached_built_in_gem(spec, local: options[:local])) || (installed?(spec) && !options[:force])
print_using_message "Using #{version_message(spec, options[:previous_spec])}"
return nil # no post-install message
end
@@ -222,9 +222,9 @@ module Bundler
raise InstallError, e.message
end
- def cached_built_in_gem(spec)
+ def cached_built_in_gem(spec, local: false)
cached_path = cached_gem(spec)
- if cached_path.nil?
+ if cached_path.nil? && !local
remote_spec = remote_specs.search(spec).first
if remote_spec
cached_path = fetch_gem(remote_spec)
diff --git a/spec/bundler/bundler/installer/gem_installer_spec.rb b/spec/bundler/bundler/installer/gem_installer_spec.rb
index ea506c36c8..6583bd8181 100644
--- a/spec/bundler/bundler/installer/gem_installer_spec.rb
+++ b/spec/bundler/bundler/installer/gem_installer_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe Bundler::GemInstaller do
let(:installer) { instance_double("Installer", definition: definition) }
let(:spec_source) { instance_double("SpecSource") }
let(:spec) { instance_double("Specification", name: "dummy", version: "0.0.1", loaded_from: "dummy", source: spec_source) }
+ let(:base_options) { { force: false, local: false, previous_spec: nil } }
subject { described_class.new(spec, installer) }
@@ -14,7 +15,7 @@ RSpec.describe Bundler::GemInstaller do
it "invokes install method with empty build_args" do
allow(spec_source).to receive(:install).with(
spec,
- { force: false, build_args: [], previous_spec: nil }
+ base_options.merge(build_args: [])
)
subject.install_from_spec
end
@@ -28,7 +29,7 @@ RSpec.describe Bundler::GemInstaller do
allow(Bundler.settings).to receive(:[]).with("build.dummy").and_return("--with-dummy-config=dummy")
expect(spec_source).to receive(:install).with(
spec,
- { force: false, build_args: ["--with-dummy-config=dummy"], previous_spec: nil }
+ base_options.merge(build_args: ["--with-dummy-config=dummy"])
)
subject.install_from_spec
end
@@ -42,7 +43,7 @@ RSpec.describe Bundler::GemInstaller do
allow(Bundler.settings).to receive(:[]).with("build.dummy").and_return("--with-dummy-config=dummy --with-another-dummy-config")
expect(spec_source).to receive(:install).with(
spec,
- { force: false, build_args: ["--with-dummy-config=dummy", "--with-another-dummy-config"], previous_spec: nil }
+ base_options.merge(build_args: ["--with-dummy-config=dummy", "--with-another-dummy-config"])
)
subject.install_from_spec
end
diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb
index 31272ebec6..a694df2700 100644
--- a/spec/bundler/cache/gems_spec.rb
+++ b/spec/bundler/cache/gems_spec.rb
@@ -108,6 +108,11 @@ RSpec.describe "bundle cache" do
expect(out).to include("Installing json #{default_json_version}")
end
+ it "does not use remote gems when installing with --local flag" do
+ install_gemfile %(source "https://gem.repo2"; gem 'json', '#{default_json_version}'), verbose: true, local: true
+ expect(out).to include("Using json #{default_json_version}")
+ end
+
it "caches remote and builtin gems" do
install_gemfile <<-G
source "https://gem.repo2"