8000 Consider extensions in gems outside of ext/ · ruby/ruby@5e62374 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e62374

Browse files
Consider extensions in gems outside of ext/
1 parent 796126e commit 5e62374

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

tool/rbinstall.rb

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,23 @@ def collect
552552
requirable_features.sort
553553
end
554554

555+
private
556+
557+
def features_from_makefile(makefile_path)
558+
makefile = File.read(makefile_path)
559+
560+
name = makefile[/^TARGET[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1]
561+
return [] if name.empty?
562+
563+
feature = makefile[/^DLLIB[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1]
564+
feature = feature.sub("$(TARGET)", name)
565+
566+
target_prefix = makefile[/^target_prefix[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1]
567+
feature = File.join(target_prefix.delete_prefix("/"), feature) unless target_prefix.empty?
568+
569+
Array(feature)
570+
end
571+
555572
class Ext < self
556573
def requirable_features
557574
# install ext only when it's configured
@@ -567,18 +584,7 @@ def ruby_features
567584
end
568585

569586
def ext_features
570-
makefile = File.read(makefile_path)
571-
572-
name = makefile[/^TARGET[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1]
573-
return [] if name.empty?
574-
575-
feature = makefile[/^DLLIB[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1]
576-
feature = feature.sub("$(TARGET)", name)
577-
578-
target_prefix = makefile[/^target_prefix[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1]
579-
feature = File.join(target_prefix.delete_prefix("/"), feature) unless target_prefix.empty?
580-
581-
Array(feature)
587+
features_from_makefile(makefile_path)
582588
end
583589

584590
def makefile_path
@@ -596,6 +602,12 @@ def root
596602

597603
class Lib < self
598604
def requirable_features
605+
ruby_features + ext_features
606+
end
607+
608+
private
609+
610+
def ruby_features
599611
gemname = File.basename(gemspec, ".gemspec")
600612
base = relative_base || gemname
601613
# for lib/net/net-smtp.gemspec
@@ -618,6 +630,19 @@ def requirable_features
618630
files
619631
end
620632

633+
def ext_features
634+
loaded_gemspec = Gem::Specification.load("#{root}/#{gemspec}")
635+
extension = loaded_gemspec.extensions.first
636+
return [] unless extension
637+
638+
extconf = File.expand_path(extension, srcdir)
639+
ext_build_dir = File.dirname(extconf)
640+
makefile_path = "#{ext_build_dir}/Makefile"
641+
return [] unless File.exist?(makefile_path)
642+
643+
features_from_makefile(makefile_path)
644+
end
645+
621646
def root
622647
"#{srcdir}/lib"
623648
end

0 commit comments

Comments
 (0)
0