[Exherbo-dev] expatch and default_src_prepare

Bo Ørsted Andresen bo.andresen at zlin.dk
Mon Feb 18 14:13:17 GMT 2008


As discussed on irc a wrapper for patch that doesn't suck would be nice. I
hence propose we add the following expatch function to exheres-0 in
paludis/repositories/e/ebuild/exheres-0/build_functions.bash:

expatch()
{
    if [[ "${EBUILD_PHASE}" != "prepare" ]] ; then
        die "epatch called in EBUILD_PHASE ${EBUILD_PHASE}"
    fi

    local recognise= patchlevel= options=() cmd=

    if [[ ${1} == "--recognised-suffixes" ]]; then
        recognise=true
        shift
    fi

    while [[ -n ${1} ]]; do
        if [[ ${1} == -p[0-9]* ]]; then
            patchlevel="${1}"
        elif [[ ${1} == -* ]]; then
            options+=("${1}")
        elif [[ -d ${1} ]]; then
            expatch --recognised-suffixes ${patchlevel} "${options[@]}" "${1}"/*
        else
            case "${1}" in
                *.bz2)
                cmd="bzip2 -dc"
                ;;
                *.gz|*.Z|*.z)
                cmd="gzip -dc"
                ;;
                *.zip|*.ZIP|*.jar)
                cmd="unzip -p"
                ;;
                *.diff|*.patch)
                cmd="cat"
                ;;
                *)
                if [[ -n ${recognise} ]]; then
                    continue
                else
                    cmd="cat"
                fi
                ;;
            esac

            einfo "Applying ${1##*/}"
            ${cmd} "${1}" | patch -s ${patchlevel:--p1} "${options[@]}" || \
                die "patch -s ${options[@]} ${1} failed"
        fi
        shift
    done
}

If further we use this default_src_prepare:

default_src_prepare()
{
    if [[ -n "${DEFAULT_SRC_PREPARE_PATCHES[@]}" ]]; then
        expatch "${DEFAULT_SRC_PREPARE_PATCHES[@]}"
    fi
}

This will allow us to put things like e.g.:

DEFAULT_SRC_PREPARE_PATCHES=(-p0 "${FILESDIR}/foo.bleh" -p1 "${FILESDIR}/${PV}/")

in an exheres and thus have first foo.bleh applied with -p0 and then all *.diff
and *.patch files in the ${PV}/ directory applied with -p1...

-- 
Bo Andresen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.exherbo.org/mailman/private/exherbo-dev/attachments/20080218/0e70d29f/attachment.pgp 


More information about the Exherbo-dev mailing list