Skip to content

Commit

Permalink
Improve handling of MSVC include flags in compile commands logger (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkryza committed Nov 11, 2024
1 parent d742fb7 commit 9895a38
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions util/msbuild_compile_commands_logger/CompileCommandsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CompileCommandsLogger : Logger
private static readonly string CCompilerFrontend = "clang.exe";
private static readonly string CPPCompilerFrontend = "clang++.exe";

private static readonly string[] IgnoredFlags = {"/MP", "/Gm-"};
private static readonly string[] SourceFileTypeQualifierFlags = {"/Tc", "/Tp"};

private static readonly string[] CppExtensions = { ".cpp", ".cxx", ".cc", ".c" };

Expand Down Expand Up @@ -99,12 +99,13 @@ private void EventSource_AnyEventRaised(object sender, BuildEventArgs args)
List<string> filenames = new List<string>();
List<string> compileFlags = new List<string>();



// Here we assume that source files are at the end of the command and are absolute
int argIndex = cmdArgs.Length - 1;
for(;argIndex >= 0; argIndex--) {
if(IsCPPSourcePath(cmdArgs[argIndex])) {
if(SourceFileTypeQualifierFlags.Contains(cmdArgs[argIndex])) {
continue;
}
else if(IsCPPSourcePath(cmdArgs[argIndex])) {
filenames.Add(cmdArgs[argIndex]);
}
else {
Expand All @@ -113,6 +114,13 @@ private void EventSource_AnyEventRaised(object sender, BuildEventArgs args)
}

for(int i = 0; i < argIndex; i++) {
if(cmdArgs[i] == "/I") {
compileFlags.Add("-isystem" + cmdArgs[i+1]);
i++;

continue;
}

if(cmdArgs[i].StartsWith("/I")) {
compileFlags.Add("-isystem");
compileFlags.Add("\"" + cmdArgs[i].Substring(2) + "\"");
Expand Down

0 comments on commit 9895a38

Please sign in to comment.