'meson find_program() not finding python program in yocto environment

I have an external application that converted to an exe using pyinstaller. This needs to be added in yocto framework. But the application has a dependency on pylint & pyinstaller. pylint is already part of yocto framework. I used meson.build file in my application and have a recipe file in yocto that will source the entire application from git repo and builds using instructions in meson.build. In my application meson build file uses find_program() to find pylint program installation. It works currently on my laptop, but when I build my application recipe in yocto environment, it is unable to find pylint. Even though I added "python3-pylint" in IMAGE_INSTALL_append.

| Program python3 found: YES (.../usr/bin/python3-native/python3)
| Program python3 (pylint) found: NO
|
| ../git/src/meson.build:10:0: ERROR: python3 is missing modules: pylint

pyinst = find_program('pylint') // as per meson this is probably searching in /usr/local/bin. But this is not the case in yocto. How can I modify find_program() call to find this in the right location in yocto framework. Or is there any method to handle this?

meson.build under source file folder:

# get & run pylint to check for errors
prog = import('python').find_installation('python3', modules: ['pylint'])
if not prog.found()
    message('pylint not found')
else
    message(prog.path())
    cmd = find_program('pylint', prog.path())
    message('Running pylint on src files')
    foreach each : src_files
        run_command(cmd, '--confidence=HIGH', each)
    endforeach
endif

project's meson.build

project('proj_name', 
    ['cpp'],
    version : '0.1',
    license : 'MIT',
    default_options: [
            'cpp_std=c++11']
)

project_pretty_name = 'proj_name'
project_url = '<git repo of project>'

python = import('python')
python3 = python.find_installation('python3', required: false)
 
subdir('src')
subdir('tools') # cpp tools
subdir('build')

yocto recipe file:

inherit meson pkgconfig python3native

DEPENDS += "${PYTHON_PN}-distro-native"
DEPENDS += "zlib"

RDEPENDS:${PN} += "${PYTHON_PN}-requests \
                   ${PYTHON_PN}-pylint"                

SRC_URI += "<git branch>"
SRCREV = "<src-rev>"
S = "${WORKDIR}/git"

FILES:${PN}:append = " ${bindir}/mesonexe"


Solution 1:[1]

Your Meson build requires pylint to be available during compilation, therefore you need to add:

DEPENDS += "${PYTHON_PN}-pylint-native"

and then you will need to ensure the pylint recipe is available in one of your configured Yocto layers. It's in meta-openembedded/meta-python.

Finally, the python3-pylint recipe and one of its dependencies (python3-astroid) do not have native support enabled, so you'll need to create the followin .bbappends as well:

# python3-pylint_%.bbappend
BBCLASSEXTEND += "native"
# python3-astroid_%.bbappend
BBCLASSEXTEND += "native"

You should then see the following line in the Meson output:

Program pylint found: YES (.../recipe-sysroot-native/usr/bin/pylint)

As a suggestion - if this recipe is building your own source code, I'd suggest linting the code as it is pushed into the repository (via a CI job), rather than at compile-time. This will reduce the dependencies required to build your project.

Of course, there would still be an optional Meson target for developers to lint their code before they push new code. Perhaps something that is enabled for non-release builds by default.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 justinsg