Skip to content

Commit daadf13

Browse files
authored
Fix md5 hash command to work for all platforms (#669)
1 parent 31bda76 commit daadf13

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

rules/computed_dependencies/hash.bzl

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,28 @@ def _impl(ctx):
4444

4545
# Compute the hash
4646
out = ctx.outputs.text
47-
ctx.actions.run_shell(
47+
hasher = ctx.actions.declare_file(ctx.label.name + "_hasher.py")
48+
ctx.actions.write(
49+
output = hasher,
50+
content = """
51+
import hashlib
52+
import sys
53+
54+
with open(sys.argv[1], 'rb') as f:
55+
data = f.read()
56+
md5 = hashlib.md5(data).hexdigest()
57+
58+
with open(sys.argv[2], 'w') as f:
59+
f.write(md5)
60+
""",
61+
)
62+
63+
ctx.actions.run(
4864
outputs = [out],
49-
inputs = [processed],
50-
use_default_shell_env = True,
51-
command = "md5sum < %s > %s" % (processed.path, out.path),
65+
inputs = [processed, hasher],
66+
executable = "python3",
67+
arguments = [hasher.path, processed.path, out.path],
68+
mnemonic = "ComputeHash",
5269
)
5370

5471
_md5_sum = rule(

0 commit comments

Comments
 (0)