Check PKGBUILDs for arches hint

This commit is contained in:
jld3103 2021-10-06 21:00:47 +02:00
parent 06fb2af77f
commit 13c284012d

View file

@ -557,7 +557,6 @@ def cmd_clean():
@cmd_packages.command(name='check') @cmd_packages.command(name='check')
@click.argument('paths', nargs=-1) @click.argument('paths', nargs=-1)
def cmd_check(paths): def cmd_check(paths):
enforce_wrap()
paths = list(paths) paths = list(paths)
packages = filter_packages_by_paths(discover_packages(), paths) packages = filter_packages_by_paths(discover_packages(), paths)
@ -568,9 +567,14 @@ def cmd_check(paths):
if name.endswith('-git'): if name.endswith('-git'):
is_git_package = True is_git_package = True
required_arches = ''
provided_arches = []
mode_key = '_mode' mode_key = '_mode'
pkgbase_key = 'pkgbase' pkgbase_key = 'pkgbase'
pkgname_key = 'pkgname' pkgname_key = 'pkgname'
arches_key = '_arches'
arch_key = 'arch'
commit_key = '_commit' commit_key = '_commit'
source_key = 'source' source_key = 'source'
sha256sums_key = 'sha256sums' sha256sums_key = 'sha256sums'
@ -581,7 +585,8 @@ def cmd_check(paths):
'pkgdesc': False, 'pkgdesc': False,
'pkgver': True, 'pkgver': True,
'pkgrel': True, 'pkgrel': True,
'arch': True, arches_key: True,
arch_key: True,
'license': True, 'license': True,
'url': False, 'url': False,
'provides': is_git_package, 'provides': is_git_package,
@ -598,9 +603,13 @@ def cmd_check(paths):
} }
with open(os.path.join(package.path, 'PKGBUILD'), 'r') as file: with open(os.path.join(package.path, 'PKGBUILD'), 'r') as file:
lines = file.read().split('\n') content = file.read()
if '\t' in content:
logging.fatal(f'\\t is not allowed in {os.path.join(package.path, "PKGBUILD")}')
exit(1)
lines = content.split('\n')
if len(lines) == 0: if len(lines) == 0:
logging.fatal(f'Empty PKGBUILD for {package.path}') logging.fatal(f'Empty {os.path.join(package.path, "PKGBUILD")}')
exit(1) exit(1)
line_index = 0 line_index = 0
key_index = 0 key_index = 0
@ -613,7 +622,7 @@ def cmd_check(paths):
line_index += 1 line_index += 1
continue continue
if line.startswith('_') and not line.startswith(mode_key) and not line.startswith(commit_key): if line.startswith('_') and not line.startswith(mode_key) and not line.startswith(arches_key) and not line.startswith(commit_key):
line_index += 1 line_index += 1
continue continue
@ -653,6 +662,9 @@ def cmd_check(paths):
formatted = False formatted = False
reason = f'Package name needs to have "{package.repo}-" as prefix' reason = f'Package name needs to have "{package.repo}-" as prefix'
if key == arches_key:
required_arches = line.split('=')[1]
if line.endswith('=('): if line.endswith('=('):
hold_key = True hold_key = True
@ -692,9 +704,25 @@ def cmd_check(paths):
logging.fatal(reason) logging.fatal(reason)
exit(1) exit(1)
if key == arch_key:
if line.endswith(')'):
if line.startswith(f'{arch_key}=('):
check_arches_hint(os.path.join(package.path, "PKGBUILD"), required_arches, [line[6:-1]])
else:
check_arches_hint(os.path.join(package.path, "PKGBUILD"), required_arches, provided_arches)
elif line.startswith(' '):
provided_arches.append(line[4:])
if next_key and not hold_key: if next_key and not hold_key:
key_index += 1 key_index += 1
if next_line: if next_line:
line_index += 1 line_index += 1
logging.info(f'{package.path} nicely formatted!') logging.info(f'{package.path} nicely formatted!')
def check_arches_hint(path: str, required: str, provided: list[str]):
if required == 'all':
for arch in ARCHES:
if arch not in provided:
logging.warning(f'Missing {arch} in arches list in {path}, because hint is `all`')