зеркало из https://github.com/github/codeql.git
C#: Reduce logging output and write arguments to separate files. Fix missing response file.
This commit is contained in:
Родитель
ec2bf914c8
Коммит
681953ae70
|
@ -399,14 +399,6 @@ namespace Semmle.Extraction.CSharp
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int TotalErrors => CompilationErrors + ExtractorErrors;
|
public int TotalErrors => CompilationErrors + ExtractorErrors;
|
||||||
|
|
||||||
void AppendQuoted(StringBuilder sb, string s)
|
|
||||||
{
|
|
||||||
if (s.IndexOf(' ') != -1)
|
|
||||||
sb.Append('\"').Append(s).Append('\"');
|
|
||||||
else
|
|
||||||
sb.Append(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs detailed information about this invocation,
|
/// Logs detailed information about this invocation,
|
||||||
/// in the event that errors were detected.
|
/// in the event that errors were detected.
|
||||||
|
@ -414,36 +406,21 @@ namespace Semmle.Extraction.CSharp
|
||||||
/// <param name="roslynArgs">The arguments passed to Roslyn.</param>
|
/// <param name="roslynArgs">The arguments passed to Roslyn.</param>
|
||||||
public void LogDiagnostics(string[] roslynArgs)
|
public void LogDiagnostics(string[] roslynArgs)
|
||||||
{
|
{
|
||||||
Logger.Log(Severity.Info, " Current working directory: {0}", Directory.GetCurrentDirectory());
|
|
||||||
Logger.Log(Severity.Info, " Extractor: {0}", Environment.GetCommandLineArgs().First());
|
Logger.Log(Severity.Info, " Extractor: {0}", Environment.GetCommandLineArgs().First());
|
||||||
if (extractor != null)
|
if (extractor != null)
|
||||||
Logger.Log(Severity.Info, " Extractor version: {0}", extractor.Version);
|
Logger.Log(Severity.Info, " Extractor version: {0}", extractor.Version);
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(" Expanded command line: ");
|
Logger.Log(Severity.Info, " Current working directory: {0}", Directory.GetCurrentDirectory());
|
||||||
bool first = true;
|
|
||||||
foreach (var arg in Environment.GetCommandLineArgs().Skip(1))
|
|
||||||
{
|
|
||||||
if (arg[0] == '@')
|
|
||||||
{
|
|
||||||
foreach (var line in File.ReadAllLines(arg.Substring(1)))
|
|
||||||
{
|
|
||||||
if (first) first = false;
|
|
||||||
else sb.Append(" ");
|
|
||||||
sb.Append(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (first) first = false;
|
|
||||||
else sb.Append(" ");
|
|
||||||
AppendQuoted(sb, arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Logger.Log(Severity.Info, sb.ToString());
|
|
||||||
|
|
||||||
if (roslynArgs != null)
|
if (roslynArgs != null)
|
||||||
Logger.Log(Severity.Info, $" Arguments to Roslyn: {string.Join(' ', roslynArgs)}");
|
Logger.Log(Severity.Info, $" Arguments to Roslyn: {string.Join(' ', roslynArgs)}");
|
||||||
|
|
||||||
|
// Create a new file in the log folder.
|
||||||
|
var argsFile = Path.Combine(Extractor.GetCSharpLogDirectory(), $"csharp.{Path.GetRandomFileName()}.txt");
|
||||||
|
|
||||||
|
if (roslynArgs.ArchiveCommandLine(argsFile))
|
||||||
|
Logger.Log(Severity.Info, $" Arguments have been written to {argsFile}");
|
||||||
|
|
||||||
foreach (var error in FilteredDiagnostics)
|
foreach (var error in FilteredDiagnostics)
|
||||||
{
|
{
|
||||||
Logger.Log(Severity.Error, " Compilation error: {0}", error);
|
Logger.Log(Severity.Error, " Compilation error: {0}", error);
|
||||||
|
|
|
@ -124,7 +124,7 @@ namespace Semmle.Extraction.CSharp
|
||||||
/// <returns>Modified list of arguments.</returns>
|
/// <returns>Modified list of arguments.</returns>
|
||||||
static IEnumerable<string> AddDefaultResponse(string responseFile, IEnumerable<string> args)
|
static IEnumerable<string> AddDefaultResponse(string responseFile, IEnumerable<string> args)
|
||||||
{
|
{
|
||||||
return SuppressDefaultResponseFile(args) && File.Exists(responseFile) ?
|
return SuppressDefaultResponseFile(args) || !File.Exists(responseFile) ?
|
||||||
args :
|
args :
|
||||||
new[] { "@" + responseFile }.Concat(args);
|
new[] { "@" + responseFile }.Concat(args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,12 @@ namespace Semmle.Extraction.CSharp
|
||||||
|
|
||||||
public void Analysed(int item, int total, string source, string output, TimeSpan time, AnalysisAction action)
|
public void Analysed(int item, int total, string source, string output, TimeSpan time, AnalysisAction action)
|
||||||
{
|
{
|
||||||
Logger.Log(Severity.Info, " {0} -> {1} ({2})", source, output,
|
if (action != AnalysisAction.UpToDate)
|
||||||
|
{
|
||||||
|
Logger.Log(Severity.Info, " {0} ({2})", source, output,
|
||||||
action == AnalysisAction.Extracted ? time.ToString() : action == AnalysisAction.Excluded ? "excluded" : "up to date");
|
action == AnalysisAction.Extracted ? time.ToString() : action == AnalysisAction.Excluded ? "excluded" : "up to date");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void MissingNamespace(string @namespace) { }
|
public void MissingNamespace(string @namespace) { }
|
||||||
|
|
||||||
|
@ -361,27 +364,28 @@ namespace Semmle.Extraction.CSharp
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the `csharp.log` file written to by the C# extractor.
|
/// Gets the path to the `csharp.log` file written to by the C# extractor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetCSharpLogPath()
|
public static string GetCSharpLogPath() =>
|
||||||
|
Path.Combine(GetCSharpLogDirectory(), "csharp.log");
|
||||||
|
|
||||||
|
public static string GetCSharpLogDirectory()
|
||||||
{
|
{
|
||||||
string snapshot = Environment.GetEnvironmentVariable("ODASA_SNAPSHOT");
|
string snapshot = Environment.GetEnvironmentVariable("ODASA_SNAPSHOT");
|
||||||
string buildErrorDir = Environment.GetEnvironmentVariable("ODASA_BUILD_ERROR_DIR");
|
string buildErrorDir = Environment.GetEnvironmentVariable("ODASA_BUILD_ERROR_DIR");
|
||||||
string traps = Environment.GetEnvironmentVariable("TRAP_FOLDER");
|
string traps = Environment.GetEnvironmentVariable("TRAP_FOLDER");
|
||||||
string output = "csharp.log";
|
|
||||||
if (!string.IsNullOrEmpty(snapshot))
|
if (!string.IsNullOrEmpty(snapshot))
|
||||||
{
|
{
|
||||||
snapshot = Path.Combine(snapshot, "log");
|
return Path.Combine(snapshot, "log");
|
||||||
return Path.Combine(snapshot, output);
|
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(buildErrorDir))
|
if (!string.IsNullOrEmpty(buildErrorDir))
|
||||||
{
|
{
|
||||||
// Used by `qltest`
|
// Used by `qltest`
|
||||||
return Path.Combine(buildErrorDir, output);
|
return buildErrorDir;
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(traps))
|
if (!string.IsNullOrEmpty(traps))
|
||||||
{
|
{
|
||||||
return Path.Combine(traps, output);
|
return traps;
|
||||||
}
|
}
|
||||||
return output;
|
return Directory.GetCurrentDirectory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,7 @@ namespace Semmle.Extraction
|
||||||
public ISymbol symbol;
|
public ISymbol symbol;
|
||||||
public SyntaxNode node;
|
public SyntaxNode node;
|
||||||
public Exception exception;
|
public Exception exception;
|
||||||
|
|
||||||
|
public override string ToString() => message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Semmle.Util
|
||||||
|
{
|
||||||
|
public static class CommandLineExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Archives the first "@" argument in a list of command line arguments.
|
||||||
|
/// Subsequent "@" arguments are ignored.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="commandLineArguments">The raw command line arguments.</param>
|
||||||
|
/// <param name="filename">The full filename to write to.</param>
|
||||||
|
/// <returns>True iff the file was written.</returns>
|
||||||
|
public static bool ArchiveCommandLine(this IEnumerable<string> commandLineArguments, string filename)
|
||||||
|
{
|
||||||
|
foreach (var arg in commandLineArguments.Where(arg => arg[0] == '@').Select(arg => arg.Substring(1)))
|
||||||
|
{
|
||||||
|
File.Copy(arg, filename, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче