[前][次][番号順一覧][スレッド一覧]

ruby-changes:5987

From: nobu <ko1@a...>
Date: Sat, 21 Jun 2008 15:31:39 +0900 (JST)
Subject: [ruby-changes:5987] Ruby:r17495 (trunk): * tool/make-snapshot: ported to ruby.

nobu	2008-06-21 15:31:18 +0900 (Sat, 21 Jun 2008)

  New Revision: 17495

  Modified files:
    trunk/ChangeLog
    trunk/tool/make-snapshot

  Log:
    * tool/make-snapshot: ported to ruby.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=17495&r2=17494&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/tool/make-snapshot?r1=17495&r2=17494&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 17494)
+++ ChangeLog	(revision 17495)
@@ -1,7 +1,9 @@
-Sat Jun 21 08:39:43 2008  Nobuyoshi Nakada  <nobu@r...>
+Sat Jun 21 15:31:09 2008  Nobuyoshi Nakada  <nobu@r...>
 
-	* tool/make-snapshot: fixed digets.
+	* tool/make-snapshot: ported to ruby.
 
+	* tool/make-snapshot: fixed digests.
+
 Sat Jun 21 04:36:59 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* ext/bigdecimal/lib/bigdecimal/jacobian.rb (Jacobian::dfdxi):
Index: tool/make-snapshot
===================================================================
--- tool/make-snapshot	(revision 17494)
+++ tool/make-snapshot	(revision 17495)
@@ -1,105 +1,143 @@
-#!/bin/bash
+#!/usr/bin/ruby
+require 'uri'
+require 'digest/md5'
+require 'digest/sha2'
+require 'fileutils'
+require 'tmpdir'
+STDOUT.sync = true
 
-LC_ALL=C LANG=C
-SVNURL=http://svn.ruby-lang.org/repos/ruby
-export LC_ALL LANG
-: ${VPATH=include/ruby} ${YACC=bison} ${BASERUBY=ruby} ${RUBY=ruby} ${MV=mv} ${MINIRUBY=ruby}
-for var in YACC BASERUBY RUBY MV MINIRUBY; do
-    eval 'cmd="${'$var'}"'
-    type -p ${cmd%% *} > /dev/null || {
-	echo "$0: $var command not found${cmd:+ - $cmd}" 1>&2
-	exit 1
-    }
-done
-export VPATH YACC BASERUBY RUBY MV MINIRUBY
+ENV["LC_ALL"] = ENV["LANG"] = "C"
+SVNURL = URI.parse("http://svn.ruby-lang.org/repos/ruby/")
+RUBY_VERSION_PATTERN = /^\#define\s+RUBY_VERSION\s+"([\d.]+)"/
 
-if [ ! "$1" ]; then
-    echo "usage: $(basename $0) new-directory-to-save [version ...]" 1>&2
-    exit 1
-fi
-[ -d "$1" ] || mkdir "$1" || exit 1
-dest=$(cd "$1"; pwd)
-shift
+ENV["VPATH"] ||= "include/ruby"
+YACC = ENV["YACC"] ||= "bison"
+ENV["BASERUBY"] ||= "ruby"
+ENV["RUBY"] ||= "ruby"
+ENV["MV"] ||= "mv"
+ENV["MINIRUBY"] ||= "ruby"
 
-[ "$#" = 0 ] && set trunk
+path = ENV["PATH"].split(File::PATH_SEPARATOR)
+%w[YACC BASERUBY RUBY MV MINIRUBY].each do |var|
+  cmd = ENV[var]
+  unless path.any? {|dir|
+      file = File.join(dir, cmd)
+      File.file?(file) and File.executable?(file)
+    }
+    abort "#{File.basename $0}: #{var} command not found - #{cmd}"
+  end
+end
 
