2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/package'
|
2011-03-09 17:32:29 -05:00
|
|
|
require 'time'
|
2018-02-05 21:58:35 -05:00
|
|
|
require 'tmpdir'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
begin
|
2009-06-09 17:38:59 -04:00
|
|
|
gem 'builder'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'builder/xchar'
|
2018-11-21 05:20:47 -05:00
|
|
|
rescue LoadError
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Top level class for building the gem repository index.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
class Gem::Indexer
|
|
|
|
|
|
|
|
include Gem::UserInteraction
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Build indexes for RubyGems 1.2.0 and newer when true
|
|
|
|
|
|
|
|
attr_accessor :build_modern
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
##
|
|
|
|
# Index install location
|
|
|
|
|
|
|
|
attr_reader :dest_directory
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Specs index install location
|
|
|
|
|
|
|
|
attr_reader :dest_specs_index
|
|
|
|
|
|
|
|
##
|
|
|
|
# Latest specs index install location
|
|
|
|
|
|
|
|
attr_reader :dest_latest_specs_index
|
|
|
|
|
|
|
|
##
|
|
|
|
# Prerelease specs index install location
|
|
|
|
|
|
|
|
attr_reader :dest_prerelease_specs_index
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
##
|
|
|
|
# Index build directory
|
|
|
|
|
|
|
|
attr_reader :directory
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Create an indexer that will index the gems in +directory+.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def initialize(directory, options = {})
|
2011-01-18 19:08:49 -05:00
|
|
|
require 'fileutils'
|
|
|
|
require 'tmpdir'
|
|
|
|
require 'zlib'
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless defined?(Builder::XChar)
|
2012-12-06 00:26:46 -05:00
|
|
|
raise "Gem::Indexer requires that the XML Builder library be installed:" +
|
|
|
|
"\n\tgem install builder"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
options = { :build_modern => true }.merge options
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
@build_modern = options[:build_modern]
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@dest_directory = directory
|
2018-02-05 21:58:35 -05:00
|
|
|
@directory = Dir.mktmpdir 'gem_generate_index'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
marshal_name = "Marshal.#{Gem.marshal_version}"
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
@master_index = File.join @directory, 'yaml'
|
|
|
|
@marshal_index = File.join @directory, marshal_name
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
@quick_dir = File.join @directory, 'quick'
|
|
|
|
@quick_marshal_dir = File.join @quick_dir, marshal_name
|
2011-05-31 23:45:05 -04:00
|
|
|
@quick_marshal_dir_base = File.join "quick", marshal_name # FIX: UGH
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
@quick_index = File.join @quick_dir, 'index'
|
|
|
|
@latest_index = File.join @quick_dir, 'latest_index'
|
|
|
|
|
|
|
|
@specs_index = File.join @directory, "specs.#{Gem.marshal_version}"
|
2011-05-31 23:45:05 -04:00
|
|
|
@latest_specs_index =
|
|
|
|
File.join(@directory, "latest_specs.#{Gem.marshal_version}")
|
|
|
|
@prerelease_specs_index =
|
|
|
|
File.join(@directory, "prerelease_specs.#{Gem.marshal_version}")
|
|
|
|
@dest_specs_index =
|
|
|
|
File.join(@dest_directory, "specs.#{Gem.marshal_version}")
|
|
|
|
@dest_latest_specs_index =
|
|
|
|
File.join(@dest_directory, "latest_specs.#{Gem.marshal_version}")
|
|
|
|
@dest_prerelease_specs_index =
|
|
|
|
File.join(@dest_directory, "prerelease_specs.#{Gem.marshal_version}")
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
@files = []
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2015-05-09 23:01:18 -04:00
|
|
|
# Build various indices
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2015-05-09 23:01:18 -04:00
|
|
|
def build_indices
|
2015-07-01 17:50:14 -04:00
|
|
|
specs = map_gems_to_specs gem_file_list
|
|
|
|
Gem::Specification._resort! specs
|
|
|
|
build_marshal_gemspecs specs
|
|
|
|
build_modern_indices specs if @build_modern
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2015-05-09 23:01:18 -04:00
|
|
|
compress_indices
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Builds Marshal quick index gemspecs.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def build_marshal_gemspecs(specs)
|
2015-07-01 17:50:14 -04:00
|
|
|
count = specs.count
|
2011-05-31 23:45:05 -04:00
|
|
|
progress = ui.progress_reporter count,
|
|
|
|
"Generating Marshal quick index gemspecs for #{count} gems",
|
2008-06-17 18:04:18 -04:00
|
|
|
"Complete"
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
files = []
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
Gem.time 'Generated Marshal quick index gemspecs' do
|
2015-07-01 17:50:14 -04:00
|
|
|
specs.each do |spec|
|
2013-10-15 20:14:16 -04:00
|
|
|
next if spec.default_gem?
|
2011-05-31 23:45:05 -04:00
|
|
|
spec_file_name = "#{spec.original_name}.gemspec.rz"
|
2009-06-09 17:38:59 -04:00
|
|
|
marshal_name = File.join @quick_marshal_dir, spec_file_name
|
|
|
|
|
|
|
|
marshal_zipped = Gem.deflate Marshal.dump(spec)
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open marshal_name, 'wb' do |io| io.write marshal_zipped end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
files << marshal_name
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
progress.updated spec.original_name
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
progress.done
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@files << @quick_marshal_dir
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
files
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Build a single index for RubyGems 1.2 and newer
|
|
|
|
|
|
|
|
def build_modern_index(index, file, name)
|
|
|
|
say "Generating #{name} index"
|
|
|
|
|
|
|
|
Gem.time "Generated #{name} index" do
|
|
|
|
open(file, 'wb') do |io|
|
|
|
|
specs = index.map do |*spec|
|
2011-05-31 23:45:05 -04:00
|
|
|
# We have to splat here because latest_specs is an array, while the
|
|
|
|
# others are hashes.
|
2009-06-09 17:38:59 -04:00
|
|
|
spec = spec.flatten.last
|
|
|
|
platform = spec.original_platform
|
|
|
|
|
|
|
|
# win32-api-1.0.4-x86-mswin32-60
|
2018-11-21 05:20:47 -05:00
|
|
|
unless String === platform
|
2009-06-09 17:38:59 -04:00
|
|
|
alert_warning "Skipping invalid platform in gem: #{spec.full_name}"
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
|
|
|
|
[spec.name, spec.version, platform]
|
|
|
|
end
|
|
|
|
|
|
|
|
specs = compact_specs(specs)
|
|
|
|
Marshal.dump(specs, io)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2015-05-09 23:01:18 -04:00
|
|
|
# Builds indices for RubyGems 1.2 and newer. Handles full, latest, prerelease
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def build_modern_indices(specs)
|
2013-10-15 20:14:16 -04:00
|
|
|
prerelease, released = specs.partition { |s|
|
2011-05-31 23:45:05 -04:00
|
|
|
s.version.prerelease?
|
|
|
|
}
|
2013-10-15 20:14:16 -04:00
|
|
|
latest_specs =
|
2015-07-01 17:50:14 -04:00
|
|
|
Gem::Specification._latest_specs specs
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
build_modern_index(released.sort, @specs_index, 'specs')
|
|
|
|
build_modern_index(latest_specs.sort, @latest_specs_index, 'latest specs')
|
|
|
|
build_modern_index(prerelease.sort, @prerelease_specs_index,
|
2009-06-09 17:38:59 -04:00
|
|
|
'prerelease specs')
|
|
|
|
|
|
|
|
@files += [@specs_index,
|
|
|
|
"#{@specs_index}.gz",
|
|
|
|
@latest_specs_index,
|
|
|
|
"#{@latest_specs_index}.gz",
|
|
|
|
@prerelease_specs_index,
|
|
|
|
"#{@prerelease_specs_index}.gz"]
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def map_gems_to_specs(gems)
|
2011-05-31 23:45:05 -04:00
|
|
|
gems.map { |gemfile|
|
2018-11-21 05:20:47 -05:00
|
|
|
if File.size(gemfile) == 0
|
2011-05-31 23:45:05 -04:00
|
|
|
alert_warning "Skipping zero-length gem: #{gemfile}"
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
2012-11-29 01:52:18 -05:00
|
|
|
spec = Gem::Package.new(gemfile).spec
|
2011-05-31 23:45:05 -04:00
|
|
|
spec.loaded_from = gemfile
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
spec.abbreviate
|
|
|
|
spec.sanitize
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
spec
|
2014-11-16 22:55:02 -05:00
|
|
|
rescue SignalException
|
2011-05-31 23:45:05 -04:00
|
|
|
alert_error "Received signal, exiting"
|
|
|
|
raise
|
|
|
|
rescue Exception => e
|
|
|
|
msg = ["Unable to process #{gemfile}",
|
|
|
|
"#{e.message} (#{e.class})",
|
|
|
|
"\t#{e.backtrace.join "\n\t"}"].join("\n")
|
|
|
|
alert_error msg
|
|
|
|
end
|
|
|
|
}.compact
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
2015-05-09 23:01:18 -04:00
|
|
|
# Compresses indices on disk
|
2009-06-09 17:38:59 -04:00
|
|
|
#--
|
|
|
|
# All future files should be compressed using gzip, not deflate
|
|
|
|
|
2015-05-09 23:01:18 -04:00
|
|
|
def compress_indices
|
|
|
|
say "Compressing indices"
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2015-05-09 23:01:18 -04:00
|
|
|
Gem.time 'Compressed indices' do
|
2018-11-21 05:20:47 -05:00
|
|
|
if @build_modern
|
2009-06-09 17:38:59 -04:00
|
|
|
gzip @specs_index
|
|
|
|
gzip @latest_specs_index
|
|
|
|
gzip @prerelease_specs_index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# Compacts Marshal output for the specs index data source by using identical
|
|
|
|
# objects as much as possible.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def compact_specs(specs)
|
|
|
|
names = {}
|
|
|
|
versions = {}
|
|
|
|
platforms = {}
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
specs.map do |(name, version, platform)|
|
|
|
|
names[name] = name unless names.include? name
|
|
|
|
versions[version] = version unless versions.include? version
|
|
|
|
platforms[platform] = platform unless platforms.include? platform
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
[names[name], versions[version], platforms[platform]]
|
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# Compress +filename+ with +extension+.
|
|
|
|
|
|
|
|
def compress(filename, extension)
|
|
|
|
data = Gem.read_binary filename
|
|
|
|
|
|
|
|
zipped = Gem.deflate data
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open "#{filename}.#{extension}", 'wb' do |io|
|
2008-06-17 18:04:18 -04:00
|
|
|
io.write zipped
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# List of gem file names to index.
|
|
|
|
|
|
|
|
def gem_file_list
|
2018-08-27 06:05:04 -04:00
|
|
|
Gem::Util.glob_files_in_dir("*.gem", File.join(@dest_directory, "gems"))
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2015-05-09 23:01:18 -04:00
|
|
|
# Builds and installs indices.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def generate_index
|
2008-06-25 22:06:00 -04:00
|
|
|
make_temp_directories
|
2015-05-09 23:01:18 -04:00
|
|
|
build_indices
|
|
|
|
install_indices
|
2007-11-10 02:48:56 -05:00
|
|
|
rescue SignalException
|
|
|
|
ensure
|
|
|
|
FileUtils.rm_rf @directory
|
|
|
|
end
|
|
|
|
|
2009-12-08 02:19:09 -05:00
|
|
|
##
|
2008-06-17 18:04:18 -04:00
|
|
|
# Zlib::GzipWriter wrapper that gzips +filename+ on disk.
|
|
|
|
|
|
|
|
def gzip(filename)
|
|
|
|
Zlib::GzipWriter.open "#{filename}.gz" do |io|
|
|
|
|
io.write Gem.read_binary(filename)
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
2015-05-09 23:01:18 -04:00
|
|
|
# Install generated indices into the destination directory.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2015-05-09 23:01:18 -04:00
|
|
|
def install_indices
|
2008-06-17 18:04:18 -04:00
|
|
|
verbose = Gem.configuration.really_verbose
|
|
|
|
|
|
|
|
say "Moving index into production dir #{@dest_directory}" if verbose
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
files = @files
|
2009-06-09 17:38:59 -04:00
|
|
|
files.delete @quick_marshal_dir if files.include? @quick_dir
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if files.include? @quick_marshal_dir and not files.include? @quick_dir
|
2009-06-09 17:38:59 -04:00
|
|
|
files.delete @quick_marshal_dir
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
dst_name = File.join(@dest_directory, @quick_marshal_dir_base)
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir_p File.dirname(dst_name), :verbose => verbose
|
|
|
|
FileUtils.rm_rf dst_name, :verbose => verbose
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.mv(@quick_marshal_dir, dst_name,
|
|
|
|
:verbose => verbose, :force => true)
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
files = files.map do |path|
|
2011-05-31 23:45:05 -04:00
|
|
|
path.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK?
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
files.each do |file|
|
2008-06-17 18:04:18 -04:00
|
|
|
src_name = File.join @directory, file
|
|
|
|
dst_name = File.join @dest_directory, file
|
|
|
|
|
|
|
|
FileUtils.rm_rf dst_name, :verbose => verbose
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.mv(src_name, @dest_directory,
|
|
|
|
:verbose => verbose, :force => true)
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-25 22:06:00 -04:00
|
|
|
##
|
|
|
|
# Make directories for index generation
|
|
|
|
|
|
|
|
def make_temp_directories
|
|
|
|
FileUtils.rm_rf @directory
|
|
|
|
FileUtils.mkdir_p @directory, :mode => 0700
|
|
|
|
FileUtils.mkdir_p @quick_marshal_dir
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
|
|
|
# Ensure +path+ and path with +extension+ are identical.
|
|
|
|
|
|
|
|
def paranoid(path, extension)
|
|
|
|
data = Gem.read_binary path
|
|
|
|
compressed_data = Gem.read_binary "#{path}.#{extension}"
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless data == Gem::Util.inflate(compressed_data)
|
2008-06-17 18:04:18 -04:00
|
|
|
raise "Compressed file #{compressed_path} does not match uncompressed file #{path}"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# Perform an in-place update of the repository from newly added gems.
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
def update_index
|
|
|
|
make_temp_directories
|
|
|
|
|
|
|
|
specs_mtime = File.stat(@dest_specs_index).mtime
|
|
|
|
newest_mtime = Time.at 0
|
|
|
|
|
|
|
|
updated_gems = gem_file_list.select do |gem|
|
|
|
|
gem_mtime = File.stat(gem).mtime
|
|
|
|
newest_mtime = gem_mtime if gem_mtime > newest_mtime
|
|
|
|
gem_mtime >= specs_mtime
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if updated_gems.empty?
|
2009-06-09 17:38:59 -04:00
|
|
|
say 'No new gems'
|
|
|
|
terminate_interaction 0
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
specs = map_gems_to_specs updated_gems
|
|
|
|
prerelease, released = specs.partition { |s| s.version.prerelease? }
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
files = build_marshal_gemspecs specs
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
Gem.time 'Updated indexes' do
|
2011-05-31 23:45:05 -04:00
|
|
|
update_specs_index released, @dest_specs_index, @specs_index
|
|
|
|
update_specs_index released, @dest_latest_specs_index, @latest_specs_index
|
|
|
|
update_specs_index(prerelease,
|
|
|
|
@dest_prerelease_specs_index,
|
2009-06-09 17:38:59 -04:00
|
|
|
@prerelease_specs_index)
|
|
|
|
end
|
|
|
|
|
2015-05-09 23:01:18 -04:00
|
|
|
compress_indices
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
verbose = Gem.configuration.really_verbose
|
|
|
|
|
|
|
|
say "Updating production dir #{@dest_directory}" if verbose
|
|
|
|
|
|
|
|
files << @specs_index
|
|
|
|
files << "#{@specs_index}.gz"
|
|
|
|
files << @latest_specs_index
|
|
|
|
files << "#{@latest_specs_index}.gz"
|
|
|
|
files << @prerelease_specs_index
|
|
|
|
files << "#{@prerelease_specs_index}.gz"
|
|
|
|
|
|
|
|
files = files.map do |path|
|
2011-05-31 23:45:05 -04:00
|
|
|
path.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK?
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
files.each do |file|
|
|
|
|
src_name = File.join @directory, file
|
2011-05-31 23:45:05 -04:00
|
|
|
dst_name = File.join @dest_directory, file # REFACTOR: duped above
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
FileUtils.mv src_name, dst_name, :verbose => verbose,
|
|
|
|
:force => true
|
|
|
|
|
|
|
|
File.utime newest_mtime, newest_mtime, dst_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Combines specs in +index+ and +source+ then writes out a new copy to
|
|
|
|
# +dest+. For a latest index, does not ensure the new file is minimal.
|
|
|
|
|
|
|
|
def update_specs_index(index, source, dest)
|
|
|
|
specs_index = Marshal.load Gem.read_binary(source)
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
index.each do |spec|
|
2009-06-09 17:38:59 -04:00
|
|
|
platform = spec.original_platform
|
|
|
|
platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
|
|
|
|
specs_index << [spec.name, spec.version, platform]
|
|
|
|
end
|
|
|
|
|
|
|
|
specs_index = compact_specs specs_index.uniq.sort
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open dest, 'wb' do |io|
|
2009-06-09 17:38:59 -04:00
|
|
|
Marshal.dump specs_index, io
|
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|