Python 3 support for get_toolchain_if_necessary.py

get_toolchain_if_necessary.py would fail on Python 3 when passing a
string to digest.update - this string needs to be encoded to bytes.
This even stops packaging of new toolchains from working.

With this change digest.update get_toolchain_if_necessary.py works with
Python 2 and Python 3.

As a test the current toolchain directory was repackaged - the same hash
was generated.

Change-Id: Ia682d15be42521a35f4df2e14d1f715d9e42d96f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2234586
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
changes/86/2234586/2
Bruce Dawson 5 years ago committed by LUCI CQ
parent a85d58e50e
commit 355e6449e7

@ -175,7 +175,10 @@ def CalculateHash(root, expected_hash):
if expected_hash:
path_without_hash = path_without_hash.replace(
os.path.join(root, expected_hash).replace('/', '\\'), root)
digest.update(path_without_hash.lower())
if sys.version_info[0] < 3:
digest.update(path_without_hash.lower())
else:
digest.update(bytes(path_without_hash.lower(), 'utf-8'))
with open(path, 'rb') as f:
digest.update(f.read())

Loading…
Cancel
Save