aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/thinlto_cache.py
blob: 35ab7552620f934ccb86db291305f28c85556f89 (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
import os
import tarfile


CACHE_DIR_NAME='thinlto_cache_dir'


def add_options(parser):
    parser.add_option('--thinlto-cache')
    parser.add_option('--thinlto-cache-write', action='store_true')

def preprocess(opts, cmd):
    if opts.thinlto_cache:
        cache_dir = os.path.join(opts.build_root, CACHE_DIR_NAME)
        cmd +=['-Wl,--thinlto-cache-dir={}'.format(cache_dir)]
        if opts.thinlto_cache_write:
            os.mkdir(cache_dir)
        else:
            with tarfile.open(opts.thinlto_cache, 'r') as tar:
                tar.extractall(opts.build_root)

def postprocess(opts):
    if opts.thinlto_cache:
        cache_dir = os.path.join(opts.build_root, CACHE_DIR_NAME)
        if opts.thinlto_cache_write:
            with tarfile.open(opts.thinlto_cache, 'w:gz') as tar:
                tar.add(cache_dir, arcname=os.path.basename(cache_dir))