| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2016 The Meson development team |
| 3 |
|
| 4 |
from __future__ import annotations |
| 5 |
|
| 6 |
import os |
| 7 |
import sys |
| 8 |
import shutil |
| 9 |
import pickle |
| 10 |
import typing as T |
| 11 |
|
| 12 |
from ..utils.platform import path_has_root |
| 13 |
|
| 14 |
def rmtrees(build_dir: str, trees: T.List[str]) -> None: |
| 15 |
for t in trees: |
| 16 |
# Never delete trees outside of the builddir |
| 17 |
if path_has_root(t): |
| 18 |
print(f'Cannot delete dir with absolute path {t!r}') |
| 19 |
continue |
| 20 |
bt = os.path.join(build_dir, t) |
| 21 |
# Skip if it doesn't exist, or if it is not a directory |
| 22 |
if os.path.isdir(bt): |
| 23 |
shutil.rmtree(bt, ignore_errors=True) |
| 24 |
|
| 25 |
def run(args: T.List[str]) -> int: |
| 26 |
if len(args) != 1: |
| 27 |
print('Cleaner script for Meson. Do not run on your own please.') |
| 28 |
print('cleantrees.py <data-file>') |
| 29 |
return 1 |
| 30 |
with open(args[0], 'rb') as f: |
| 31 |
data = pickle.load(f) |
| 32 |
rmtrees(data.build_dir, data.trees) |
| 33 |
# Never fail cleaning |
| 34 |
return 0 |
| 35 |
|
| 36 |
if __name__ == '__main__': |
| 37 |
run(sys.argv[1:]) |