Caphyon / clang-power-tools

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

Environment variables in vcxproj are not replaced #132

Closed neusdan closed 6 years ago

neusdan commented 6 years ago

First of all, thanks for your great work.

Unfortunately, for me, environment variables in include paths are still not working (GH #33). There is no error, the path from the environment variable is just missing.

I am using version 2.0.

Even tried to achieve it with user-defined macros, but they are also not evaluated.

Another problem:

...
AUSFšHRLICH: SET_VAR IncludePath: 
;C:\Coding\tools\MyTool\..\..\..\..\;..\..\..\..\..\..\libs\Utils;
...

The semicolon at the front is the environment var which is not evaluated. The second problem is, that ..\..\..\..\..\..\libs\Utils; is not added to the include directories:

...
AUSFšHRLICH: Include directories:
AUSFšHRLICH:   C:\Coding\tools\
AUSFšHRLICH:   C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include
AUSFšHRLICH:   C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\8.1\Include\um
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\8.1\Include\shared
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\8.1\Include\winrt
...
cpp-red-lion commented 6 years ago

Hi,

Can you attach a sample vcxproj or VS property-sheets reproducing the issue, so we can investigate ?

Thanks.

neusdan commented 6 years ago

Please find attached a minimal Visual Studio solution which should reproduce the issue.

I've set a system environment variable: MY_INCLUDE=G:\Coding\MyInclude

This variable is added as $(MY_INCLUDE) to the include path. While Visual Studio is able to compile it, clang generates the following output:


Start Clang Compile

AUSFšHRLICH: clang-build.ps1 invocation args: 
  aVcxprojToCompile = G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj 
  aVcxprojConfigPlatform = Debug|x64 
  aClangCompileFlags = -Werror -std=c++14 -Wall -fms-compatibility-version=19.10 -fms-compatibility -Wmicrosoft 
-Wno-invalid-token-paste -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-value 
  Verbose = True 
  aUseParallelCompile = True 
  aVisualStudioVersion = 2017 
  aVisualStudioSku = Community 
  aDirectory = G:\Coding\ClangPowerToolsTest 
  aDisableNameRegexMatching = True 
AUSFšHRLICH: CPU logical core count: 8
AUSFšHRLICH: Scanning for solution files
AUSFšHRLICH: Solution file paths:
AUSFšHRLICH:   G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest.sln
AUSFšHRLICH: Source directory: G:\Coding\ClangPowerToolsTest
AUSFšHRLICH: Scanning for project files
AUSFšHRLICH: Found 1 projects
[ INFO ] WILL PROCESS PROJECTS: 
    ClangPowetToolsTest.vcxproj
[ INFO ] 1. PROCESSING PROJECT G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildProjectFullPath: 
G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR ProjectDir: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\
AUSFšHRLICH: SET_VAR MSBuildProjectExtension: .vcxproj
AUSFšHRLICH: SET_VAR MSBuildProjectName: ClangPowetToolsTest
AUSFšHRLICH: SET_VAR MSBuildProjectDirectory: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\
AUSFšHRLICH: SET_VAR MSBuildProgramFiles32: C:\Program Files (x86)
AUSFšHRLICH: SET_VAR VisualStudioVersion: 15.0
AUSFšHRLICH: SET_VAR SolutionDir: G:\Coding\ClangPowerToolsTest\
AUSFšHRLICH: SET_VAR MSBuildThisFileFullPath: 
G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileExtension: .vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFile: ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileName: ClangPowetToolsTest
AUSFšHRLICH: SET_VAR MSBuildThisFileDirectory: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\
AUSFšHRLICH: SET_VAR Configuration: Debug
AUSFšHRLICH: SET_VAR Platform: x64
AUSFšHRLICH: 
Sanitizing G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileFullPath: 
G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileExtension: .vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFile: ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileName: ClangPowetToolsTest
AUSFšHRLICH: SET_VAR MSBuildThisFileDirectory: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\
AUSFšHRLICH: SET_VAR VCProjectVersion: 15.0
AUSFšHRLICH: SET_VAR ProjectGuid: {19C1B6E1-B378-412F-9528-FDA004C242D3}
AUSFšHRLICH: SET_VAR Keyword: Win32Proj
AUSFšHRLICH: SET_VAR RootNamespace: ClangPowetToolsTest
AUSFšHRLICH: SET_VAR WindowsTargetPlatformVersion: 10.0.16299.0
AUSFšHRLICH: SET_VAR ConfigurationType: Application
AUSFšHRLICH: SET_VAR UseDebugLibraries: true
AUSFšHRLICH: SET_VAR PlatformToolset: v141
AUSFšHRLICH: SET_VAR CharacterSet: Unicode
AUSFšHRLICH: SET_VAR LinkIncremental: true
AUSFšHRLICH: SET_VAR IncludePath: ;
AUSFšHRLICH: PCH not enabled for this project!
AUSFšHRLICH: Preprocessor definitions:
AUSFšHRLICH:   -D_DEBUG
AUSFšHRLICH:   -D_CONSOLE
AUSFšHRLICH:   -DUNICODE
AUSFšHRLICH:   -D_UNICODE
AUSFšHRLICH: Platform toolset: v141
AUSFšHRLICH: Additional includes:
AUSFšHRLICH:   
AUSFšHRLICH: Visual Studio location: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
AUSFšHRLICH: MSCVER: 14.11.25503
AUSFšHRLICH: WinSDK version: 10.0.16299.0
AUSFšHRLICH: Include directories:
AUSFšHRLICH:   G:\Coding\ClangPowerToolsTest
AUSFšHRLICH:   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include
AUSFšHRLICH:   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc\include
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\winrt
AUSFšHRLICH:   
AUSFšHRLICH: Force includes: 
AUSFšHRLICH: Processing 1 cpps
AUSFšHRLICH: Clang job tool: clang++.exe
AUSFšHRLICH: Clang job args[0]: -x c++ "G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.cpp" 
-Werror -std=c++14 -Wall -fms-compatibility-version=19.10 -fms-compatibility -Wmicrosoft -Wno-invalid-token-paste 
-Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-value -fsyntax-only -D_DEBUG -D_CONSOLE -DUNICODE -D_UNICODE
1: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.cpp
G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.cpp:2:10: fatal error: 'MyExternalIncludeFile.hxx' file not found
#include <MyExternalIncludeFile.hxx>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1
 error generated.

Got errors.
AUSFšHRLICH: Cleaning up PCH temporaries:

Done Clang Compile

Thanks in advance!

ClangPowerToolsTest.zip

neusdan commented 6 years ago

Another example which does not involve environment variables.

Here i set ..\..\..\LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG; as a include path and copied there my include file.

Clang output:


Start Clang Compile

AUSFšHRLICH: clang-build.ps1 invocation args: 
  aVcxprojToCompile = G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj 
  aVcxprojConfigPlatform = Debug|x64 
  aClangCompileFlags = -Werror -std=c++14 -Wall -fms-compatibility-version=19.10 -fms-compatibility -Wmicrosoft 
-Wno-invalid-token-paste -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-value 
  Verbose = True 
  aUseParallelCompile = True 
  aVisualStudioVersion = 2017 
  aVisualStudioSku = Community 
  aDirectory = G:\Coding\ClangPowerToolsTest 
  aDisableNameRegexMatching = True 
AUSFšHRLICH: CPU logical core count: 8
AUSFšHRLICH: Scanning for solution files
AUSFšHRLICH: Solution file paths:
AUSFšHRLICH:   G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest.sln
AUSFšHRLICH: Source directory: G:\Coding\ClangPowerToolsTest
AUSFšHRLICH: Scanning for project files
AUSFšHRLICH: Found 1 projects
[ INFO ] WILL PROCESS PROJECTS: 
    ClangPowetToolsTest.vcxproj
[ INFO ] 1. PROCESSING PROJECT G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildProjectFullPath: 
G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR ProjectDir: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\
AUSFšHRLICH: SET_VAR MSBuildProjectExtension: .vcxproj
AUSFšHRLICH: SET_VAR MSBuildProjectName: ClangPowetToolsTest
AUSFšHRLICH: SET_VAR MSBuildProjectDirectory: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\
AUSFšHRLICH: SET_VAR MSBuildProgramFiles32: C:\Program Files (x86)
AUSFšHRLICH: SET_VAR VisualStudioVersion: 15.0
AUSFšHRLICH: SET_VAR SolutionDir: G:\Coding\ClangPowerToolsTest\
AUSFšHRLICH: SET_VAR MSBuildThisFileFullPath: 
G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileExtension: .vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFile: ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileName: ClangPowetToolsTest
AUSFšHRLICH: SET_VAR MSBuildThisFileDirectory: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\
AUSFšHRLICH: SET_VAR Configuration: Debug
AUSFšHRLICH: SET_VAR Platform: x64
AUSFšHRLICH: 
Sanitizing G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileFullPath: 
G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileExtension: .vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFile: ClangPowetToolsTest.vcxproj
AUSFšHRLICH: SET_VAR MSBuildThisFileName: ClangPowetToolsTest
AUSFšHRLICH: SET_VAR MSBuildThisFileDirectory: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\
AUSFšHRLICH: SET_VAR VCProjectVersion: 15.0
AUSFšHRLICH: SET_VAR ProjectGuid: {19C1B6E1-B378-412F-9528-FDA004C242D3}
AUSFšHRLICH: SET_VAR Keyword: Win32Proj
AUSFšHRLICH: SET_VAR RootNamespace: ClangPowetToolsTest
AUSFšHRLICH: SET_VAR WindowsTargetPlatformVersion: 10.0.16299.0
AUSFšHRLICH: SET_VAR ConfigurationType: Application
AUSFšHRLICH: SET_VAR UseDebugLibraries: true
AUSFšHRLICH: SET_VAR PlatformToolset: v141
AUSFšHRLICH: SET_VAR CharacterSet: Unicode
AUSFšHRLICH: SET_VAR LinkIncremental: true
AUSFšHRLICH: SET_VAR IncludePath: ..\..\..\LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG;
AUSFšHRLICH: PCH not enabled for this project!
AUSFšHRLICH: Preprocessor definitions:
AUSFšHRLICH:   -D_DEBUG
AUSFšHRLICH:   -D_CONSOLE
AUSFšHRLICH:   -DUNICODE
AUSFšHRLICH:   -D_UNICODE
AUSFšHRLICH: Platform toolset: v141
AUSFšHRLICH: Additional includes:
AUSFšHRLICH:   
AUSFšHRLICH: Visual Studio location: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
AUSFšHRLICH: MSCVER: 14.11.25503
AUSFšHRLICH: WinSDK version: 10.0.16299.0
AUSFšHRLICH: Include directories:
AUSFšHRLICH:   G:\Coding\ClangPowerToolsTest
AUSFšHRLICH:   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include
AUSFšHRLICH:   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\atlmfc\include
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared
AUSFšHRLICH:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\winrt
AUSFšHRLICH:   
AUSFšHRLICH: Force includes: 
AUSFšHRLICH: Processing 1 cpps
AUSFšHRLICH: Clang job tool: clang++.exe
AUSFšHRLICH: Clang job args[0]: -x c++ "G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.cpp" 
-Werror -std=c++14 -Wall -fms-compatibility-version=19.10 -fms-compatibility -Wmicrosoft -Wno-invalid-token-paste 
-Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-value -fsyntax-only -D_DEBUG -D_CONSOLE -DUNICODE -D_UNICODE
1: G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.cpp
G:\Coding\ClangPowerToolsTest\ClangPowetToolsTest\ClangPowetToolsTest.cpp:2:10: fatal error: 'MyExternalIncludeFile.hxx' file not found
#include <MyExternalIncludeFile.hxx>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1
 error generated.

Got errors.
AUSFšHRLICH: Cleaning up PCH temporaries:

Done Clang Compile

ClangPowerToolsTest2.zip

mariusz102102 commented 6 years ago

I think that writing reliable sln, vcxproj parse is very difficult.

As we already know there is many options: nuget, vcpkg, Property pages, reach vcxproj syntax, environment variables i.e. INCLUDES ... and new are coming: Visual Studio CMake support

Your extension is very popular. Maybe you can ask someone from Microsoft for help?

What do you think about parsing output of msbuild ? msbuild /property:SelectedFiles="stdafx.cpp" Lib.sln

cpp-red-lion commented 6 years ago

Hi @mariusz102102 ,

It is quite possible that we'll switch to MSBuild tools (APIs) for parsing the vcxproj and VS property-sheets in the future, but, at least for now, we're sticking with our PowerShell script, as we've invested heavily into its development and we fixed most of the outstanding issues regarding parsing.

When we'll incur limitations on what we can do with the current strategy, we'll definitely re-implement our parsing engine on top of MSBuild.

cpp-red-lion commented 6 years ago

Hi @neusdan ,

Thanks for attaching the project. We'll debug and get back to you with a fix/workaround.

hero101111 commented 6 years ago

Hi @neusdan ,

Thank you for your sample projects. We've identified and fixed two issues that affect your projects:

Please update your clang-build.ps1 file from the VS extension folder using the instructions below and let us know if your projects compile.


This fix is currently live only for the github repository. The latest Visual Studio extension (2.0) does not contain the fix. It will be included in the next release.

Until then, as a workaround, you can manually replace clang-build.ps1 in the VS extension directory with the latest from github. To locate the extension directory search for clang-build.ps1 in %LOCALAPPDATA%

Don't forget to restart Visual Studio after replacing the script file.