bamos
bamos

Reputation: 556

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:

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

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

Upvotes: 4

Views: 5314

Answers (1)

bamos
bamos

Reputation: 556

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

Upvotes: 3

Related Questions