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.
pull/7900/head
Paolo Bonzini 4 years ago
parent 59cacbbfc1
commit fc9b0cbb7f
  1. 2
      mesonbuild/depfile.py
  2. 4
      mesonbuild/modules/sourceset.py
  3. 2
      run_unittests.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)

@ -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):

@ -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()

Loading…
Cancel
Save