Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit c852c14

Browse files
authored
Merge pull request #235 from siu/deterministicCreateManifestEntry
Deterministic create manifest entry
2 parents 02be13a + fc41196 commit c852c14

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

clcache.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class ManifestRepository(object):
192192
# invalidation, such that a manifest that was stored using the old format is not
193193
# interpreted using the new format. Instead the old file will not be touched
194194
# again due to a new manifest hash and is cleaned away after some time.
195-
MANIFEST_FILE_FORMAT_VERSION = 5
195+
MANIFEST_FILE_FORMAT_VERSION = 6
196196

197197
def __init__(self, manifestsRootDir):
198198
self._manifestsRootDir = manifestsRootDir
@@ -1398,11 +1398,13 @@ def processCacheHit(cache, objectFile, cachekey):
13981398

13991399

14001400
def createManifestEntry(manifestHash, includePaths):
1401-
includesWithHash = {path:getFileHash(path) for path in includePaths}
1402-
includesContentHash = ManifestRepository.getIncludesContentHashForHashes(includesWithHash.values())
1401+
sortedIncludePaths = sorted(set(includePaths))
1402+
includeHashes = [getFileHash(path) for path in sortedIncludePaths]
1403+
1404+
safeIncludes = [collapseBasedirToPlaceholder(path) for path in sortedIncludePaths]
1405+
includesContentHash = ManifestRepository.getIncludesContentHashForHashes(includeHashes)
14031406
cachekey = CompilerArtifactsRepository.computeKeyDirect(manifestHash, includesContentHash)
14041407

1405-
safeIncludes = [collapseBasedirToPlaceholder(path) for path in includesWithHash.keys()]
14061408
return ManifestEntry(safeIncludes, includesContentHash, cachekey)
14071409

14081410

unittests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import multiprocessing
1414
import os
1515
import unittest
16+
import tempfile
1617

1718
import clcache
1819
from clcache import (
@@ -939,6 +940,45 @@ def testTouchEntry(self):
939940
self.assertEqual(TestManifest.entry2, manifest.entries()[0])
940941

941942

943+
class TestCreateManifestEntry(unittest.TestCase):
944+
@classmethod
945+
def setUpClass(cls):
946+
cls.tempDir = tempfile.TemporaryDirectory()
947+
for i in range(10):
948+
sampleName = 'sample{}.h'.format(i)
949+
filePath = os.path.join(cls.tempDir.name, '{}.h'.format(sampleName))
950+
with open(filePath, 'w') as f:
951+
f.write('#define {}'.format(sampleName))
952+
953+
cls.includePaths = list(sorted(clcache.filesBeneath(cls.tempDir.name)))
954+
cls.manifestHash = 'ffffffffffffffffffffffffffffffff'
955+
cls.expectedManifestEntry = clcache.createManifestEntry(TestCreateManifestEntry.manifestHash,
956+
TestCreateManifestEntry.includePaths)
957+
958+
@classmethod
959+
def tearDownClass(cls):
960+
cls.tempDir.cleanup()
961+
962+
def assertManifestEntryIsCorrect(self, entry):
963+
self.assertEqual(entry.includesContentHash, TestCreateManifestEntry.expectedManifestEntry.includesContentHash)
964+
self.assertEqual(entry.objectHash, TestCreateManifestEntry.expectedManifestEntry.objectHash)
965+
self.assertEqual(entry.includeFiles, TestCreateManifestEntry.expectedManifestEntry.includeFiles)
966+
967+
def testIsConsistentWithSameInput(self):
968+
entry = clcache.createManifestEntry(TestCreateManifestEntry.manifestHash, TestCreateManifestEntry.includePaths)
969+
self.assertManifestEntryIsCorrect(entry)
970+
971+
def testIsConsistentWithReverseList(self):
972+
reversedIncludePaths = list(reversed(TestCreateManifestEntry.includePaths))
973+
entry = clcache.createManifestEntry(TestCreateManifestEntry.manifestHash, reversedIncludePaths)
974+
self.assertManifestEntryIsCorrect(entry)
975+
976+
def testIsConsistentWithDuplicateEntries(self):
977+
includePathsWithDuplicates = TestCreateManifestEntry.includePaths + TestCreateManifestEntry.includePaths
978+
entry = clcache.createManifestEntry(TestCreateManifestEntry.manifestHash, includePathsWithDuplicates)
979+
self.assertManifestEntryIsCorrect(entry)
980+
981+
942982
if __name__ == '__main__':
943983
unittest.TestCase.longMessage = True
944984
unittest.main()

0 commit comments

Comments
 (0)