From 79eeb0021859f9397065eaa391b44763361dd19f Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Wed, 20 Mar 2024 16:43:26 +0100 Subject: [PATCH 1/7] Use `$ext_build_dir` consistently Instead of hardcoded "ext". --- tool/rbinstall.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index 832e22324c6c02..6100310648209a 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -555,11 +555,17 @@ def collect class Ext < self def skip_install?(files) # install ext only when it's configured - !File.exist?("#{$ext_build_dir}/#{relative_base}/Makefile") + !File.exist?("#{makefile_dir}/Makefile") end def ruby_libraries - Dir.glob("lib/**/*.rb", base: "#{srcdir}/ext/#{relative_base}") + Dir.glob("lib/**/*.rb", base: makefile_dir) + end + + private + + def makefile_dir + File.expand_path("#{$ext_build_dir}/#{relative_base}", srcdir) end end From a5b6a148f86fc4389a820d7a51fa992f4230f787 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Wed, 20 Mar 2024 17:10:36 +0100 Subject: [PATCH 2/7] Simplify FileCollector interface --- tool/rbinstall.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index 6100310648209a..5b18beb8ea70a1 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -553,12 +553,10 @@ def collect end class Ext < self - def skip_install?(files) + def ruby_libraries # install ext only when it's configured - !File.exist?("#{makefile_dir}/Makefile") - end + return [] unless File.exist?("#{makefile_dir}/Makefile") - def ruby_libraries Dir.glob("lib/**/*.rb", base: makefile_dir) end @@ -570,10 +568,6 @@ def makefile_dir end class Lib < self - def skip_install?(files) - files.empty? - end - def ruby_libraries gemname = File.basename(gemspec, ".gemspec") base = relative_base || gemname @@ -763,7 +757,7 @@ def install_default_gem(dir, srcdir, bindir) spec = load_gemspec("#{base}/#{src}") file_collector = RbInstall::Specs::FileCollector.for(srcdir, dir, src) files = file_collector.collect - if file_collector.skip_install?(files) + if files.empty? next end spec.files = files From 0cdad94ab27d3083f15b42f27e08d4b2d2351669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jan 2024 10:16:48 +0100 Subject: [PATCH 3/7] Fix gemspec file list for extension gems So that it also includes requirable features provided by extensions. --- tool/rbinstall.rb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index 5b18beb8ea70a1..94b69b91fa83bb 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -549,26 +549,44 @@ def initialize(gemspec, srcdir, relative_base) end def collect - ruby_libraries.sort + libraries.sort end class Ext < self - def ruby_libraries + def libraries # install ext only when it's configured - return [] unless File.exist?("#{makefile_dir}/Makefile") + return [] unless File.exist?(makefile_path) - Dir.glob("lib/**/*.rb", base: makefile_dir) + ruby_libraries + ext_libraries end private + def ruby_libraries + Dir.glob("**/*.rb", base: "#{makefile_dir}/lib") + end + + def ext_libraries + makefile = File.read(makefile_path) + + name = makefile[/^TARGET[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] + return [] if name.empty? + + feature = makefile[/^DLLIB[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] + Array(feature.sub("$(TARGET)", name)) + end + + def makefile_path + "#{makefile_dir}/Makefile" + end + def makefile_dir File.expand_path("#{$ext_build_dir}/#{relative_base}", srcdir) end end class Lib < self - def ruby_libraries + def libraries gemname = File.basename(gemspec, ".gemspec") base = relative_base || gemname # for lib/net/net-smtp.gemspec From f52810a026f65108dc4a9d24eefd3f69061b9f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 24 Jan 2024 10:22:26 +0100 Subject: [PATCH 4/7] Consistently put requirable features in default gemspecs file list --- tool/rbinstall.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index 94b69b91fa83bb..c6d823ea04a1c4 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -549,24 +549,24 @@ def initialize(gemspec, srcdir, relative_base) end def collect - libraries.sort + requirable_features.sort end class Ext < self - def libraries + def requirable_features # install ext only when it's configured return [] unless File.exist?(makefile_path) - ruby_libraries + ext_libraries + ruby_features + ext_features end private - def ruby_libraries + def ruby_features Dir.glob("**/*.rb", base: "#{makefile_dir}/lib") end - def ext_libraries + def ext_features makefile = File.read(makefile_path) name = makefile[/^TARGET[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] @@ -586,24 +586,24 @@ def makefile_dir end class Lib < self - def libraries + def requirable_features gemname = File.basename(gemspec, ".gemspec") base = relative_base || gemname # for lib/net/net-smtp.gemspec if m = /.*(?=-(.*)\z)/.match(gemname) base = File.join(base, *m.to_a.select {|n| !base.include?(n)}) end - files = Dir.glob("lib/#{base}{.rb,/**/*.rb}", base: srcdir) + files = Dir.glob("#{base}{.rb,/**/*.rb}", base: "#{srcdir}/lib") if !relative_base and files.empty? # no files at the toplevel # pseudo gem like ruby2_keywords - files << "lib/#{gemname}.rb" + files << "#{gemname}.rb" end case gemname when "net-http" - files << "lib/net/https.rb" + files << "net/https.rb" when "optparse" - files << "lib/optionparser.rb" + files << "optionparser.rb" end files From ebd44313652b5083d375561306b0e15a901c65c9 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Mon, 18 Mar 2024 20:58:49 +0100 Subject: [PATCH 5/7] Consider `target_prefix` in extension Makefiles --- tool/rbinstall.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index c6d823ea04a1c4..f4ca7226de45a7 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -573,7 +573,12 @@ def ext_features return [] if name.empty? feature = makefile[/^DLLIB[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] - Array(feature.sub("$(TARGET)", name)) + feature = feature.sub("$(TARGET)", name) + + target_prefix = makefile[/^target_prefix[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] + feature = File.join(target_prefix.delete_prefix("/"), feature) unless target_prefix.empty? + + Array(feature) end def makefile_path From 6cb72572eb775ad395b0ab62d64c9a53f941e5e0 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Wed, 20 Mar 2024 17:17:40 +0100 Subject: [PATCH 6/7] Extract `root` helper It holds the root directory for each type of default gem (ext/ or lib/). --- tool/rbinstall.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index f4ca7226de45a7..dc6e887283482d 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -586,7 +586,11 @@ def makefile_path end def makefile_dir - File.expand_path("#{$ext_build_dir}/#{relative_base}", srcdir) + "#{root}/#{relative_base}" + end + + def root + File.expand_path($ext_build_dir, srcdir) end end @@ -598,7 +602,7 @@ def requirable_features if m = /.*(?=-(.*)\z)/.match(gemname) base = File.join(base, *m.to_a.select {|n| !base.include?(n)}) end - files = Dir.glob("#{base}{.rb,/**/*.rb}", base: "#{srcdir}/lib") + files = Dir.glob("#{base}{.rb,/**/*.rb}", base: root) if !relative_base and files.empty? # no files at the toplevel # pseudo gem like ruby2_keywords files << "#{gemname}.rb" @@ -613,6 +617,10 @@ def requirable_features files end + + def root + "#{srcdir}/lib" + end end end end From 126e51ac2859c183b08df69279e4a600394ac2d1 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Wed, 20 Mar 2024 17:18:20 +0100 Subject: [PATCH 7/7] Consider extensions in gems outside of ext/ --- tool/rbinstall.rb | 49 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index dc6e887283482d..b3c6c1de4ce5ee 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -552,6 +552,23 @@ def collect requirable_features.sort end + private + + def features_from_makefile(makefile_path) + makefile = File.read(makefile_path) + + name = makefile[/^TARGET[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] + return [] if name.empty? + + feature = makefile[/^DLLIB[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] + feature = feature.sub("$(TARGET)", name) + + target_prefix = makefile[/^target_prefix[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] + feature = File.join(target_prefix.delete_prefix("/"), feature) unless target_prefix.empty? + + Array(feature) + end + class Ext < self def requirable_features # install ext only when it's configured @@ -567,18 +584,7 @@ def ruby_features end def ext_features - makefile = File.read(makefile_path) - - name = makefile[/^TARGET[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] - return [] if name.empty? - - feature = makefile[/^DLLIB[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] - feature = feature.sub("$(TARGET)", name) - - target_prefix = makefile[/^target_prefix[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] - feature = File.join(target_prefix.delete_prefix("/"), feature) unless target_prefix.empty? - - Array(feature) + features_from_makefile(makefile_path) end def makefile_path @@ -596,6 +602,12 @@ def root class Lib < self def requirable_features + ruby_features + ext_features + end + + private + + def ruby_features gemname = File.basename(gemspec, ".gemspec") base = relative_base || gemname # for lib/net/net-smtp.gemspec @@ -618,6 +630,19 @@ def requirable_features files end + def ext_features + loaded_gemspec = Gem::Specification.load("#{root}/#{gemspec}") + extension = loaded_gemspec.extensions.first + return [] unless extension + + extconf = File.expand_path(extension, srcdir) + ext_build_dir = File.dirname(extconf) + makefile_path = "#{ext_build_dir}/Makefile" + return [] unless File.exist?(makefile_path) + + features_from_makefile(makefile_path) + end + def root "#{srcdir}/lib" end