arch: optimizing tar.xz compression

This commit is contained in:
Vinicius Moreira
2019-09-24 18:29:51 -03:00
parent 15856cc3cd
commit c8ed693b2f
2 changed files with 30 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ GLOBAL_MAKEPKG = '/etc/makepkg.conf'
USER_MAKEPKG = '{}/makepkg.conf'.format(HOME_PATH)
RE_MAKE_FLAGS = re.compile(r'#?\s*MAKEFLAGS\s*=\s*.+\s*')
RE_COMPRESS_XZ = re.compile(r'#?\s*COMPRESSXZ\s*=\s*.+')
class AURIndexUpdater(Thread):
@@ -88,21 +89,39 @@ class ArchCompilationOptimizer(Thread if bool(os.getenv('BAUH_DEBUG', 0)) else P
with open(GLOBAL_MAKEPKG) as f:
global_makepkg = f.read()
makeflags = RE_MAKE_FLAGS.findall(global_makepkg)
user_makepkg = None
optimizations = []
makeflags = RE_MAKE_FLAGS.findall(global_makepkg)
if makeflags:
not_commented = [f for f in makeflags if not makeflags[0].startswith('#')]
not_commented = [f for f in makeflags if not f.startswith('#')]
if not not_commented:
user_makepkg = RE_MAKE_FLAGS.sub('', global_makepkg)
optimizations.append('MAKEFLAGS="-j{}"'.format(ncpus))
else:
self.logger.warning("It seems '{}' compilation flags are already customized".format(GLOBAL_MAKEPKG))
else:
user_makepkg = global_makepkg
optimizations.append('MAKEFLAGS="-j{}"'.format(ncpus))
compress_xz = RE_COMPRESS_XZ.findall(user_makepkg if user_makepkg else global_makepkg)
if compress_xz:
not_eligible = [f for f in compress_xz if not f.startswith('#') and '--threads' in f]
if not not_eligible:
user_makepkg = RE_COMPRESS_XZ.sub('', global_makepkg)
optimizations.append('COMPRESSXZ=(xz -c -z - --threads=0)')
else:
self.logger.warning("It seems '{}' COMPRESSXZ is already customized".format(GLOBAL_MAKEPKG))
else:
optimizations.append('COMPRESSXZ=(xz -c -z - --threads=0)')
if optimizations:
generated_by = '# <generated by bauh>\n'
user_makepkg = generated_by + user_makepkg + '\n' + generated_by + '\n'.join(optimizations) + '\n'
if user_makepkg:
user_makepkg = '# <generated by bauh>\n' + user_makepkg + '\nMAKEFLAGS="-j{}"'.format(ncpus)
with open(USER_MAKEPKG, 'w+') as f:
f.write(user_makepkg)