@@ -552,6 +552,23 @@ def collect
552
552
requirable_features . sort
553
553
end
554
554
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
+
555
572
class Ext < self
556
573
def requirable_features
557
574
# install ext only when it's configured
@@ -567,18 +584,7 @@ def ruby_features
567
584
end
568
585
569
586
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 )
582
588
end
583
589
584
590
def makefile_path
@@ -596,6 +602,12 @@ def root
596
602
597
603
class Lib < self
598
604
def requirable_features
605
+ ruby_features + ext_features
606
+ end
607
+
608
+ private
609
+
610
+ def ruby_features
599
611
gemname = File . basename ( gemspec , ".gemspec" )
600
612
base = relative_base || gemname
601
613
# for lib/net/net-smtp.gemspec
@@ -618,6 +630,19 @@ def requirable_features
618
630
files
619
631
end
620
632
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
+
621
646
def root
622
647
"#{ srcdir } /lib"
623
648
end
0 commit comments