thinlto_cache.py 868 B

123456789101112131415161718192021222324252627
  1. import os
  2. import tarfile
  3. CACHE_DIR_NAME='thinlto_cache_dir'
  4. def add_options(parser):
  5. parser.add_option('--thinlto-cache')
  6. parser.add_option('--thinlto-cache-write', action='store_true')
  7. def preprocess(opts, cmd):
  8. if opts.thinlto_cache:
  9. cache_dir = os.path.join(opts.build_root, CACHE_DIR_NAME)
  10. cmd +=['-Wl,--thinlto-cache-dir={}'.format(cache_dir)]
  11. if opts.thinlto_cache_write:
  12. os.mkdir(cache_dir)
  13. else:
  14. with tarfile.open(opts.thinlto_cache, 'r') as tar:
  15. tar.extractall(opts.build_root)
  16. def postprocess(opts):
  17. if opts.thinlto_cache:
  18. cache_dir = os.path.join(opts.build_root, CACHE_DIR_NAME)
  19. if opts.thinlto_cache_write:
  20. with tarfile.open(opts.thinlto_cache, 'w:gz') as tar:
  21. tar.add(cache_dir, arcname=os.path.basename(cache_dir))