Skip to content

Commit

Permalink
Bugfixes for multiple projects checking
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletGiraffe committed May 29, 2015
1 parent 8b6d874 commit 6b9a344
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
54 changes: 36 additions & 18 deletions CPPCheckPlugin/AnalyzerCppcheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public AnalyzerCppcheck()
{
DateTime fileModifiedDate = File.GetLastWriteTime(file);

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

~AnalyzerCppcheck()
{
// Delete the temp file. Doesn't throw an exception if the file was never
// created, so we don't need to worry about that.
File.Delete(tempFileName);
cleanupTempFiles();
}

private string getCPPCheckArgs(ConfiguredFiles configuredFiles, bool analysisOnSavedFile, bool multipleProjects, StreamWriter tempFile)
private string getCPPCheckArgs(ConfiguredFiles configuredFiles, bool analysisOnSavedFile, bool multipleProjects, string tempFileName)
{
Debug.Assert(_numCores > 0);
String cppheckargs = Properties.Settings.Default.DefaultArguments;
Expand Down Expand Up @@ -112,10 +110,13 @@ private string getCPPCheckArgs(ConfiguredFiles configuredFiles, bool analysisOnS
}
}

foreach (SourceFile file in filesToAnalyze)
using (StreamWriter tempFile = new StreamWriter(tempFileName))
{
if (!matchMasksList(file.FileName, unitedSuppressionsInfo.SkippedFilesMask))
tempFile.WriteLine(file.FilePath);
foreach (SourceFile file in filesToAnalyze)
{
if (!matchMasksList(file.FileName, unitedSuppressionsInfo.SkippedFilesMask))
tempFile.WriteLine(file.FilePath);
}
}

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

List<string> cppheckargs = new List<string>();
using( StreamWriter tempFile = new StreamWriter(tempFileName) )
{
foreach (var configuredFiles in allConfiguredFiles)
cppheckargs.Add(getCPPCheckArgs(configuredFiles, analysisOnSavedFile, allConfiguredFiles.Count > 1, tempFile));
}
foreach (var configuredFiles in allConfiguredFiles)
cppheckargs.Add(getCPPCheckArgs(configuredFiles, analysisOnSavedFile, allConfiguredFiles.Count > 1, createNewTempFileName()));

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

protected override void analysisFinished()
protected override void analysisFinished(string arguments)
{
if (_unfinishedProblem != null)
addProblemToToolwindow(_unfinishedProblem);

// Delete the temp file. Doesn't throw an exception if the file was never
// created, so we don't need to worry about that.
const string fileListPattern = "--file-list=\"";
int filenamePos = arguments.IndexOf(fileListPattern) + fileListPattern.Length;
int filenameLength = arguments.IndexOf('\"', filenamePos) - filenamePos;
string tempFileName = arguments.Substring(filenamePos, filenameLength);

File.Delete(tempFileName);
}

private void cleanupTempFiles()
{
// Delete the temp files. Doesn't throw an exception if the file was never
// created, so we don't need to worry about that.
foreach (string name in _tempFileNamesInUse)
File.Delete(name);

_tempFileNamesInUse.Clear();
}

private string createNewTempFileName()
{
string name = Path.GetTempPath() + tempFilePrefix + "_" + Path.GetRandomFileName();
_tempFileNamesInUse.Add(name);
return name;
}

private Problem _unfinishedProblem = null;
private string tempFileName = Path.GetTempPath() + tempFilePrefix + "_" + Path.GetRandomFileName();
private List<string> _tempFileNamesInUse = new List<string>();
}
}
13 changes: 10 additions & 3 deletions CPPCheckPlugin/ICodeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected ICodeAnalyzer()

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

protected abstract void analysisFinished();
protected abstract void analysisFinished(string arguments);

protected void run(string analyzerExePath, List<string> arguments, OutputWindowPane outputPane)
{
Expand Down Expand Up @@ -210,7 +210,14 @@ private void startAnalyzerProcess(string analyzerExePath, string arguments)
var timer = Stopwatch.StartNew();
// Start the process.
process.Start();
process.PriorityClass = ProcessPriorityClass.Idle;

try
{
process.PriorityClass = ProcessPriorityClass.Idle;
}
catch (System.InvalidOperationException ex)
{
}

onProgressUpdated(0);

Expand All @@ -227,7 +234,7 @@ private void startAnalyzerProcess(string analyzerExePath, string arguments)
}
}
timer.Stop();
analysisFinished();
analysisFinished(arguments);
if (process.ExitCode != 0)
_outputPane.OutputString(analyzerExePath + " has exited with code " + process.ExitCode.ToString() + "\n");
else
Expand Down

0 comments on commit 6b9a344

Please sign in to comment.