From 4caa0577ecfdc9b4d7101cfb07154384fdd191a9 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 26 Oct 2020 06:14:54 -0400 Subject: stabilize iteration order for dictionaries The order of keys in dictionaries cannot be relied upon, because the hash values are randomized by Python. Whenever we iterate on dictionaries and meson.build generates a list during the iteration, the different iteration orders may cause random changes in the command line and cause ninja to rebuild a lot of files unnecessarily. --- mesonbuild/interpreterbase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mesonbuild/interpreterbase.py') diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index d3f8181..e57580b 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -823,7 +823,7 @@ The result of this is undefined and will become a hard error in a future Meson r elif isinstance(items, dict): if len(node.varnames) != 2: raise InvalidArguments('Foreach on dict unpacks key and value') - for key, value in items.items(): + for key, value in sorted(items.items()): self.set_variable(node.varnames[0], key) self.set_variable(node.varnames[1], value) try: @@ -1166,7 +1166,7 @@ The result of this is undefined and will become a hard error in a future Meson r if method_name == 'keys': if len(posargs) != 0: raise InterpreterException('keys() takes no arguments.') - return list(obj.keys()) + return sorted(obj.keys()) raise InterpreterException('Dictionaries do not have a method called "%s".' % method_name) -- cgit v1.1