Make Glob() sort, to prevent spurious rebuilds. Fixes issue #2131.
authorgaryo <garyo@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 6 Sep 2008 02:12:20 +0000 (02:12 +0000)
committergaryo <garyo@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 6 Sep 2008 02:12:20 +0000 (02:12 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@3342 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py

index 7045b0fe8f529bdbe74bba57c29ff6c030bb6695..9f46e887c24d1b08f94adc43a2b5cd4b92b083a6 100644 (file)
 
 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
index eda6e71f2e5514d4650df43eecbd98079518a53c..182acd29d834fe5c08fe0876857fb0fd9e614168 100644 (file)
@@ -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):
index 9d3cabb012c527adad0e5a23678c375460292206..ca854b2c3e78a3c5f993ecc05d521f67ec9a6caa 100644 (file)
@@ -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):