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

ruby-changes:68403

From: Pavel <ko1@a...>
Date: Tue, 12 Oct 2021 21:11:24 +0900 (JST)
Subject: [ruby-changes:68403] 94882df3a2 (master): [ruby/digest] jruby support

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

From 94882df3a215a3de16fa7ca18cf5c160f904c904 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20Rosick=C3=BD?= <pavel.rosicky@e...>
Date: Sat, 12 Jun 2021 18:49:57 +0200
Subject: [ruby/digest] jruby support

https://github.com/ruby/digest/commit/2e9dc14693
---
 ext/digest/bubblebabble/lib/bubblebabble.rb |  9 ++++++++
 ext/digest/digest.gemspec                   | 36 +++++++++++++++++++++--------
 ext/digest/lib/digest.rb                    |  8 +++++--
 ext/digest/md5/lib/md5.rb                   |  9 ++++++++
 ext/digest/rmd160/lib/rmd160.rb             |  9 ++++++++
 ext/digest/sha1/lib/sha1.rb                 |  9 ++++++++
 ext/digest/sha2/lib/sha2.rb                 |  7 +++++-
 tool/lib/core_assertions.rb                 |  1 +
 8 files changed, 76 insertions(+), 12 deletions(-)
 create mode 100644 ext/digest/bubblebabble/lib/bubblebabble.rb
 create mode 100644 ext/digest/md5/lib/md5.rb
 create mode 100644 ext/digest/rmd160/lib/rmd160.rb
 create mode 100644 ext/digest/sha1/lib/sha1.rb

diff --git a/ext/digest/bubblebabble/lib/bubblebabble.rb b/ext/digest/bubblebabble/lib/bubblebabble.rb
new file mode 100644
index 0000000000..8ad06c7740
--- /dev/null
+++ b/ext/digest/bubblebabble/lib/bubblebabble.rb
@@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/bubblebabble/lib/bubblebabble.rb#L1
+# frozen_string_literal: false
+
+require 'digest'
+
+if RUBY_ENGINE == 'jruby'
+  JRuby::Util.load_ext("org.jruby.ext.digest.BubbleBabble")
+else
+  require 'digest/bubblebabble.so'
+end
diff --git a/ext/digest/digest.gemspec b/ext/digest/digest.gemspec
index 381df92761..a6c6f159bb 100644
--- a/ext/digest/digest.gemspec
+++ b/ext/digest/digest.gemspec
@@ -10,7 +10,11 @@ Gem::Specification.new do |spec| https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.gemspec#L10
   spec.summary       = %q{Provides a framework for message digest libraries.}
   spec.description   = %q{Provides a framework for message digest libraries.}
   spec.homepage      = "https://github.com/ruby/digest"
