Caphyon / clang-power-tools

Bringing clang-tidy magic to Visual Studio C++ developers.
http://www.clangpowertools.com
Apache License 2.0
472 stars 57 forks source link

"Get-ChildItem : Illegal characters in path" on clang-tidy #1315

Closed brt-v closed 10 months ago

brt-v commented 10 months ago

When I run clang tidy from VS2017 I get:

Get-ChildItem : Illegal characters in path.
At C:\users\<me>\appdata\local\microsoft\visualstudio\15.0_83117ebd\extensions\lhiblryq.qr0\Tooling\v1\clang-build.ps1:5
62 char:12
+    $slns = Get-ChildItem -recurse -LiteralPath $pathToCheck -Filter " ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetChildItemCommand

This is with 2023.8.0, but I've also seen it with older versions.

Things go wrong for me in function Load-Solutions(): https://github.com/Caphyon/clang-power-tools/blob/master/ClangPowerTools/ClangPowerTools/Tooling/v1/clang-build.ps1#L534

The bit:

if ($kPsMajorVersion -lt 6)
{
  # we need not bother with long path support in PowerShell 6+
  # only in Windows PowerShell
  $pathToCheck = "\\?\$aSolutionsPath"
}

prefixes the path with \\?\ and that causes the error on Get-ChildItem. My $kPsMajorVersion is 5, so if I change it to

if ($kPsMajorVersion -lt 5) 
{
   ...
}

it works again. I'm happy to create a PR, however I'm not sure if this breaks tidy for anyone else.

mariru27 commented 10 months ago

Hi @brt-v,

Thank you for reporting this issue

We will investigate this problem, but as I remember our tidy does not work on powershell 5.1 without using prefix path

Kind regard, Marina

brt-v commented 10 months ago

Thanks for looking into this @mariru27! My PS version is 5.1 (on an up-to-date Win 10 Enterprise), and after the change clang-tidy works perfectly fine. Perhaps it might have been an issue with PS 5.0?

edit: Maybe change the whole thing to this, and be done with it?

[string] $pathToCheck = $aSolutionsPath
  Try
  {
      $slns = Get-ChildItem -recurse -LiteralPath $pathToCheck -Filter "*$kExtensionSolution"
  }
  Catch
  {
    # Try fall back for PowerShell <= 5
    $pathToCheck = "\\?\$aSolutionsPath"
    $slns = Get-ChildItem -recurse -LiteralPath $pathToCheck -Filter "*$kExtensionSolution"
  }
mariru27 commented 10 months ago

Thank you @brt-v, this is a good idea I will make the changes and let you know when a release is available

Kind regards, Marina

mariru27 commented 10 months ago

Hi @brt-v, a fix for this issue is available

You can update manually our scripts, just make sure you have a good connection to internet Go to -> Settings -> Compiler -> PowerShell scripts image

Kind regards, Marina

brt-v commented 10 months ago

Hi @mariru27, That's great, thanks! I've done the update and can confirm that it works that clang-tidy now works for me.

Thanks again for the quick action!

Bart