mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
gitlab: Add soft check against bashisms
Even .sh (Unix) scripts being "forbidden" by us on Meson to allowing GIMP being 100% natively built on Windows, it is a good pratice anyway .sh being portable even outside Meson.
This commit is contained in:
parent
073a7a208f
commit
aa10583576
2 changed files with 42 additions and 14 deletions
|
@ -601,8 +601,8 @@ meson-health:
|
||||||
- <<: *CI_COMMIT
|
- <<: *CI_COMMIT
|
||||||
stage: analysis
|
stage: analysis
|
||||||
script:
|
script:
|
||||||
- apt-get update
|
- apt-get update -qq
|
||||||
- apt-get install -y git
|
- apt-get install -qq -y --no-install-recommends git shellcheck devscripts
|
||||||
- sh .gitlab/run_meson_health_diff.sh
|
- sh .gitlab/run_meson_health_diff.sh
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
. .gitlab/search-common-ancestor.sh
|
. .gitlab/search-common-ancestor.sh
|
||||||
|
|
||||||
|
|
||||||
|
# CHECK SCRIPTS RUNNED BY MESON (ALL OSes)
|
||||||
|
printf "\e[0Ksection_start:`date +%s`:nonunix_test[collapsed=false]\r\e[0KChecking for non-Unix compatibility\n"
|
||||||
diff=$(git diff -U0 --no-color "${newest_common_ancestor_sha}" -- '*.build' '*.py' | grep -E '^\+[^+]' | sed 's/^+//')
|
diff=$(git diff -U0 --no-color "${newest_common_ancestor_sha}" -- '*.build' '*.py' | grep -E '^\+[^+]' | sed 's/^+//')
|
||||||
|
|
||||||
|
## List of commonly used utilities on Unix world
|
||||||
#List of commonly used utilities on Unix world
|
## See the context: https://gitlab.gnome.org/GNOME/gimp/-/issues/11385
|
||||||
#See the context: https://gitlab.gnome.org/GNOME/gimp/-/issues/11385
|
|
||||||
coreutils_list="
|
coreutils_list="
|
||||||
\.sh \
|
\.sh \
|
||||||
'sh' \
|
'sh' \
|
||||||
|
@ -125,20 +127,18 @@ coreutils_list="
|
||||||
'whoami' \
|
'whoami' \
|
||||||
'yes'
|
'yes'
|
||||||
"
|
"
|
||||||
|
|
||||||
for coreutil in $coreutils_list; do
|
for coreutil in $coreutils_list; do
|
||||||
if echo "$diff" | grep -q "$coreutil"; then
|
if echo "$diff" | grep -q "$coreutil"; then
|
||||||
found_coreutils="$(echo "$found_coreutils $coreutil" | sed 's|\\||g')"
|
found_coreutils="$(echo "$found_coreutils $coreutil" | sed 's|\\||g')"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$found_coreutils" ]; then
|
if [ "$found_coreutils" ]; then
|
||||||
|
printf "$diff\n"
|
||||||
printf '\033[31m(ERROR)\033[0m: Seems that you are trying to add an Unix-specific dependency to be called by Meson.\n'
|
printf '\033[31m(ERROR)\033[0m: Seems that you are trying to add an Unix-specific dependency to be called by Meson.\n'
|
||||||
printf " Please, port to Python (which is crossplatform), your use of:${found_coreutils}.\n"
|
printf " Please, port to Python (which is crossplatform), your use of:${found_coreutils}.\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## Limited list of commonly used utilities on Windows world
|
||||||
#Limited list of commonly used utilities on Windows world
|
|
||||||
ntutils_list="
|
ntutils_list="
|
||||||
\.bat \
|
\.bat \
|
||||||
\.cmd \
|
\.cmd \
|
||||||
|
@ -146,23 +146,51 @@ ntutils_list="
|
||||||
'cmd' \
|
'cmd' \
|
||||||
'powershell'
|
'powershell'
|
||||||
"
|
"
|
||||||
|
|
||||||
for ntutil in $ntutils_list; do
|
for ntutil in $ntutils_list; do
|
||||||
if echo "$diff" | grep -q "$ntutil"; then
|
if echo "$diff" | grep -q "$ntutil"; then
|
||||||
found_ntutils="$(echo "$found_ntutils $ntutil" | sed 's|\\||g')"
|
found_ntutils="$(echo "$found_ntutils $ntutil" | sed 's|\\||g')"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$found_ntutils" ]; then
|
if [ "$found_ntutils" ]; then
|
||||||
|
printf "$diff\n"
|
||||||
printf '\033[31m(ERROR)\033[0m: Seems that you are trying to add a NT-specific dependency to be called by Meson.\n'
|
printf '\033[31m(ERROR)\033[0m: Seems that you are trying to add a NT-specific dependency to be called by Meson.\n'
|
||||||
printf " Please, port to Python (which is crossplatform), your use of:${found_ntutils}.\n"
|
printf " Please, port to Python (which is crossplatform), your use of:${found_ntutils}.\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$found_coreutils" ] && [ -z "$found_ntutils" ]; then
|
||||||
|
printf '(INFO): Meson .build and .py files are alright regarding being crossplatform.\n'
|
||||||
|
fi
|
||||||
|
printf "\e[0Ksection_end:`date +%s`:nonunix_test\r\e[0K\n"
|
||||||
|
|
||||||
if [ "$found_coreutils" ] || [ "$found_ntutils" ]; then
|
|
||||||
echo "$diff"
|
# CHECK SCRIPTS NOT RUN BY MESON (UNIX ONLY)
|
||||||
|
# Shell scripts have potential portability issues if:
|
||||||
|
# 1) contain bash shebang or are called by bash;
|
||||||
|
# 2) contain bashisms.
|
||||||
|
printf "\e[0Ksection_start:`date +%s`:unix_test[collapsed=false]\r\e[0KChecking for Unix portability (optional)\n"
|
||||||
|
diff=$(git diff -U0 --no-color "${newest_common_ancestor_sha}" | grep -E '^\+[^+]' | sed 's/^+//')
|
||||||
|
|
||||||
|
## Check shebang and external call (1)
|
||||||
|
echo "$diff" | grep -E '^#!\s*/usr/bin/env\s+bash|^#!\s*/(usr/bin|bin)/bash(\s|$)' && found_bashism='extrinsic_bashism'
|
||||||
|
echo "$diff" | grep -E "bash\s+.*\.sh" && found_bashism='extrinsic_bashism'
|
||||||
|
|
||||||
|
## Check content with shellcheck and checkbashisms (2)
|
||||||
|
for sh_script in $(find "$CI_PROJECT_DIR" -type d -name .git -prune -o -type f \( ! -name '*.ps1' ! -name '*.c' -exec grep -lE '^#!\s*/usr/bin/env\s+(sh|bash)|^#!\s*/(usr/bin|bin)/(sh|bash)(\s|$)' {} \; -o -name '*.sh' ! -exec grep -q '^#!' {} \; -print \)); do
|
||||||
|
shellcheck --severity=warning --shell=sh -x "$sh_script" | grep -v 'set option posix is' | grep -vE '.*http.*SC[0-9]+.*POSIX' | grep --color=always -B 2 -E 'SC[0-9]+.*POSIX' && found_bashism='intrinsic_bashism'
|
||||||
|
checkbashisms -f $sh_script || found_bashism='intrinsic_bashism'
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$found_bashism" ]; then
|
||||||
|
printf '\033[33m(WARNING)\033[0m: Seems that you added a Bash-specific code (aka "bashism").\n'
|
||||||
|
printf " It is recommended to make it POSIX-compliant (which is portable).\n"
|
||||||
|
else
|
||||||
|
printf '(INFO): Shell .sh files are alright regarding being portable.\n'
|
||||||
|
fi
|
||||||
|
printf "\e[0Ksection_end:`date +%s`:unix_test\r\e[0K\n"
|
||||||
|
|
||||||
|
|
||||||
|
if [ "$found_coreutils" ] || [ "$found_ntutils" ] || [ "$found_bashism" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf 'Meson .build files are alright regarding crossplatform.\n'
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue