summaryrefslogtreecommitdiff
path: root/tool/make-snapshot
diff options
context:
space:
mode:
Diffstat (limited to 'tool/make-snapshot')
-rwxr-xr-xtool/make-snapshot191
1 files changed, 103 insertions, 88 deletions
diff --git a/tool/make-snapshot b/tool/make-snapshot
index 131d7b91c9..dff636d601 100755
--- a/tool/make-snapshot
+++ b/tool/make-snapshot
@@ -1,5 +1,8 @@
#!/usr/bin/ruby -s
# -*- coding: us-ascii -*-
+require 'rubygems'
+require 'rubygems/package'
+require 'rubygems/package/tar_writer'
require 'uri'
require 'digest/sha1'
require 'digest/sha2'
@@ -7,6 +10,7 @@ require 'fileutils'
require 'shellwords'
require 'tmpdir'
require 'pathname'
+require 'date'
require 'yaml'
require 'json'
require File.expand_path("../lib/vcs", __FILE__)
@@ -19,6 +23,7 @@ $keep_temp ||= nil
$patch_file ||= nil
$packages ||= nil
$digests ||= nil
+$no7z ||= nil
$tooldir = File.expand_path("..", __FILE__)
$unicode_version = nil if ($unicode_version ||= nil) == ""
$colorize = Colorize.new
@@ -34,8 +39,6 @@ options:
-packages=PKG[,...] make PKG packages (#{PACKAGES.keys.join(", ")})
-digests=ALG[,...] show ALG digests (#{DIGESTS.join(", ")})
-unicode_version=VER Unicode version to generate encodings
- -svn[=URL] make snapshot from SVN repository
- (#{SVNURL})
-help, --help show this message
version:
master, trunk, stable, branches/*, tags/*, X.Y, X.Y.Z, X.Y.Z-pL
@@ -51,10 +54,10 @@ PACKAGES = {
"xz" => %w".tar.xz xz -c",
"zip" => %w".zip zip -Xqr",
}
-DEFAULT_PACKAGES = PACKAGES.keys - ["tar"]
+DEFAULT_PACKAGES = PACKAGES.keys - ["tar", "bzip"]
if !$no7z and system("7z", out: IO::NULL)
PACKAGES["gzip"] = %w".tar.gz 7z a dummy -tgzip -mx -so"
- PACKAGES["zip"] = %w".zip 7z a -tzip -l -mx -mtc=off" << {out: IO::NULL}
+ PACKAGES["zip"] = %w".zip 7z a -tzip -mx -mtc=off" << {out: IO::NULL}
elsif gzip = ENV.delete("GZIP")
PACKAGES["gzip"].concat(gzip.shellsplit)
end
@@ -65,21 +68,10 @@ if mflags = ENV["GNUMAKEFLAGS"] and /\A-(\S*)j\d*/ =~ mflags
ENV["GNUMAKEFLAGS"] = (mflags unless mflags.empty?)
end
ENV["LC_ALL"] = ENV["LANG"] = "C"
-SVNURL = URI.parse("https://svn.ruby-lang.org/repos/ruby/")
# https git clone is disabled at git.ruby-lang.org/ruby.git.
GITURL = URI.parse("https://github.com/ruby/ruby.git")
RUBY_VERSION_PATTERN = /^\#define\s+RUBY_VERSION\s+"([\d.]+)"/
-ENV["VPATH"] ||= "include/ruby"
-YACC = ENV["YACC"] ||= "bison"
-ENV["BASERUBY"] ||= "ruby"
-ENV["RUBY"] ||= "ruby"
-ENV["MV"] ||= "mv"
-ENV["RM"] ||= "rm -f"
-ENV["MINIRUBY"] ||= "ruby"
-ENV["PROGRAM"] ||= "ruby"
-ENV["AUTOCONF"] ||= "autoconf"
-ENV["BUILTIN_TRANSOBJS"] ||= "newline.o"
ENV["TZ"] = "UTC"
class String
@@ -116,22 +108,32 @@ $digests &&= $digests.split(/[, ]+/).tap {|dig|
$digests ||= DIGESTS
$patch_file &&= File.expand_path($patch_file)
-path = ENV["PATH"].split(File::PATH_SEPARATOR)
-%w[YACC BASERUBY RUBY MV MINIRUBY].each do |var|
- cmd, = ENV[var].shellsplit
- unless path.any? {|dir|
+PATH = ENV["PATH"].split(File::PATH_SEPARATOR)
+def PATH.executable_env(var, command = nil)
+ command = ENV[var] ||= (command or return)
+ cmd, = command.shellsplit
+ unless any? {|dir|
file = File.expand_path(cmd, dir)
File.file?(file) and File.executable?(file)
}
abort "#{File.basename $0}: #{var} command not found - #{cmd}"
end
+ command
end
+PATH.executable_env("MV", "mv")
+PATH.executable_env("RM", "rm -f")
+PATH.executable_env("AUTOCONF", "autoconf")
+
%w[BASERUBY RUBY MINIRUBY].each do |var|
- %x[#{ENV[var]} --disable-gem -e1 2>&1]
- if $?.success?
- ENV[var] += ' --disable-gem'
+ cmd = PATH.executable_env(var, "ruby")
+ help = IO.popen("#{cmd} --help", err: %i[child out], &:read)
+ unless $?.success? and /ruby/ =~ help
+ abort "#{File.basename $0}: #{var} ruby not found - #{cmd}"
end
+ IO.popen("#{cmd} --disable-gem -eexit", err: %i[child out], &:read)
+ cmd += ' --disable-gem' if $?.success?
+ ENV[var] = cmd
end
if defined?($help) or defined?($_help)
@@ -143,7 +145,7 @@ unless destdir = ARGV.shift
end
revisions = ARGV.empty? ? [nil] : ARGV
-if $exported
+if defined?($exported)
abort "#{File.basename $0}: -exported option is deprecated; use -srcdir instead"
end
@@ -157,9 +159,6 @@ at_exit {
} unless $keep_temp
def tar_create(tarball, dir)
- require 'rubygems'
- require 'rubygems/package'
- require 'rubygems/package/tar_writer'
header = Gem::Package::TarHeader
dir_type = "5"
uname = gname = "ruby"
@@ -254,7 +253,6 @@ end
def package(vcs, rev, destdir, tmp = nil)
pwd = Dir.pwd
- patchlevel = false
prerelease = false
if rev and revision = rev[/@(\h+)\z/, 1]
rev = $`
@@ -271,22 +269,23 @@ def package(vcs, rev, destdir, tmp = nil)
when /\Astable\z/
vcs.branch_list("ruby_[0-9]*") {|n| url = n[/\Aruby_\d+_\d+\z/]}
url &&= vcs.branch(url)
- when /\A(.*)\.(.*)\.(.*)-(preview|rc)(\d+)/
+ when /\A(\d+)\.(\d+)\.(\d+)-(preview|rc)(\d+)/
prerelease = true
tag = "#{$4}#{$5}"
- url = vcs.tag("v#{$1}_#{$2}_#{$3}_#{$4}#{$5}")
- when /\A(.*)\.(.*)\.(.*)-p(\d+)/
- patchlevel = true
- tag = "p#{$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 = vcs.tag("v#{$1}_#{$2}_#{$3}")
+ if Integer($1) >= 4
+ url = vcs.tag("v#{rev}")
+ else
+ url = vcs.tag("v#{$1}_#{$2}_#{$3}_#{$4}#{$5}")
+ end
+ when /\A(\d+)\.(\d+)\.(\d+)\z/
+ tag = ""
+ if Integer($1) >= 4
+ url = vcs.tag("v#{rev}")
else
- url = vcs.branch("ruby_#{rev.tr('.', '_')}")
+ url = vcs.tag("v#{$1}_#{$2}_#{$3}")
end
+ when /\A(\d+)\.(\d+)\z/
+ url = vcs.branch("ruby_#{rev.tr('.', '_')}")
else
warn "#{$0}: unknown version - #{rev}"
return
@@ -294,7 +293,7 @@ def package(vcs, rev, destdir, tmp = nil)
if info = vcs.get_revisions(url)
modified = info[2]
else
- modified = Time.now - 10
+ _, _, modified = VCS::Null.new(nil).get_revisions(url)
end
if !revision and info
revision = info
@@ -332,7 +331,11 @@ def package(vcs, rev, destdir, tmp = nil)
end
end
- status = IO.read(File.dirname(__FILE__) + "/prereq.status")
+ Dir.glob("#{exported}/.*.yml") do |file|
+ FileUtils.rm(file, verbose: $VERBOSE)
+ end
+
+ status = File.read(File.dirname(__FILE__) + "/prereq.status")
Dir.chdir(tmp) if tmp
if !File.directory?(v)
@@ -341,33 +344,23 @@ def package(vcs, rev, destdir, tmp = nil)
v = v[0]
end
- open("#{v}/revision.h", "wb") {|f|
- short = vcs.short_revision(revision)
- f.puts "#define RUBY_REVISION #{short.inspect}"
- unless short == revision
- f.puts "#define RUBY_FULL_REVISION #{revision.inspect}"
- end
+ File.open("#{v}/revision.h", "wb") {|f|
+ f.puts vcs.revision_header(revision, modified)
}
- version ||= (versionhdr = IO.read("#{v}/version.h"))[RUBY_VERSION_PATTERN, 1]
+ version ||= (versionhdr = File.read("#{v}/version.h"))[RUBY_VERSION_PATTERN, 1]
version ||=
begin
- include_ruby_versionhdr = IO.read("#{v}/include/ruby/version.h")
+ include_ruby_versionhdr = File.read("#{v}/include/ruby/version.h")
api_major_version = include_ruby_versionhdr[/^\#define\s+RUBY_API_VERSION_MAJOR\s+([\d.]+)/, 1]
api_minor_version = include_ruby_versionhdr[/^\#define\s+RUBY_API_VERSION_MINOR\s+([\d.]+)/, 1]
version_teeny = versionhdr[/^\#define\s+RUBY_VERSION_TEENY\s+(\d+)/, 1]
[api_major_version, api_minor_version, version_teeny].join('.')
end
version or return
- if patchlevel
- unless tag.empty?
- versionhdr ||= IO.read("#{v}/version.h")
- patchlevel = versionhdr[/^\#define\s+RUBY_PATCHLEVEL\s+(\d+)/, 1]
- tag = (patchlevel ? "p#{patchlevel}" : vcs.revision_name(revision))
- end
- elsif prerelease
- versionhdr ||= IO.read("#{v}/version.h")
- versionhdr.sub!(/^\#define\s+RUBY_PATCHLEVEL_STR\s+"\K.+?(?=")/, tag)
- IO.write("#{v}/version.h", versionhdr)
+ if prerelease
+ versionhdr ||= File.read("#{v}/version.h")
+ versionhdr.sub!(/^\#\s*define\s+RUBY_PATCHLEVEL_STR\s+"\K.+?(?=")/, tag) or raise "no match of RUBY_PATCHLEVEL_STR to replace"
+ File.write("#{v}/version.h", versionhdr)
else
tag ||= vcs.revision_name(revision)
end
@@ -386,7 +379,21 @@ def package(vcs, rev, destdir, tmp = nil)
puts $colorize.fail("patching failed")
return
end
- def (clean = []).add(n) push(n); n end
+
+ class << (clean = [])
+ def add(n) push(n)
+ n
+ end
+ def create(file, content = "", &block)
+ add(file)
+ if block
+ File.open(file, "wb", &block)
+ else
+ File.binwrite(file, content)
+ end
+ end
+ end
+
Dir.chdir(v) do
unless File.exist?("ChangeLog")
vcs.export_changelog(url, nil, revision, "ChangeLog")
@@ -407,7 +414,7 @@ def package(vcs, rev, destdir, tmp = nil)
puts
end
- File.open(clean.add("cross.rb"), "w") do |f|
+ clean.create("cross.rb") do |f|
f.puts "Object.__send__(:remove_const, :CROSS_COMPILING) if defined?(CROSS_COMPILING)"
f.puts "CROSS_COMPILING=true"
f.puts "Object.__send__(:remove_const, :RUBY_PLATFORM)"
@@ -415,9 +422,10 @@ def package(vcs, rev, destdir, tmp = nil)
f.puts "Object.__send__(:remove_const, :RUBY_VERSION)"
f.puts "RUBY_VERSION='#{version}'"
end
+ puts "cross.rb:", File.read("cross.rb").gsub(/^/, "> "), "" if $VERBOSE
unless File.exist?("configure")
print "creating configure..."
- unless system([ENV["AUTOCONF"]]*2)
+ unless system(File.exist?(gen = "./autogen.sh") ? gen : [ENV["AUTOCONF"]]*2)
puts $colorize.fail(" failed")
return
end
@@ -426,25 +434,24 @@ def package(vcs, rev, destdir, tmp = nil)
clean.add("autom4te.cache")
clean.add("enc/unicode/data")
print "creating prerequisites..."
- if File.file?("common.mk") && /^prereq/ =~ commonmk = IO.read("common.mk")
+ if File.file?("common.mk") && /^prereq/ =~ commonmk = File.read("common.mk")
puts
extout = clean.add('tmp')
begin
- status = IO.read("tool/prereq.status")
+ status = File.read("tool/prereq.status")
rescue Errno::ENOENT
# use fallback file
end
- File.open(clean.add("config.status"), "w") {|f|
- f.print status
- }
+ clean.create("config.status", status)
+ clean.create("noarch-fake.rb", "require_relative 'cross'\n")
FileUtils.mkpath(hdrdir = "#{extout}/include/ruby")
- File.open("#{hdrdir}/config.h", "w") {}
+ File.binwrite("#{hdrdir}/config.h", "")
FileUtils.mkpath(defaults = "#{extout}/rubygems/defaults")
- File.open("#{defaults}/operating_system.rb", "w") {}
- File.open("#{defaults}/ruby.rb", "w") {}
+ File.binwrite("#{defaults}/operating_system.rb", "")
+ File.binwrite("#{defaults}/ruby.rb", "")
miniruby = ENV['MINIRUBY'] + " -I. -I#{extout} -rcross"
baseruby = ENV["BASERUBY"]
- mk = (IO.read("template/Makefile.in") rescue IO.read("Makefile.in")).
+ mk = (File.read("template/Makefile.in") rescue File.read("Makefile.in")).
gsub(/^@.*\n/, '')
vars = {
"EXTOUT"=>extout,
@@ -457,6 +464,10 @@ def package(vcs, rev, destdir, tmp = nil)
"MAJOR"=>api_major_version,
"MINOR"=>api_minor_version,
"TEENY"=>version_teeny,
+ "VPATH"=>(ENV["VPATH"] || "include/ruby"),
+ "PROGRAM"=>(ENV["PROGRAM"] || "ruby"),
+ "BUILTIN_TRANSOBJS"=>(ENV["BUILTIN_TRANSOBJS"] || "newline.o"),
+ "DUMP_AST"=>"build-tool/dump_ast#{RbConfig::CONFIG['EXEEXT']} ",
}
status.scan(/^s([%,])@([A-Za-z_][A-Za-z_0-9]*)@\1(.*?)\1g$/) do
vars[$2] ||= $3
@@ -465,6 +476,13 @@ def package(vcs, rev, destdir, tmp = nil)
vars["UNICODE_VERSION"] = $unicode_version if $unicode_version
args = vars.dup
mk.gsub!(/@([A-Za-z_]\w*)@/) {args.delete($1); vars[$1] || ENV[$1]}
+ commonmk.gsub!(/^!(?:include \$\(srcdir\)\/(.*))?/) do
+ if inc = $1 and File.exist?(inc)
+ File.binread(inc).gsub(/^!/, '# !')
+ else
+ "#"
+ end
+ end
mk << commonmk.gsub(/\{\$([^(){}]*)[^{}]*\}/, "").sub(/^revision\.tmp::$/, '\& Makefile')
mk << <<-'APPEND'
@@ -477,11 +495,9 @@ update-gems:
$(UNICODE_SRC_DATA_DIR)/.unicode-tables.time:
touch-unicode-files:
APPEND
- open(clean.add("Makefile"), "w") do |f|
- f.puts mk
- end
- File.open(clean.add("revision.tmp"), "w") {}
- File.open(clean.add(".revision.time"), "w") {}
+ clean.create("Makefile", mk)
+ clean.create("revision.tmp")
+ clean.create(".revision.time")
ENV["CACHE_SAVE"] = "no"
make = MAKE.new(args)
return unless make.run("update-download")
@@ -495,6 +511,7 @@ touch-unicode-files:
File.utime(modified, modified, *Dir.glob(["tool/config.{guess,sub}", "gems/*.gem", "tool"]))
return unless make.run("prepare-package")
return unless make.run("clean-cache")
+ return unless make.run("clean")
if modified
new_time = modified + 2
touch_all(new_time, "**/*", File::FNM_DOTMATCH) do |name, stat|
@@ -504,12 +521,11 @@ touch-unicode-files:
end
print "prerequisites"
else
- system(*%W"#{YACC} -o parse.c parse.y")
+ system(*%W[#{PATH.executable_env("YACC", "bison")} -o parse.c parse.y])
end
vcs.after_export(".") if exported
clean.concat(Dir.glob("ext/**/autom4te.cache"))
- FileUtils.rm_rf(clean) unless $keep_temp
- FileUtils.rm_rf(".downloaded-cache")
+ clean.add(".downloaded-cache")
if File.exist?("gems/bundled_gems")
gems = Dir.glob("gems/*.gem")
gems -= File.readlines("gems/bundled_gems").map {|line|
@@ -517,10 +533,11 @@ touch-unicode-files:
name, version, _ = line.split(' ')
"gems/#{name}-#{version}.gem"
}
- FileUtils.rm_f(gems)
+ clean.concat(gems)
else
- FileUtils.rm_rf("gems")
+ clean.add("gems")
end
+ FileUtils.rm_rf(clean)
if modified
touch_all(modified, "**/*/", 0) do |name, stat|
stat.mtime > modified
@@ -589,20 +606,18 @@ ensure
Dir.chdir(pwd)
end
-if [$srcdir, ($svn||=nil), ($git||=nil)].compact.size > 1
- abort "#{File.basename $0}: -srcdir, -svn, and -git are exclusive"
+if [$srcdir, ($git||=nil)].compact.size > 1
+ abort "#{File.basename $0}: -srcdir and -git are exclusive"
end
if $srcdir
vcs = VCS.detect($srcdir)
-elsif $svn
- vcs = VCS::SVN.new($svn == true ? SVNURL : URI.parse($svn))
elsif $git
abort "#{File.basename $0}: use -srcdir with cloned local repository"
else
begin
vcs = VCS.detect(File.expand_path("../..", __FILE__))
rescue VCS::NotFoundError
- vcs = VCS::SVN.new(SVNURL)
+ abort "#{File.expand_path("../..", __FILE__)}: cannot find git repository"
end
end
@@ -615,7 +630,7 @@ revisions.collect {|rev| package(vcs, rev, destdir, tmp)}.flatten.each do |name|
success = false
next
end
- str = open(name, "rb") {|f| f.read}
+ str = File.binread(name)
pathname = Pathname(name)
basename = pathname.basename.to_s
extname = pathname.extname.sub(/\A\./, '')
@@ -623,7 +638,7 @@ revisions.collect {|rev| package(vcs, rev, destdir, tmp)}.flatten.each do |name|
key = basename[/\A(.*)\.(?:tar|zip)/, 1]
info[key] ||= Hash.new{|h,k|h[k]={}}
info[key]['version'] = version if version
- info[key]['date'] = release_date.strftime('%Y-%m-%d')
+ info[key]['date'] = release_date.to_date
if version
info[key]['post'] = "/en/news/#{release_date.strftime('%Y/%m/%d')}/ruby-#{version.tr('.', '-')}-released/"
info[key]['url'][extname] = "https://cache.ruby-lang.org/pub/ruby/#{version[/\A\d+\.\d+/]}/#{basename}"