diff --git a/aliBuild b/aliBuild index fbdd81f0..c85c2fd0 100755 --- a/aliBuild +++ b/aliBuild @@ -778,8 +778,9 @@ def doMain(): h(str(time.time())) if spec["package"] in develPkgs and "incremental_recipe" in spec: h(spec["incremental_recipe"]) - incremental_hash = hashlib.sha1(spec["incremental_recipe"]).hexdigest() - spec["incremental_hash"] = incremental_hash + ih = Hasher() + ih(spec["incremental_recipe"]) + spec["incremental_hash"] = ih.hexdigest() elif p in develPkgs: h(spec.get("devel_hash")) spec["hash"] = h.hexdigest() diff --git a/alibuild_helpers/utilities.py b/alibuild_helpers/utilities.py index c37009db..dbd47446 100644 --- a/alibuild_helpers/utilities.py +++ b/alibuild_helpers/utilities.py @@ -284,6 +284,8 @@ class Hasher: def __init__(self): self.h = hashlib.sha1() def __call__(self, txt): - self.h.update(txt.encode('utf-8', 'ignore')) + if not type(txt) == bytes: + txt = txt.encode('utf-8', 'ignore') + self.h.update(txt) def hexdigest(self): return self.h.hexdigest() diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 784c951a..66c53665 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -120,10 +120,13 @@ def test_Hasher(self): def test_UTF8_Hasher(self): h1 = Hasher() h2 = Hasher() + h3 = Hasher() h1(u'\ua000') h2(u'\ua001') + h3(b'foo') self.assertEqual(h1.hexdigest(), "2af8e41129115eb231a0af76ec5465d3a9184fc4") self.assertEqual(h2.hexdigest(), "1619bcdbeff6828138ad9b6e43cc17e856457603") + self.assertEqual(h3.hexdigest(), "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33") self.assertNotEqual(h1.hexdigest(), h2.hexdigest()) if __name__ == '__main__':