Search code examples
python-3.xlinuxyoctobitbake

How to transfer python3-flask project into yocto image?


I am a beginner in yocto. Till now i have learnt about how to build a yocto image and add recipes through layers.openembedded. But i am not able to figure out e.g. i have developed a python3-flask project in my PC and then i want to copy/transfer that project into my yocto os. how can i do that? do i have to make something like executable of that project and then copy that into my os using some recipe?

I have seen this recipe but i am not able to understand what does LIC_FILES_CHSUM means and where to get it? where should i put these file e.g. setup.py? in the same directory as my .bb file? and on building where my project would be copied in the yocto os?

DESCRIPTION = "Simple Python setuptools hello world application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://setup.py \
           file://python-helloworld.py \
           file://helloworld/__init__.py \
           file://helloworld/main.py"

S = "${WORKDIR}"

inherit setuptools

do_install_append () {
    install -d ${D}${bindir}
    install -m 0755 python-helloworld.py ${D}${bindir}
}

Solution

  • The LICENSE field should obviously correspond to the license you picked for your SW. LIC_FILES_CHKSUM needs a file that holds the actual license defined in LICENSE and its md5sum passed as an "argument". It is just a way to monitor if the license ever changes. Then its md5sum changes and then the recipe fail to build because the license probably changed and requires the maintainer's attention.

    THISDIR being the directory containing the recipe (not exactly but enough for the example), files in SRC_URI will be searched for in FILESPATH (which is first ${THISDIR}/<recipe_name>-<recipe_version> then ${THISDIR}/<recipe-name> then ${THISDIR}/files). So you need to put files (the ones starting with file://) declared in SRC_URI into one of those directories.

    Best would actually to have your SW in a git repo somewhere. This better follows the philosophy of having SW source code separate from your build system (what if you decide you want to use a different build system later?).

    When you're wondering what some variables or tasks are doing, I highly recommend looking them up on the mega manual: https://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html. This works extremely well as a "dictionary". The documentation is great albeit dense and long but it is rare not to found what you look for as a beginner.

    Update

    LIC_FILES_CHKSUM can be found in yocto meta/files/common-licenses in the Source Directory. You can also take your own license and check the checksum with md5sum filename and copy that to bb file. If your SW is to be distributed, it is highly recommended to have the license mentioned somewhere in your sources. So better use that part of the code in LIC_FILES_CHKSUM than using the ones in ${COMMON_LICENSE_DIR} so that people will know if and when there is a license change in your project.

    The below recipe works fine and you can find your app in /usr/bin directory.

    DESCRIPTION = "Simple Python setuptools  application"
    SECTION = "examples"
    LICENSE = "MIT"
    LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
    
    SRC_URI = "file://setup.py \
            file://packagetest.py \
            file://example/__init__.py \
            file://example/file1.py \
            file://example/file2.py \
            file://example/file3.py"
    
    S = "${WORKDIR}"
    
    inherit pypi setuptools3
    
    do_install_append () {
        install -d ${D}${bindir}
        install -m 0755 packagetest.py ${D}${bindir}
    }