Commit 355e6449 authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

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/+/2234586Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
parent a85d58e5
......@@ -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)
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())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment