Bitbake recipe not applying patch as expected

aicastell picture aicastell · Mar 16, 2016 · Viewed 8.7k times · Source

I have a tarball src.tar.gz whose contents are unpacked into src/ and a patch of this sources generated with this command:

$ diff -Nurp src/ src_mod/ > my.patch

The patch header starts with this three lines:

 diff -Nurp src/path/to/file src_PATCHED/path/to/file
 --- src/path/to/file  2012-10-22 05:52:59.000000000 +0200
 +++ src_PATCHED/path/to/file  2016-03-14 12:27:52.892802283 +0100

My bitbake recipe references both path and tarball files using this SRC_URI:

SRC_URI = " \
    file://my.patch \
    file://src.tar.gz \
"

do_fetch and do_unpack tasks work as expected, leaving my.patch and src/ inside ${S} directory, that is:

${S}/my.path
${S}/src.tar.gz

But do_patch task is failing with this ERROR message:

ERROR: Command Error: exit status: 1  Output:
Applying patch my.patch
can't find file to patch at input line 4
Perhaps you used the wrong -p or --strip option?

I have tested different alternatives, for example setting "patchdir" attribute like showed below:

SRC_URI = " \
    file://my.patch;patchdir=${S}/src \
    file://src.tar.gz \
"

I expected "patchdir" being the same as using "patch -d dir". But it doesn't work as expected, it always returns the same ERROR message.

What I am doing wrong?

Answer

aicastell picture aicastell · Mar 16, 2016

My variable ${S} was re-defined inside my recipe with this content:

S = "${WORKDIR}/${PN}-${PV}"

But the fetchers downloads my.patch and src/ inside ${WORKDIR}, not inside ${S} directory, so:

${WORKDIR}/my.path
${WORKDIR}/src.tar.gz

And tarball was also extracted inside ${WORKDIR}

${WORKDIR}/src/

The fix was setting "patchdir" attribute properly, replacing ${S} by ${WORKDIR}

SRC_URI = " \
    file://my.patch;patchdir=${WORKDIR}/src \
    file://src.tar.gz \
"

That is already working!