OSDN Git Service

[lit] Re-apply: Fix some convoluted logic around Unicode encoding, and de-duplicate...
authorDavid L. Jones <dlj@google.com>
Thu, 29 Jun 2017 04:37:35 +0000 (04:37 +0000)
committerDavid L. Jones <dlj@google.com>
Thu, 29 Jun 2017 04:37:35 +0000 (04:37 +0000)
commitd1176ce9c6a96426b64e22e7a4777150a904b33b
treece0e0b39b21499b4e6848c99afc09c5c0da8402f
parent6956b5e8f102f4e1f19230abe1c12c11f80cfcaf
[lit] Re-apply: Fix some convoluted logic around Unicode encoding, and de-duplicate across modules that used it.

(Take 2: this patch re-applies r306625, which was reverted in r306629. This
patch includes only trivial fixes.)

In Python2 and Python3, the various (non-)?Unicode string types are sort of
spaghetti. Python2 has unicode support tacked on via the 'unicode' type, which
is distinct from 'str' (which are bytes). Python3 takes the "unicode-everywhere"
approach, with 'str' representing a Unicode string.

Both have a 'bytes' type. In Python3, it is the only way to represent raw bytes.
However, in Python2, 'bytes' is an alias for 'str'. This leads to interesting
problems when an interface requires a precise type, but has to run under both
Python2 and Python3.

The previous logic appeared to be correct in all cases, but went through more
layers of indirection than necessary. This change does the necessary conversions
in one shot, with documentation about which paths might be taken in Python2 or
Python3.

Changes from r306625: some tests just print binary outputs, so in those cases,
fall back to str() in Python3. For googletests, add one missing call to
to_string().

(Tested by verifying the visible breakage with Python3. Verified that everything
works in py2 and py3.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306643 91177308-0d34-0410-b5e6-96231b3b80d8
utils/lit/lit/formats/googletest.py
utils/lit/lit/util.py