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

ruby-changes:72161

From: Alan <ko1@a...>
Date: Wed, 15 Jun 2022 01:06:05 +0900 (JST)
Subject: [ruby-changes:72161] 9357e310fb (master): [ruby/psych] Fix libyaml download failure rescue under miniruby

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

From 9357e310fb420bab7092a665be7875272820e2a3 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Tue, 14 Jun 2022 12:05:33 -0400
Subject: [ruby/psych] Fix libyaml download failure rescue under miniruby

I tried to build Ruby on a system without libyaml today and realized
that my attempt from <https://github.com/ruby/psych/pull/557> doesn't
fix the error in <https://github.com/ruby/psych/issues/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>.

https://github.com/ruby/psych/commit/251289ba83
---
 ext/psych/extconf.rb | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/ext/psych/extconf.rb b/ext/psych/extconf.rb
index b9cd12033d..6d03870436 100644
--- a/ext/psych/extconf.rb
+++ b/ext/psych/extconf.rb
@@ -19,15 +19,17 @@ if yaml_source == true https://github.com/ruby/ruby/blob/trunk/ext/psych/extconf.rb#L19
   # search the latest libyaml source under $srcdir
   yaml_source = Dir.glob("#{$srcdir}/yaml{,-*}/").max_by {|n| File.basename(n).scan(/\d+/).map(&:to_i)}
   unless yaml_source
-    download_failure = "failed to download libyaml source"
+    download_failure = "failed to download libyaml source. Try manually installing libyaml?"
     begin
       require_relative '../../tool/extlibs.rb'
-      extlibs = ExtLibs.new(cache_dir: File.expand_path("../../tmp/download_cache", $srcdir))
-      unless extlibs.process_under($srcdir)
-        raise download_failure
-      end
-    rescue
-      # Implicitly captures Exception#cause. Newer rubies show it in the backtrace.
+    rescue LoadError
+      # When running in ruby/ruby, we use miniruby and don't have stdlib.
+      # Avoid LoadError because it aborts the whole build. Usually when
+      # stdlib extension fail to configure we skip it and continue.
+      raise download_failure
+    end
+    extlibs = ExtLibs.new(cache_dir: File.expand_path("../../tmp/download_cache", $srcdir))
+    unless extlibs.process_under($srcdir)
       raise download_failure
     end
     yaml_source, = Dir.glob("#{$srcdir}/yaml-*/")
-- 
cgit v1.2.1


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

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