3
votes

I'm attempting to replace a file from another layer with a .bbappend file. My goal is to overwrite a specific configuration file with a customized one during the unpack stage.

In my .bbappend I'm attempting to append the do_unpack to copy a file from the same directory as the .bbappend file into the working directory ${WORKDIR} The problem is: When inside do_unpack_append, ${THISDIR} is returning the directory of the original .bb recipe, rather than the directory of .bbappend

Here's an example:

  • The original recipe resides in: meta-origLayer/recipe.bb
  • My *.bbappend resides in: meta-newLayer/recipe.bbappend

recipe.bbappend:

`FILESEXTRAPATHS_prepend := "${THISDIR}:"`
do_unpack_append(){
    bb.build.exec_func('replace_file', d)
}

replace_file(){
    cp -f ${THISDIR}/fileToBeReplaced ${WORKDIR}/fileToBeReplaced
    echo ${THISDIR} > ${WORKDIR}/shouldContain_meta-newLayer
}

There are two issues with recipe.bbappend:

  1. I would expect the file shouldContain_meta-newLayer to contain meta-newLayer, but instead it contains meta-origLayer.
    I'd primarily like to understand why ${THISDIR} behaves differently when placed inside do_unpack_append() from when it is used for prepending FILESEXTRAPATHS
  2. When running bitbake, the recipe fails, producing the following error:

cp: cannot stat '/fileToBeReplaced': No such file or directory

  • This error occurs because fileToBeReplaced resides in a subdirectory of meta-origLayer (i.e. meta-origLayer/machine1/fileToBeReplaced) and the .bbappend expects to find the file in /fileToBeReplaced

My Question. . .

I have assumed ${THISDIR} would behave consistently within the same .bbappend, but it doesn't appear to. What is the best way to reference meta-newLayer/fileToBeReplaced from within do_unpack_append()?

1
${THISDIR} is only stable during parse time. You need to immediately-assign it to another variable outside tasks, like THISDIRSAVED := "${THISDIR}". The "correct" (?) way is to add your file to SRC_URI (use _append/_prepend, possibly including your machine, target-os or distribution, whatever is most appropriate, like _append_supercomputer = " work-on-1petabyte.patch"). That way, your file's checkum can be analyzed and added to the tasks, so if the input file changes, yocto knows when to reexecute do_unpack. In do_unpack, you could then replace whatever file you want. - Johannes Schaub - litb
So it turns out I was missing two major components: SRC_URI_append and the saved copy of ${THISDIR} being the second. I was thinking that since the parent recipe already included SRC_URI for fileToBeReplaced I didn't need to add it again in the *.bbappend (as you point out, a rebuild isn't properly triggered if SRC_URI isn't present in the bbappend). Thanks! - bamos

1 Answers

2
votes

This *.bbappend correctly overwrites fileToBeReplaced in the working directory during the unpack task:

FILESEXTRAPATHS_prepend := "${THISDIR}:"
SRC_URI_append += " file://fileToBeReplaced "
SAVED_DIR := "${THISDIR}"

do_unpack_append(){
    bb.build.exec_func('replace_file', d)
}

replace_file(){
    cp -f ${SAVED_DIR}/fileToBeReplaced ${WORKDIR}/fileToBeReplaced
}

Thanks for the explanation between bbappend parsing and execution johannes-schaub-ltb