2012-03-28 04:25:54 -05:00
|
|
|
import re, os, sys, glob, tarfile, shutil, subprocess, tempfile
|
|
|
|
|
|
|
|
try:
|
|
|
|
import hashlib
|
|
|
|
sha_func = hashlib.sha1
|
|
|
|
except ImportError:
|
|
|
|
import sha
|
|
|
|
sha_func = sha.new
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2011-05-03 11:25:59 -05:00
|
|
|
def scrub(b):
|
|
|
|
if sys.version_info >= (3,) and type(b) == bytes:
|
|
|
|
return b.decode('ascii')
|
|
|
|
else:
|
|
|
|
return b
|
|
|
|
|
|
|
|
src_dir = scrub(os.getenv("CFG_SRC_DIR"))
|
2011-05-03 01:37:52 -05:00
|
|
|
if not src_dir:
|
|
|
|
raise Exception("missing env var CFG_SRC_DIR")
|
|
|
|
|
2011-05-03 13:34:44 -05:00
|
|
|
snapshotfile = os.path.join(src_dir, "src", "snapshots.txt")
|
2012-12-11 14:55:43 -06:00
|
|
|
download_url_base = "http://static.rust-lang.org/stage0-snapshots"
|
2011-05-02 20:56:13 -05:00
|
|
|
download_dir_base = "dl"
|
|
|
|
download_unpack_base = os.path.join(download_dir_base, "unpack")
|
|
|
|
|
2011-10-31 15:28:54 -05:00
|
|
|
snapshot_files = {
|
2011-12-07 17:34:16 -06:00
|
|
|
"linux": ["bin/rustc",
|
2011-12-08 10:02:25 -06:00
|
|
|
"lib/libcore-*.so",
|
|
|
|
"lib/libstd-*.so",
|
2011-12-16 19:21:18 -06:00
|
|
|
"lib/librustc-*.so",
|
2012-05-30 03:32:45 -05:00
|
|
|
"lib/libsyntax-*.so",
|
2011-12-07 17:34:16 -06:00
|
|
|
"lib/librustrt.so",
|
|
|
|
"lib/librustllvm.so"],
|
|
|
|
"macos": ["bin/rustc",
|
2011-12-08 10:02:25 -06:00
|
|
|
"lib/libcore-*.dylib",
|
|
|
|
"lib/libstd-*.dylib",
|
2011-12-16 19:21:18 -06:00
|
|
|
"lib/librustc-*.dylib",
|
2012-05-30 03:32:45 -05:00
|
|
|
"lib/libsyntax-*.dylib",
|
2011-12-07 17:34:16 -06:00
|
|
|
"lib/librustrt.dylib",
|
|
|
|
"lib/librustllvm.dylib"],
|
|
|
|
"winnt": ["bin/rustc.exe",
|
2012-01-10 19:45:03 -06:00
|
|
|
"bin/core-*.dll",
|
|
|
|
"bin/std-*.dll",
|
|
|
|
"bin/rustc-*.dll",
|
2012-05-30 03:32:45 -05:00
|
|
|
"bin/syntax-*.dll",
|
2012-01-10 19:45:03 -06:00
|
|
|
"bin/rustrt.dll",
|
|
|
|
"bin/rustllvm.dll"],
|
2012-01-01 11:24:07 -06:00
|
|
|
"freebsd": ["bin/rustc",
|
|
|
|
"lib/libcore-*.so",
|
|
|
|
"lib/libstd-*.so",
|
|
|
|
"lib/librustc-*.so",
|
2012-05-30 03:32:45 -05:00
|
|
|
"lib/libsyntax-*.so",
|
2012-01-01 11:24:07 -06:00
|
|
|
"lib/librustrt.so",
|
|
|
|
"lib/librustllvm.so"]
|
2011-10-31 15:28:54 -05:00
|
|
|
}
|
|
|
|
|
2011-05-02 20:56:13 -05:00
|
|
|
def parse_line(n, line):
|
|
|
|
global snapshotfile
|
|
|
|
|
|
|
|
if re.match(r"\s*$", line): return None
|
|
|
|
|
2011-05-16 17:14:44 -05:00
|
|
|
if re.match(r"^T\s*$", line): return None
|
|
|
|
|
2011-05-02 20:56:13 -05:00
|
|
|
match = re.match(r"\s+([\w_-]+) ([a-fA-F\d]{40})\s*$", line)
|
|
|
|
if match:
|
|
|
|
return { "type": "file",
|
|
|
|
"platform": match.group(1),
|
|
|
|
"hash": match.group(2).lower() }
|
|
|
|
|
|
|
|
match = re.match(r"([ST]) (\d{4}-\d{2}-\d{2}) ([a-fA-F\d]+)\s*$", line);
|
|
|
|
if (not match):
|
2012-10-08 13:59:51 -05:00
|
|
|
raise Exception("%s:%d:E syntax error: " % (snapshotfile, n))
|
2011-05-13 19:00:43 -05:00
|
|
|
return {"type": "snapshot",
|
2011-05-02 20:56:13 -05:00
|
|
|
"date": match.group(2),
|
|
|
|
"rev": match.group(3)}
|
|
|
|
|
|
|
|
|
2011-05-03 09:23:05 -05:00
|
|
|
def partial_snapshot_name(date, rev, platform):
|
|
|
|
return ("rust-stage0-%s-%s-%s.tar.bz2"
|
|
|
|
% (date, rev, platform))
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2011-05-03 09:23:05 -05:00
|
|
|
def full_snapshot_name(date, rev, platform, hsh):
|
|
|
|
return ("rust-stage0-%s-%s-%s-%s.tar.bz2"
|
|
|
|
% (date, rev, platform, hsh))
|
2011-05-02 20:56:13 -05:00
|
|
|
|
|
|
|
|
2011-11-28 08:06:32 -06:00
|
|
|
def get_kernel(triple):
|
|
|
|
os_name = triple.split('-')[-1]
|
2011-11-28 23:23:42 -06:00
|
|
|
#scrub(os.getenv("CFG_ENABLE_MINGW_CROSS")):
|
|
|
|
if os_name == "nt" or os_name == "mingw32":
|
2011-05-02 20:56:13 -05:00
|
|
|
return "winnt"
|
2011-11-28 08:06:32 -06:00
|
|
|
if os_name == "darwin":
|
|
|
|
return "macos"
|
2012-01-01 11:24:07 -06:00
|
|
|
if os_name == "freebsd":
|
|
|
|
return "freebsd"
|
2011-11-28 08:06:32 -06:00
|
|
|
return "linux"
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2011-11-28 08:06:32 -06:00
|
|
|
def get_cpu(triple):
|
|
|
|
arch = triple.split('-')[0]
|
|
|
|
if arch == "i686":
|
|
|
|
return "i386"
|
|
|
|
return arch
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2011-11-28 08:06:32 -06:00
|
|
|
def get_platform(triple):
|
|
|
|
return "%s-%s" % (get_kernel(triple), get_cpu(triple))
|
2011-05-02 20:56:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
def cmd_out(cmdline):
|
|
|
|
p = subprocess.Popen(cmdline,
|
|
|
|
stdout=subprocess.PIPE)
|
2011-05-03 01:37:52 -05:00
|
|
|
return scrub(p.communicate()[0].strip())
|
2011-05-02 20:56:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
def local_rev_info(field):
|
2011-05-03 11:25:59 -05:00
|
|
|
return cmd_out(["git", "--git-dir=" + os.path.join(src_dir, ".git"),
|
|
|
|
"log", "-n", "1",
|
2011-05-02 20:56:13 -05:00
|
|
|
"--format=%%%s" % field, "HEAD"])
|
|
|
|
|
|
|
|
|
|
|
|
def local_rev_full_sha():
|
|
|
|
return local_rev_info("H").split()[0]
|
|
|
|
|
|
|
|
|
|
|
|
def local_rev_short_sha():
|
|
|
|
return local_rev_info("h").split()[0]
|
|
|
|
|
|
|
|
|
|
|
|
def local_rev_committer_date():
|
|
|
|
return local_rev_info("ci")
|
|
|
|
|
2011-05-03 01:37:52 -05:00
|
|
|
def get_url_to_file(u,f):
|
2012-01-17 14:51:31 -06:00
|
|
|
# no security issue, just to stop partial download leaving a stale file
|
2012-01-17 14:54:23 -06:00
|
|
|
tmpf = f + '.tmp'
|
2012-03-28 04:25:54 -05:00
|
|
|
returncode = subprocess.call(["curl", "-o", tmpf, u])
|
|
|
|
if returncode != 0:
|
2012-01-17 08:41:11 -06:00
|
|
|
os.unlink(tmpf)
|
|
|
|
raise
|
|
|
|
os.rename(tmpf, f)
|
2011-05-02 20:56:13 -05:00
|
|
|
|
2011-05-17 10:26:38 -05:00
|
|
|
def snap_filename_hash_part(snap):
|
|
|
|
match = re.match(r".*([a-fA-F\d]{40}).tar.bz2$", snap)
|
|
|
|
if not match:
|
|
|
|
raise Exception("unable to find hash in filename: " + snap)
|
|
|
|
return match.group(1)
|
|
|
|
|
2011-05-02 20:56:13 -05:00
|
|
|
def hash_file(x):
|
2012-03-28 04:25:54 -05:00
|
|
|
h = sha_func()
|
2011-05-03 01:37:52 -05:00
|
|
|
h.update(open(x, "rb").read())
|
|
|
|
return scrub(h.hexdigest())
|
2011-05-03 09:23:05 -05:00
|
|
|
|
|
|
|
|
2011-11-30 20:33:39 -06:00
|
|
|
def make_snapshot(stage, triple, flag):
|
2011-11-28 08:06:32 -06:00
|
|
|
kernel = get_kernel(triple)
|
|
|
|
platform = get_platform(triple)
|
2011-05-03 09:23:05 -05:00
|
|
|
rev = local_rev_short_sha()
|
|
|
|
date = local_rev_committer_date().split()[0]
|
|
|
|
|
|
|
|
file0 = partial_snapshot_name(date, rev, platform)
|
|
|
|
|
2011-12-08 10:02:25 -06:00
|
|
|
def in_tar_name(fn):
|
2011-12-13 14:31:50 -06:00
|
|
|
cs = re.split(r"[\\/]", fn)
|
2011-12-08 10:02:25 -06:00
|
|
|
if len(cs) >= 2:
|
|
|
|
return os.sep.join(cs[-2:])
|
|
|
|
|
2011-05-03 09:23:05 -05:00
|
|
|
tar = tarfile.open(file0, "w:bz2")
|
|
|
|
for name in snapshot_files[kernel]:
|
2011-07-27 04:34:39 -05:00
|
|
|
dir = stage
|
|
|
|
if stage == "stage1" and re.match(r"^lib/(lib)?std.*", name):
|
|
|
|
dir = "stage0"
|
2011-12-08 10:02:25 -06:00
|
|
|
fn_glob = os.path.join(triple, dir, name)
|
|
|
|
matches = glob.glob(fn_glob)
|
|
|
|
if not matches:
|
|
|
|
raise Exception("Not found file with name like " + fn_glob)
|
|
|
|
if len(matches) == 1:
|
|
|
|
tar.add(matches[0], "rust-stage0/" + in_tar_name(matches[0]))
|
|
|
|
else:
|
|
|
|
raise Exception("Found stale files: \n %s\n\
|
|
|
|
Please make a clean build." % "\n ".join(matches))
|
2011-05-03 09:23:05 -05:00
|
|
|
tar.close()
|
|
|
|
|
|
|
|
h = hash_file(file0)
|
|
|
|
file1 = full_snapshot_name(date, rev, platform, h)
|
|
|
|
|
|
|
|
shutil.move(file0, file1)
|
2011-11-30 20:33:39 -06:00
|
|
|
|
|
|
|
if flag == "install":
|
2012-06-21 18:44:10 -05:00
|
|
|
# FIXME (#2664): this is an ugly quick hack; pls make it better
|
2011-11-30 20:33:39 -06:00
|
|
|
path = file1
|
|
|
|
comps = path.split("-")
|
|
|
|
parts = { 'year': comps[2], \
|
|
|
|
'month': comps[3], \
|
|
|
|
'date': comps[4], \
|
|
|
|
'check': comps[5], \
|
|
|
|
'plat': comps[6], \
|
|
|
|
'arch': comps[7], \
|
|
|
|
'sha': comps[8].split(".")[0] }
|
|
|
|
|
|
|
|
shutil.move(path, "dl/" + path)
|
|
|
|
shutil.move('src/snapshots.txt', 'src/snapshots-old.txt')
|
|
|
|
|
|
|
|
newf = open('src/snapshots.txt', 'w')
|
|
|
|
newf.write("T %(year)s-%(month)s-%(date)s %(check)s\n" % parts)
|
|
|
|
newf.write(" %(plat)s-%(arch)s %(sha)s\n\n" % parts)
|
|
|
|
|
|
|
|
oldf = open('src/snapshots-old.txt', 'r')
|
|
|
|
for line in oldf:
|
|
|
|
newf.write(line)
|
|
|
|
oldf.close()
|
|
|
|
|
|
|
|
newf.close()
|
|
|
|
|
|
|
|
os.remove('src/snapshots-old.txt')
|
|
|
|
|
|
|
|
|
2011-05-03 09:23:05 -05:00
|
|
|
return file1
|