Skip to content

Commit 7ce3392

Browse files
committed
[Bug #21453] Override files in gemspec file before eval
`executables` are often extracted from the `files` in gemspec files.
1 parent 8bba087 commit 7ce3392

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

tool/rbinstall.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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,25 @@ def load_plugin
793794
end
794795
end
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 ? files.map(&:dump).join(", ") : ""
800803
code.gsub!(/(?:`git[^\`]*`|%x\[git[^\]]*\])\.split(\([^\)]*\))?/m) do
801-
"[]"
802-
end
804+
"[" + files + "]"
805+
end \
806+
or
803807
code.gsub!(/IO\.popen\(.*git.*?\)/) do
804-
"[] || itself"
808+
"[" + files + "] || itself"
805809
end
806810

807811
spec = eval(code, binding, file)
808812
unless Gem::Specification === spec
809813
raise TypeError, "[#{file}] isn't a Gem::Specification (#{spec.class} instead)."
810814
end
811815
spec.loaded_from = base ? File.join(base, File.basename(file)) : file
812-
spec.files.clear
813816
spec.date = RUBY_RELEASE_DATE
814817

815818
spec
@@ -839,14 +842,11 @@ def install_default_gem(dir, srcdir, bindir)
839842

840843
base = "#{srcdir}/#{dir}"
841844
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
845+
files = RbInstall::Specs::FileCollector.for(srcdir, dir, src).collect
845846
if files.empty?
846847
next
847848
end
848-
spec.files = files
849-
spec
849+
load_gemspec("#{base}/#{src}", files: files)
850850
}
851851
gems.compact.sort_by(&:name).each do |gemspec|
852852
old_gemspecs = Dir[File.join(with_destdir(default_spec_dir), "#{gemspec.name}-*.gemspec")]
@@ -1167,7 +1167,10 @@ class << (w = [])
11671167
next
11681168
end
11691169
base = "#{srcdir}/.bundle/gems/#{gem_name}"
1170-
spec = load_gemspec(path, base)
1170+
files = collector.new(path, base, nil).collect
1171+
files.delete("#{gem}.gemspec")
1172+
files.delete("#{gem_name}.gemspec")
1173+
spec = load_gemspec(path, base, files: files)
11711174
unless spec.platform == Gem::Platform::RUBY
11721175
skipped[gem_name] = "not ruby platform (#{spec.platform})"
11731176
next
@@ -1183,9 +1186,6 @@ class << (w = [])
11831186
end
11841187
spec.extension_dir = "#{extensions_dir}/#{spec.full_name}"
11851188

1186-
# Override files with the actual files included in the gem
1187-
spec.files = collector.new(path, base, nil).collect
1188-
11891189
package = RbInstall::DirPackage.new spec
11901190
ins = RbInstall::UnpackedInstaller.new(package, options)
11911191
puts "#{INDENT}#{spec.name} #{spec.version}"

0 commit comments

Comments
 (0)