-
Notifications
You must be signed in to change notification settings - Fork 84
Incremental builds with MSBuild/Visual Studio are broken #227
Comments
Can you provide a sample project which triggers this? On first sight, it sounds like another incarnation of https://github.com/frerich/clcache/wiki/Caveats#no-cache-hits-when-building-via-visual-studio-ide-or-msbuild -- i.e. the file tracking feature needs to be disabled. Does that help with incremental builds, too? If so, I guess that Wiki page should be extended. |
Disabling tracking is incompatible with incremental builds, as far I'm understand. |
https://github.com/Un1oR/clcache-incremental-test |
In addition to my previous comment. If I comment registerCacheHit function body a problem goes away. |
I suspect what happens is that due to the file tracing feature of Visual Studio, it notices that for any Thus, when doing an incremental build which merely compiles single I skimmed the documentation about Incremental Builds, but didn't spot anything which might help with avoiding this issue. My feeling is that if we just had a way to either disable tracking writes to |
I have simplified example. Now it contains one project with two cpp files and problem still is reproduced. I have tried to find workaround for disabling statistics file tracking. ExcludedInputPaths and TrackedOutputFilesToIgnore options wasn't have effect for me. Put cache directory into one of this folders is works, but it isn't useful solution, I think. |
|
I think we should really start looking into integration tests which use clcache the same way Visual Studio does, maybe using |
I'm observing the same behavior and even worse: compiled binaries don't contain my changes, but full rebuild helps. |
Alas I don't use |
The command line is exactly same as for regular build, but I cannot reproduce this without Visual Studio or |
Would be nice if this problem solved by #319 PR. |
I'll try to check it out soon! |
Hi, I compiled exe from https://github.com/izmmisha/clcache/tree/add-tracker-support and try to compile project https://github.com/Un1oR/clcache-incremental-test with it. Got fail https://gist.github.com/RomanYudintsev/9978f7dadcf090bb010f257e42837776#file-gistfile1-txt |
@RomanYudintsev yeah, I saw such errors before.
This problem related to freezing of app. There is multiprocessing.freeze_support() to solve this problem, but looks like it not works in your case. I'm using PyInstaller to create exe and it works. How you generate exe? Could you please show output of this process, probably it can show any error with multiprocessing module. |
@RomanYudintsev also incremental build will not work with |
build log for my clcache_branch.exe - https://gist.github.com/RomanYudintsev/4cd8657a0d682839bbceef128e9624b0 |
Ok, I see that I'm building exe in different way (I'm new to this project), should be fixed at izmmisha@137a3e2 Thank you @RomanYudintsev |
It's works! and not full rebuild :) |
After some time of inspecting msbuild I found another things.
v140 toolchain use CLToolExe for filenames
So @RomanYudintsev I see that your linker version is 14, probably you are using v140 toolchain. But as mentioned earlier msbuild have some properties to set ignore files:
In case of stats.txt and manifests it is possible to setup TrackedInputFilesToIgnore using So probably with v140 toolchain you can use NoDependencies without clcache modification at all. |
Ok, finally I found correct way how to make it work.
@frerich, Added some tests at |
@izmmisha : I tested your fork on a large project (600 000 LoC, 173 projects). It works almost perfectly! Thanks a lot! The compilation time dropped from 30 minutes to 3 minutes, and incremental builds now work flawlessly under MSVC 2015 and 2017 (and it integrates well with Qt moc). I wrote a script to simplify the integration with Visual Studio : you can find it here:
However I have one small issue : sometimes one invocation of
This is extremey rare : the probability is about 0.1%, so it happens only with large projects with a large number of hits. Using clcache-server does not solve it. However when I encounter, I just need to do a second build, and it always work (and build only the missing files). Do you have an idea on how to solve this problem? Here is the full trace when I have this issue:
|
Glad to hear, thanks.
I had such problem on my side. It related to windows explorer, you are keep open window with |
Thanks for your answer! Actually I had no explorer window opened on this folder. So, I posted a workaround for the stats.txt issue : it is here On my side, it works perfectly. Do you want to add this patch to your PR? Or do you prefer that I post a separate PR? Thanks! |
Well, would be better to identify the root of problem, so probably it introduced when used ProcessPoolExecutor, but I have only MSVS 2013 toolchain and it is necessary to make it work. But if you are able to reproduce this problem on your side and it looks like you are using MSVS 2017 (or 2015), you can try revert this commit 1aebba3 then we will know is ProcessPoolExecutor related to this problem or not. |
Hi, I tried to revert your commit (and my modif), and the problem is still present. I suspect the issue revolves around the locking mechanism inside the So I tried to use the lock inside the @untrackable
def __exit__(self, typ, value, traceback):
with self.lock:
# Does not write to disc when unchanged
self._stats.save() But it did not solve the problem either. I think the issue is difficult to solve by code : See the class class CacheLock:
def __init__(self, mutexName, timeoutMs):
self._mutexName = 'Local\\' + mutexName
self._mutex = None
self._timeoutMs = timeoutMs
def acquire(self):
if not self._mutex:
self.createMutex()
result = windll.kernel32.WaitForSingleObject(
self._mutex, wintypes.INT(self._timeoutMs))
if result not in [0, self.WAIT_ABANDONED_CODE]:
if result == self.WAIT_TIMEOUT_CODE: |
On a side note, I have discovered that this PR only works with python 32 bits. This is due to the fact that MSVC and msbuild is itself a 32 bits program, and this PR needs to communicate with msbuild via a 32 bits dll (FileTracker.dll) |
@pthom Well, I did some tests using this simple script:
So, I'm able to reproduce this problem with ThreadPoolExecutor and without untracker's decorators:
The thing I get from this test is that I'm able to easily reproduce such problem only when file located at So probably this problem should be added to caveat section of wiki. |
I am using x86 toolchains and x64 python, and this commit helped in my case: |
I think it problem related with #33, but a bit more complicated.
When I try incremental build, all solution fully rebuilds. I found it not happens if I comment body of PersistentJSONDict.save function. As I understand, MSBuild tracks writing a statistics file and mark projects in solution as outdated.
Affects only solutions with two or more projects with build dependencies between it!
The text was updated successfully, but these errors were encountered: