1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

vcs.rb: abstract

* tool/vcs.rb: abstract VCS interfaces from make-snapshot.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-12-15 01:02:52 +00:00
parent 81ac745846
commit fff1128281
2 changed files with 112 additions and 19 deletions

View file

@ -5,6 +5,7 @@ require 'digest/md5'
require 'digest/sha2'
require 'fileutils'
require 'tmpdir'
require File.expand_path("../vcs", __FILE__)
STDOUT.sync = true
$exported = nil if ($exported ||= nil) == ""
@ -121,50 +122,53 @@ unless tmp = $exported
FileUtils.rm_rf(tmp)
} unless $keep_temp
end
Dir.chdir tmp
def package(rev, destdir)
def package(vcs, rev, destdir, tmp = nil)
patchlevel = false
prerelease = false
if revision = rev[/@(\d+)\z/, 1]
rev = $`
end
case rev
when /\Atrunk\z/, /\Abranches\//, /\Atags\//
url = SVNURL + rev
when /\Atrunk\z/
url = vcs.trunk
when /\Abranches\//
url = vcs.branch($')
when /\Atags\//
url = vcs.tag($')
when /\Astable\z/
url = SVNURL + "branches/"
url = url + `svn ls #{url}`[/.*^(ruby_\d+_\d+)\//m, 1]
vcs.branch_list(/ruby_[0-9]*/) {|n| url = /\Aruby_\d+_\d+\z/ =~ n}
url &&= vcs.branch(url)
when /\A(.*)\.(.*)\.(.*)-(preview|rc)(\d+)/
prerelease = true
tag = "#{$4}#{$5}"
url = SVNURL + "tags/v#{$1}_#{$2}_#{$3}_#{$4}#{$5}"
url = vcs.tag("v#{$1}_#{$2}_#{$3}_#{$4}#{$5}")
when /\A(.*)\.(.*)\.(.*)-p(\d+)/
patchlevel = true
tag = "p#{$4}"
url = SVNURL + "tags/v#{$1}_#{$2}_#{$3}_#{$4}"
url = vcs.tag("v#{$1}_#{$2}_#{$3}_#{$4}")
when /\A(\d+)\.(\d+)(?:\.(\d+))?\z/
if $3 && ($1 > "2" || $1 == "2" && $2 >= "1")
patchlevel = true
tag = ""
url = SVNURL + "tags/v#{$1}_#{$2}_#{$3}"
url = vcs.tag("v#{$1}_#{$2}_#{$3}")
else
url = SVNURL + "branches/ruby_#{rev.tr('.', '_')}"
url = vcs.branch("ruby_#{rev.tr('.', '_')}")
end
else
warn "#{$0}: unknown version - #{rev}"
return
end
revision ||= `svn info #{url} 2>&1`[/Last Changed Rev: (\d+)/, 1]
revision ||= vcs.get_revisions(url)[1]
version = nil
unless revision
url = SVNURL + "trunk"
version = `svn cat #{url + "version.h"}`[RUBY_VERSION_PATTERN, 1]
url = vcs.trunk
vcs.grep(RUBY_VERSION_PATTERN, url, "version.h") {version = $1}
unless rev == version
warn "#{$0}: #{rev} not found"
return
end
revision = `svn info #{url}`[/Last Changed Rev: (\d+)/, 1]
revision = vcs.get_revisions(url)[1]
end
v = nil
if $exported
@ -174,15 +178,14 @@ def package(rev, destdir)
else
v = "ruby"
puts "Exporting #{rev}@#{revision}"
IO.popen(%W"svn export -r #{revision} #{url} #{v}") do |pipe|
pipe.each {|line| /^A/ =~ line or print line}
end
unless $?.success?
unless vcs.export(revision, url, tmp ? File.join(tmp, v) : v) {|line| print line}
warn("Export failed")
return
end
end
Dir.chdir(tmp) if tmp
if !File.directory?(v)
v = Dir.glob("ruby-*").select(&File.method(:directory?))
v.size == 1 or abort "not exported"
@ -338,8 +341,10 @@ ensure
FileUtils.rm_rf(v) if v and !$exported and !$keep_temp
end
vcs = VCS::SVN.new(SVNURL)
success = true
revisions.collect {|rev| package(rev, destdir)}.flatten.each do |name|
revisions.collect {|rev| package(vcs, rev, destdir, tmp)}.flatten.each do |name|
if !name
success = false
next

View file

@ -134,6 +134,54 @@ class VCS
modified = info_xml[/<date>([^<>]*)/, 1]
[last, changed, modified]
end
def url
unless defined?(@url)
url = IO.pread(%W"svn info --xml #{@srcdir}")[/<url>(.*)<\/url>/, 1]
@url = URI.parse(url+"/") if url
end
@url
end
def branch(name)
url + "branches/#{name}"
end
def tag(name)
url + "tags/#{name}"
end
def trunk
url + "trunk"
end
def branch_list(pat)
IO.popen(%W"svn ls #{branch('')}") do |f|
f.each do |line|
line.chomp!('/')
yield(line) if File.fnmatch?(pat, line)
end
end
end
def grep(pat, tag, *files, &block)
cmd = %W"svn cat"
files.map! {|n| File.join(tag, n)} if tag
set = block.binding.eval("proc {|match| $~ = match}")
IO.popen([cmd, *files]) do |f|
f.grep(pat) do |s|
set[$~]
yield s
end
end
end
def export(revision, url, dir)
IO.popen(%W"svn export -r #{revision} #{url} #{dir}") do |pipe|
pipe.each {|line| /^A/ =~ line or yield line}
end
$?.success?
end
end
class GIT < self
@ -154,5 +202,45 @@ class VCS
modified = log[/^Date:\s+(.*)/, 1]
[last, changed, modified]
end
def branch(name)
name
end
alias tag branch
def trunk
branch("trunk")
end
def stable
cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/ruby_[0-9]*"
cmd[1, 0] = ["-C", @srcdir] if @srcdir
branch(IO.pread(cmd)[/.*^(ruby_\d+_\d+)$/m, 1])
end
def branch_list(pat, &block)
cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/#{pat}"
cmd[1, 0] = ["-C", @srcdir] if @srcdir
IO.popen(cmd, &block)
end
def grep(pat, tag, *files, &block)
cmd = %W[git grep -h --perl-regexp #{tag} --]
cmd[1, 0] = ["-C", @srcdir] if @srcdir
set = block.binding.eval("proc {|match| $~ = match}")
IO.popen([cmd, *files]) do |f|
f.grep(pat) do |s|
set[$~]
yield s
end
end
end
def export(revision, url, dir)
ret = system("git", "clone", "-s", (@srcdir || '.'), "-b", url, dir)
FileUtils.rm_rf("#{dir}/.git") if ret
ret
end
end
end