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

Commit 6b9a344

Browse files
committed
Bugfixes for multiple projects checking
1 parent 8b6d874 commit 6b9a344

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

CPPCheckPlugin/AnalyzerCppcheck.cs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public AnalyzerCppcheck()
2727
{
2828
DateTime fileModifiedDate = File.GetLastWriteTime(file);
2929

30-
if (fileModifiedDate.AddMinutes(60) < DateTime.Now)
30+
if (fileModifiedDate.AddMinutes(120) < DateTime.Now)
3131
{
32-
// File hasn't been written to in the last 60 mins, so it must be
32+
// File hasn't been written to in the last 120 minutes, so it must be
3333
// from an earlier instance which didn't exit gracefully.
3434
File.Delete(file);
3535
}
@@ -40,12 +40,10 @@ public AnalyzerCppcheck()
4040

4141
~AnalyzerCppcheck()
4242
{
43-
// Delete the temp file. Doesn't throw an exception if the file was never
44-
// created, so we don't need to worry about that.
45-
File.Delete(tempFileName);
43+
cleanupTempFiles();
4644
}
4745

48-
private string getCPPCheckArgs(ConfiguredFiles configuredFiles, bool analysisOnSavedFile, bool multipleProjects, StreamWriter tempFile)
46+
private string getCPPCheckArgs(ConfiguredFiles configuredFiles, bool analysisOnSavedFile, bool multipleProjects, string tempFileName)
4947
{
5048
Debug.Assert(_numCores > 0);
5149
String cppheckargs = Properties.Settings.Default.DefaultArguments;
@@ -112,10 +110,13 @@ private string getCPPCheckArgs(ConfiguredFiles configuredFiles, bool analysisOnS
112110
}
113111
}
114112

115-
foreach (SourceFile file in filesToAnalyze)
113+
using (StreamWriter tempFile = new StreamWriter(tempFileName))
116114
{
117-
if (!matchMasksList(file.FileName, unitedSuppressionsInfo.SkippedFilesMask))
118-
tempFile.WriteLine(file.FilePath);
115+
foreach (SourceFile file in filesToAnalyze)
116+
{
117+
if (!matchMasksList(file.FileName, unitedSuppressionsInfo.SkippedFilesMask))
118+
tempFile.WriteLine(file.FilePath);
119+
}
119120
}
120121

121122
cppheckargs += " --file-list=\"" + tempFileName + "\"";
@@ -209,11 +210,8 @@ public override void analyze(List<ConfiguredFiles> allConfiguredFiles, OutputWin
209210
return;
210211

211212
List<string> cppheckargs = new List<string>();
212-
using( StreamWriter tempFile = new StreamWriter(tempFileName) )
213-
{
214-
foreach (var configuredFiles in allConfiguredFiles)
215-
cppheckargs.Add(getCPPCheckArgs(configuredFiles, analysisOnSavedFile, allConfiguredFiles.Count > 1, tempFile));
216-
}
213+
foreach (var configuredFiles in allConfiguredFiles)
214+
cppheckargs.Add(getCPPCheckArgs(configuredFiles, analysisOnSavedFile, allConfiguredFiles.Count > 1, createNewTempFileName()));
217215

218216
string analyzerPath = Properties.Settings.Default.CPPcheckPath;
219217
while (!File.Exists(analyzerPath))
@@ -361,17 +359,37 @@ protected override List<Problem> parseOutput(String output)
361359
return result;
362360
}
363361

364-
protected override void analysisFinished()
362+
protected override void analysisFinished(string arguments)
365363
{
366364
if (_unfinishedProblem != null)
367365
addProblemToToolwindow(_unfinishedProblem);
368366

369-
// Delete the temp file. Doesn't throw an exception if the file was never
370-
// created, so we don't need to worry about that.
367+
const string fileListPattern = "--file-list=\"";
368+
int filenamePos = arguments.IndexOf(fileListPattern) + fileListPattern.Length;
369+
int filenameLength = arguments.IndexOf('\"', filenamePos) - filenamePos;
370+
string tempFileName = arguments.Substring(filenamePos, filenameLength);
371+
371372
File.Delete(tempFileName);
372373
}
374+
375+
private void cleanupTempFiles()
376+
{
377+
// Delete the temp files. Doesn't throw an exception if the file was never
378+
// created, so we don't need to worry about that.
379+
foreach (string name in _tempFileNamesInUse)
380+
File.Delete(name);
381+
382+
_tempFileNamesInUse.Clear();
383+
}
384+
385+
private string createNewTempFileName()
386+
{
387+
string name = Path.GetTempPath() + tempFilePrefix + "_" + Path.GetRandomFileName();
388+
_tempFileNamesInUse.Add(name);
389+
return name;
390+
}
373391

374392
private Problem _unfinishedProblem = null;
375-
private string tempFileName = Path.GetTempPath() + tempFilePrefix + "_" + Path.GetRandomFileName();
393+
private List<string> _tempFileNamesInUse = new List<string>();
376394
}
377395
}

CPPCheckPlugin/ICodeAnalyzer.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected ICodeAnalyzer()
7777

7878
protected abstract List<Problem> parseOutput(String output);
7979

80-
protected abstract void analysisFinished();
80+
protected abstract void analysisFinished(string arguments);
8181

8282
protected void run(string analyzerExePath, List<string> arguments, OutputWindowPane outputPane)
8383
{
@@ -210,7 +210,14 @@ private void startAnalyzerProcess(string analyzerExePath, string arguments)
210210
var timer = Stopwatch.StartNew();
211211
// Start the process.
212212
process.Start();
213-
process.PriorityClass = ProcessPriorityClass.Idle;
213+
214+
try
215+
{
216+
process.PriorityClass = ProcessPriorityClass.Idle;
217+
}
218+
catch (System.InvalidOperationException ex)
219+
{
220+
}
214221

215222
onProgressUpdated(0);
216223

@@ -227,7 +234,7 @@ private void startAnalyzerProcess(string analyzerExePath, string arguments)
227234
}
228235
}
229236
timer.Stop();
230-
analysisFinished();
237+
analysisFinished(arguments);
231238
if (process.ExitCode != 0)
232239
_outputPane.OutputString(analyzerExePath + " has exited with code " + process.ExitCode.ToString() + "\n");
233240
else

0 commit comments

Comments
 (0)