1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Use Fiddle in bundle doctor to check for dynamic library presence

https://github.com/rubygems/rubygems/commit/ecd495ce1b
This commit is contained in:
Vyacheslav Alexeev 2022-01-11 23:38:32 +08:00 committed by git
parent 9828502570
commit d0a0637948
2 changed files with 12 additions and 4 deletions

View file

@ -2,6 +2,7 @@
require "rbconfig" require "rbconfig"
require "shellwords" require "shellwords"
require "fiddle"
module Bundler module Bundler
class CLI::Doctor class CLI::Doctor
@ -71,7 +72,14 @@ module Bundler
definition.specs.each do |spec| definition.specs.each do |spec|
bundles_for_gem(spec).each do |bundle| 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? if bad_paths.any?
broken_links[spec] ||= [] broken_links[spec] ||= []
broken_links[spec].concat(bad_paths) broken_links[spec].concat(bad_paths)

View file

@ -49,8 +49,8 @@ RSpec.describe "bundle doctor" do
doctor = Bundler::CLI::Doctor.new({}) 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(: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"] 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) allow(Fiddle).to receive(:dlopen).with("/usr/lib/libSystem.dylib").and_return(true)
expect { doctor.run }.not_to(raise_error, @stdout.string) expect { doctor.run }.not_to raise_error
expect(@stdout.string).to be_empty expect(@stdout.string).to be_empty
end end
@ -58,7 +58,7 @@ RSpec.describe "bundle doctor" do
doctor = Bundler::CLI::Doctor.new({}) 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(: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"] 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 expect { doctor.run }.to raise_error(Bundler::ProductionError, strip_whitespace(<<-E).strip), @stdout.string
The following gems are missing OS dependencies: The following gems are missing OS dependencies:
* bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib * bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib