Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Override files of bundled gem specs #13699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions tool/rbinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,16 @@ def root
"#{srcdir}/lib"
end
end

class UnpackedGem < self
def collect
base = @srcdir or return []
Dir.glob("**/*", File::FNM_DOTMATCH, base: base).select do |n|
case File.basename(n); when ".", ".."; next; end
!File.directory?(File.join(base, n))
end
end
end
end
end

Expand Down Expand Up @@ -772,32 +782,34 @@ def ensure_writable_dir(dir)
$installed_list.puts(d+"/") if $installed_list
end
end

def load_plugin
# Suppress warnings for constant re-assignment
verbose, $VERBOSE = $VERBOSE, nil
super
ensure
$VERBOSE = verbose
end
end
end

def load_gemspec(file, base = nil)
file = File.realpath(file)
code = File.read(file, encoding: "utf-8:-")

files = []
Dir.glob("**/*", File::FNM_DOTMATCH, base: base) do |n|
case File.basename(n); when ".", ".."; next; end
next if File.directory?(File.join(base, n))
files << n.dump
end if base
code.gsub!(/(?:`git[^\`]*`|%x\[git[^\]]*\])\.split(\([^\)]*\))?/m) do
"[" + files.join(", ") + "]"
"[]"
end
code.gsub!(/IO\.popen\(.*git.*?\)/) do
"[" + files.join(", ") + "] || itself"
"[] || itself"
end

spec = eval(code, binding, file)
unless Gem::Specification === spec
raise TypeError, "[#{file}] isn't a Gem::Specification (#{spec.class} instead)."
end
spec.loaded_from = base ? File.join(base, File.basename(file)) : file
spec.files.reject! {|n| n.end_with?(".gemspec") or n.start_with?(".git")}
spec.files.clear
spec.date = RUBY_RELEASE_DATE

spec
Expand Down Expand Up @@ -1135,6 +1147,7 @@ class << (w = [])
# the newly installed ruby.
ENV.delete('RUBYOPT')

collector = RbInstall::Specs::FileCollector::UnpackedGem
File.foreach("#{srcdir}/gems/bundled_gems") do |name|
next if /^\s*(?:#|$)/ =~ name
next unless /^(\S+)\s+(\S+).*/ =~ name
Expand All @@ -1153,7 +1166,8 @@ class << (w = [])
skipped[gem_name] = "gemspec not found"
next
end
spec = load_gemspec(path, "#{srcdir}/.bundle/gems/#{gem_name}")
base = "#{srcdir}/.bundle/gems/#{gem_name}"
spec = load_gemspec(path, base)
unless spec.platform == Gem::Platform::RUBY
skipped[gem_name] = "not ruby platform (#{spec.platform})"
next
Expand All @@ -1168,6 +1182,10 @@ class << (w = [])
next
end
spec.extension_dir = "#{extensions_dir}/#{spec.full_name}"

# Override files with the actual files included in the gem
spec.files = collector.new(path, base, nil).collect

package = RbInstall::DirPackage.new spec
ins = RbInstall::UnpackedInstaller.new(package, options)
puts "#{INDENT}#{spec.name} #{spec.version}"
Expand Down
Loading