aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2020-10-26 06:14:54 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2020-11-15 14:21:31 +0100
commit4caa0577ecfdc9b4d7101cfb07154384fdd191a9 (patch)
tree25ae044cb7845de601d94535daddf55337d7fe18
parentfc9b0cbb7fe718cbbd63e3b51839b90b3e558037 (diff)
downloadmeson-4caa0577ecfdc9b4d7101cfb07154384fdd191a9.zip
meson-4caa0577ecfdc9b4d7101cfb07154384fdd191a9.tar.gz
meson-4caa0577ecfdc9b4d7101cfb07154384fdd191a9.tar.bz2
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.
-rw-r--r--mesonbuild/interpreterbase.py4
1 files changed, 2 insertions, 2 deletions
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)