mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 17:54:15 +02:00
[improvement][aur] generating the optimized makepkg.conf at ~/.config/bauh/arch and using it as a build parameter
This commit is contained in:
@@ -4,20 +4,19 @@ import re
|
||||
import time
|
||||
from math import ceil
|
||||
from multiprocessing import Process
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
|
||||
import requests
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager
|
||||
from bauh.api.constants import HOME_PATH
|
||||
from bauh.gems.arch import pacman, disk
|
||||
from bauh.gems.arch import pacman, disk, CUSTOM_MAKEPKG_PATH, CONFIG_DIR
|
||||
|
||||
URL_INDEX = 'https://aur.archlinux.org/packages.gz'
|
||||
URL_INFO = 'https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'
|
||||
|
||||
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*.+')
|
||||
@@ -89,13 +88,15 @@ class ArchCompilationOptimizer(Thread if bool(os.getenv('BAUH_DEBUG', 0)) else P
|
||||
self.logger.error('Could not determine the number of processors. Aborting...')
|
||||
ncpus = None
|
||||
|
||||
if os.path.exists(GLOBAL_MAKEPKG) and not os.path.exists(USER_MAKEPKG):
|
||||
if os.path.exists(GLOBAL_MAKEPKG):
|
||||
self.logger.info("Verifying if it is possible to optimize Arch packages compilation")
|
||||
|
||||
with open(GLOBAL_MAKEPKG) as f:
|
||||
global_makepkg = f.read()
|
||||
|
||||
user_makepkg, optimizations = None, []
|
||||
Path(CONFIG_DIR).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
custom_makepkg, optimizations = None, []
|
||||
|
||||
if ncpus:
|
||||
makeflags = RE_MAKE_FLAGS.findall(global_makepkg)
|
||||
@@ -104,20 +105,20 @@ class ArchCompilationOptimizer(Thread if bool(os.getenv('BAUH_DEBUG', 0)) else P
|
||||
not_commented = [f for f in makeflags if not f.startswith('#')]
|
||||
|
||||
if not not_commented:
|
||||
user_makepkg = RE_MAKE_FLAGS.sub('', global_makepkg)
|
||||
custom_makepkg = RE_MAKE_FLAGS.sub('', global_makepkg)
|
||||
optimizations.append('MAKEFLAGS="-j$(nproc)"')
|
||||
else:
|
||||
self.logger.warning("It seems '{}' compilation flags are already customized".format(GLOBAL_MAKEPKG))
|
||||
else:
|
||||
optimizations.append('MAKEFLAGS="-j$(nproc)"')
|
||||
|
||||
compress_xz = RE_COMPRESS_XZ.findall(user_makepkg if user_makepkg else global_makepkg)
|
||||
compress_xz = RE_COMPRESS_XZ.findall(custom_makepkg if custom_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)
|
||||
custom_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))
|
||||
@@ -126,11 +127,9 @@ class ArchCompilationOptimizer(Thread if bool(os.getenv('BAUH_DEBUG', 0)) else P
|
||||
|
||||
if optimizations:
|
||||
generated_by = '# <generated by bauh>\n'
|
||||
user_makepkg = generated_by + user_makepkg + '\n' + generated_by + '\n'.join(optimizations) + '\n'
|
||||
custom_makepkg = generated_by + custom_makepkg + '\n' + generated_by + '\n'.join(optimizations) + '\n'
|
||||
|
||||
with open(USER_MAKEPKG, 'w+') as f:
|
||||
f.write(user_makepkg)
|
||||
with open(CUSTOM_MAKEPKG_PATH, 'w+') as f:
|
||||
f.write(custom_makepkg)
|
||||
|
||||
self.logger.info("A custom optimized 'makepkg.conf' was generated at '{}'".format(HOME_PATH))
|
||||
else:
|
||||
self.logger.warning("A custom 'makepkg.conf' is already defined at '{}'".format(HOME_PATH))
|
||||
self.logger.info("A custom optimized 'makepkg.conf' was generated at '{}'".format(CUSTOM_MAKEPKG_PATH))
|
||||
|
||||
Reference in New Issue
Block a user