Bug 14670 - Promoting a Function to a Task: example is wrong
Summary: Promoting a Function to a Task: example is wrong
Status: RESOLVED FIXED
Alias: None
Product: BitBake User Manual
Classification: Documentation
Component: bitbake-manual (show other bugs)
Version: 4.1
Hardware: x86 Multiple
: Medium+ normal
Target Milestone: 5.2 M4
Assignee: Antonin Godard
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2021-12-21 09:57 UTC by Robert Berger
Modified: 2025-04-11 08:39 UTC (History)
2 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Yes (doc changes required)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Berger 2021-12-21 09:57:04 UTC
https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-metadata.html#promoting-a-function-to-a-task

Bitbake does not like this python task - we should at least try to show valid examples ;)

python do_printdate () {
    import time
    print time.strftime('%Y%m%d', time.gmtime())
}
addtask printdate after do_fetch before do_build

Not sure what exactly we'll try to show here but maybe it is more like this:

    python do_printdate () {
-       import time
-       print time.strftime('%Y%m%d', time.gmtime())
+       import datetime
+       bb.plain('Date: %s' % (datetime.date.today()))
    }
    addtask printdate after do_fetch before do_build

With bb.plain it shows up in the cooker shell and not just in some log file like with print. This would of course need additional explanations.

In case we would like to show even more maybe something like this, or a subset of it:

# this is a python task:
python do_printdate () {
    import datetime
    # goes to cooker shell:
    bb.warn('py: --> S: %s <--' % (d.getVar("S", True)))
    bb.plain('py: Date: %s' % (datetime.date.today()))
    # goes to log:
    print(datetime.datetime.now())
    print(datetime.date.today())
    # goes to cooker shell:
    bb.plain("py: Check the logs!")
    bb.plain('py: this log file: %s/log.do_printdate' % (d.getVar("T", True)))
}
addtask do_printdate after do_compile before do_install

Please advise how the example should look like.
Comment 1 Randy MacLeod 2024-10-24 15:03:56 UTC
Bulk move of 5.1 M4 to 5.2 M2 as approved by AlexB.
Comment 2 Antonin Godard 2025-04-11 08:39:23 UTC
Fixed with commit https://git.openembedded.org/bitbake/commit/?id=874c607f475f3d60677d2720b80a28d0c2e963c6.

Moving to Resolved Fixed.