clang-power-tools icon indicating copy to clipboard operation
clang-power-tools copied to clipboard

clang-build.ps1: -tidy -parallel gives errors (introduced with always writing a .clang-tidy file)

Open gerboengels opened this issue 4 years ago • 6 comments

PR #886 broke clang-build.ps1 MySolution.sln -tidy .clang-tidy -parallel.

With this (simplified) snippet from Function Run-ClangJobs:

    if (![string]::IsNullOrWhiteSpace($job.TidyFlagsTempFile) -and (Test-Path $job.TidyFlagsTempFile))
    {
        $clangTidyFile       = "$cppDirectory\.clang-tidy"
    }
    if (![string]::IsNullOrWhiteSpace($clangTidyFile))
    {
      Copy-Item -Path $job.TidyFlagsTempFile -Destination $clangTidyFile                         #### A
    }
    $callOutput = cmd.exe /c "$($job.FilePath) $($job.ArgumentList) 2>&1" | Out-String           #### B
    if (![string]::IsNullOrWhiteSpace($clangTidyFile))
    {
	Remove-Item $clangTidyFile                                                               #### C
    }

I've got .clang-tidy, project\a.cpp and project\b.cpp, and run tidy on a.cpp and b.cpp. They start right after each other. First, a.cpp get at A and copies .clang-tidy to project\.clang-tidy. Then it starts processing for some time (B). Meanwhile b.cpp gets at A and copies .clang-tidy to project\.clang-tidy, but that already exists! Then it also starts processing for some time (B). After processing is done (say, a.cpp is a bit quicker), it removes project\.clang-tidy (C). Then b.cpp wants to remove project\.clang-tidy (C) as well, but it is already gone! This results in an error.

So this copying (and creating backups) doesn't play well with parallellism. And on top of that, I already have a .clang-tidy file, and I don't provide explicit checks on the command line. So why is this copying needed at all?

gerboengels avatar Nov 10 '20 15:11 gerboengels

Hi @gerboengels

Apologies for the inconveniences you've encountered. This is clearly a bug, the copying mechanism is intended to address only the explicit checks situation, because we've encountered issues when a lot of them are passed (the PR you mentioned addressed such an issue). We will fix the bug you've encountered as soon as possible and push it to a bugfix release of Clang Power Tools.

Thank you for the helpful feedback.

Regards, Gabriel

hero101111 avatar Nov 10 '20 15:11 hero101111

I think I'm also hitting this bug. My .clang-tidy file is in the root of my project folder, and seems to disappearing when needed.

Here is a chunk of the logging output, where the path is correct but the file is not found by Copy-Item.

1: C:\Users\bo3b\Documents\code\geo-11\util.cpp
Copy-Item : Cannot find path 'C:\Users\bo3b\Documents\code\geo-11\.clang-tidy' because it does not exist.
At C:\users\bo3b\appdata\local\microsoft\visualstudio\16.0_337686a5\extensions\b2hralti.ctm\Tooling\v1\clang-build.ps1:
993 char:7
+       Copy-Item -Path $job.TidyFlagsTempFile -Destination $clangTidyF ...
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\bo3b\D...-11\.clang-tidy:String) [Copy-Item], ItemNotFoundExce 
   ption
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
Remove-Item : Cannot find path 'C:\Users\bo3b\Documents\code\geo-11\.clang-tidy' because it does not exist.
At C:\users\bo3b\appdata\local\microsoft\visualstudio\16.0_337686a5\extensions\b2hralti.ctm\Tooling\v1\clang-build.ps1:
1007 char:7
+       Remove-Item $clangTidyFile
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\bo3b\D...-11\.clang-tidy:String) [Remove-Item], ItemNotFoundEx 
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

Is there an easy way to disable this for the time being? My clang-tidy fixes are failing to be applied.

bo3b avatar Feb 18 '22 21:02 bo3b

Hello @bo3b

It looks like what you're experiencing is a bit different from the original issue. Please enable verbose logging and attach the full log to help us investigate this.

hero101111 avatar Feb 21 '22 12:02 hero101111

Hello @bo3b

It looks like what you're experiencing is a bit different from the original issue. Please enable verbose logging and attach the full log to help us investigate this.

Hello-

OK, I tried to capture a verbose log, but I can no longer reproduce the problem. I tried a few experiments to see if I could get back to a failing case, but I don't know what has changed.

If you can give me some idea of where that Copy/Remove operation would be active, I can try to reproduce that setup. In all my experiments to try to reproduce this, I no longer see the Copy-Item in the log.

Edit: Well, spoke too soon. When I switched back to the same Util.cpp file, I can reproduce the problem. This file is at the solution level, not the DX11 project level, because it's shared with other projects in the solution. It is at the same level as the .clang-tidy file.

Here is the verbose log: clangpower.log

bo3b avatar Feb 21 '22 21:02 bo3b

In case it is helpful, this project is a copy of an open-source Github project called 3Dmigoto, and should be possible to reproduce using that. A close copy of this code will be the branch for Rename_Reformat.

https://github.com/bo3b/3Dmigoto/tree/Rename_Reformat

Sorry if this not related to this bug report- please refile as needed.

bo3b avatar Feb 21 '22 21:02 bo3b

Hi @gerboengels, @bo3b,

We have changed the way we applying fixes from Clang Power Tools v9.5 Try to update Clang Power Tools to the latest version 2023.6.0

Do you still have the same issue?

Kind regards, Marina

mariru27 avatar Jul 06 '23 08:07 mariru27