Skip to content

Commit 1220a09

Browse files
committed
fix(smol): add gyp patch for Python 3 hashlib.md5() compatibility
Fixes TypeError: Strings must be encoded before hashing at tools/gyp/pylib/gyp/generator/ninja.py:813 Python 3's hashlib.md5() requires bytes, not strings. The gyp code was passing a string (file path) directly to hashlib.md5() when generating unique_name for Windows builds. This patch adds .encode() to convert the string to bytes before hashing, fixing compatibility with all Python 3 versions.
1 parent fc7fb60 commit 1220a09

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @node-versions: v24.10.0+
2+
# @description: Fix gyp Python 3 hashlib.md5() compatibility
3+
#
4+
# Python 3's hashlib.md5() requires bytes, not strings.
5+
# Fixes: TypeError: Strings must be encoded before hashing
6+
# At: tools/gyp/pylib/gyp/generator/ninja.py:813
7+
#
8+
# This issue affects all Python 3 versions when gyp tries to hash
9+
# file paths for unique_name generation on Windows.
10+
#
11+
# References:
12+
# - https://github.com/nodejs/node/blob/main/BUILDING.md
13+
# - https://docs.python.org/3/library/hashlib.html
14+
15+
--- a/tools/gyp/pylib/gyp/generator/ninja.py
16+
+++ b/tools/gyp/pylib/gyp/generator/ninja.py
17+
@@ -810,7 +810,7 @@
18+
if self.flavor == "win":
19+
# WriteNewNinjaRule uses unique_name to create a rsp file on win.
20+
extra_bindings.append(
21+
- ("unique_name", hashlib.md5(outputs[0]).hexdigest())
22+
+ ("unique_name", hashlib.md5(outputs[0].encode()).hexdigest())
23+
)
24+
25+
self.ninja.build(

0 commit comments

Comments
 (0)