aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo/bootstrap_commands.py
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2014-12-09 09:31:23 +0000
committerSimon Sapin <simon.sapin@exyr.org>2014-12-09 09:31:23 +0000
commitb337b0e5e066f1e6e04b061a903c60a6eb55e99e (patch)
tree7748d4c883cb272cbf0581463d1c704d6022303d /python/servo/bootstrap_commands.py
parent7d4ec333750fd7d57226c1d915f3227a2998e02f (diff)
downloadservo-b337b0e5e066f1e6e04b061a903c60a6eb55e99e.tar.gz
servo-b337b0e5e066f1e6e04b061a903c60a6eb55e99e.zip
Add a `./mach clean-snapshots` command to remove old Cargo and Rust.
Bootstrapping automatically downloads new Rust and Cargo snapshots as needed into versioned directories, but do not remove now-unused versions. This is the desired behavior for `git bisect` to be usable. However, this means that old version keep accumulating, taking up disk space. This adds a mach command to remove snapshots other than the ones currently being used. It is never run automatically. To be safe, the command defaults to only printing what would be removed, and only removes stuff when run with a `-f` argument.
Diffstat (limited to 'python/servo/bootstrap_commands.py')
-rw-r--r--python/servo/bootstrap_commands.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/python/servo/bootstrap_commands.py b/python/servo/bootstrap_commands.py
index 11509e5ede5..e0cff7097de 100644
--- a/python/servo/bootstrap_commands.py
+++ b/python/servo/bootstrap_commands.py
@@ -152,3 +152,29 @@ class MachCommands(CommandBase):
["git", "submodule", "--quiet", "sync", "--recursive"])
subprocess.check_call(
["git", "submodule", "update", "--init", "--recursive"])
+
+ @Command('clean-snapshots',
+ description='Clean unused snapshots of Rust and Cargo',
+ category='bootstrap')
+ @CommandArgument('--force', '-f',
+ action='store_true',
+ help='Actually remove stuff')
+ def clean_snapshots(self, force=False):
+ rust_current = self.rust_snapshot_path().split('/')[0]
+ cargo_current = self.cargo_build_id()
+ print("Current Rust version: " + rust_current)
+ print("Current Cargo version: " + cargo_current)
+ action = "Removing " if force else "Would remove "
+ for current, base in [(rust_current, "rust"), (cargo_current, "cargo")]:
+ base = path.join(self.context.sharedir, base)
+ for name in os.listdir(base):
+ if name != current:
+ name = path.join(base, name)
+ if force:
+ print("Removing " + name)
+ shutil.rmtree(name)
+ else:
+ print("Would remove " + name)
+ if not force:
+ print("Nothing done. "
+ "Run `./mach clean-snapshots -f` to actually remove.")