Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions clcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
# ? is invalid character for file name, so it seems ok
# to use it as mark for relative path.
BASEDIR_REPLACEMENT = '?'
SOURCEDIR_REPLACEMENT = '*'

# Define some Win32 API constants here to avoid dependency on win32pipe
NMPWAIT_WAIT_FOREVER = wintypes.DWORD(0xFFFFFFFF)
Expand Down Expand Up @@ -271,8 +272,10 @@ def getManifestHash(compilerBinary, commandLine, sourceFile):

commandLine.extend(collapseBasedirInCmdPath(arg) for arg in inputFiles)

printTraceStatement("Hashing commandLine: {}".format(commandLine))
additionalData = "{}|{}|{}".format(
compilerHash, commandLine, ManifestRepository.MANIFEST_FILE_FORMAT_VERSION)
printTraceStatement("Hashing additionalData: {}".format(additionalData))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two printTraceStatement statements seem unrelated to the commit - can you move them into a separate commit?

return getFileHash(sourceFile, additionalData)

@staticmethod
Expand Down Expand Up @@ -918,25 +921,35 @@ def getStringHash(dataString):

def expandBasedirPlaceholder(path):
baseDir = normalizeBaseDir(os.environ.get('CLCACHE_BASEDIR'))
sourceDir = normalizeBaseDir(os.environ.get('CLCACHE_SOURCEDIR'))
if path.startswith(BASEDIR_REPLACEMENT):
if not baseDir:
raise LogicException('No CLCACHE_BASEDIR set, but found relative path ' + path)
return path.replace(BASEDIR_REPLACEMENT, baseDir, 1)
elif path.startswith(SOURCEDIR_REPLACEMENT):
if not sourceDir:
raise LogicException('No CLCACHE_SOURCEDIR set, but found relative path ' + path)
return path.replace(SOURCEDIR_REPLACEMENT, sourceDir, 1)
else:
return path


def collapseBasedirToPlaceholder(path):
baseDir = normalizeBaseDir(os.environ.get('CLCACHE_BASEDIR'))
if baseDir is None:
sourceDir = normalizeBaseDir(os.environ.get('CLCACHE_SOURCEDIR'))
if baseDir is None and sourceDir is None:
return path
else:
assert path == os.path.normcase(path)
assert baseDir == os.path.normcase(baseDir)
if path.startswith(baseDir):
if not baseDir is None:
assert baseDir == os.path.normcase(baseDir)
if path.startswith(baseDir):
return path.replace(baseDir, BASEDIR_REPLACEMENT, 1)
else:
return path
if not sourceDir is None:
assert sourceDir == os.path.normcase(sourceDir)
if path.startswith(sourceDir):
return path.replace(sourceDir, SOURCEDIR_REPLACEMENT, 1)
return path


def ensureDirectoryExists(path):
Expand Down