mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
Have the Rust snapshot directory include the Rust version and hash.
That way, whenever rust-snapshot-hash changes, mach will look for the Rust snapshot in a different directory and re-boostrap as needed. However, older rust version will be left behind never cleaned up. This is good for git-bisect, but not for disk space: the current snapshot is 618 MB. In the future, we may want `mach clean` or some other comment to remove unused Rust snapshots. CC #3388
This commit is contained in:
parent
516b608a2f
commit
04d839328b
2 changed files with 42 additions and 34 deletions
|
@ -14,31 +14,7 @@ from mach.decorators import (
|
|||
Command,
|
||||
)
|
||||
|
||||
from servo.command_base import CommandBase, cd
|
||||
|
||||
|
||||
def host_triple():
|
||||
os_type = subprocess.check_output(["uname", "-s"]).strip().lower()
|
||||
if os_type == "linux":
|
||||
os_type = "unknown-linux-gnu"
|
||||
elif os_type == "darwin":
|
||||
os_type = "apple-darwin"
|
||||
elif os_type == "android":
|
||||
os_type == "linux-androideabi"
|
||||
else:
|
||||
os_type == "unknown"
|
||||
|
||||
cpu_type = subprocess.check_output(["uname", "-m"]).strip().lower()
|
||||
if cpu_type in ["i386", "i486", "i686", "i768", "x86"]:
|
||||
cpu_type = "i686"
|
||||
elif cpu_type in ["x86_64", "x86-64", "x64", "amd64"]:
|
||||
cpu_type = "x86_64"
|
||||
elif cpu_type == "arm":
|
||||
cpu_type = "arm"
|
||||
else:
|
||||
cpu_type = "unknown"
|
||||
|
||||
return "%s-%s" % (cpu_type, os_type)
|
||||
from servo.command_base import CommandBase, cd, host_triple
|
||||
|
||||
|
||||
def download(desc, src, dst):
|
||||
|
@ -90,7 +66,8 @@ class MachCommands(CommandBase):
|
|||
action='store_true',
|
||||
help='Force download even if a snapshot already exists')
|
||||
def bootstrap_rustc(self, force=False):
|
||||
rust_dir = path.join(self.context.topdir, "rust")
|
||||
rust_dir = path.join(
|
||||
self.context.topdir, "rust", *self.rust_snapshot_path().split("/"))
|
||||
if not force and path.exists(path.join(rust_dir, "bin", "rustc")):
|
||||
print("Snapshot Rust compiler already downloaded.", end=" ")
|
||||
print("Use |bootstrap_rust --force| to download again.")
|
||||
|
@ -98,13 +75,11 @@ class MachCommands(CommandBase):
|
|||
|
||||
if path.isdir(rust_dir):
|
||||
shutil.rmtree(rust_dir)
|
||||
os.mkdir(rust_dir)
|
||||
os.makedirs(rust_dir)
|
||||
|
||||
filename = path.join(self.context.topdir, "rust-snapshot-hash")
|
||||
snapshot_hash = open(filename).read().strip()
|
||||
snapshot_path = "%s-%s.tar.gz" % (snapshot_hash, host_triple())
|
||||
snapshot_url = "https://servo-rust.s3.amazonaws.com/%s" % snapshot_path
|
||||
tgz_file = path.join(rust_dir, path.basename(snapshot_path))
|
||||
snapshot_url = ("https://servo-rust.s3.amazonaws.com/%s.tar.gz"
|
||||
% self.rust_snapshot_path())
|
||||
tgz_file = rust_dir + '.tar.gz'
|
||||
|
||||
download("Rust snapshot", snapshot_url, tgz_file)
|
||||
|
||||
|
|
|
@ -19,6 +19,30 @@ def cd(new_path):
|
|||
os.chdir(previous_path)
|
||||
|
||||
|
||||
def host_triple():
|
||||
os_type = subprocess.check_output(["uname", "-s"]).strip().lower()
|
||||
if os_type == "linux":
|
||||
os_type = "unknown-linux-gnu"
|
||||
elif os_type == "darwin":
|
||||
os_type = "apple-darwin"
|
||||
elif os_type == "android":
|
||||
os_type == "linux-androideabi"
|
||||
else:
|
||||
os_type == "unknown"
|
||||
|
||||
cpu_type = subprocess.check_output(["uname", "-m"]).strip().lower()
|
||||
if cpu_type in ["i386", "i486", "i686", "i768", "x86"]:
|
||||
cpu_type = "i686"
|
||||
elif cpu_type in ["x86_64", "x86-64", "x64", "amd64"]:
|
||||
cpu_type = "x86_64"
|
||||
elif cpu_type == "arm":
|
||||
cpu_type = "arm"
|
||||
else:
|
||||
cpu_type = "unknown"
|
||||
|
||||
return "%s-%s" % (cpu_type, os_type)
|
||||
|
||||
|
||||
class CommandBase(object):
|
||||
"""Base class for mach command providers.
|
||||
|
||||
|
@ -44,11 +68,20 @@ class CommandBase(object):
|
|||
self.config["tools"].setdefault("cargo-root", "")
|
||||
if not self.config["tools"]["system-rust"]:
|
||||
self.config["tools"]["rust-root"] = path.join(
|
||||
context.topdir, "rust")
|
||||
context.topdir, "rust", *self.rust_snapshot_path().split("/"))
|
||||
if not self.config["tools"]["system-cargo"]:
|
||||
self.config["tools"]["cargo-root"] = path.join(
|
||||
context.topdir, "cargo")
|
||||
|
||||
_rust_snapshot_path = None
|
||||
|
||||
def rust_snapshot_path(self):
|
||||
if self._rust_snapshot_path is None:
|
||||
filename = path.join(self.context.topdir, "rust-snapshot-hash")
|
||||
snapshot_hash = open(filename).read().strip()
|
||||
self._rust_snapshot_path = "%s-%s" % (snapshot_hash, host_triple())
|
||||
return self._rust_snapshot_path
|
||||
|
||||
def build_env(self):
|
||||
"""Return an extended environment dictionary."""
|
||||
env = os.environ.copy()
|
||||
|
@ -95,7 +128,7 @@ class CommandBase(object):
|
|||
|
||||
if not self.config["tools"]["system-rust"] and \
|
||||
not path.exists(path.join(
|
||||
self.context.topdir, "rust", "bin", "rustc")):
|
||||
self.config["tools"]["rust-root"], "bin", "rustc")):
|
||||
Registrar.dispatch("bootstrap-rust", context=self.context)
|
||||
if not self.config["tools"]["system-cargo"] and \
|
||||
not path.exists(path.join(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue