Bug 14480 - cannot use helper functions
Summary: cannot use helper functions
Status: RESOLVED NOTABUG
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Undecided normal
Target Milestone: ---
Assignee: Richard Purdie
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2021-07-14 13:29 UTC by Frans Meulenbroeks
Modified: 2021-07-15 14:49 UTC (History)
3 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Don't know


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frans Meulenbroeks 2021-07-14 13:29:46 UTC
According to https://www.yoctoproject.org/docs/1.6/bitbake-user-manual/bitbake-user-manual.html#shell-functions I can call other shell functions

However this did not work

do_install_prepend_jetson-nano-emmc() {
        install -d ${D}/etc
        install -d ${D}/etc/network
        install -m 0640 ${WORKDIR}/interfaces_nano ${D}/etc/network/interfaces
}

do_install_prepend_jetson-nano-devkit-emmc() {
        do_install_prepend_jetson-nano-emmc
}

Idea here was to use the same code for two different machines

The dump dumps all the environment. In the beginning it says

Traceback (most recent call last):
  File "/workdir/poky/bitbake/lib/bb/siggen.py", line 150, in SignatureGeneratorOEEquivHash._build_data(fn='/workdir/layers/myrecipe.bb', d=<bb.data_smart.DataSmart object at 0x7fd122baf6a0>):
             ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or '') == '1')
    >        tasklist, gendeps, lookupcache = bb.data.generate_dependencies(d, self.basewhitelist)

Then there is the env; at the end there is:

                     parser = bb.codeparser.ShellParser(key, logger)
    >                parser.parse_shell(parsedvar.value)
                     deps = deps | shelldeps
  File "/workdir/poky/bitbake/lib/bb/codeparser.py", line 343, in ShellParser.parse_shell(value=None):

    >        self._parse_shell(value)
             self.execs = set(cmd for cmd in self.allexecs if cmd not in self.funcdefs)
  File "/workdir/poky/bitbake/lib/bb/codeparser.py", line 354, in ShellParser._parse_shell(value=None):
             except Exception:
    >            bb.error('Error during parse shell code, the last 5 lines are:\n%s' % '\n'.join(value.split('\n')[-5:]))
                 raise
AttributeError: 'NoneType' object has no attribute 'split'


I've no idea is this is an issue in bitbake or in the documentation or in poky
(btw this is on dunfell)
Comment 1 Ross Burton 2021-07-15 14:49:50 UTC
The problem is that you're using overrides, so what you're entering into the recipe isn't what actually gets evaluated.

do_install_prepend_jetson-nano-emmc means "prepend this body to do_install if jeson-nano-emmc is in OVERRIDES".  At no point is there a shell function called do_install_prepend_jetson-nano-emmc.  Also, - isn't valid in shell functions so even if it was exposed in shell, it wouldn't have that name.

If you want to refactor your recipe to have common fragments then write explicit shell functions for those:

install_interfaces() {
        install -d ${D}/etc
        install -d ${D}/etc/network
        install -m 0640 ${WORKDIR}/interfaces_nano ${D}/etc/network/interfaces
}

do_install_prepend_jetson-nano-emmc() {
        install_interfaces
}

do_install_prepend_jetson-nano-devkit-emmc() {
        install_interfaces
}