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

Add msbuild tracker support #319

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
42 changes: 42 additions & 0 deletions clcache/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,44 @@ def normalizeBaseDir(baseDir):
return None


class SuspendTracker():
izmmisha marked this conversation as resolved.
Show resolved Hide resolved
fileTracker = None
def __init__(self):
if not SuspendTracker.fileTracker:
if windll.kernel32.GetModuleHandleW("FileTracker.dll"):
SuspendTracker.fileTracker = windll.FileTracker
elif windll.kernel32.GetModuleHandleW("FileTracker32.dll"):
SuspendTracker.fileTracker = windll.FileTracker32

def __enter__(self):
SuspendTracker.suspend()

def __exit__(self, typ, value, traceback):
SuspendTracker.resume()

@staticmethod
def suspend():
if SuspendTracker.fileTracker:
SuspendTracker.fileTracker.SuspendTracking()

@staticmethod
def resume():
if SuspendTracker.fileTracker:
SuspendTracker.fileTracker.ResumeTracking()

def isTrackerEnabled():
return 'TRACKER_ENABLED' in os.environ

def untrackable(func):
if not isTrackerEnabled():
return func

def untrackedFunc(*args, **kwargs):
with SuspendTracker():
return func(*args, **kwargs)

return untrackedFunc

@contextlib.contextmanager
def atomicWrite(fileName):
tempFileName = fileName + '.new'
Expand Down Expand Up @@ -193,6 +231,7 @@ def manifestPath(self, manifestHash):
def manifestFiles(self):
return filesBeneath(self.manifestSectionDir)

@untrackable
def setManifest(self, manifestHash, manifest):
manifestPath = self.manifestPath(manifestHash)
printTraceStatement("Writing manifest with manifestHash = {} to {}".format(manifestHash, manifestPath))
Expand All @@ -203,6 +242,7 @@ def setManifest(self, manifestHash, manifest):
jsonobject = {'entries': entries}
json.dump(jsonobject, outFile, sort_keys=True, indent=2)

@untrackable
def getManifest(self, manifestHash):
fileName = self.manifestPath(manifestHash)
if not os.path.exists(fileName):
Expand Down Expand Up @@ -741,13 +781,15 @@ def __init__(self, statsFile):
self._stats = None
self.lock = CacheLock.forPath(self._statsFile)

@untrackable
def __enter__(self):
self._stats = PersistentJSONDict(self._statsFile)
for k in Statistics.RESETTABLE_KEYS | Statistics.NON_RESETTABLE_KEYS:
if k not in self._stats:
self._stats[k] = 0
return self

@untrackable
def __exit__(self, typ, value, traceback):
# Does not write to disc when unchanged
self._stats.save()
Expand Down