<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>9382</bug_id>
          
          <creation_ts>2016-04-04 09:26:35 +0000</creation_ts>
          <short_desc>git fetcher fails if certain environment variables contain non-ASCII chars</short_desc>
          <delta_ts>2016-04-06 09:48:37 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Undecided</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Daniel Klauer">daniel.klauer</reporter>
          <assigned_to name="Richard Purdie">richard.purdie</assigned_to>
          <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>60728</commentid>
    <comment_count>0</comment_count>
      <attachid>3089</attachid>
    <who name="Daniel Klauer">daniel.klauer</who>
    <bug_when>2016-04-04 09:26:35 +0000</bug_when>
    <thetext>Created attachment 3089
Suggested fix: make Python sqlite3 module return byte strings for SQL text queries

Hello,

bitbake&apos;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: &apos;.../poky/bitbake/lib/bb/fetch2/__init__.py&apos;, lineno: 812, function: runfetchcmd
     0808:
    0809:    for var in exportvars:
     0810:        val = d.getVar(var, True)
     0811:        if val:
 *** 0812:            cmd = &apos;export &apos; + var + &apos;=\&quot;%s\&quot;; %s&apos; % (val, cmd)
     0813:
     0814:    logger.debug(1, &quot;Running %s&quot;, cmd)
     0815:
     0816:    success = False
Exception: UnicodeDecodeError: &apos;ascii&apos; codec can&apos;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 = &quot;CLOSED&quot;
        SRC_URI = &quot;git://github.com/schacon/simplegit.git;protocol=https&quot;
        SRCREV = &quot;${AUTOREV}&quot;
    5. $ source oe-init-build-env
    6. $ SOCKS5_USER=ü bitbake testgit

It looks like this error happens because bitbake&apos;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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60729</commentid>
    <comment_count>1</comment_count>
    <who name="Daniel Klauer">daniel.klauer</who>
    <bug_when>2016-04-04 09:31:12 +0000</bug_when>
    <thetext>oops, messed up the links, that should be:
[1] http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/bitbake/lib/bb/fetch2/__init__.py?h=jethro&amp;id=2fb7ee2628e23d7efc9b041bb9daae7c4a8de541#n789
[2] https://docs.python.org/2/library/sqlite3.html#sqlite-and-python-types</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60745</commentid>
    <comment_count>2</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2016-04-04 15:21:40 +0000</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60796</commentid>
    <comment_count>3</comment_count>
    <who name="Daniel Klauer">daniel.klauer</who>
    <bug_when>2016-04-05 11:18:11 +0000</bug_when>
    <thetext>Ok, done.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60838</commentid>
    <comment_count>4</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2016-04-06 09:48:37 +0000</bug_when>
    <thetext>Thanks for posting it, much appreciated. It went through testing and was merged: http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=4f07c2220bedf50743bc384dd221eb14f6b0b300</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>3089</attachid>
            <date>2016-04-04 09:26:35 +0000</date>
            <delta_ts>2016-04-04 09:26:35 +0000</delta_ts>
            <desc>Suggested fix: make Python sqlite3 module return byte strings for SQL text queries</desc>
            <filename>bitbake-git-fetcher-unicode.patch</filename>
            <type>text/plain</type>
            <size>467</size>
            <attacher name="Daniel Klauer">daniel.klauer</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL2JpdGJha2UvbGliL2JiL3BlcnNpc3RfZGF0YS5weSBiL2JpdGJha2UvbGli
L2JiL3BlcnNpc3RfZGF0YS5weQppbmRleCA1Nzk1YmM4Li5lNDUwNDIzIDEwMDY0NAotLS0gYS9i
aXRiYWtlL2xpYi9iYi9wZXJzaXN0X2RhdGEucHkKKysrIGIvYml0YmFrZS9saWIvYmIvcGVyc2lz
dF9kYXRhLnB5CkBAIC0yMDEsNiArMjAxLDcgQEAgY2xhc3MgUGVyc2lzdERhdGEob2JqZWN0KToK
IGRlZiBjb25uZWN0KGRhdGFiYXNlKToKICAgICBjb25uZWN0aW9uID0gc3FsaXRlMy5jb25uZWN0
KGRhdGFiYXNlLCB0aW1lb3V0PTUsIGlzb2xhdGlvbl9sZXZlbD1Ob25lKQogICAgIGNvbm5lY3Rp
b24uZXhlY3V0ZSgicHJhZ21hIHN5bmNocm9ub3VzID0gb2ZmOyIpCisgICAgY29ubmVjdGlvbi50
ZXh0X2ZhY3RvcnkgPSBzdHIKICAgICByZXR1cm4gY29ubmVjdGlvbgogCiBkZWYgcGVyc2lzdChk
b21haW4sIGQpOgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>