From 69aa94c817157de91eb544dac0ffd31ab69823a7 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Sat, 2 Aug 2025 15:32:11 +1000 Subject: [PATCH] libmakepkg: add linting of BUILDENV and OPTIONS from makepkg.conf Currently the options array from a PKGBUILD is linted, but the global BUILDENV and OPTIONS are not. Fixes #233. Signed-off-by: Allan McRae --- scripts/libmakepkg/lint_config/buildenv.sh.in | 57 +++++++++++++++++++ scripts/libmakepkg/lint_config/meson.build | 1 + 2 files changed, 58 insertions(+) create mode 100644 scripts/libmakepkg/lint_config/buildenv.sh.in diff --git a/scripts/libmakepkg/lint_config/buildenv.sh.in b/scripts/libmakepkg/lint_config/buildenv.sh.in new file mode 100644 index 00000000..b644f606 --- /dev/null +++ b/scripts/libmakepkg/lint_config/buildenv.sh.in @@ -0,0 +1,57 @@ +#!/bin/bash +# +# buildenv.sh - Check that the BUILDENV and OPTIONS arrays are valid +# +# Copyright (c) 2025 Pacman Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +[[ -n $LIBMAKEPKG_LINT_CONFIG_BUILDENV_SH ]] && return +LIBMAKEPKG_LINT_CONFIG_BUILDENV_SH=1 + +MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} + +source "$MAKEPKG_LIBRARY/util/message.sh" + +lint_config_functions+=('lint_buildenv') + + +lint_buildenv() { + local ret=0 kopt + local known_buildenv=(ccache check color distcc sign) + local known_option=(autodeps debug docs emptydirs libtool lto purge staticlibs strip zipman) + + for i in "${BUILDENV[@]}"; do + for kopt in "${known_buildenv[@]}"; do + if [[ $i = "$kopt" || $i = "!$kopt" ]]; then + continue 2 + fi + done + + error "$(gettext "%s array contains unknown option '%s'")" "BUILDENV" "$i" + ret=1 + done + + for i in "${OPTIONS[@]}"; do + for kopt in "${known_option[@]}"; do + if [[ $i = "$kopt" || $i = "!$kopt" ]]; then + continue 2 + fi + done + + error "$(gettext "%s array contains unknown option '%s'")" "OPTIONS" "$i" + ret=1 + done +} diff --git a/scripts/libmakepkg/lint_config/meson.build b/scripts/libmakepkg/lint_config/meson.build index 9bcdad16..048e8c28 100644 --- a/scripts/libmakepkg/lint_config/meson.build +++ b/scripts/libmakepkg/lint_config/meson.build @@ -1,6 +1,7 @@ libmakepkg_module = 'lint_config' sources = [ + 'buildenv.sh.in', 'ext.sh.in', 'nproc.sh.in', 'packager.sh.in',