From c1b686e39568784a9db572dd3b6a4e4e254daaa7 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 29 Oct 2021 18:25:22 +0300 Subject: Make environment objects hash deterministically. --- mesonbuild/backend/backends.py | 11 ++++++++--- mesonbuild/build.py | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'mesonbuild') diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 3d8654e..1d04c91 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -648,9 +648,14 @@ class Backend: # avoids collisions and also makes the name deterministic over # regenerations which avoids a rebuild by Ninja because the cmdline # stays the same. - data = bytes(str(es.env) + str(es.cmd_args) + str(es.workdir) + str(capture) + str(feed), - encoding='utf-8') - digest = hashlib.sha1(data).hexdigest() + hasher = hashlib.sha1() + if es.env: + es.env.hash(hasher) + hasher.update(bytes(str(es.cmd_args), encoding='utf-8')) + hasher.update(bytes(str(es.workdir), encoding='utf-8')) + hasher.update(bytes(str(capture), encoding='utf-8')) + hasher.update(bytes(str(feed), encoding='utf-8')) + digest = hasher.hexdigest() scratch_file = f'meson_exe_{basename}_{digest}.dat' exe_data = os.path.join(self.environment.get_scratch_dir(), scratch_file) with open(exe_data, 'wb') as f: diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 02e8da9..dd55fc6 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -468,6 +468,14 @@ class EnvironmentVariables(HoldableObject): repr_str = "<{0}: {1}>" return repr_str.format(self.__class__.__name__, self.envvars) + def hash(self, hasher: T.Any): + myenv = self.get_env({}) + for key in sorted(myenv.keys()): + hasher.update(bytes(key, encoding='utf-8')) + hasher.update(b',') + hasher.update(bytes(myenv[key], encoding='utf-8')) + hasher.update(b';') + def has_name(self, name: str) -> bool: return name in self.varnames -- cgit v1.1