Search code examples
yoctobitbake

how to get ${THISDIR} inside do_unpack_append in .bbappend file


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()?


Solution

  • The key point is to expand the THISDIR variable immediately during the parse of the .bbappend file using the := operator.

    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