Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nit Compatiblity tools improvements #45685

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exclusion.dic
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
awaiter
crossgen
csharp
cshtml
deserializer
msbuild
nuget
nupkg
nuspec
roslyn
sdk
sdks
tfm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public ApiCompatServiceProvider(Func<ISuppressionEngine, ISuppressibleLog> logFa

// The attribute data symbol filter is a composite that contains both the accessibility
// symbol filter and the doc id symbol filter.
CompositeSymbolFilter attributeDataSymbolFilter = new CompositeSymbolFilter()
.Add(accessibilitySymbolFilter);
CompositeSymbolFilter attributeDataSymbolFilter = new(accessibilitySymbolFilter);
if (excludeAttributesFiles is not null)
{
attributeDataSymbolFilter.Add(new DocIdSymbolFilter(excludeAttributesFiles));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class RegexStringTransformer
/// <param name="replacementString">The replacement string that contains the capture group markers (i.e. $1).</param>

public RegexStringTransformer(string captureGroupPattern, string replacementString)
: this(new (string, string)[] { (captureGroupPattern, replacementString) })
: this([(captureGroupPattern, replacementString)])
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public void Unregister()
private Assembly? LoadRoslyn(AssemblyName name, Func<string, Assembly> loadFromPath)
{
const string codeAnalysisName = "Microsoft.CodeAnalysis";
const string codeAnalysisCsharpName = "Microsoft.CodeAnalysis.CSharp";
const string codeAnalysisCSharpName = "Microsoft.CodeAnalysis.CSharp";

if (name.Name == codeAnalysisName || name.Name == codeAnalysisCsharpName)
if (name.Name == codeAnalysisName || name.Name == codeAnalysisCSharpName)
{
Assembly asm = loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{name.Name}.dll"));
Version? resolvedVersion = asm.GetName().Version;
Expand All @@ -78,7 +78,7 @@ public void Unregister()
// Being extra defensive but we want to avoid that we accidentally load two different versions of either
// of the roslyn assemblies from a different location, so let's load them both on the first request.
if (name.Name == codeAnalysisName)
loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisCsharpName}.dll"));
loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisCSharpName}.dll"));
else
loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisName}.dll"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private static IEnumerable<string> GetFilesFromPath(string path)
}
}

return new string[] { path };
return [path];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="Runtime" />
<ProjectReference Include="..\Microsoft.DotNet.PackageValidation\Microsoft.DotNet.PackageValidation.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.ApiCompatibility\Microsoft.DotNet.ApiCompatibility.csproj" />
<!-- We carry NuGet as part of the package in case the package is used with an older SDKs or with full framework MSBuild. -->
<PackageReference Include="NuGet.Packaging" PrivateAssets="All" Publish="true" />
<!-- The ApiCompatibility/PackageValidation stuff depends on CodeAnalysis.CSharp at the version that is
Expand All @@ -47,6 +45,9 @@
it should never share types with this assembly. Within this task, the RoslynResolver should provide a good
closure of references. -->
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" ExcludeAssets="Runtime" PrivateAssets="all" />

<ProjectReference Include="..\Microsoft.DotNet.PackageValidation\Microsoft.DotNet.PackageValidation.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.ApiCompatibility\Microsoft.DotNet.ApiCompatibility.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<IsShippingPackage>true</IsShippingPackage>
<PackAsTool>true</PackAsTool>
<ToolCommandName>apicompat</ToolCommandName>
<RollForward>Major</RollForward>
<PackageDescription>Tool to perform api compatibility checks on assemblies and packages.</PackageDescription>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SuppressionEngine(string? noWarn = null, bool baselineAllErrors = f
protected const string DiagnosticIdDocumentationComment = " https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids ";
private readonly HashSet<Suppression> _baselineSuppressions = [];
private readonly HashSet<Suppression> _suppressions = [];
private readonly HashSet<string> _noWarn = string.IsNullOrEmpty(noWarn) ? [] : new HashSet<string>(noWarn!.Split(';'));
private readonly HashSet<string> _noWarn = string.IsNullOrEmpty(noWarn) ? [] : new(noWarn!.Split(';'));

/// <inheritdoc/>
public bool BaselineAllErrors { get; } = baselineAllErrors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static Package Create(string? packagePath, IReadOnlyDictionary<NuGetFrame
{
NuGetFramework assemblyReferencesFramework = tfmQueue.Dequeue();

NuGetFramework? bestAssemblyReferencesFramework = NuGetFrameworkUtility.GetNearest(tfmQueue.Concat(new NuGetFramework[] { framework }), assemblyReferencesFramework, (key) => key);
NuGetFramework? bestAssemblyReferencesFramework = NuGetFrameworkUtility.GetNearest(tfmQueue.Concat([framework]), assemblyReferencesFramework, (key) => key);
if (bestAssemblyReferencesFramework == framework)
{
return AssemblyReferences[assemblyReferencesFramework];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,22 @@ private static Dictionary<NuGetFramework, HashSet<NuGetFramework>> InitializeTfm
{
Dictionary<NuGetFramework, HashSet<NuGetFramework>> packageTfmMapping = [];

// creating a map framework in package => frameworks to test based on default compatibilty mapping.
// creating a map framework in package => frameworks to test based on default compatibility mapping.
foreach (OneWayCompatibilityMappingEntry item in DefaultFrameworkMappings.Instance.CompatibilityMappings)
{
NuGetFramework forwardTfm = item.SupportedFrameworkRange.Max;
NuGetFramework reverseTfm = item.TargetFrameworkRange.Min;
#if NET
if (packageTfmMapping.TryGetValue(forwardTfm, out HashSet<NuGetFramework>? value))
{
value.Add(reverseTfm);
}
#else
if (packageTfmMapping.ContainsKey(forwardTfm))
{
packageTfmMapping[forwardTfm].Add(reverseTfm);
}
#endif
else
{
packageTfmMapping.Add(forwardTfm, [ reverseTfm ]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace Microsoft.DotNet.ApiSymbolExtensions.Filtering
/// Implements the composite pattern, group the list of <see cref="ISymbol"/> and interact with them
/// the same way as a single instance of a <see cref="ISymbol"/> object.
/// </summary>
public sealed class CompositeSymbolFilter : ISymbolFilter
public sealed class CompositeSymbolFilter(params IEnumerable<ISymbolFilter> filters) : ISymbolFilter
{
/// <summary>
/// List on inner filters.
/// </summary>
public List<ISymbolFilter> Filters { get; } = [];
public List<ISymbolFilter> Filters { get; } = new(filters);

/// <summary>
/// Determines whether the <see cref="ISymbol"/> should be included.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static IEnumerable<ITypeSymbol> GetAllBaseTypes(this ITypeSymbol type)
}

/// <summary>
/// Determines if a symbol was generated by the compiler by checking for the presense of the CompilerGeneratedAttribute.
/// Determines if a symbol was generated by the compiler by checking for the presence of the CompilerGeneratedAttribute.
/// </summary>
/// <param name="symbol">Symbol to check</param>
/// <returns>True if the attribute was found.</returns>
Expand Down
Loading