[aur] respecting BAUH_ARCH_OPTIMIZE when makepkg calls are executed

This commit is contained in:
Vinicius Moreira
2019-11-29 09:05:20 -03:00
parent 915c3b50a3
commit dca66b315e
3 changed files with 26 additions and 12 deletions

View File

@@ -10,3 +10,7 @@ CATEGORIES_FILE_PATH = CATEGORIES_CACHE_DIR + '/aur.txt'
URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/aur/categories.txt'
CONFIG_DIR = '{}/.config/bauh/arch'.format(HOME_PATH)
CUSTOM_MAKEPKG_PATH = '{}/makepkg.conf'.format(CONFIG_DIR)
def should_optimize_compilation() -> bool:
return bool(int(os.getenv('BAUH_ARCH_OPTIMIZE', 1)))

View File

@@ -3,7 +3,7 @@ import re
from typing import Tuple
from bauh.commons.system import SimpleProcess, ProcessHandler
from bauh.gems.arch import CUSTOM_MAKEPKG_PATH
from bauh.gems.arch import CUSTOM_MAKEPKG_PATH, should_optimize_compilation
RE_DEPS_PATTERN = re.compile(r'\n?\s+->\s(.+)\n')
RE_UNKNOWN_GPG_KEY = re.compile(r'\(unknown public key (\w+)\)')
@@ -14,9 +14,12 @@ def check(pkgdir: str, handler: ProcessHandler) -> dict:
cmd = ['makepkg', '-ALcf', '--check', '--noarchive', '--nobuild', '--noprepare']
if should_optimize_compilation():
if os.path.exists(CUSTOM_MAKEPKG_PATH):
handler.watcher.print('Using custom makepkg.conf -> {}'.format(CUSTOM_MAKEPKG_PATH))
cmd.append('--config={}'.format(CUSTOM_MAKEPKG_PATH))
else:
handler.watcher.print('Custom optimized makepkg.conf ( {} ) not found'.format(CUSTOM_MAKEPKG_PATH))
success, output = handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir))
@@ -37,9 +40,11 @@ def check(pkgdir: str, handler: ProcessHandler) -> dict:
def make(pkgdir: str, handler: ProcessHandler) -> Tuple[bool, str]:
cmd = ['makepkg', '-ALcsmf']
if should_optimize_compilation():
if os.path.exists(CUSTOM_MAKEPKG_PATH):
handler.watcher.print('Using custom makepkg.conf -> {}'.format(CUSTOM_MAKEPKG_PATH))
cmd.append('--config={}'.format(CUSTOM_MAKEPKG_PATH))
else:
handler.watcher.print('Custom optimized makepkg.conf ( {} ) not found'.format(CUSTOM_MAKEPKG_PATH))
return handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir))

View File

@@ -11,7 +11,7 @@ import requests
from bauh.api.abstract.context import ApplicationContext
from bauh.api.abstract.controller import SoftwareManager
from bauh.gems.arch import pacman, disk, CUSTOM_MAKEPKG_PATH, CONFIG_DIR
from bauh.gems.arch import pacman, disk, CUSTOM_MAKEPKG_PATH, CONFIG_DIR, should_optimize_compilation
URL_INDEX = 'https://aur.archlinux.org/packages.gz'
URL_INFO = 'https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'
@@ -75,12 +75,17 @@ class ArchCompilationOptimizer(Thread if bool(os.getenv('BAUH_DEBUG', 0)) else P
def __init__(self, logger: logging.Logger):
super(ArchCompilationOptimizer, self).__init__(daemon=True)
self.logger = logger
self.compilation_optimizations = bool(int(os.getenv('BAUH_ARCH_OPTIMIZE', 1)))
def run(self):
if not self.compilation_optimizations:
self.logger.info("Arch packages compilation optimization is disabled. Aborting...")
if not should_optimize_compilation():
self.logger.info("Arch packages compilation optimization is disabled")
if os.path.exists(CUSTOM_MAKEPKG_PATH):
self.logger.info("Removing custom 'makepkg.conf' -> '{}'".format(CUSTOM_MAKEPKG_PATH))
os.remove(CUSTOM_MAKEPKG_PATH)
self.logger.info('Finished')
else:
try:
ncpus = os.cpu_count()