Skip to content

Commit 251289b

Browse files
authored
Fix libyaml download failure rescue under miniruby
I tried to build Ruby on a system without libyaml today and realized that my attempt from <#557> doesn't fix the error in <#552>. I still got the same `LoadError` from `digest` which stopped the build. Since `LoadError` is not a `StandardError`, a plain `rescue` doesn't catch it. Catch `LoadError` explicitly instead and reduce the scope of the `begin` block. I tested this change in a Ruby build on macOS without libyaml installed and confirmed that `make` continues with a warning instead of aborting: *** Following extensions are not compiled: psych: Could not be configured. It will not be installed. ... This should address <https://bugs.ruby-lang.org/issues/18790>.
1 parent c3b5183 commit 251289b

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

ext/psych/extconf.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@
1919
# search the latest libyaml source under $srcdir
2020
yaml_source = Dir.glob("#{$srcdir}/yaml{,-*}/").max_by {|n| File.basename(n).scan(/\d+/).map(&:to_i)}
2121
unless yaml_source
22-
download_failure = "failed to download libyaml source"
22+
download_failure = "failed to download libyaml source. Try manually installing libyaml?"
2323
begin
2424
require_relative '../../tool/extlibs.rb'
25-
extlibs = ExtLibs.new(cache_dir: File.expand_path("../../tmp/download_cache", $srcdir))
26-
unless extlibs.process_under($srcdir)
27-
raise download_failure
28-
end
29-
rescue
30-
# Implicitly captures Exception#cause. Newer rubies show it in the backtrace.
25+
rescue LoadError
26+
# When running in ruby/ruby, we use miniruby and don't have stdlib.
27+
# Avoid LoadError because it aborts the whole build. Usually when
28+
# stdlib extension fail to configure we skip it and continue.
29+
raise download_failure
30+
end
31+
extlibs = ExtLibs.new(cache_dir: File.expand_path("../../tmp/download_cache", $srcdir))
32+
unless extlibs.process_under($srcdir)
3133
raise download_failure
3234
end
3335
yaml_source, = Dir.glob("#{$srcdir}/yaml-*/")

0 commit comments

Comments
 (0)