cleantrees.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright 2016 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import os
  12. import sys
  13. import shutil
  14. import pickle
  15. def rmtrees(build_dir, trees):
  16. for t in trees:
  17. # Never delete trees outside of the builddir
  18. if os.path.isabs(t):
  19. print('Cannot delete dir with absolute path {!r}'.format(t))
  20. continue
  21. bt = os.path.join(build_dir, t)
  22. # Skip if it doesn't exist, or if it is not a directory
  23. if os.path.isdir(bt):
  24. shutil.rmtree(bt, ignore_errors=True)
  25. def run(args):
  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. if __name__ == '__main__':
  36. run(sys.argv[1:])