yoctobitbakeyocto-recipe

Building a recipe fails on Yocto styhead because Bitbake doesn't move the source file


My recipe build fails and I don't know why. Here is the command I type:

bitbake example1

Then I got these error logs:

Loading cache: 100% |#################################################################| Time: 0:00:00
Loaded 245 entries from dependency cache.
Parsing recipes: 100% |################################################################################################| Time: 0:01:11
Parsing of 920 .bb files complete (123 cached, 797 parsed). 1875 targets, 70 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "2.9.1"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "arm-poky-linux-gnueabi"
MACHINE              = "beaglebone-yocto"
DISTRO               = "poky"
DISTRO_VERSION       = "5.1"
TUNE_FEATURES        = "arm vfp cortexa8 neon callconvention-hard"
TARGET_FPU           = "hard"
meta                 
meta-poky            
meta-yocto-bsp       
workspace            
meta-mylayer         = "master:e72d641a9988976ca9144ca3fd8f9a9988d3bdc5"

Checking sstate mirror object availability: 100% |#####################################################################| Time: 0:00:11
Sstate summary: Wanted 126 Local 0 Mirrors 116 Missed 10 Current 150 (92% match, 96% complete)
NOTE: Executing Tasks
WARNING: example1-1.0-r0 do_unpack: example1: the directory ${WORKDIR}/${BP} (/home/user/Projects/yocto/sources/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/example1/1.0/example1-1.0) pointed to by the S variable doesn't exist - please set S within the recipe to point to where the source has been unpacked to
ERROR: example1-1.0-r0 do_compile: Execution of '/home/user/Projects/yocto/sources/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/example1/1.0/temp/run.do_compile.2977111' failed with exit code 1
ERROR: Logfile of failure stored in: /home/user/Projects/yocto/sources/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/example1/1.0/temp/log.do_compile.2977111
Log data follows:
| DEBUG: Executing shell function do_compile
| cc1: fatal error: /home/user/Projects/yocto/sources/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/example1/1.0/example1.c: No such file or directory
| compilation terminated.
| WARNING: exit code 1 from a shell command.
ERROR: Task (/home/user/Projects/yocto/poky/meta-mylayer/recipes-example/example/example1.bb:do_compile) failed with exit code '1'
NOTE: Tasks Summary: Attempted 833 tasks of which 823 didn't need to be rerun and 1 failed.

Summary: 1 task failed:
  /home/user/Projects/yocto/poky/meta-mylayer/recipes-example/example/example1.bb:do_compile
    log: /home/user/Projects/yocto/sources/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/example1/1.0/temp/log.do_compile.2977111
Summary: There was 1 WARNING message.
Summary: There was 1 ERROR message, returning a non-zero exit code.

Here is my recipe:

meta-mylayer/recipes-example/example/example1.bb

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://example1.c"

do_compile() {
  ${CC} ${FLAGS} ${LDFLAGS} ${WORKDIR}/example1.c -o example1
}

do_install() {
  install -d ${D}/${bindir}
  install -m 0755 ${S}/example1 ${D}/${bindir}
}

meta-mylayer/recipes-example/example/files/example1.c

#include <stdio.h>

int main() {
  printf("Hello world");

  return 0;
}

It seems the problem is just that bitbake can't find example1.c but I thought meta-mylayer/recipes-example/example/files was the right place to put it. So I don't really understand what's wrong.

I read several times the 3 Understanding and Creating Layers chapter in the Development Tasks Manual especially the 3.1 Creating Your Own Layer section, but I didn't find a solution.

A workaround I found

By chance I managed to build the recipe by adding this task in example1.bb, but I guess it's not the correct way to fix the problem

do_unpack() {
  cp /home/user/Projects/yocto/poky/meta-mylayer/recipes-example/example/files/example1.c /home/user/Projects/yocto/sources/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/example1/1.0
}

EDIT : I retried to compile the recipe because I was on a specific commit. So I did checkout on the current styhead stable release (e72d641a9988976ca9144ca3fd8f9a9988d3bdc5) and now I have a warning :

WARNING: example1-1.0-r0 do_unpack: example1: the directory ${WORKDIR}/${BP} (/home/user/Projects/yocto/sources/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/example1/1.0/example1-1.0) pointed to by the S variable doesn't exist - please set S within the recipe to point to where the source has been unpacked to

Solution

  • I ran into this : https://docs.yoctoproject.org/next/migration-guides/migration-5.1.html#general-notes

    "Files from do_unpack now unpack to WORKDIR/sources-unpack/ rather than WORKDIR/."

    That's why bitbake doesn't find example1.c. The source files are now just moved to WORKDIR/sources-unpack since styhead release.

    Apparently, the Yocto developers now recommend to write the following in recipes :

    S = "${WORKDIR}/sources"
    UNPACKDIR = "${S}"
    

    This prevents the source files from being moved to WORKDIR/sources-unpack and instead places them directly in WORKDIR/sources. As a result, the WORKDIR/sources-unpack directory becomes unnecessary.

    At the end, the final solution is :

    meta-mylayer/recipes-example/example/example1.bb

    LICENSE = "MIT"
    LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
    
    SRC_URI = "file://example1.c"
    
    S = "${WORKDIR}/sources"
    UNPACKDIR = "${S}"
    
    do_compile() {
      ${CC} ${FLAGS} ${LDFLAGS} ${WORKDIR}/sources/example1.c -o ${WORKDIR}/example1
    }
    
    do_install() {
      install -d ${D}/${bindir}
      install -m 0755 ${WORKDIR}/example1 ${D}/${bindir}
    }