[improvement][aur] generating the optimized makepkg.conf at ~/.config/bauh/arch and using it as a build parameter

This commit is contained in:
Vinicius Moreira
2019-11-27 11:33:13 -03:00
parent 7dda304c7a
commit 374c697196
5 changed files with 42 additions and 17 deletions

View File

@@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Adding all english (**en**) i18n keys to help people with the application translation
- AppImage
- AppImage updater daemon replaced by a default Python thread to reduce memory usage
- AUR
- The optimized **makepkg.conf** file is now generated at **~/.config/bauh/arch/makepkg.conf** and passed as a parameter during package builds to not provoke the auto-merge of **/etc/makepkg.conf** and the old generated **~/.makepkg.conf**.
(P.S: if your **~/.makepkg.conf** was generated by bauh, consider deleting it as it will be useless for bauh now and may impact your other Arch compilation tools)
- Caching Snap and Flatpak suggestions [#23](https://github.com/vinifmor/bauh/issues/23)
- i18n:
- Catalan contributions by [fitojb](https://github.com/fitojb)

View File

@@ -1,6 +1,6 @@
import os
from bauh.api.constants import CACHE_PATH
from bauh.api.constants import CACHE_PATH, HOME_PATH
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_DIR = '/tmp/bauh/aur'
@@ -8,3 +8,5 @@ ARCH_CACHE_PATH = CACHE_PATH + '/arch'
CATEGORIES_CACHE_DIR = ARCH_CACHE_PATH + '/categories'
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)

View File

@@ -435,7 +435,7 @@ class ArchManager(SoftwareManager):
# building main package
handler.watcher.change_substatus(self.i18n['arch.building.package'].format(bold(pkgname)))
pkgbuilt, output = handler.handle_simple(SimpleProcess(['makepkg', '-ALcsmf', '--noprepare'], cwd=project_dir))
pkgbuilt, output = makepkg.make(project_dir, handler)
self._update_progress(handler.watcher, 65, change_progress)
if pkgbuilt:

View File

@@ -1,6 +1,9 @@
import os
import re
from typing import Tuple
from bauh.commons.system import SimpleProcess, ProcessHandler
from bauh.gems.arch import CUSTOM_MAKEPKG_PATH
RE_DEPS_PATTERN = re.compile(r'\n?\s+->\s(.+)\n')
RE_UNKNOWN_GPG_KEY = re.compile(r'\(unknown public key (\w+)\)')
@@ -8,7 +11,14 @@ RE_UNKNOWN_GPG_KEY = re.compile(r'\(unknown public key (\w+)\)')
def check(pkgdir: str, handler: ProcessHandler) -> dict:
res = {}
success, output = handler.handle_simple(SimpleProcess(['makepkg', '-ALcf', '--check', '--noarchive', '--nobuild'], cwd=pkgdir))
cmd = ['makepkg', '-ALcf', '--check', '--noarchive', '--nobuild']
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))
success, output = handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir))
if 'Missing dependencies' in output:
res['missing_deps'] = RE_DEPS_PATTERN.findall(output)
@@ -22,3 +32,14 @@ def check(pkgdir: str, handler: ProcessHandler) -> dict:
res['validity_check'] = True
return res
def make(pkgdir: str, handler: ProcessHandler) -> Tuple[bool, str]:
cmd = ['makepkg', '-ALcsmf', '--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))
return handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir))

View File

@@ -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))