[OE-core] Bitbake class - how to escape special characters?

Richard Purdie richard.purdie at linuxfoundation.org
Mon Mar 2 13:32:11 UTC 2015


On Mon, 2015-03-02 at 11:49 +0000, Peter Gejgus wrote:
> Hello,
> 
> This is the excerpt of my bitbake class:
> 
> data_migration_common() {
> 	if [ x"$D" = "x" ]; then
> 		if [[ ! ${CURRENT_DATA_VERSION} =~ ^[0-9]?[0-9].[0-9]?[0-9]$ ]]; then
> 			error-exit "Version information was provided in invalid format!"
> 		fi
> 	...
> 	fi
> }
> 
> python populate_packages_append() {
>     data_migration_pkgs = d.getVar('DATA_MIGRATION_PACKAGES', True).split()
> 
>     for pkg in data_migration_pkgs:
>         bb.note("adding data migration postinst scripts to %s" % pkg)
>         postinst = d.getVar('pkg_postinst_%s' % pkg, True) or d.getVar('pkg_postinst', True)
>         if not postinst:
>             postinst = '#!/bin/sh\n'
>         postinst += d.getVar('data_migration_common', True)
>         d.setVar('pkg_postinst_%s' % pkg, postinst)
> }
> 
> This class generates post-install scriptlet for the packages
> inheriting from this bitbake class.
>
> But bitbake is unable to parse the code in the data_migration_common
> function and claiming:
> ERROR: ExpansionError during parsing .../xyz_0.1.0.bb: Failure
> expanding variable data_migration_common: ShellSyntaxError: Invalid
> token "%s"
>
> This problem is because the regular expression in the function
> data_migration_common contains character '$'. Bitbake succeeds when I
> remove character '$' from this regular expression. Is there some way
> to escape this '$' character? Because I need '$' in my regex.

The problem is in the shell parser that bitbake uses (lib/bb/pysh)
doesn't like that syntax. The expression you have above is bash specific
and we tend to support /bin/dash as /bin/sh so the function you have
there isn't portable.

Cheers,

Richard




More information about the Openembedded-core mailing list