From fc9b0cbb7fe718cbbd63e3b51839b90b3e558037 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 26 Oct 2020 06:13:38 -0400 Subject: [PATCH] stabilize sets that are converted to lists The order of elements in sets cannot be relied upon, because the hash values are randomized by Python. Whenever sets are converted to lists we need to keep their order stable, or random changes in the command line cause ninja to rebuild a lot of files unnecessarily. To stabilize them, use either sort or OrderedSet. Sorting is not always applicable, but it can be faster because it's done in C and it can produce slightly nicer output. --- mesonbuild/depfile.py | 2 +- mesonbuild/modules/sourceset.py | 4 ++-- run_unittests.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mesonbuild/depfile.py b/mesonbuild/depfile.py index 7a896cd27..62cbe8125 100644 --- a/mesonbuild/depfile.py +++ b/mesonbuild/depfile.py @@ -82,4 +82,4 @@ class DepFile: deps.update(target.deps) for dep in target.deps: deps.update(self.get_all_dependencies(dep, visited)) - return deps + return sorted(deps) diff --git a/mesonbuild/modules/sourceset.py b/mesonbuild/modules/sourceset.py index e23e12ec4..e49a54802 100644 --- a/mesonbuild/modules/sourceset.py +++ b/mesonbuild/modules/sourceset.py @@ -14,7 +14,7 @@ from collections import namedtuple from .. import mesonlib -from ..mesonlib import listify +from ..mesonlib import listify, OrderedSet from . import ExtensionModule from ..interpreterbase import ( noPosargs, noKwargs, permittedKwargs, @@ -111,7 +111,7 @@ class SourceSetHolder(MutableInterpreterObject, ObjectHolder): def collect(self, enabled_fn, all_sources, into=None): if not into: - into = SourceFiles(set(), set()) + into = SourceFiles(OrderedSet(), OrderedSet()) for entry in self.held_object: if all(x.found() for x in entry.dependencies) and \ all(enabled_fn(key) for key in entry.keys): diff --git a/run_unittests.py b/run_unittests.py index 7f7df360c..98150586e 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1187,7 +1187,7 @@ class InternalTests(unittest.TestCase): ]: d = mesonbuild.depfile.DepFile(f) deps = d.get_all_dependencies(target) - self.assertEqual(deps, expdeps) + self.assertEqual(sorted(deps), sorted(expdeps)) def test_log_once(self): f = io.StringIO()