0xabu / MsBuildCompileCommandsJson

An MSBuild logger that emits compile_commands.json for C++ projects
MIT License
43 stars 8 forks source link

If the compiler path includes spaces, such as `C:\Program Files (x86)\...`, the output is incorrect #2

Closed roachsinai closed 2 years ago

roachsinai commented 2 years ago

The command I used to export compile_commands.json is:

& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" .\YBlaze.sln /p:Configuration=Release /t:Rebuild -logger:F:\code\tools\MsBuildCompileCommandsJson\bin\Release\netstandard2.0\CompileCommandsJson.dll

And I found there are some entries in json compile database has wrong value of "file":

image image image image

It look likes it split Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\CL.exe to 4 entries.

So did I run wrong command which leads to this? Thanks in advanced!

0xabu commented 2 years ago

This looks like a bug on my part. A workaround would be to install the compiler tools in a path without a space in it (which is the way I've used this code).

0xabu commented 2 years ago

Hmm, I'm actually calling shell32!CommandLineToArgvW to process the command line, which I would expect to do the right thing. I'm guessing that either msbuild is not quoting the path to CL.exe correctly in the command line, or we're hitting the "special interpretation of backslash characters" mentioned at the end of the above link.

roachsinai commented 2 years ago

This looks like a bug on my part. A workaround would be to install the compiler tools in a path without a space in it (which is the way I've used this code).

Maybe, I've tried create a soft link of msbuild, and get same results.

0xabu commented 2 years ago

Could you show me the "command" portion from one of the erroneous entries in the json DB? It's fine to obfuscate everything after the compiler path.

roachsinai commented 2 years ago

Could you show me the "command" portion from one of the erroneous entries in the json DB? It's fine to obfuscate everything after the compiler path.

Yes,

{"directory": "C:\\Users\\xq\\source\\repos\\YBlaze\\YBlaze",
 "command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\CL.exe /c /IC:\\Users\\xq\\source\\repos\\YBlaze\\packages\\Microsoft.ML.OnnxRuntime.Gpu.1.8.1\\build\\native\\../../build/native/include/ /I\"E:\\vcpkg\\installed\\x64-windows\\include\" /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /D _DEBUG /D _CONSOLE /D _USE_MATH_DEFINES /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /Fo\"x64\\Debug\\\\\" /Fd\"x64\\Debug\\vc142.pdb\" /external:W3 /Gd /TP /FC /errorReport:queue YBlaze.cpp dt\\yolo5.cpp dt\\dtBase.cpp dt\\Palmdt.cpp l1k\\Handl1k.cpp l1k\\l1kBase.cpp ort\\Ortsshl.cpp utils\\ctRect.cpp utils\\LoadFile.cpp utils\\Padii.cpp utils\\rtii.cpp",
 "file": "Files"},
{"directory": "C:\\Users\\xq\\source\\repos\\YBlaze\\YBlaze",
 "command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\CL.exe /c /IC:\\Users\\xq\\source\\repos\\YBlaze\\packages\\Microsoft.ML.OnnxRuntime.Gpu.1.8.1\\build\\native\\../../build/native/include/ /I\"E:\\vcpkg\\installed\\x64-windows\\include\" /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /D _DEBUG /D _CONSOLE /D _USE_MATH_DEFINES /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /Fo\"x64\\Debug\\\\\" /Fd\"x64\\Debug\\vc142.pdb\" /external:W3 /Gd /TP /FC /errorReport:queue YBlaze.cpp dt\\yolo5.cpp dt\\dtBase.cpp dt\\Palmdt.cpp l1k\\Handl1k.cpp l1k\\l1kBase.cpp ort\\Ortsshl.cpp utils\\ctRect.cpp utils\\LoadFile.cpp utils\\Padii.cpp utils\\rtii.cpp",
 "file": "(x86)\\Microsoft"},
{"directory": "C:\\Users\\xq\\source\\repos\\YBlaze\\YBlaze",
 "command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\CL.exe /c /IC:\\Users\\xq\\source\\repos\\YBlaze\\packages\\Microsoft.ML.OnnxRuntime.Gpu.1.8.1\\build\\native\\../../build/native/include/ /I\"E:\\vcpkg\\installed\\x64-windows\\include\" /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /D _DEBUG /D _CONSOLE /D _USE_MATH_DEFINES /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /Fo\"x64\\Debug\\\\\" /Fd\"x64\\Debug\\vc142.pdb\" /external:W3 /Gd /TP /FC /errorReport:queue YBlaze.cpp dt\\yolo5.cpp dt\\dtBase.cpp dt\\Palmdt.cpp l1k\\Handl1k.cpp l1k\\l1kBase.cpp ort\\Ortsshl.cpp utils\\ctRect.cpp utils\\LoadFile.cpp utils\\Padii.cpp utils\\rtii.cpp",
 "file": "Visual"},
{"directory": "C:\\Users\\xq\\source\\repos\\YBlaze\\YBlaze",
 "command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\CL.exe /c /IC:\\Users\\xq\\source\\repos\\YBlaze\\packages\\Microsoft.ML.OnnxRuntime.Gpu.1.8.1\\build\\native\\../../build/native/include/ /I\"E:\\vcpkg\\installed\\x64-windows\\include\" /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /D _DEBUG /D _CONSOLE /D _USE_MATH_DEFINES /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /Fo\"x64\\Debug\\\\\" /Fd\"x64\\Debug\\vc142.pdb\" /external:W3 /Gd /TP /FC /errorReport:queue YBlaze.cpp dt\\yolo5.cpp dt\\dtBase.cpp dt\\Palmdt.cpp l1k\\Handl1k.cpp l1k\\l1kBase.cpp ort\\Ortsshl.cpp utils\\ctRect.cpp utils\\LoadFile.cpp utils\\Padii.cpp utils\\rtii.cpp",
 "file": "Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\CL.exe"},
0xabu commented 2 years ago

Please reopen if you still encounter this problem.

roachsinai commented 2 years ago

@0xabu disappears, thanks!