mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Classify extlibs tool
* tool/extlibs.rb (ExtLibs): classify the tool to make it able to reuse it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a0035eb620
commit
873d62b1e2
1 changed files with 148 additions and 130 deletions
|
@ -7,6 +7,7 @@ require 'fileutils'
|
||||||
require 'digest'
|
require 'digest'
|
||||||
require_relative 'downloader'
|
require_relative 'downloader'
|
||||||
|
|
||||||
|
class ExtLibs
|
||||||
def do_download(url, base, cache_dir)
|
def do_download(url, base, cache_dir)
|
||||||
Downloader.download(url, base, cache_dir, nil)
|
Downloader.download(url, base, cache_dir, nil)
|
||||||
end
|
end
|
||||||
|
@ -75,10 +76,36 @@ def do_patch(dest, patch, args)
|
||||||
$?.success? or raise "failed to patch #{patch}"
|
$?.success? or raise "failed to patch #{patch}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def do_command(mode, dest, url, cache_dir, chksums)
|
||||||
|
base = File.basename(url)
|
||||||
|
cache = File.join(cache_dir, base)
|
||||||
|
target = File.join(dest, base[/.*(?=\.tar(?:\.\w+)?\z)/])
|
||||||
|
|
||||||
|
extracted = false
|
||||||
|
case mode
|
||||||
|
when :download
|
||||||
|
do_download(url, base, cache_dir)
|
||||||
|
do_checksum(cache, chksums)
|
||||||
|
when :extract
|
||||||
|
unless File.directory?(target)
|
||||||
|
do_checksum(cache, chksums)
|
||||||
|
extracted = do_extract(cache, dest)
|
||||||
|
end
|
||||||
|
when :all
|
||||||
|
do_download(url, base, cache_dir)
|
||||||
|
unless File.directory?(target)
|
||||||
|
do_checksum(cache, chksums)
|
||||||
|
extracted = do_extract(cache, dest)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
extracted
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(argv)
|
||||||
cache_dir = ENV['CACHE_DIR'] || ".downloaded-cache"
|
cache_dir = ENV['CACHE_DIR'] || ".downloaded-cache"
|
||||||
mode = :all
|
mode = :all
|
||||||
until ARGV.empty?
|
until argv.empty?
|
||||||
case ARGV[0]
|
case argv[0]
|
||||||
when '--download'
|
when '--download'
|
||||||
mode = :download
|
mode = :download
|
||||||
when '--extract'
|
when '--extract'
|
||||||
|
@ -88,25 +115,26 @@ until ARGV.empty?
|
||||||
when '--all'
|
when '--all'
|
||||||
mode = :all
|
mode = :all
|
||||||
when '--cache'
|
when '--cache'
|
||||||
ARGV.shift
|
argv.shift
|
||||||
cache_dir = ARGV[0]
|
cache_dir = argv[0]
|
||||||
when /\A--cache=/
|
when /\A--cache=/
|
||||||
cache_dir = $'
|
cache_dir = $'
|
||||||
when '--'
|
when '--'
|
||||||
ARGV.shift
|
argv.shift
|
||||||
break
|
break
|
||||||
when /\A-/
|
when /\A-/
|
||||||
abort "unknown option: #{ARGV[0]}"
|
warn "unknown option: #{argv[0]}"
|
||||||
|
return false
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
ARGV.shift
|
argv.shift
|
||||||
end
|
end
|
||||||
|
|
||||||
FileUtils.mkdir_p(cache_dir)
|
FileUtils.mkdir_p(cache_dir)
|
||||||
|
|
||||||
success = true
|
success = true
|
||||||
ARGV.each do |dir|
|
argv.each do |dir|
|
||||||
Dir.glob("#{dir}/**/extlibs") do |list|
|
Dir.glob("#{dir}/**/extlibs") do |list|
|
||||||
if $VERBOSE
|
if $VERBOSE
|
||||||
$stdout.puts "downloading for #{list}"
|
$stdout.puts "downloading for #{list}"
|
||||||
|
@ -125,27 +153,8 @@ ARGV.each do |dir|
|
||||||
end
|
end
|
||||||
url, *chksums = line.split(' ')
|
url, *chksums = line.split(' ')
|
||||||
next unless url
|
next unless url
|
||||||
extracted = false
|
|
||||||
base = File.basename(url)
|
|
||||||
cache = File.join(cache_dir, base)
|
|
||||||
target = File.join(dest, base[/.*(?=\.tar(?:\.\w+)?\z)/])
|
|
||||||
begin
|
begin
|
||||||
case mode
|
extracted = do_command(mode, dest, url, cache_dir, chksums)
|
||||||
when :download
|
|
||||||
do_download(url, base, cache_dir)
|
|
||||||
do_checksum(cache, chksums)
|
|
||||||
when :extract
|
|
||||||
unless File.directory?(target)
|
|
||||||
do_checksum(cache, chksums)
|
|
||||||
extracted = do_extract(cache, dest)
|
|
||||||
end
|
|
||||||
when :all
|
|
||||||
do_download(url, base, cache_dir)
|
|
||||||
unless File.directory?(target)
|
|
||||||
do_checksum(cache, chksums)
|
|
||||||
extracted = do_extract(cache, dest)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue => e
|
rescue => e
|
||||||
warn e.inspect
|
warn e.inspect
|
||||||
success = false
|
success = false
|
||||||
|
@ -153,5 +162,14 @@ ARGV.each do |dir|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
exit(success)
|
def self.run(argv)
|
||||||
|
self.new.run(argv)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if $0 == __FILE__
|
||||||
|
exit ExtLibs.run(ARGV)
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue