Bug 9382 - git fetcher fails if certain environment variables contain non-ASCII chars
Summary: git fetcher fails if certain environment variables contain non-ASCII chars
Status: RESOLVED FIXED
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: 2016-04-04 09:26 UTC by Daniel Klauer
Modified: 2016-04-06 09:48 UTC (History)
2 users (show)

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


Attachments
Suggested fix: make Python sqlite3 module return byte strings for SQL text queries (467 bytes, patch)
2016-04-04 09:26 UTC, Daniel Klauer
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Klauer 2016-04-04 09:26:35 UTC
Created attachment 3089 [details]
Suggested fix: make Python sqlite3 module return byte strings for SQL text queries

Hello,

bitbake's git fetcher is prepending shell export commands for certain environment variables (HOME, PATH, but also others - see [1]) to every shell command it runs via runfetchcmd(). It fails if these variables contain non-ASCII chars:

File: '.../poky/bitbake/lib/bb/fetch2/__init__.py', lineno: 812, function: runfetchcmd
     0808:
    0809:    for var in exportvars:
     0810:        val = d.getVar(var, True)
     0811:        if val:
 *** 0812:            cmd = 'export ' + var + '=\"%s\"; %s' % (val, cmd)
     0813:
     0814:    logger.debug(1, "Running %s", cmd)
     0815:
     0816:    success = False
Exception: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 
17: ordinal not in range(128)

Reproducing the issue seems to be as simple as:

    1. $ git clone -b jethro git://git.yoctoproject.org/poky.git
    2. $ cd poky
    3. $ mkdir meta/recipes-support/test
    4. create recipe meta/recipes-support/test/testgit.bb:
        # just a test recipe
        LICENSE = "CLOSED"
        SRC_URI = "git://github.com/schacon/simplegit.git;protocol=https"
        SRCREV = "${AUTOREV}"
    5. $ source oe-init-build-env
    6. $ SOCKS5_USER=ΓΌ bitbake testgit

It looks like this error happens because bitbake's internal SQL database (bb.persist_data.SQLTable) returns Unicode strings instead of byte strings, which sometimes trickle down to runfetchcmd() (due to dynamic typing), causing Unicode conversions when appending to the cmd string.

I have only observed this problem with the Git fetcher when using AUTOREV. FetchMethod.latest_revision() caches the HEAD revision as a string in an SQL database (bb.persist_data.SQLTable) using the Python 2 sqlite3 module, which defaults to returning unicode strings when querying text, according to [1].

[1] https://docs.python.org/2/library/sqlite3.html#sqlite-and-python-types
Comment 2 Richard Purdie 2016-04-04 15:21:40 UTC
Could you send that patch to the bitbake mailing list with a signed-off-by line and a condensed explanation as a commit message please? The patch seems reasonable to me.
Comment 3 Daniel Klauer 2016-04-05 11:18:11 UTC
Ok, done.
Comment 4 Richard Purdie 2016-04-06 09:48:37 UTC
Thanks for posting it, much appreciated. It went through testing and was merged: http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=4f07c2220bedf50743bc384dd221eb14f6b0b300