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

ruby-changes:68406

From: Akinori <ko1@a...>
Date: Tue, 12 Oct 2021 21:11:25 +0900 (JST)
Subject: [ruby-changes:68406] b245b67d9e (master): [ruby/digest] Place common parts in lib and engine specific parts under ext/**/lib

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

From b245b67d9e325824f3869d839a16d06c6a1e8392 Mon Sep 17 00:00:00 2001
From: Akinori MUSHA <knu@i...>
Date: Mon, 27 Sep 2021 16:31:55 +0900
Subject: [ruby/digest] Place common parts in lib and engine specific parts
 under ext/**/lib

https://github.com/ruby/digest/commit/8d7496c3be
---
 ext/digest/bubblebabble/lib/bubblebabble.rb |   9 --
 ext/digest/digest.gemspec                   |  55 +++--------
 ext/digest/lib/digest.rb                    | 113 ---------------------
 ext/digest/lib/digest/loader.rb             |   3 +
 ext/digest/lib/digest/sha2/loader.rb        |   3 +
 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                 | 147 ----------------------------
 lib/digest.rb                               | 110 +++++++++++++++++++++
 lib/digest/sha2.rb                          | 142 +++++++++++++++++++++++++++
 11 files changed, 269 insertions(+), 340 deletions(-)
 delete mode 100644 ext/digest/bubblebabble/lib/bubblebabble.rb
 delete mode 100644 ext/digest/lib/digest.rb
 create mode 100644 ext/digest/lib/digest/loader.rb
 create mode 100644 ext/digest/lib/digest/sha2/loader.rb
 delete mode 100644 ext/digest/md5/lib/md5.rb
 delete mode 100644 ext/digest/rmd160/lib/rmd160.rb
 delete mode 100644 ext/digest/sha1/lib/sha1.rb
 delete mode 100644 ext/digest/sha2/lib/sha2.rb
 create mode 100644 lib/digest.rb
 create mode 100644 lib/digest/sha2.rb

diff --git a/ext/digest/bubblebabble/lib/bubblebabble.rb b/ext/digest/bubblebabble/lib/bubblebabble.rb
deleted file mode 100644
index 8ad06c7740..0000000000
--- a/ext/digest/bubblebabble/lib/bubblebabble.rb
+++ /dev/null
@@ -1,9 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/#L0
-# 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 f9357b0f23..151d1607b6 100644
--- a/ext/digest/digest.gemspec
+++ b/ext/digest/digest.gemspec
@@ -12,60 +12,27 @@ Gem::Specification.new do |spec| https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.gemspec#L12
   spec.homepage      = "https://github.com/ruby/digest"
   spec.licenses      = ["Ruby", "BSD-2-Clause"]
 
-  spec.files         = [
-    "LICENSE.txt", "README.md",
-
-    "ext/digest/defs.h", "ext/digest/digest.c", "ext/digest/digest.h",
-    "ext/digest/digest_conf.rb", "ext/digest/extconf.rb",
-    "ext/digest/lib/digest.rb",
-
-    "ext/digest/bubblebabble/bubblebabble.c",
-    "ext/digest/bubblebabble/extconf.rb",
-
-    "ext/digest/md5/extconf.rb", "ext/digest/md5/md5.c",
-    "ext/digest/md5/md5.h", "ext/digest/md5/md5cc.h",
-    "ext/digest/md5/md5init.c",
-
-    "ext/digest/rmd160/extconf.rb", "ext/digest/rmd160/rmd160.c",
-    "ext/digest/rmd160/rmd160.h", "ext/digest/rmd160/rmd160init.c",
-
-    "ext/digest/sha1/extconf.rb", "ext/digest/sha1/sha1.c",
-    "ext/digest/sha1/sha1.h", "ext/digest/sha1/sha1cc.h",
-    "ext/digest/sha1/sha1init.c",
-
-    "ext/digest/sha2/extconf.rb", "ext/digest/sha2/lib/sha2.rb",
-    "ext/digest/sha2/sha2.c", "ext/digest/sha2/sha2.h",
-    "ext/digest/sha2/sha2cc.h", "ext/digest/sha2/sha2init.c",
-
-    "ext/openssl/deprecation.rb",
-    "ext/digest/test.sh",
+  spec.files = [
+    "LICENSE.txt",
+    "README.md",
+    *Dir["lib/digest{.rb,/**/*.rb}"],
   ]
 
   spec.required_ruby_version = ">= 2.5.0"
 
   spec.bindir        = "exe"
   spec.executables   = []
-  spec.require_paths = ["lib"]
 
   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"
-    ]
+
+    spec.files += Dir["ext/java/**/*.{rb,java}"]
+    spec.require_paths = %w[lib ext/java/org/jruby/ext/digest/lib]
   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
