mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Revert unneeded changes and simplify code
This commit is contained in:
@@ -157,7 +157,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
return frameworkLocations;
|
||||
}
|
||||
|
||||
private void RestoreNugetPackages(List<FileInfo> allNonBinaryFiles, List<string> allProjects, List<string> allSolutions, HashSet<string> dllPaths)
|
||||
private void RestoreNugetPackages(List<FileInfo> allNonBinaryFiles, IEnumerable<string> allProjects, IEnumerable<string> allSolutions, HashSet<string> dllPaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -719,7 +719,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
/// Returns a list of projects that are up to date with respect to restore.
|
||||
/// </summary>
|
||||
/// <param name="solutions">A list of paths to solution files.</param>
|
||||
private IEnumerable<string> RestoreSolutions(List<string> solutions, out IEnumerable<string> assets)
|
||||
private IEnumerable<string> RestoreSolutions(IEnumerable<string> solutions, out IEnumerable<string> assets)
|
||||
{
|
||||
var successCount = 0;
|
||||
var assetFiles = new List<string>();
|
||||
@@ -841,21 +841,13 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
if (!res.Success)
|
||||
{
|
||||
logger.LogInfo($"Failed to restore nuget package {package}");
|
||||
}
|
||||
else
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
successCount++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
lock (sync)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
successCount++;
|
||||
}
|
||||
successCount++;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
/// Restore all files in a specified package.
|
||||
/// </summary>
|
||||
/// <param name="package">The package file.</param>
|
||||
private bool RestoreNugetPackage(string package)
|
||||
private bool TryRestoreNugetPackage(string package)
|
||||
{
|
||||
logger.LogInfo($"Restoring file {package}...");
|
||||
|
||||
@@ -157,17 +157,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
/// </summary>
|
||||
public int InstallPackages()
|
||||
{
|
||||
var success = 0;
|
||||
foreach (var package in packageFiles)
|
||||
{
|
||||
var result = RestoreNugetPackage(package.FullName);
|
||||
if (result)
|
||||
{
|
||||
success++;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
return packageFiles.Count(package => TryRestoreNugetPackage(package.FullName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Semmle.Extraction.CSharp.DependencyFetching;
|
||||
using Semmle.Util;
|
||||
using Semmle.Util.Logging;
|
||||
|
||||
@@ -12,7 +13,6 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
{
|
||||
public static class Extractor
|
||||
{
|
||||
|
||||
private static IEnumerable<Action> GetResolvedReferencesStandalone(IEnumerable<string> referencePaths, BlockingCollection<MetadataReference> references)
|
||||
{
|
||||
return referencePaths.Select<string, Action>(path => () =>
|
||||
@@ -138,10 +138,9 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
|
||||
using var logger = new ConsoleLogger(options.Verbosity, logThreadId: true);
|
||||
logger.Log(Severity.Info, "Extracting C# in buildless mode");
|
||||
using var a = new Analysis(logger, options);
|
||||
var sourceFileCount = a.Extraction.Sources.Count;
|
||||
using var dependencyManager = new DependencyManager(options.SrcDir, options.Dependencies, logger);
|
||||
|
||||
if (sourceFileCount == 0)
|
||||
if (!dependencyManager.AllSourceFiles.Any())
|
||||
{
|
||||
logger.Log(Severity.Error, "No source files found");
|
||||
return ExitCode.Errors;
|
||||
@@ -152,7 +151,7 @@ namespace Semmle.Extraction.CSharp.Standalone
|
||||
logger.Log(Severity.Info, "");
|
||||
logger.Log(Severity.Info, "Extracting...");
|
||||
ExtractStandalone(
|
||||
new ExtractionInput(a.Extraction.Sources, a.References, a.CompilationInfos),
|
||||
new ExtractionInput(dependencyManager.AllSourceFiles, dependencyManager.ReferenceFiles, dependencyManager.CompilationInfos),
|
||||
new ExtractionProgress(logger),
|
||||
fileLogger,
|
||||
options);
|
||||
|
||||
@@ -5,51 +5,6 @@ using Semmle.Extraction.CSharp.DependencyFetching;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Standalone
|
||||
{
|
||||
/// <summary>
|
||||
/// One independent run of the extractor.
|
||||
/// </summary>
|
||||
internal class Extraction
|
||||
{
|
||||
public Extraction(string directory)
|
||||
{
|
||||
Directory = directory;
|
||||
}
|
||||
|
||||
public string Directory { get; }
|
||||
public List<string> Sources { get; } = new List<string>();
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Searches for source/references and creates separate extractions.
|
||||
/// </summary>
|
||||
internal sealed class Analysis : IDisposable
|
||||
{
|
||||
public Analysis(ILogger logger, Options options)
|
||||
{
|
||||
dependencyManager = new DependencyManager(options.SrcDir, options.Dependencies, logger);
|
||||
References = dependencyManager.ReferenceFiles;
|
||||
Extraction = new Extraction(options.SrcDir);
|
||||
Extraction.Sources.AddRange(dependencyManager.AllSourceFiles);
|
||||
CompilationInfos = dependencyManager.CompilationInfos;
|
||||
}
|
||||
|
||||
public IEnumerable<string> References { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The extraction configuration.
|
||||
/// </summary>
|
||||
public Extraction Extraction { get; }
|
||||
|
||||
public IEnumerable<(string, string)> CompilationInfos { get; }
|
||||
|
||||
private readonly DependencyManager dependencyManager;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
dependencyManager.Dispose();
|
||||
}
|
||||
};
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp
|
||||
protected CSharpCompilation? compilation;
|
||||
protected CommonOptions? options;
|
||||
private protected Entities.Compilation? compilationEntity;
|
||||
private TrapWriter? compilationTrapFile;
|
||||
private IDisposable? compilationTrapFile;
|
||||
|
||||
private readonly object progressMutex = new object();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user