meson: Run patches on setup (#7)

* Add patching script with error checking+reporting
	new file:   patches/apply.sh

* Run patching script with run_command() at setup
and print the output with message() at the end
	modified:   meson.build

* Report on patch application failure and exit script with code 1
	modified:   patches/apply.sh

---------

Co-authored-by: Agent_00Ming <agent00ming9366@gmail.com>
This commit is contained in:
Agent00Ming 2024-04-19 22:24:20 -04:00 committed by GitHub
parent 611a4f24cd
commit dcea6ce763
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View file

@ -80,6 +80,8 @@ else
) )
endif endif
patching = run_command('./patches/apply.sh', capture: true, check: true)
features = { features = {
'drm-backend': false, 'drm-backend': false,
'x11-backend': false, 'x11-backend': false,
@ -204,3 +206,5 @@ pkgconfig.generate(
url: 'https://gitlab.freedesktop.org/wlroots/wlroots', url: 'https://gitlab.freedesktop.org/wlroots/wlroots',
variables: wlr_vars, variables: wlr_vars,
) )
message(patching.stdout().strip())

32
patches/apply.sh Executable file
View file

@ -0,0 +1,32 @@
#!/bin/bash
# find all patches in patches/
PATCHES=$(find patches/ -type f -name '*.patch')
check () {
git apply --check -q -p1 $PATCH
}
apply () {
git apply -p1 $PATCH
}
check_applied () {
git apply --check --reverse -q -p1 $PATCH
}
fail () {
echo =======\> \'$PATCH\' was not applied && exit 1
}
if [[ -n "$PATCHES" ]];
then
# check patch validity and apply, else check if already applied and report and exit on failure
echo 'Patches found. Applying...';
for PATCH in $PATCHES;
do
check && apply || check_applied || fail;
done
else
echo 'No patches found.'
fi