Bug 13205

Summary: Bitbake should warn about whitespace misuse in variable assignments
Product: [Build System, Metadata & Runtime] BitBake Reporter: Evadeflow <evadeflow>
Component: bitbakeAssignee: Unassigned <unassigned>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: Medium CC: alexandre.belloni, poky.bs.watcher, poky.watcher, randy.macleod
Version: unspecified   
Target Milestone: 6.99   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Yes (doc changes required)

Description Evadeflow 2019-02-26 19:09:30 UTC
It's a bit unfortunate that Bitbake silently accepts lines like this:

> SRC_URI_append = "file://capture.sh"

when the user almost certainly should have typed:

> SRC_URI_append = " file://capture.sh"

In a similar vein, likes like this:

> RM_WORK_EXCLUDE += " rawv4l2cap"

are accepted, even though—in the vast majority of cases—they should read:

> RM_WORK_EXCLUDE += "rawv4l2cap"


Personally, I must have copy/pasted += assignments with [useless] extra whitespace at least a hundred times in the last five years. This anti-pattern is *everywhere* out there in the wild, and it makes the output from running `bitbake -e` inscrutable.

Bitbake should warn users when they misuse whitespace, perhaps with an override to silence the warning for those rare cases where the usage is legitimate/necessary. Although... I've not personally encountered a case where, say `FOO_append = ".sh"` couldn't be replaced with `FOO .= ".sh"`, so... perhaps it ought to be a warning for a few Bitbake versions, which eventually becomes a 'hard' error after the deprecation period is over.

Anyway, leveraging the tool itself to lint out this rampant anti-pattern may be the only practical way to grapple with it. If Bitbake continues permitting users to include extra whitespace—or omit it when it should be required—they'll just keep doing it, and posting recipes with 'bad' snippets that get copy/pasted around to other recipes, perpetuating the cycle.
Comment 1 Randy MacLeod 2023-02-23 15:57:50 UTC
Still a useful idea.
Comment 2 Alexandre Belloni 2023-05-30 16:12:11 UTC
There are variables that are colon separated lists, like FILESEXTRAPATHS where one would use:

FILESEXTRAPATHS:prepend := "${THISDIR}/util-linux:"

as in meta/recipes-core/util-linux/util-linux.inc

So the first example is not something we can warn about without annotating whether the variable is a space separated list or not which will add overhead to bitbake parsing code.

Also, if someone omits the space, the result is likely to not work as expected which will get fixed.


The second case is cosmetic and is easier to warn about. However, we have variables that will include other variables that may be empty, so we will never be able to catch all the duplicated spaces. E.g:

CORE_IMAGE_BASE_INSTALL = '\
    packagegroup-core-boot \
    packagegroup-base-extended \
    \
    ${CORE_IMAGE_EXTRA_INSTALL} \
    '

CORE_IMAGE_EXTRA_INSTALL ?= ""

IMAGE_INSTALL ?= "${CORE_IMAGE_BASE_INSTALL}"

As soon as you append something to IMAGE_INSTALL (with a space then) and CORE_IMAGE_EXTRA_INSTALL stays empty, you will have two consecutive spaces.
Comment 3 Randy MacLeod 2023-10-24 14:24:34 UTC
Bulk move from 4.99 or 0.00 to 5.99