From dcea6ce7632da2c290c28da2e1aa5ef3c7ac1eb8 Mon Sep 17 00:00:00 2001 From: Agent00Ming <107314235+Agent00Ming@users.noreply.github.com> Date: Fri, 19 Apr 2024 22:24:20 -0400 Subject: [PATCH] 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 --- meson.build | 4 ++++ patches/apply.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 patches/apply.sh diff --git a/meson.build b/meson.build index c2e408bb..e1f690c3 100644 --- a/meson.build +++ b/meson.build @@ -80,6 +80,8 @@ else ) endif +patching = run_command('./patches/apply.sh', capture: true, check: true) + features = { 'drm-backend': false, 'x11-backend': false, @@ -204,3 +206,5 @@ pkgconfig.generate( url: 'https://gitlab.freedesktop.org/wlroots/wlroots', variables: wlr_vars, ) + +message(patching.stdout().strip()) diff --git a/patches/apply.sh b/patches/apply.sh new file mode 100755 index 00000000..280f72d6 --- /dev/null +++ b/patches/apply.sh @@ -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