-tmp="${TMP_DIR-/tmp}/ruby-snapshot-$$"
-mkdir -p "$tmp"
-trap "cd /; exec rm -fr $tmp" 0 2 3 13 15
-cd "$tmp"
-files=
+unless destdir = ARGV.shift
+  abort "usage: #{File.basename $0} new-directory-to-save [version ...]"
+end
+FileUtils.mkpath(destdir)
+destdir = File.expand_path(destdir)
+revisions = ARGV.empty? ? ["trunk"] : ARGV
+tmp = Dir.mktmpdir("ruby-snapshot")
+FileUtils.mkpath(tmp)
+at_exit {
+  Dir.chdir "/"
+  FileUtils.rm_rf(tmp)
+}
+Dir.chdir tmp
 
-exec 3>&1
-for rev; do
-    tag=
-    case "$rev" in
-	trunk | branches/* | tags/*)
-	    url=$SVNURL/$rev;;
-	stable)
-	    url=$SVNURL/branches
-	    url=/$(svn ls $url | grep '^ruby_[0-9]_[0-9]/' | tail -1);;
-	*.*.*-p* | *.*.*-*)
-	    tag=${rev##*-}; url=${rev/-p/_}; url=${url/-/_}; url=$SVNURL/tags/v${url//./_};;
-	*.*)
-	    url=$SVNURL/branches/ruby_${rev//./_};;
-	*)
-	    echo "$0: unknown version - $rev" 1>&2
-	    continue;;
-    esac
+def package(rev, destdir)
+  patchlevel = false
+  case rev
+  when /\Atrunk\z/, /\Abranches\//, /\Atags\//
+    url = SVNURL + rev
+  when /\Astable\z/
+    url = SVNURL + "branches/"
+    url = url + `svn ls #{url}`[/.*^(ruby_\d+_\d+)\//m, 1]
+  when /\A\(.*\..*\..*\)-/
+    patchlevel = true
+    url = SVNURL + "tags/v#{rev.sub(/-p?/, '_').tr('.', '_')}"
+  when /\./
+    url = SVNURL + "branches/ruby_#{rev.tr('.', '_')}"
+  else
+    warn "#{$0}: unknown version - #{rev}"
+    return
+  end
+  revision = `svn info #{url} 2>&1`[/Last Changed Rev: (\d+)/, 1]
+  version = nil
+  unless revision
+    url = SVNURL + "trunk"
+    version = `svn cat #{url + "version.h"}`[RUBY_VERSION_PATTERN, 1]
+    unless rev == version
+      warn "#{$0}: #{rev} not found"
+      return
+    end
+    revision = `svn info #{url}`[/Last Changed Rev: (\d+)/, 1]
+  end
+  puts "Exporting #{rev}@#{revision}"
+  IO.popen("svn export #{url} ruby") do |pipe|
+    pipe.each {|line| /^A/ =~ line or print line}
+  end
+  unless $?.success?
+    warn("Export failed")
+    return
+  end
+  open("ruby/revision.h", "wb") {|f| f.puts "#define RUBY_REVISION #{revision}"}
+  version ||= (versionhdr = IO.read("ruby/version.h"))[RUBY_VERSION_PATTERN, 1]
+  version or return
+  if patchlevel
+    versionhdr ||= IO.read("ruby/version.h")
+    patchlevel = versionhdr[/^\#define\s+RUBY_PATCHLEVEL\s+(\d+)/, 1]
+    tag = (patchlevel ? "p#{patchlevel}" : "r#{revision}")
+  else
+    tag = "r#{revision}"
+  end
+  v = "ruby-#{version}-#{tag}"
+  File.rename "ruby", v
+  Dir.chdir(v) do
+    print "creating configure..."
+    unless system("autoconf")
+      puts " failed"
+      return
+    end
+    puts " done"
+    FileUtils.rm_rf("autom4te.cache")
+    print "creating prerequisites..."
+    if File.file?("common.mk") && /^prereq/ =~ commonmk = IO.read("common.mk")
+      IO.popen("make -f - prereq srcdir=. IFCHANGE=tool/ifchange", "w") do |f|
+        f.puts(IO.read("Makefile.in")[/^lex\.c.*?^$/m])
+        f.puts(commonmk.gsub(/\{[^{}]*\}/, ""))
+      end
+    else
+      system("#{YACC} -o parse.c parse.y")
+    end
+    unless $?.success?
+      puts " failed"
+      return
+    end
+    puts " done"
+  end
 
-    revision=$(svn info "$url" 2>&1 | sed -n 's/Last Changed Rev: //p')
-    if [ "$revision" = "" ]; then
-	url="$SVNURL/trunk"
-	version=$(svn cat "$url/version.h" | sed -n -e '/^#define RUBY_VERSION /s/[^0-9.]//gp')
-	[ "$rev" = "$version" ] || { echo "$0: $rev not found"; exit 1; }
-	revision=$(svn info "$url" | sed -n 's/Last Changed Rev: //p' 2>/dev/null)
-    fi
-    echo "Exporting $rev@$revision"
-    status=$(exec 4>&1; { svn export "$url" ruby; echo $? 1>&4; } | grep -v '^A' 1>&3)
-    [ "$status" = 0 ] || exit $status
-    echo "#define RUBY_REVISION $revision" > ruby/revision.h
-    version=$(sed -n -e '/^#define RUBY_VERSION /s/[^0-9.]//gp' ruby/version.h)
-    if [ x"$tag" = x ]; then
-	patchlevel=$(sed -n -e '/^#define RUBY_PATCHLEVEL /s/[^0-9.]//gp' ruby/version.h)
-	if [ "${patchlevel:-0}" = 0 ]; then
-	    tag=r$revision
-	else
-	    tag=p$patchlevel
-	fi
-    fi
-    v=ruby-$version-$tag
-    mv ruby $v
-    (cd $v
-    autoconf
-    rm -fr autom4te.cache
-    if [ -f common.mk ] && grep '^prereq' common.mk > /dev/null; then
-	(sed '/lex\.c/,/^$/!d' Makefile.in; sed 's/{[^{}]*}//g' common.mk) |
-	make -f - prereq srcdir=. IFCHANGE=tool/ifchange
+  return [["bzip tarball", ".tar.bz2", %w"tar cjf"],
+          ["gzip tarball", ".tar.gz", %w"tar czf"],
+          ["zip archive", ".zip", %w"zip -qr"]
+         ].collect do |mesg, ext, cmd|
+    file = "#{destdir}/#{v}#{ext}"
+    print "creating #{mesg}... #{file}"
+    if system(*(cmd + [file, v]))
+      puts " done"
+      file
     else
-	${YACC} -o parse.c parse.y
-    fi || exit $?) || exit $?
+      puts " failed"
+      nil
+    end
+  end.compact
+ensure
+  FileUtils.rm_rf(v) if v
+end
 
-    for cmd in "bzip tarball.tar.bz2 tar cjf" "gzip tarball.tar.gz tar czf" "zip archive.zip zip -qr"; do
-	mesg="${cmd%%.*}" cmd="${cmd#*.}"
-	ext="${cmd%% *}" cmd="${cmd#* }"
-	echo -n creating $mesg... $dest/$v.$ext
-	if $cmd $dest/$v.$ext $v; then
-	    echo " done"
-	else
-	    echo " failed"
-	fi
-	files="$files $dest/$v.$ext"
-    done
-    rm -fr $v
-done
-${BASERUBY} -r digest -e '
-    ARGV.each do |name|
-	str = open(name, "rb") {|f| f.read}
-	md5 = Digest::MD5.hexdigest str
-	sha = Digest::SHA256.hexdigest str
-	printf "MD5(%s)= %s\nSHA256(%s)= %s\nSIZE(%s)= %s\n\n",
-		name, md5,
-		name, sha,
-		name, str.size
-    end
-' $files
+revisions.collect {|rev| package(rev, destdir)}.flatten.each do |name|
+  str = open(name, "rb") {|f| f.read}
+  md5 = Digest::MD5.hexdigest str
+  sha = Digest::SHA256.hexdigest str
+  puts "MD5(#{name})= #{md5}"
+  puts "SHA256(#{name})= #{sha}"
+  puts "SIZE(name)= #{str.size}"
+  puts
+end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]