-  spec.licenses      = ["Ruby", "BSD-2-Clause"]
+  if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby'
+    spec.licenses      = ["Ruby", "BSD-2-Clause", "EPL-2.0", "GPL-2.0", "LGPL-2.1"]
+  else
+    spec.licenses      = ["Ruby", "BSD-2-Clause"]
+  end
 
   spec.files         = [
     "LICENSE.txt", "README.md",
@@ -46,13 +50,27 @@ Gem::Specification.new do |spec| https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.gemspec#L50
   spec.bindir        = "exe"
   spec.executables   = []
   spec.require_paths = ["lib"]
-  spec.extensions    = %w[
-    ext/digest/extconf.rb
-    ext/digest/bubblebabble/extconf.rb
-    ext/digest/md5/extconf.rb
-    ext/digest/rmd160/extconf.rb
-    ext/digest/sha1/extconf.rb
-    ext/digest/sha2/extconf.rb
-  ]
+
+  if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby'
+    spec.platform = 'java'
+    spec.files.concat [
+      "lib/digest.jar",
+      "lib/digest/md5.rb",
+      "lib/digest/sha1.rb",
+      "lib/digest/sha2.rb",
+      "lib/digest/rmd160.rb",
+      "lib/digest/bubblebabble.rb"
+    ]
+  else
+    spec.extensions    = %w[
+      ext/digest/extconf.rb
+      ext/digest/bubblebabble/extconf.rb
+      ext/digest/md5/extconf.rb
+      ext/digest/rmd160/extconf.rb
+      ext/digest/sha1/extconf.rb
+      ext/digest/sha2/extconf.rb
+    ]
+  end
+
   spec.metadata["msys2_mingw_dependencies"] = "openssl"
 end
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb
index ba0637af32..912198811b 100644
--- a/ext/digest/lib/digest.rb
+++ b/ext/digest/lib/digest.rb
@@ -1,5 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest.rb#L1
 # frozen_string_literal: false
-require 'digest.so'
+if RUBY_ENGINE == 'jruby'
+  JRuby::Util.load_ext("org.jruby.ext.digest.DigestLibrary")
+else
+  require 'digest.so'
+end
 
 module Digest
   # A mutex for Digest().
@@ -8,7 +12,7 @@ module Digest https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest.rb#L12
   def self.const_missing(name) # :nodoc:
     case name
     when :SHA256, :SHA384, :SHA512
-      lib = 'digest/sha2.so'
+      lib = 'digest/sha2'
     else
       lib = File.join('digest', name.to_s.downcase)
     end
diff --git a/ext/digest/md5/lib/md5.rb b/ext/digest/md5/lib/md5.rb
new file mode 100644
index 0000000000..3748f9d187
--- /dev/null
+++ b/ext/digest/md5/lib/md5.rb
@@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/lib/md5.rb#L1
+# frozen_string_literal: false
+
+require 'digest'
+
+if RUBY_ENGINE == 'jruby'
+  JRuby::Util.load_ext("org.jruby.ext.digest.MD5")
+else
+  require 'digest/md5.so'
+end
diff --git a/ext/digest/rmd160/lib/rmd160.rb b/ext/digest/rmd160/lib/rmd160.rb
new file mode 100644
index 0000000000..eabb92a496
--- /dev/null
+++ b/ext/digest/rmd160/lib/rmd160.rb
@@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/lib/rmd160.rb#L1
+# frozen_string_literal: false
+
+require 'digest'
+
+if RUBY_ENGINE == 'jruby'
+  JRuby::Util.load_ext("org.jruby.ext.digest.RMD160")
+else
+  require 'digest/rmd160.so'
+end
diff --git a/ext/digest/sha1/lib/sha1.rb b/ext/digest/sha1/lib/sha1.rb
new file mode 100644
index 0000000000..864997b1f6
--- /dev/null
+++ b/ext/digest/sha1/lib/sha1.rb
@@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/lib/sha1.rb#L1
+# frozen_string_literal: false
+
+require 'digest'
+
+if RUBY_ENGINE == 'jruby'
+  JRuby::Util.load_ext("org.jruby.ext.digest.SHA1")
+else
+  require 'digest/sha1.so'
+end
diff --git a/ext/digest/sha2/lib/sha2.rb b/ext/digest/sha2/lib/sha2.rb
index 61a0734850..22e099768c 100644
--- a/ext/digest/sha2/lib/sha2.rb
+++ b/ext/digest/sha2/lib/sha2.rb
@@ -11,7 +11,12 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/lib/sha2.rb#L11
 #   $Id$
 
 require 'digest'
-require 'digest/sha2.so'
+
+if RUBY_ENGINE == 'jruby'
+  JRuby::Util.load_ext("org.jruby.ext.digest.SHA2")
+else
+  require 'digest/sha2.so'
+end
 
 module Digest
   #
diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb
index 6769ee7a91..47d711f4fa 100644
--- a/tool/lib/core_assertions.rb
+++ b/tool/lib/core_assertions.rb
@@ -270,6 +270,7 @@ BEGIN { https://github.com/ruby/ruby/blob/trunk/tool/lib/core_assertions.rb#L270
 eom
         args = args.dup
         args.insert((Hash === args.first ? 1 : 0), "-w", "--disable=gems", *$:.map {|l| "-I#{l}"})
+        args << "--debug" if RUBY_ENGINE == 'jruby' # warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
         stdout, stderr, status = EnvUtil.invoke_ruby(args, src, capture_stdout, true, **opt)
       ensure
         if res_c
-- 
cgit v1.2.1


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

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