with_coverage.py 749 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # TODO prettyboy remove after ya-bin release
  2. import os
  3. import sys
  4. import subprocess
  5. import tarfile
  6. import random
  7. import shutil
  8. def mkdir_p(path):
  9. try:
  10. os.makedirs(path)
  11. except OSError:
  12. pass
  13. def main(args):
  14. coverage_path = os.path.abspath(args[0])
  15. coverage_dir = coverage_path + '.' + str(random.getrandbits(64))
  16. mkdir_p(coverage_dir)
  17. env = os.environ.copy()
  18. env['GCOV_PREFIX'] = coverage_dir
  19. subprocess.check_call(args[1:], env=env)
  20. arch_path = coverage_dir + '.archive'
  21. with tarfile.open(arch_path, 'w:') as tar:
  22. tar.add(coverage_dir, arcname='.')
  23. os.rename(arch_path, coverage_path)
  24. shutil.rmtree(coverage_dir)
  25. if __name__ == '__main__':
  26. main(sys.argv[1:])