mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
C#: Refactor dotnet source generator execution
This commit is contained in:
@@ -1,15 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using Semmle.Util;
|
||||
using System.Text.RegularExpressions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Semmle.Util;
|
||||
using Semmle.Util.Logging;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
{
|
||||
internal partial class Sdk
|
||||
{
|
||||
private readonly IDotNet dotNet;
|
||||
private readonly ILogger logger;
|
||||
private readonly Lazy<string?> cscPath;
|
||||
public string? CscPath => cscPath.Value;
|
||||
|
||||
public Sdk(IDotNet dotNet) => this.dotNet = dotNet;
|
||||
private readonly Lazy<DotNetVersion?> newestSdkVersion;
|
||||
public DotNetVersion? Version => newestSdkVersion.Value;
|
||||
|
||||
public Sdk(IDotNet dotNet, ILogger logger)
|
||||
{
|
||||
this.dotNet = dotNet;
|
||||
this.logger = logger;
|
||||
|
||||
newestSdkVersion = new Lazy<DotNetVersion?>(GetNewestSdk);
|
||||
cscPath = new Lazy<string?>(GetCscPath);
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^(\d+\.\d+\.\d+)(-([a-z]+)\.(\d+\.\d+\.\d+))?\s\[(.+)\]$")]
|
||||
private static partial Regex SdkRegex();
|
||||
@@ -30,11 +46,31 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
return sdks;
|
||||
}
|
||||
|
||||
public DotNetVersion? GetNewestSdk()
|
||||
private DotNetVersion? GetNewestSdk()
|
||||
{
|
||||
var listed = dotNet.GetListedSdks();
|
||||
var sdks = ParseSdks(listed);
|
||||
return sdks.Max();
|
||||
}
|
||||
|
||||
private string? GetCscPath()
|
||||
{
|
||||
var sdk = GetNewestSdk();
|
||||
if (sdk is null)
|
||||
{
|
||||
logger.LogWarning("No dotnet SDK found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var path = Path.Combine(sdk.FullPath, "Roslyn", "bincore", "csc.dll");
|
||||
logger.LogInfo($"Source generator CSC: '{path}'");
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
logger.LogInfo($"csc.dll not found at '{path}'.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user