diff options
author | Nobuyoshi Nakada <[email protected]> | 2022-08-17 00:48:11 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2022-08-17 00:58:56 +0900 |
commit | cc443f6cde287944e00ab5d9b6ad868b3d9fc9db () | |
tree | ed2fadfd68c22cd6d75c5d7446ce6a365599e576 /tool/rbinstall.rb | |
parent | 5528648a913cee8a0b3c8b0bc59764e3c361c404 (diff) |
Refactor `RbInstall::Specs::FileCollector`
- Split into `Ext` and `Lib` classes. - `Ext#files` should not include built extension libraries. - `Ext#files` should include scripts under its own `lib`. - `Lib#files` should be prefixed with `lib/`.
-rwxr-xr-x | tool/rbinstall.rb | 107 |
1 files changed, 41 insertions, 66 deletions
@@ -729,86 +729,60 @@ module RbInstall module Specs class FileCollector - def initialize(gemspec) @gemspec = gemspec - @base_dir = File.dirname(gemspec) end def collect - (ruby_libraries + built_libraries).sort end - def skip_install?(files) - case type - when "ext" # install ext only when it's configured !File.exist?("#{$ext_build_dir}/#{relative_base}/Makefile") - when "lib" - files.empty? end - end - - private - def type - /\/(ext|lib)?\/.*?\z/ =~ @base_dir - $1 - end - def ruby_libraries - case type - when "ext" - prefix = "#{$extout}/common/" - base = "#{prefix}#{relative_base}" - when "lib" - base = @base_dir - prefix = base.sub(/lib\/.*?\z/, "") - # for lib/net/net-smtp.gemspec - if m = File.basename(@gemspec, ".gemspec").match(/.*\-(.*)\z/) - base = "#{@base_dir}/#{m[1]}" unless remove_prefix(prefix, @base_dir).include?(m[1]) - end end - files = if base - Dir.glob("#{base}{.rb,/**/*.rb}").collect do |ruby_source| - remove_prefix(prefix, ruby_source) - end - else - [@gemspec[%r[(?:[^/]+/)?[^/]+(?=\.gemspec\z)]] + '.rb'] - end - - case File.basename(@gemspec, ".gemspec") - when "net-http" - files << "lib/net/https.rb" - when "optparse" - files << "lib/optionparser.rb" end - files - end - - def built_libraries - case type - when "ext" - prefix = "#{$extout}/#{CONFIG['arch']}/" - base = "#{prefix}#{relative_base}" - dlext = CONFIG['DLEXT'] - Dir.glob("#{base}{.#{dlext},/**/*.#{dlext}}").collect do |built_library| - remove_prefix(prefix, built_library) end - when "lib" - [] - else - [] - end - end - def relative_base - /\/#{Regexp.escape(type)}\/(.*?)\z/ =~ @base_dir - $1 - end - def remove_prefix(prefix, string) - string.sub(/\A#{Regexp.escape(prefix)}/, "") end end end @@ -984,9 +958,10 @@ def install_default_gem(dir, srcdir, bindir) } default_spec_dir = Gem.default_specifications_dir - gems = Dir.glob("#{srcdir}/#{dir}/**/*.gemspec").map {|src| - spec = load_gemspec(src) - file_collector = RbInstall::Specs::FileCollector.new(src) files = file_collector.collect if file_collector.skip_install?(files) next |