From dca66b315ef269b21c953f35c465db407a7596c1 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Fri, 29 Nov 2019 09:05:20 -0300 Subject: [PATCH] [aur] respecting BAUH_ARCH_OPTIMIZE when makepkg calls are executed --- bauh/gems/arch/__init__.py | 4 ++++ bauh/gems/arch/makepkg.py | 21 +++++++++++++-------- bauh/gems/arch/worker.py | 13 +++++++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/bauh/gems/arch/__init__.py b/bauh/gems/arch/__init__.py index 3111c128..2a027234 100644 --- a/bauh/gems/arch/__init__.py +++ b/bauh/gems/arch/__init__.py @@ -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))) diff --git a/bauh/gems/arch/makepkg.py b/bauh/gems/arch/makepkg.py index 41bf1717..a6ba0ff9 100644 --- a/bauh/gems/arch/makepkg.py +++ b/bauh/gems/arch/makepkg.py @@ -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 os.path.exists(CUSTOM_MAKEPKG_PATH): - handler.watcher.print('Using custom makepkg.conf -> {}'.format(CUSTOM_MAKEPKG_PATH)) - cmd.append('--config={}'.format(CUSTOM_MAKEPKG_PATH)) + 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 os.path.exists(CUSTOM_MAKEPKG_PATH): - handler.watcher.print('Using custom makepkg.conf -> {}'.format(CUSTOM_MAKEPKG_PATH)) - cmd.append('--config={}'.format(CUSTOM_MAKEPKG_PATH)) + 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)) - diff --git a/bauh/gems/arch/worker.py b/bauh/gems/arch/worker.py index 58078d31..ca628663 100644 --- a/bauh/gems/arch/worker.py +++ b/bauh/gems/arch/worker.py @@ -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()