From d669165e6fdc38150b0debbda3b766c7db4f1178 Mon Sep 17 00:00:00 2001 From: garyo Date: Sat, 6 Sep 2008 02:12:20 +0000 Subject: [PATCH] Make Glob() sort, to prevent spurious rebuilds. Fixes issue #2131. git-svn-id: http://scons.tigris.org/svn/scons/trunk@3342 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 5 +++++ src/engine/SCons/Node/FS.py | 1 + src/engine/SCons/Node/FSTests.py | 15 +++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 7045b0fe..9f46e887 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,11 @@ RELEASE 1.X - XXX + From Gary Oberbrunner: + + - Make Glob() sort the returned list of Files or Nodes + to prevent spurious rebuilds. + From Ian P. Cardenas: - Fix Glob() polluting LIBPATH by returning copy of list diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index eda6e71f..182acd29 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -1865,6 +1865,7 @@ class Dir(Base): if strings: r = map(lambda x, d=str(dir): os.path.join(d, x), r) result.extend(r) + result.sort(lambda a, b: cmp(str(a), str(b))) return result def _glob1(self, pattern, ondisk=True, source=False, strings=False): diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 9d3cabb0..ca854b2c 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -2162,17 +2162,17 @@ class GlobTestCase(_tempdirTestCase): self.hhh = fs.File('hhh') self.iii = fs.File('iii') self.subdir1 = fs.Dir('subdir1') + self.subdir1_lll = self.subdir1.File('lll') self.subdir1_jjj = self.subdir1.File('jjj') self.subdir1_kkk = self.subdir1.File('kkk') - self.subdir1_lll = self.subdir1.File('lll') self.subdir2 = fs.Dir('subdir2') - self.subdir2_jjj = self.subdir2.File('jjj') - self.subdir2_kkk = self.subdir2.File('kkk') self.subdir2_lll = self.subdir2.File('lll') + self.subdir2_kkk = self.subdir2.File('kkk') + self.subdir2_jjj = self.subdir2.File('jjj') self.sub = fs.Dir('sub') self.sub_dir3 = self.sub.Dir('dir3') - self.sub_dir3_jjj = self.sub_dir3.File('jjj') self.sub_dir3_kkk = self.sub_dir3.File('kkk') + self.sub_dir3_jjj = self.sub_dir3.File('jjj') self.sub_dir3_lll = self.sub_dir3.File('lll') @@ -2396,6 +2396,13 @@ class GlobTestCase(_tempdirTestCase): self.do_cases(cases) + def test_sort(self): + """Test whether globbing sorts""" + join = os.path.join + # At least sometimes this should return out-of-order items + # if Glob doesn't sort. + g = self.fs.Glob('disk-sub/*', strings=True) + assert g == ['disk-sub/disk-ddd', 'disk-sub/disk-eee', 'disk-sub/disk-fff'], str(g) + " is not sorted, but should be!" class RepositoryTestCase(_tempdirTestCase): -- 2.26.2