[前][次][番号順一覧][スレッド一覧]

ruby-changes:70852

From: Vyacheslav <ko1@a...>
Date: Thu, 13 Jan 2022 18:16:13 +0900 (JST)
Subject: [ruby-changes:70852] d0a0637948 (master): [rubygems/rubygems] Use `Fiddle` in `bundle doctor` to check for dynamic library presence

https://git.ruby-lang.org/ruby.git/commit/?id=d0a0637948

From d0a063794873eafed413957cb7ab93279945258a Mon Sep 17 00:00:00 2001
From: Vyacheslav Alexeev <alexeev.corp@g...>
Date: Tue, 11 Jan 2022 23:38:32 +0800
Subject: [rubygems/rubygems] Use `Fiddle` in `bundle doctor` to check for
 dynamic library presence

https://github.com/rubygems/rubygems/commit/ecd495ce1b
---
 lib/bundler/cli/doctor.rb            | 10 +++++++++-
 spec/bundler/commands/doctor_spec.rb |  6 +++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb
index 43f1ca92e2d..74444ad0cef 100644
--- a/lib/bundler/cli/doctor.rb
+++ b/lib/bundler/cli/doctor.rb
@@ -2,6 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/doctor.rb#L2
 
 require "rbconfig"
 require "shellwords"
+require "fiddle"
 
 module Bundler
   class CLI::Doctor
@@ -71,7 +72,14 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli/doctor.rb#L72
 
       definition.specs.each do |spec|
         bundles_for_gem(spec).each do |bundle|
-          bad_paths = dylibs(bundle).select {|f| !File.exist?(f) }
+          bad_paths = dylibs(bundle).select do |f|
+            begin
+              Fiddle.dlopen(f)
+              false
+            rescue Fiddle::DLError
+              true
+            end
+          end
           if bad_paths.any?
             broken_links[spec] ||= []
             broken_links[spec].concat(bad_paths)
diff --git a/spec/bundler/commands/doctor_spec.rb b/spec/bundler/commands/doctor_spec.rb
index 860b638f06e..1eeb2761051 100644
--- a/spec/bundler/commands/doctor_spec.rb
+++ b/spec/bundler/commands/doctor_spec.rb
@@ -49,8 +49,8 @@ RSpec.describe "bundle doctor" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/doctor_spec.rb#L49
       doctor = Bundler::CLI::Doctor.new({})
       expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/rack/rack.bundle"]
       expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/lib/libSystem.dylib"]
-      allow(File).to receive(:exist?).with("/usr/lib/libSystem.dylib").and_return(true)
-      expect { doctor.run }.not_to(raise_error, @stdout.string)
+      allow(Fiddle).to receive(:dlopen).with("/usr/lib/libSystem.dylib").and_return(true)
+      expect { doctor.run }.not_to raise_error
       expect(@stdout.string).to be_empty
     end
 
@@ -58,7 +58,7 @@ RSpec.describe "bundle doctor" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/doctor_spec.rb#L58
       doctor = Bundler::CLI::Doctor.new({})
       expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/rack/rack.bundle"]
       expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib"]
-      allow(File).to receive(:exist?).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_return(false)
+      allow(Fiddle).to receive(:dlopen).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_raise(Fiddle::DLError)
       expect { doctor.run }.to raise_error(Bundler::ProductionError, strip_whitespace(<<-E).strip), @stdout.string
         The following gems are missing OS dependencies:
          * bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]