--- tool/rbinstall.rb.orig 2024-07-08 23:28:22 UTC +++ tool/rbinstall.rb @@ -970,175 +970,6 @@ end # :startdoc: -install?(:ext, :comm, :gem, :'default-gems', :'default-gems-comm') do - install_default_gem('lib', srcdir, bindir) -end -install?(:ext, :arch, :gem, :'default-gems', :'default-gems-arch') do - install_default_gem('ext', srcdir, bindir) -end - -def load_gemspec(file, base = nil) - file = File.realpath(file) - code = File.read(file, encoding: "utf-8:-") - code.gsub!(/(?:`git[^\`]*`|%x\[git[^\]]*\])\.split\([^\)]*\)/m) do - files = [] - if base - 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 - end - "[" + files.join(", ") + "]" - 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.date = RUBY_RELEASE_DATE - - spec -end - -def install_default_gem(dir, srcdir, bindir) - gem_dir = Gem.default_dir - install_dir = with_destdir(gem_dir) - prepare "default gems from #{dir}", gem_dir - RbInstall.no_write do - makedirs(Gem.ensure_default_gem_subdirectories(install_dir, $dir_mode).map {|d| File.join(gem_dir, d)}) - end - - options = { - :install_dir => with_destdir(gem_dir), - :bin_dir => with_destdir(bindir), - :ignore_dependencies => true, - :dir_mode => $dir_mode, - :data_mode => $data_mode, - :prog_mode => $script_mode, - :wrappers => true, - :format_executable => true, - :install_as_default => true, - } - default_spec_dir = Gem.default_specifications_dir - - base = "#{srcdir}/#{dir}" - gems = Dir.glob("**/*.gemspec", base: base).map {|src| - spec = load_gemspec("#{base}/#{src}") - file_collector = RbInstall::Specs::FileCollector.for(srcdir, dir, src) - files = file_collector.collect - if files.empty? - next - end - spec.files = files - spec - } - gems.compact.sort_by(&:name).each do |gemspec| - old_gemspecs = Dir[File.join(with_destdir(default_spec_dir), "#{gemspec.name}-*.gemspec")] - if old_gemspecs.size > 0 - old_gemspecs.each {|spec| rm spec } - end - - full_name = "#{gemspec.name}-#{gemspec.version}" - - gemspec.loaded_from = File.join srcdir, gemspec.spec_name - - package = RbInstall::DirPackage.new gemspec, {gemspec.bindir => 'libexec'} - ins = RbInstall::UnpackedInstaller.new(package, options) - puts "#{INDENT}#{gemspec.name} #{gemspec.version}" - ins.install - end -end - -install?(:ext, :comm, :gem, :'bundled-gems') do - gem_dir = Gem.default_dir - install_dir = with_destdir(gem_dir) - prepare "bundled gems", gem_dir - RbInstall.no_write do - makedirs(Gem.ensure_gem_subdirectories(install_dir, $dir_mode).map {|d| File.join(gem_dir, d)}) - end - - installed_gems = {} - skipped = {} - options = { - :install_dir => install_dir, - :bin_dir => with_destdir(bindir), - :domain => :local, - :ignore_dependencies => true, - :dir_mode => $dir_mode, - :data_mode => $data_mode, - :prog_mode => $script_mode, - :wrappers => true, - :format_executable => true, - } - - extensions_dir = Gem::StubSpecification.gemspec_stub("", gem_dir, gem_dir).extensions_dir - specifications_dir = File.join(gem_dir, "specifications") - build_dir = Gem::StubSpecification.gemspec_stub("", ".bundle", ".bundle").extensions_dir - - # We are about to build extensions, and want to configure extensions with the - # newly installed ruby. - Gem.instance_variable_set(:@ruby, with_destdir(File.join(bindir, ruby_install_name))) - # Prevent fake.rb propagation. It conflicts with the natural mkmf configs of - # the newly installed ruby. - ENV.delete('RUBYOPT') - - File.foreach("#{srcdir}/gems/bundled_gems") do |name| - next if /^\s*(?:#|$)/ =~ name - next unless /^(\S+)\s+(\S+).*/ =~ name - gem = $1 - gem_name = "#$1-#$2" - # Try to find the original gemspec file - path = "#{srcdir}/.bundle/gems/#{gem_name}/#{gem}.gemspec" - unless File.exist?(path) - # Try to find the gemspec file for C ext gems - # ex .bundle/gems/debug-1.7.1/debug-1.7.1.gemspec - # This gemspec keep the original dependencies - path = "#{srcdir}/.bundle/gems/#{gem_name}/#{gem_name}.gemspec" - unless File.exist?(path) - # Try to find the gemspec file for gems that hasn't own gemspec - path = "#{srcdir}/.bundle/specifications/#{gem_name}.gemspec" - unless File.exist?(path) - skipped[gem_name] = "gemspec not found" - next - end - end - end - spec = load_gemspec(path, "#{srcdir}/.bundle/gems/#{gem_name}") - unless spec.platform == Gem::Platform::RUBY - skipped[gem_name] = "not ruby platform (#{spec.platform})" - next - end - unless spec.full_name == gem_name - skipped[gem_name] = "full name unmatch #{spec.full_name}" - next - end - spec.extension_dir = "#{extensions_dir}/#{spec.full_name}" - package = RbInstall::DirPackage.new spec - ins = RbInstall::UnpackedInstaller.new(package, options) - puts "#{INDENT}#{spec.name} #{spec.version}" - ins.install - install_recursive("#{build_dir}/#{gem_name}", "#{extensions_dir}/#{gem_name}") do |src, dest| - # puts "#{INDENT} #{dest[extensions_dir.size+gem_name.size+2..-1]}" - install src, dest, :mode => (File.executable?(src) ? $prog_mode : $data_mode) - end - installed_gems[spec.full_name] = true - end - installed_gems, gems = Dir.glob(srcdir+'/gems/*.gem').partition {|gem| installed_gems.key?(File.basename(gem, '.gem'))} - unless installed_gems.empty? - prepare "bundled gem cache", gem_dir+"/cache" - install installed_gems, gem_dir+"/cache" - end - unless gems.empty? - skipped.default = "not found in bundled_gems" - puts "skipped bundled gems:" - gems.each do |gem| - printf " %-32s%s\n", File.basename(gem), skipped[gem] - end - end -end - parse_args() include FileUtils