From 3477bd1e134af033d6c0e273b68e8d2c9dae374d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 8 Nov 2022 18:00:19 +0000 Subject: [PATCH] macros: Move patch script into macros We no longer have a way to copy any scripts into the build environment, but we can simply embed them. Signed-off-by: Michael Tremer --- Makefile.am | 1 - macros/build.macro | 84 +++++++++++++++++++++++++++++++++++++++++++++- src/scripts/patch | 82 -------------------------------------------- 3 files changed, 83 insertions(+), 84 deletions(-) delete mode 100644 src/scripts/patch diff --git a/Makefile.am b/Makefile.am index f5de8ec5d..da8ac0e85 100644 --- a/Makefile.am +++ b/Makefile.am @@ -707,7 +707,6 @@ dist_scripts_SCRIPTS = \ src/scripts/find-prerequires \ src/scripts/find-provides \ src/scripts/find-requires \ - src/scripts/patch \ src/scripts/perl.prov \ src/scripts/perl.req \ src/scripts/py-compile \ diff --git a/macros/build.macro b/macros/build.macro index 2251074d6..dc79cc9ad 100644 --- a/macros/build.macro +++ b/macros/build.macro @@ -71,7 +71,89 @@ def MACRO_FIX_AUTOTOOLS fi end -MACRO_PATCHES = /usr/lib/pakfire/patch --search-path=%{DIR_PATCHES} "%{patches}" +def MACRO_PATCHES + __patch() { + local paths=() + local path + local patches=() + local patch + + while [ $# -gt 0 ]; do + case "${1}" in + --search-path=*) + paths+=( "${1#--search-path=}" ) + ;; + *) + patches+=( "${1}" ) + ;; + esac + shift + done + + # Apply all patches given on command line. + for patch in ${patches[@]}; do + case "${patch}" in + /*) + ;; + *) + for path in ${paths[@]}; do + if [ -e "${path}/${patch}" ]; then + patch="${path}/${patch}" + break + fi + done + ;; + esac + + # Check if patch file does exist. + if ! [ -e "${patch}" ]; then + echo >&2 " ERROR: Patch file does not exist: ${patch}" + return 1 + fi + + # Options applied to patch command. + options="-N" + + # Get right -p1 option. + case "${patch}" in + *.patch[0-9]|*.patch[0-9]R) + _patch="${patch}" + # Get patch level from file name. + while [ ${#_patch} -gt 0 ]; do + last_pos=$(( ${#_patch} - 1 )) + last_char=${_patch:${last_pos}} + _patch=${_patch:0:${last_pos}} + + case "${last_char}" in + [0-9]) + options="${options} -p${last_char}" + break + ;; + R) + options="${options} -R" + ;; + esac + done + ;; + *.patch|*.diff) + # Default is -p1. + options="${options} -p1" + ;; + *) + echo >&2 " WARNING: Ignoring unknown file: ${patch}" + continue + ;; + esac + + echo " Applying ${patch} (${options})..." + patch ${options} -i ${patch} || return $? + done + + return 0 + } + + __patch --search-path=%{DIR_PATCHES} "%{patches}" +end # Pre-defined build scripts. build diff --git a/src/scripts/patch b/src/scripts/patch deleted file mode 100644 index 4d4c2ae57..000000000 --- a/src/scripts/patch +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash -# Script that automatically applies patches. - -paths= -patches= - -while [ $# -gt 0 ]; do - case "${1}" in - --search-path=*) - paths="${paths} ${1#--search-path=}" - ;; - *) - patches="${patches} ${1}" - ;; - esac - shift -done - -if [ -n "${patches}" ]; then - echo "Applying patches..." -fi - -# Apply all patches given on command line. -for patch in ${patches}; do - case "${patch}" in - /*) - ;; - *) - for path in ${paths}; do - if [ -e "${path}/${patch}" ]; then - patch="${path}/${patch}" - break - fi - done - ;; - esac - - # Check if patch file does exist. - if ! [ -e "${patch}" ]; then - echo >&2 " ERROR: Patch file does not exist: ${patch}" - exit 1 - fi - - # Options applied to patch command. - options="-N" - - # Get right -p1 option. - case "${patch}" in - *.patch[0-9]|*.patch[0-9]R) - _patch="${patch}" - # Get patch level from file name. - while [ ${#_patch} -gt 0 ]; do - last_pos=$(( ${#_patch} - 1 )) - last_char=${_patch:${last_pos}} - _patch=${_patch:0:${last_pos}} - - case "${last_char}" in - [0-9]) - options="${options} -p${last_char}" - break - ;; - R) - options="${options} -R" - ;; - esac - done - ;; - *.patch|*.diff) - # Default is -p1. - options="${options} -p1" - ;; - *) - echo >&2 " WARNING: Ignoring unknown file: ${patch}" - continue - ;; - esac - - echo " Applying ${patch} (${options})..." - patch ${options} -i ${patch} || exit $? -done - -exit 0 -- 2.39.5