Skip to content

Commit 2c1b175

Browse files
Edouard-chinmatzbot
authored andcommitted
[ruby/rubygems] Add debug logging information:
- I'd like to be able to see how long bundler takes for basic operations such as downloading a gem from Rubygems.org and installing a gem. It will now be possible with this commit by running `DEBUG=true bundle install` and have output that looks like: Fetching rack-test 2.2.0 Downloaded rack-test in: 50.523s Installing rack-test 2.2.0 Installed rack-test in: : 0.003s ruby/rubygems@46386d43e1
1 parent b4b7809 commit 2c1b175

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/bundler/source/rubygems.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ def install(spec, options = {})
211211
message += " with native extensions" if spec.extensions.any?
212212
Bundler.ui.confirm message
213213

214-
installed_spec = installer.install
214+
installed_spec = nil
215+
216+
Gem.time("Installed #{spec.name} in", 0, true) do
217+
installed_spec = installer.install
218+
end
215219

216220
spec.full_gem_path = installed_spec.full_gem_path
217221
spec.loaded_from = installed_spec.loaded_from
@@ -478,7 +482,10 @@ def download_gem(spec, download_cache_path, previous_spec = nil)
478482
uri = spec.remote.uri
479483
Bundler.ui.confirm("Fetching #{version_message(spec, previous_spec)}")
480484
gem_remote_fetcher = remote_fetchers.fetch(spec.remote).gem_remote_fetcher
481-
Bundler.rubygems.download_gem(spec, uri, download_cache_path, gem_remote_fetcher)
485+
486+
Gem.time("Downloaded #{spec.name} in", 0, true) do
487+
Bundler.rubygems.download_gem(spec, uri, download_cache_path, gem_remote_fetcher)
488+
end
482489
end
483490

484491
# Returns the global cache path of the calling Rubygems::Source object.

spec/bundler/bundler/source/rubygems_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,22 @@
4444
end
4545
end
4646
end
47+
48+
describe "log debug information" do
49+
it "log the time spent downloading and installing a gem" do
50+
build_repo2 do
51+
build_gem "warning"
52+
end
53+
54+
gemfile_content = <<~G
55+
source "https://gem.repo2"
56+
gem "warning"
57+
G
58+
59+
stdout = install_gemfile(gemfile_content, env: { "DEBUG" => "1" })
60+
61+
expect(stdout).to match(/Downloaded warning in: \d+\.\d+s/)
62+
expect(stdout).to match(/Installed warning in: \d+\.\d+s/)
63+
end
64+
end
4765
end

0 commit comments

Comments
 (0)