2011-05-03 01:37:52 -05:00
|
|
|
import re, os, sys, hashlib, tarfile, shutil, subprocess, tempfile
|
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")
|
2011-05-02 20:56:13 -05:00
|
|
|
download_url_base = "http://dl.rust-lang.org/stage0-snapshots"
|
|
|
|
download_dir_base = "dl"
|
|
|
|
download_unpack_base = os.path.join(download_dir_base, "unpack")
|
|
|
|
|
|
|
|
snapshot_files = {
|
|
|
|
"linux": ["rustc", "glue.o", "libstd.so" ],
|
|
|
|
"macos": ["rustc", "glue.o", "libstd.dylib" ],
|
|
|
|
"winnt": ["rustc.exe", "glue.o", "std.dll" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
def parse_line(n, line):
|
|
|
|
global snapshotfile
|
|
|
|
|
|
|
|
if re.match(r"\s*$", line): return None
|
|
|
|
|
|
|
|
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):
|
|
|
|
raise Exception("%s:%d:E syntax error" % (snapshotfile, n))
|
|
|
|
ttype = "snapshot"
|
|
|
|
if (match.group(1) == "T"):
|
|
|
|
ttype = "transition"
|
|
|
|
return {"type": ttype,
|
|
|
|
"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
|
|
|
|
|
|
|
|
|
|
|
def get_kernel():
|
|
|
|
if os.name == "nt":
|
|
|
|
return "winnt"
|
|
|
|
kernel = os.uname()[0].lower()
|
|
|
|
if kernel == "darwin":
|
|
|
|
kernel = "macos"
|
|
|
|
return kernel
|
|
|
|
|
|
|
|
|
|
|
|
def get_cpu():
|
|
|
|
# return os.uname()[-1].lower()
|
|
|
|
return "i386"
|
|
|
|
|
|
|
|
|
|
|
|
def get_platform():
|
|
|
|
return "%s-%s" % (get_kernel(), get_cpu())
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
subprocess.check_call(["curl", "-o", f, u])
|
2011-05-02 20:56:13 -05:00
|
|
|
|
|
|
|
def hash_file(x):
|
|
|
|
h = hashlib.sha1()
|
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
|
|
|
|
|
|
|
|
|
|
|
def make_snapshot():
|
|
|
|
kernel = get_kernel()
|
|
|
|
platform = get_platform()
|
|
|
|
rev = local_rev_short_sha()
|
|
|
|
date = local_rev_committer_date().split()[0]
|
|
|
|
|
|
|
|
file0 = partial_snapshot_name(date, rev, platform)
|
|
|
|
|
|
|
|
tar = tarfile.open(file0, "w:bz2")
|
|
|
|
for name in snapshot_files[kernel]:
|
2011-05-03 11:25:59 -05:00
|
|
|
tar.add(os.path.join("stage2", name),
|
|
|
|
os.path.join("rust-stage0", name))
|
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)
|
|
|
|
return file1
|