@@ -666,7 +666,8 @@ class UnpackedGem < self
666666 def collect
667667 base = @srcdir or return [ ]
668668 Dir . glob ( "**/*" , File ::FNM_DOTMATCH , base : base ) . select do |n |
669- case File . basename ( n ) ; when "." , ".." ; next ; end
669+ next if n == "."
670+ next if File . fnmatch? ( "*.gemspec" , n , File ::FNM_DOTMATCH |File ::FNM_PATHNAME )
670671 !File . directory? ( File . join ( base , n ) )
671672 end
672673 end
@@ -793,23 +794,29 @@ def load_plugin
793794 end
794795end
795796
796- def load_gemspec ( file , base = nil )
797+ def load_gemspec ( file , base = nil , files : nil )
797798 file = File . realpath ( file )
798799 code = File . read ( file , encoding : "utf-8:-" )
799800
801+ code . gsub! ( /^ *#.*/ , "" )
802+ files = files . map ( &:dump )
800803 code . gsub! ( /(?:`git[^\` ]*`|%x\[ git[^\] ]*\] )\. split(\( [^\) ]*\) )?/m ) do
801- "[]"
802- end
804+ "[" + files . join ( ", " ) + "]"
805+ end \
806+ or
803807 code . gsub! ( /IO\. popen\( .*git.*?\) / ) do
804- "[] || itself"
808+ "[" + files . join ( ", " ) + "] || itself"
809+ end \
810+ or
811+ code . gsub! ( /\. files *= *\K (?!\[ ).*/ ) do
812+ "[" + files . join ( ", " ) + "]"
805813 end
806814
807815 spec = eval ( code , binding , file )
808816 unless Gem ::Specification === spec
809817 raise TypeError , "[#{ file } ] isn't a Gem::Specification (#{ spec . class } instead)."
810818 end
811819 spec . loaded_from = base ? File . join ( base , File . basename ( file ) ) : file
812- spec . files . clear
813820 spec . date = RUBY_RELEASE_DATE
814821
815822 spec
@@ -839,14 +846,11 @@ def install_default_gem(dir, srcdir, bindir)
839846
840847 base = "#{ srcdir } /#{ dir } "
841848 gems = Dir . glob ( "**/*.gemspec" , base : base ) . map { |src |
842- spec = load_gemspec ( "#{ base } /#{ src } " )
843- file_collector = RbInstall ::Specs ::FileCollector . for ( srcdir , dir , src )
844- files = file_collector . collect
849+ files = RbInstall ::Specs ::FileCollector . for ( srcdir , dir , src ) . collect
845850 if files . empty?
846851 next
847852 end
848- spec . files = files
849- spec
853+ load_gemspec ( "#{ base } /#{ src } " , files : files )
850854 }
851855 gems . compact . sort_by ( &:name ) . each do |gemspec |
852856 old_gemspecs = Dir [ File . join ( with_destdir ( default_spec_dir ) , "#{ gemspec . name } -*.gemspec" ) ]
@@ -1167,7 +1171,10 @@ class << (w = [])
11671171 next
11681172 end
11691173 base = "#{ srcdir } /.bundle/gems/#{ gem_name } "
1170- spec = load_gemspec ( path , base )
1174+ files = collector . new ( path , base , nil ) . collect
1175+ files . delete ( "#{ gem } .gemspec" )
1176+ files . delete ( "#{ gem_name } .gemspec" )
1177+ spec = load_gemspec ( path , base , files : files )
11711178 unless spec . platform == Gem ::Platform ::RUBY
11721179 skipped [ gem_name ] = "not ruby platform (#{ spec . platform } )"
11731180 next
@@ -1183,9 +1190,6 @@ class << (w = [])
11831190 end
11841191 spec . extension_dir = "#{ extensions_dir } /#{ spec . full_name } "
11851192
1186- # Override files with the actual files included in the gem
1187- spec . files = collector . new ( path , base , nil ) . collect
1188-
11891193 package = RbInstall ::DirPackage . new spec
11901194 ins = RbInstall ::UnpackedInstaller . new ( package , options )
11911195 puts "#{ INDENT } #{ spec . name } #{ spec . version } "
0 commit comments