Skip to content

Commit

Permalink
Support for nmake based projects
Browse files Browse the repository at this point in the history
  • Loading branch information
chumakovs committed Oct 17, 2023
1 parent 5f549bf commit a357637
Showing 1 changed file with 66 additions and 8 deletions.
74 changes: 66 additions & 8 deletions CPPCheckPlugin/CPPCheckPluginPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,37 @@ private static void recursiveAddToolDetails(SourceFile sourceForAnalysis, VCConf
}
}

private static void recursiveAddToolDetails(SourceFile sourceForAnalysis, VCConfiguration projectConfig, VCNMakeTool tool, dynamic propertySheets, ref bool bInheritDefs, ref bool bInheritUndefs)
{
// TODO: If the special keyword "\\\"$(INHERIT)\\\"" appears, we should inherit at that specific point.
if (bInheritDefs)
{
string[] macrosToDefine = tool.PreprocessorDefinitions.Split(';');
bInheritDefs = !macrosToDefine.Contains("\\\"$(NOINHERIT)\\\"");
for (int i = 0; i < macrosToDefine.Length; ++i)
{
macrosToDefine[i] = Environment.ExpandEnvironmentVariables(projectConfig.Evaluate(macrosToDefine[i]));
}

sourceForAnalysis.addMacros(macrosToDefine);
}

if (propertySheets != null && (bInheritDefs || bInheritUndefs))
{
// Scan any inherited property sheets.
foreach (var propSheet in propertySheets)
{
VCNMakeTool propSheetTool = (VCNMakeTool)propSheet.Tools.Item("VCNMakeTool");
if (propSheetTool != null)
{
// When looping over the inherited property sheets, don't allow rules to filter back up the way.
bool bInheritDefs1 = bInheritDefs, bInheritUndefs1 = bInheritUndefs;
recursiveAddToolDetails(sourceForAnalysis, projectConfig, propSheetTool, propSheet.PropertySheets, ref bInheritDefs1, ref bInheritUndefs1);
}
}
}
}

private static async Task<SourceFile> createSourceFileAsync(ProjectItem item)
{
try
Expand All @@ -715,15 +746,23 @@ private static async Task<SourceFile> createSourceFileAsync(ProjectItem item)
bool bInheritDefs = true, bInheritUndefs = true;
string[] includePaths = { };

// Do the file-level first in case it disables inheritance. Include files don't have file-level config.
if (implementsInterface(fileConfig.Tool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
// Possible exception thrown for nmake based project
try
{
// Do the file-level first in case it disables inheritance. Include files don't have file-level config.
if (implementsInterface(fileConfig.Tool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
{
VCCLCompilerTool vcTool = (VCCLCompilerTool)fileConfig.Tool;
sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
includePaths = vcTool.FullIncludePath.Split(';');
string macros = vcTool.PreprocessorDefinitions;
// Other details may be gathered from the file, project or any inherited property sheets.
recursiveAddToolDetails(sourceForAnalysis, vcconfig, vcTool, null, ref bInheritDefs, ref bInheritUndefs);
}
}
catch (Exception ex)
{
VCCLCompilerTool vcTool = (VCCLCompilerTool)fileConfig.Tool;
sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
includePaths = vcTool.FullIncludePath.Split(';');
string macros = vcTool.PreprocessorDefinitions;
// Other details may be gathered from the file, project or any inherited property sheets.
recursiveAddToolDetails(sourceForAnalysis, vcconfig, vcTool, null, ref bInheritDefs, ref bInheritUndefs);
DebugTracer.Trace(ex);
}

// Now get the full include path
Expand All @@ -746,6 +785,25 @@ private static async Task<SourceFile> createSourceFileAsync(ProjectItem item)

recursiveAddToolDetails(sourceForAnalysis, vcconfig, projectTool, vcconfig.PropertySheets, ref bInheritDefs, ref bInheritUndefs);
}

VCNMakeTool nmakeTool = (VCNMakeTool)vcconfigTools.Item("VCNMakeTool");
if (null != nmakeTool && implementsInterface(nmakeTool, "Microsoft.VisualStudio.VCProjectEngine.VCNMakeTool"))
{
if (sourceForAnalysis == null)
{
sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
includePaths = nmakeTool.IncludeSearchPath.Split(';');
}

// Take the full include path from file level, which is already fully resolved.
for (int i = 0; i < includePaths.Length; ++i)
{
includePaths[i] = Environment.ExpandEnvironmentVariables(vcconfig.Evaluate(includePaths[i]));
}
sourceForAnalysis.addIncludePaths(includePaths);

recursiveAddToolDetails(sourceForAnalysis, vcconfig, nmakeTool, vcconfig.PropertySheets, ref bInheritDefs, ref bInheritUndefs);
}
}

return sourceForAnalysis;
Expand Down

0 comments on commit a357637

Please sign in to comment.