Skip to content

Commit

Permalink
[improvement][aur] generating the optimized makepkg.conf at ~/.config…
Browse files Browse the repository at this point in the history
…/bauh/arch and using it as a build parameter
  • Loading branch information
vinifmor committed Nov 27, 2019
1 parent 7dda304 commit 374c697
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion bauh/gems/arch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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'
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)
2 changes: 1 addition & 1 deletion bauh/gems/arch/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def _make_pkg(self, pkgname: str, maintainer: str, root_password: str, handler:

# 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:
Expand Down
23 changes: 22 additions & 1 deletion bauh/gems/arch/makepkg.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
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+)\)')


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

27 changes: 13 additions & 14 deletions bauh/gems/arch/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
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*.+')
Expand Down Expand Up @@ -89,13 +88,15 @@ def run(self):
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)
Expand All @@ -104,20 +105,20 @@ def run(self):
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))
Expand All @@ -126,11 +127,9 @@ def run(self):

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

0 comments on commit 374c697

Please sign in to comment.