Skip to content
This repository was archived by the owner on Aug 9, 2025. It is now read-only.

Commit a357637

Browse files
committed
Support for nmake based projects
1 parent 5f549bf commit a357637

File tree

1 file changed

+66
-8
lines changed

1 file changed

+66
-8
lines changed

CPPCheckPlugin/CPPCheckPluginPackage.cs

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,37 @@ private static void recursiveAddToolDetails(SourceFile sourceForAnalysis, VCConf
690690
}
691691
}
692692

693+
private static void recursiveAddToolDetails(SourceFile sourceForAnalysis, VCConfiguration projectConfig, VCNMakeTool tool, dynamic propertySheets, ref bool bInheritDefs, ref bool bInheritUndefs)
694+
{
695+
// TODO: If the special keyword "\\\"$(INHERIT)\\\"" appears, we should inherit at that specific point.
696+
if (bInheritDefs)
697+
{
698+
string[] macrosToDefine = tool.PreprocessorDefinitions.Split(';');
699+
bInheritDefs = !macrosToDefine.Contains("\\\"$(NOINHERIT)\\\"");
700+
for (int i = 0; i < macrosToDefine.Length; ++i)
701+
{
702+
macrosToDefine[i] = Environment.ExpandEnvironmentVariables(projectConfig.Evaluate(macrosToDefine[i]));
703+
}
704+
705+
sourceForAnalysis.addMacros(macrosToDefine);
706+
}
707+
708+
if (propertySheets != null && (bInheritDefs || bInheritUndefs))
709+
{
710+
// Scan any inherited property sheets.
711+
foreach (var propSheet in propertySheets)
712+
{
713+
VCNMakeTool propSheetTool = (VCNMakeTool)propSheet.Tools.Item("VCNMakeTool");
714+
if (propSheetTool != null)
715+
{
716+
// When looping over the inherited property sheets, don't allow rules to filter back up the way.
717+
bool bInheritDefs1 = bInheritDefs, bInheritUndefs1 = bInheritUndefs;
718+
recursiveAddToolDetails(sourceForAnalysis, projectConfig, propSheetTool, propSheet.PropertySheets, ref bInheritDefs1, ref bInheritUndefs1);
719+
}
720+
}
721+
}
722+
}
723+
693724
private static async Task<SourceFile> createSourceFileAsync(ProjectItem item)
694725
{
695726
try
@@ -715,15 +746,23 @@ private static async Task<SourceFile> createSourceFileAsync(ProjectItem item)
715746
bool bInheritDefs = true, bInheritUndefs = true;
716747
string[] includePaths = { };
717748

718-
// Do the file-level first in case it disables inheritance. Include files don't have file-level config.
719-
if (implementsInterface(fileConfig.Tool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
749+
// Possible exception thrown for nmake based project
750+
try
751+
{
752+
// Do the file-level first in case it disables inheritance. Include files don't have file-level config.
753+
if (implementsInterface(fileConfig.Tool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
754+
{
755+
VCCLCompilerTool vcTool = (VCCLCompilerTool)fileConfig.Tool;
756+
sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
757+
includePaths = vcTool.FullIncludePath.Split(';');
758+
string macros = vcTool.PreprocessorDefinitions;
759+
// Other details may be gathered from the file, project or any inherited property sheets.
760+
recursiveAddToolDetails(sourceForAnalysis, vcconfig, vcTool, null, ref bInheritDefs, ref bInheritUndefs);
761+
}
762+
}
763+
catch (Exception ex)
720764
{
721-
VCCLCompilerTool vcTool = (VCCLCompilerTool)fileConfig.Tool;
722-
sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
723-
includePaths = vcTool.FullIncludePath.Split(';');
724-
string macros = vcTool.PreprocessorDefinitions;
725-
// Other details may be gathered from the file, project or any inherited property sheets.
726-
recursiveAddToolDetails(sourceForAnalysis, vcconfig, vcTool, null, ref bInheritDefs, ref bInheritUndefs);
765+
DebugTracer.Trace(ex);
727766
}
728767

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

747786
recursiveAddToolDetails(sourceForAnalysis, vcconfig, projectTool, vcconfig.PropertySheets, ref bInheritDefs, ref bInheritUndefs);
748787
}
788+
789+
VCNMakeTool nmakeTool = (VCNMakeTool)vcconfigTools.Item("VCNMakeTool");
790+
if (null != nmakeTool && implementsInterface(nmakeTool, "Microsoft.VisualStudio.VCProjectEngine.VCNMakeTool"))
791+
{
792+
if (sourceForAnalysis == null)
793+
{
794+
sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
795+
includePaths = nmakeTool.IncludeSearchPath.Split(';');
796+
}
797+
798+
// Take the full include path from file level, which is already fully resolved.
799+
for (int i = 0; i < includePaths.Length; ++i)
800+
{
801+
includePaths[i] = Environment.ExpandEnvironmentVariables(vcconfig.Evaluate(includePaths[i]));
802+
}
803+
sourceForAnalysis.addIncludePaths(includePaths);
804+
805+
recursiveAddToolDetails(sourceForAnalysis, vcconfig, nmakeTool, vcconfig.PropertySheets, ref bInheritDefs, ref bInheritUndefs);
806+
}
749807
}
750808

751809
return sourceForAnalysis;

0 commit comments

Comments
 (0)