-    ]
+    spec.extensions = Dir["ext/digest/**/extconf.rb"]
+
+    spec.files += Dir["ext/digest/**/*.{rb,c,h,sh}"]
+    spec.require_paths = %w[lib]
   end
 
   spec.metadata["msys2_mingw_dependencies"] = "openssl"
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb
deleted file mode 100644
index 912198811b..0000000000
--- a/ext/digest/lib/digest.rb
+++ /dev/null
@@ -1,113 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.gemspec#L0
-# frozen_string_literal: false
-if RUBY_ENGINE == 'jruby'
-  JRuby::Util.load_ext("org.jruby.ext.digest.DigestLibrary")
-else
-  require 'digest.so'
-end
-
-module Digest
-  # A mutex for Digest().
-  REQUIRE_MUTEX = Thread::Mutex.new
-
-  def self.const_missing(name) # :nodoc:
-    case name
-    when :SHA256, :SHA384, :SHA512
-      lib = 'digest/sha2'
-    else
-      lib = File.join('digest', name.to_s.downcase)
-    end
-
-    begin
-      require lib
-    rescue LoadError
-      raise LoadError, "library not found for class Digest::#{name} -- #{lib}", caller(1)
-    end
-    unless Digest.const_defined?(name)
-      raise NameError, "uninitialized constant Digest::#{name}", caller(1)
-    end
-    Digest.const_get(name)
-  end
-
-  class ::Digest::Class
-    # Creates a digest object and reads a given file, _name_.
-    # Optional arguments are passed to the constructor of the digest
-    # class.
-    #
-    #   p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
-    #   # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
-    def self.file(name, *args)
-      new(*args).file(name)
-    end
-
-    # Returns the base64 encoded hash value of a given _string_.  The
-    # return value is properly padded with '=' and contains no line
-    # feeds.
-    def self.base64digest(str, *args)
-      [digest(str, *args)].pack('m0')
-    end
-  end
-
-  module Instance
-    # Updates the digest with the contents of a given file _name_ and
-    # returns self.
-    def file(name)
-      File.open(name, "rb") {|f|
-        buf = ""
-        while f.read(16384, buf)
-          update buf
-        end
-      }
-      self
-    end
-
-    # If none is given, returns the resulting hash value of the digest
-    # in a base64 encoded form, keeping the digest's state.
-    #
-    # If a +string+ is given, returns the hash value for the given
-    # +string+ in a base64 encoded form, resetting the digest to the
-    # initial state before and after the process.
-    #
-    # In either case, the return value is properly padded with '=' and
-    # contains no line feeds.
-    def base64digest(str = nil)
-      [str ? digest(str) : digest].pack('m0')
-    end
-
-    # Returns the resulting hash value and resets the digest to the
-    # initial state.
-    def base64digest!
-      [digest!].pack('m0')
-    end
-  end
-end
-
-# call-seq:
-#   Digest(name) -> digest_subclass
-#
-# Returns a Digest subclass by +name+ in a thread-safe manner even
-# when on-demand loading is involved.
-#
-#   require 'digest'
-#
-#   Digest("MD5")
-#   # => Digest::MD5
-#
-#   Digest(:SHA256)
-#   # => Digest::SHA256
-#
-#   Digest(:Foo)
-#   # => LoadError: library not found for class Digest::Foo -- digest/foo
-def Digest(name)
-  const = name.to_sym
-  Digest::REQUIRE_MUTEX.synchronize {
-    # Ignore autoload's because it is void when we have #const_missing
-    Digest.const_missing(const)
-  }
-rescue LoadError
-  # Constants do not necessarily rely on digest/*.
-  if Digest.const_defined?(const)
-    Digest.const_get(const)
-  else
-    raise
-  end
-end
diff --git a/ext/digest/lib/digest/loader.rb b/ext/digest/lib/digest/loader.rb
new file mode 100644
index 0000000000..6b989e07be
--- /dev/null
+++ b/ext/digest/lib/digest/loader.rb
@@ -0,0 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest/loader.rb#L1
+# frozen_string_literal: true
+
+require 'digest.so'
diff --git a/ext/digest/lib/digest/sha2/loader.rb b/ext/digest/lib/digest/sha2/loader.rb
new file mode 100644
index 0000000000..7d6d04a59c
--- /dev/null
+++ b/ext/digest/lib/digest/sha2/loader.rb
@@ -0,0 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest/sha2/loader.rb#L1
+# frozen_string_literal: true
+
+require 'digest/sha2.so'
diff --git a/ext/digest/md5/lib/md5.rb b/ext/digest/md5/lib/md5.rb
deleted file mode 100644
index 3748f9d187..0000000000
--- a/ext/digest/md5/lib/md5.rb
+++ /dev/null
@@ -1,9 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest/sha2/loader.rb#L0
-# 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
deleted file mode 100644
index eabb92a496..0000000000
--- a/ext/digest/rmd160/lib/rmd160.rb
+++ /dev/null
@@ -1,9 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest/sha2/loader.rb#L0
-# 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
deleted file mode 100644
index 864997b1f6..0000000000
--- a/ext/digest/sha1/lib/sha1.rb
+++ /dev/null
@@ -1,9 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest/sha2/loader.rb#L0
-# 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
deleted (... truncated)

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

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