gitlab-ci: Add Meson linter job to prevent performance degradation

Meson broadly uses one of the few languages that it is available on
all platforms so let's take advantage of it on internal scripts.

This way, we have only one build language to care (aside Perl, which
have its own purpose) and avoid terrible bugs like: #11385.
This commit is contained in:
Bruno Lopes 2025-04-22 16:09:34 -03:00
parent 73b57a9914
commit 89dfd0161a
No known key found for this signature in database
3 changed files with 156 additions and 4 deletions

View file

@ -582,6 +582,17 @@ file-plug-in-tests:
junit: "_log/import-tests.xml"
expire_in: 2 days
meson-health:
extends: .default
rules:
- <<: *CI_MERGE
- <<: *CI_COMMIT
stage: analysis
script:
- apt-get update
- apt-get install -y git
- bash .gitlab/run_meson_health_diff.sh
clang-format:
extends: .default
rules:

View file

@ -0,0 +1,141 @@
#!/bin/bash
source .gitlab/search-common-ancestor.sh
diff=$(git diff -U0 --no-color "${newest_common_ancestor_sha}" -- '*.build' | grep -E '^\+[^+]' | sed 's/^+//')
#List of commonly used utilities on Unix world
#See the context: https://gitlab.gnome.org/GNOME/gimp/-/issues/11385
coreutils_array=(
".sh"
"'sh'"
"'bash'"
"'\['"
"'arch'"
"'awk'"
"'b2sum'"
"'base32'"
"'base64'"
"'basename'"
"'basenc'"
"'cat'"
"'chcon'"
"'chgrp'"
"'chmod'"
"'chown'"
"'chroot'"
"'cksum'"
"'comm'"
"'cp'"
"'csplit'"
"'cut'"
"'date'"
"'dd'"
"'df'"
"'dir'"
"'dircolors'"
"'dirname'"
"'du'"
"'echo'"
"'env'"
"'expand'"
"'expr'"
"'factor'"
"'false'"
"'find'"
"'fmt'"
"'fold'"
"'gkill'"
"'grep'"
"'groups'"
"'head'"
"'hostid'"
"'hostname'"
"'id'"
"'install'"
"'join'"
"'link'"
"'ln'"
"'logname'"
"'ls'"
"'md5sum'"
"'mkdir'"
"'mkfifo'"
"'mknod'"
"'mktemp'"
"'mv'"
"'nice'"
"'nl'"
"'nohup'"
"'nproc'"
"'numfmt'"
"'od'"
"'paste'"
"'pathchk'"
"'pinky'"
"'pr'"
"'printenv'"
"'printf'"
"'ptx'"
"'pwd'"
"'readlink'"
"'realpath'"
"'rm'"
"'rmdir'"
"'runcon'"
"'sed'"
"'seq'"
"'sha1sum'"
"'sha224sum'"
"'sha256sum'"
"'sha384sum'"
"'sha512sum'"
"'shred'"
"'shuf'"
"'sleep'"
"'sort'"
"'split'"
"'stat'"
"'stdbuf'"
"'stty'"
"'sum'"
"'sync'"
"'tac'"
"'tail'"
"'tee'"
"'test'"
"'timeout'"
"'touch'"
"'tr'"
"'true'"
"'truncate'"
"'tsort'"
"'tty'"
"'uname'"
"'unexpand'"
"'uniq'"
"'unlink'"
"'users'"
"'vdir'"
"'wc'"
"'who'"
"'whoami'"
"'yes'"
)
for coreutil in "${coreutils_array[@]}"; do
if echo "$diff" | grep -q "$coreutil"; then
found_coreutils+=" $coreutil"
fi
done
if [ "$found_coreutils" ]; then
echo -e '\033[31m(ERROR)\033[0m: Seems that you are trying to add an Unix-specific dependency to be called by Meson.'
echo " Please, port to Python (which is crossplatform), your use of:${found_coreutils}."
exit 1
fi
echo 'Meson .build files are alright regarding crossplatform.'
exit 0

View file

@ -24,13 +24,13 @@ git fetch --shallow-since="$(date --date="${ancestor_horizon} days ago" +%Y-%m-%
# fall back to `${CI_DEFAULT_BRANCH}` or `${CI_COMMIT_BRANCH}` respectively
# otherwise.
# add mr-origin
git remote add mr-origin ${CI_MERGE_REQUEST_SOURCE_PROJECT_URL}
# add patch-origin
git remote add patch-origin ${CI_MERGE_REQUEST_SOURCE_PROJECT_URL:-${CI_PROJECT_URL}}
source_branch="${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:-${CI_COMMIT_BRANCH}}"
git fetch --shallow-since="$(date --date="${ancestor_horizon} days ago" +%Y-%m-%d)" mr-origin "${source_branch}" &> ./fetch_origin.log
git fetch --shallow-since="$(date --date="${ancestor_horizon} days ago" +%Y-%m-%d)" patch-origin "${source_branch}" &> ./fetch_origin.log
newest_common_ancestor_sha=$(diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "upstream/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}") <(git rev-list --first-parent "mr-origin/${source_branch}") | head -1)
newest_common_ancestor_sha=$(diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "upstream/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}") <(git rev-list --first-parent "patch-origin/${source_branch}") | head -1)
if [ -z "${newest_common_ancestor_sha}" ]; then
echo "Couldnt find common ancestor with upstream main branch. This typically"
echo "happens if you branched from main a long time ago. Please update"