aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/with_coverage.py
blob: d62435c3b8ff37c4fced870d25972c628332fdf9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# TODO prettyboy remove after ya-bin release

import os
import sys
import subprocess
import tarfile
import random
import shutil


def mkdir_p(path):
    try:
        os.makedirs(path)
    except OSError:
        pass


def main(args):
    coverage_path = os.path.abspath(args[0])
    coverage_dir = coverage_path + '.' + str(random.getrandbits(64))

    mkdir_p(coverage_dir)

    env = os.environ.copy()
    env['GCOV_PREFIX'] = coverage_dir

    subprocess.check_call(args[1:], env=env)

    arch_path = coverage_dir + '.archive'

    with tarfile.open(arch_path, 'w:') as tar:
        tar.add(coverage_dir, arcname='.')

    os.rename(arch_path, coverage_path)

    shutil.rmtree(coverage_dir)


if __name__ == '__main__':
    main(sys.argv[1:])