Log and emit diagnostic if incorrectly named files are found · github/codeql@1b5ed12 · GitHub
Skip to content

Commit 1b5ed12

Browse files
committed
Log and emit diagnostic if incorrectly named files are found
1 parent 5ba3b67 commit 1b5ed12

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs‎

Lines changed: 4 additions & 0 deletions

‎csharp/autobuilder/Semmle.Autobuild.Cpp.Tests/BuildScripts.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ IEnumerable<string> IBuildActions.EnumerateDirectories(string dir)
146146

147147
bool IBuildActions.IsMacOs() => IsMacOs;
148148

149+
public bool IsLinux { get; set; }
150+
151+
bool IBuildActions.IsLinux() => IsLinux;
152+
149153
public bool IsRunningOnAppleSilicon { get; set; }
150154

151155
bool IBuildActions.IsRunningOnAppleSilicon() => IsRunningOnAppleSilicon;

‎csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,43 @@ private IEnumerable<string> GetFeeds(Func<IList<string>> getNugetFeeds)
814814
private (HashSet<string> explicitFeeds, HashSet<string> allFeeds) GetAllFeeds()
815815
{
816816
var nugetConfigs = fileProvider.NugetConfigs;
817+
818+
// On systems with case-sensitive file systems (for simplicity, we assume that is Linux), the
819+
// filenames of NuGet configuration files must be named correctly. For compatibility with projects
820+
// that are typically built on Windows or macOS where this doesn't matter, we accept all variants
821+
// of `nuget.config` ourselves. However, `dotnet` does not. If we detect that incorrectly-named
822+
// files are present, we emit a diagnostic to warn the user.
823+
if (SystemBuildActions.Instance.IsLinux())
824+
{
825+
string[] acceptedNugetConfigNames = ["nuget.config", "NuGet.config", "NuGet.Config"];
826+
var invalidNugetConfigs = nugetConfigs
827+
.Where(path => acceptedNugetConfigNames.Contains(Path.GetFileName(path)));
828+
829+
if (invalidNugetConfigs.Count() > 0)
830+
{
831+
this.logger.LogWarning(string.Format(
832+
"Found incorrectly named NuGet configuration files: {0}",
833+
string.Join(", ", invalidNugetConfigs)
834+
));
835+
this.diagnosticsWriter.AddEntry(new DiagnosticMessage(
836+
Language.CSharp,
837+
"buildless/case-sensitive-nuget-config",
838+
"Found NuGet configuration files which are not correctly named",
839+
visibility: new DiagnosticMessage.TspVisibility(statusPage: true, cliSummaryTable: true, telemetry: true),
840+
markdownMessage: string.Format(
841+
"On platforms with case-sensitive file systems, NuGet only accepts files with one of the following names: {0}.\n\n" +
842+
"CodeQL found the following files while performing an analysis on a platform with a case-sensitive file system:\n\n" +
843+
"{1}\n\n" +
844+
"To avoid unexpected results, rename these files to match the casing of one of the accepted filenames.",
845+
string.Join(", ", acceptedNugetConfigNames),
846+
string.Join("\n", invalidNugetConfigs.Select(path => string.Format("- `{0}`", path)))
847+
),
848+
severity: DiagnosticMessage.TspSeverity.Warning
849+
));
850+
}
851+
}
852+
853+
// Find feeds that are explicitly configured in the NuGet configuration files that we found.
817854
var explicitFeeds = nugetConfigs
818855
.SelectMany(config => GetFeeds(() => dotnet.GetNugetFeeds(config)))
819856
.ToHashSet();

‎csharp/extractor/Semmle.Util/BuildActions.cs‎

Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)