Skip to content

Commit

Permalink
Merge pull request dotnet#537 from sharwell/netcoreapp31
Browse files Browse the repository at this point in the history
Add netcoreapp3.1 target framework
  • Loading branch information
sharwell authored Jun 2, 2020
2 parents b287682 + 0713578 commit 2f00c29
Show file tree
Hide file tree
Showing 45 changed files with 144 additions and 54 deletions.
12 changes: 11 additions & 1 deletion src/Microsoft.CodeAnalysis.Testing/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
</PropertyGroup>

<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />


<PropertyGroup>
<!--
netcoreapp3.1: Ensures full support for nullable reference types
netstandard1.5/net452: Roslyn 1.x
netstandard1.5/net46: Roslyn 2.x
netstandard2.0/net472: Roslyn 3.x
-->
<TestingLibraryTargetFrameworks>netcoreapp3.1;netstandard1.5;netstandard2.0;net452;net46;net472</TestingLibraryTargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(CopyrightMicrosoft)' != ''">
<Copyright>$(CopyrightMicrosoft)</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1249,12 +1249,21 @@ private static Diagnostic[] SortDistinctDiagnostics(IEnumerable<Diagnostic> diag
/// </returns>
protected abstract IEnumerable<DiagnosticAnalyzer> GetDiagnosticAnalyzers();

private sealed class LexicographicComparer : IComparer<IEnumerable<object?>>
private sealed class LexicographicComparer : IComparer<IEnumerable<object?>?>
{
public static LexicographicComparer Instance { get; } = new LexicographicComparer();

public int Compare(IEnumerable<object?> x, IEnumerable<object?> y)
public int Compare(IEnumerable<object?>? x, IEnumerable<object?>? y)
{
if (x is null)
{
return y is null ? 0 : -1;
}
else if (y is null)
{
return 1;
}

using var xe = x.GetEnumerator();
using var ye = y.GetEnumerator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ public int GetHashCode(IEnumerable<T>? obj)
}

// From System.Tuple
//
// The suppression is required due to an invalid contract in IEqualityComparer<T>
// https://github.com/dotnet/runtime/issues/30998
return obj
.Select(item => _itemEqualityComparer.GetHashCode(item))
.Select(item => _itemEqualityComparer.GetHashCode(item!))
.Aggregate(
0,
(aggHash, nextHash) => ((aggHash << 5) + aggHash) ^ nextHash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
Expand All @@ -19,7 +20,7 @@ public static ImmutableArray<CodeAction> GetNestedActions(this CodeAction action
return ImmutableArray<CodeAction>.Empty;
}

return (ImmutableArray<CodeAction>)property.GetValue(action);
return (ImmutableArray<CodeAction>)(property.GetValue(action) ?? throw new NotSupportedException());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis.Host;
Expand Down Expand Up @@ -53,12 +54,14 @@ public static ComposableCatalog WithDocumentTextDifferencingService(this Composa
{ "ExportTypeIdentity", typeof(IWorkspaceService).FullName },
{ nameof(ExportWorkspaceServiceAttribute.ServiceType), assemblyQualifiedServiceTypeName },
{ nameof(ExportWorkspaceServiceAttribute.Layer), ServiceLayer.Default },
{ typeof(CreationPolicy).FullName, CreationPolicy.Shared },
{ typeof(CreationPolicy).FullName!, CreationPolicy.Shared },
{ "ContractType", typeof(IWorkspaceService) },
{ "ContractName", null },
});

var serviceImplType = typeof(Workspace).GetTypeInfo().Assembly.GetType("Microsoft.CodeAnalysis.DefaultDocumentTextDifferencingService");
RoslynDebug.AssertNotNull(serviceImplType);

return catalog.AddPart(new ComposablePartDefinition(
TypeRef.Get(serviceImplType, Resolver.DefaultInstance),
new Dictionary<string, object?> { { "SharingBoundary", null } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal static class DictionaryExtensions
{
// Copied from ConcurrentDictionary since IDictionary doesn't have this useful method
public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> function)
where TKey : notnull
{
if (!dictionary.TryGetValue(key, out var value))
{
Expand All @@ -22,6 +23,7 @@ public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dicti
}

public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> function)
where TKey : notnull
=> dictionary.GetOrAdd(key, _ => function());

public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> pair, out TKey key, out TValue value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Composition;
using System.Composition.Hosting.Core;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.Composition;
Expand All @@ -28,7 +29,7 @@ public CompositionContextShim(ExportProvider exportProvider)
_exportProvider = exportProvider;
}

public override bool TryGetExport(CompositionContract contract, out object export)
public override bool TryGetExport(CompositionContract contract, [NotNullWhen(true)] out object? export)
{
var importMany = contract.MetadataConstraints.Contains(new KeyValuePair<string, object>("IsImportMany", true));
var (contractType, metadataType) = GetContractType(contract.ContractType, importMany);
Expand All @@ -42,6 +43,7 @@ where method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterT
select method).Single();
var parameterizedMethod = methodInfo.MakeGenericMethod(contractType, metadataType);
export = parameterizedMethod.Invoke(_exportProvider, new[] { contract.ContractName });
RoslynDebug.AssertNotNull(export);
}
else
{
Expand All @@ -52,6 +54,7 @@ where method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterT
select method).Single();
var parameterizedMethod = methodInfo.MakeGenericMethod(contractType);
export = parameterizedMethod.Invoke(_exportProvider, new[] { contract.ContractName });
RoslynDebug.AssertNotNull(export);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452;net46;net472</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.Analyzer.Testing</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.Testing</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
Expand All @@ -18,7 +19,7 @@
using NuGet.Protocol.Core.Types;
using NuGet.Resolver;

#if NET46 || NET472 || NETSTANDARD
#if NET46 || NET472 || NETSTANDARD || NETCOREAPP3_1
using NuGet.Packaging.Signing;
#endif

Expand Down Expand Up @@ -96,6 +97,8 @@ public static ReferenceAssemblies Default
return NetFramework.Net46.Default;
#elif NET472
return NetFramework.Net472.Default;
#elif NETCOREAPP3_1
return NetCore.NetCoreApp31;
#endif
}
}
Expand Down Expand Up @@ -270,7 +273,7 @@ private async Task<ImmutableArray<MetadataReference>> ResolveCoreAsync(string la
PackageSaveMode = PackageSaveMode.Defaultv3,
XmlDocFileSaveMode = XmlDocFileSaveMode.None,
};
#elif NET46 || NET472 || NETSTANDARD2_0
#elif NET46 || NET472 || NETSTANDARD2_0 || NETCOREAPP3_1
var packageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv3,
XmlDocFileSaveMode.None,
Expand Down Expand Up @@ -345,6 +348,11 @@ await PackageExtractor.ExtractPackageAsync(
packageReader = new PackageFolderReader(installedPath);
}

if (installedPath is null)
{
continue;
}

var libItems = await packageReader.GetLibItemsAsync(cancellationToken);
var nearestLib = frameworkReducer.GetNearest(targetFramework, libItems.Select(x => x.TargetFramework));
var frameworkItems = await packageReader.GetFrameworkItemsAsync(cancellationToken);
Expand Down Expand Up @@ -386,34 +394,39 @@ await PackageExtractor.ExtractPackageAsync(
}
}

var referenceAssemblyInstalledPath = ReferenceAssemblyPackage is object
? GetInstalledPath(localPathResolver, globalPathResolver, ReferenceAssemblyPackage.ToNuGetIdentity())
: null;
Debug.Assert(ReferenceAssemblyPackage is null || referenceAssemblyInstalledPath is object, $"Assertion failed: {nameof(ReferenceAssemblyPackage)} is null || {nameof(referenceAssemblyInstalledPath)} is object");
Debug.Assert(ReferenceAssemblyPackage is null || ReferenceAssemblyPath is object, $"Assertion failed: {nameof(ReferenceAssemblyPackage)} is null || {nameof(ReferenceAssemblyPath)} is object");

foreach (var assembly in frameworkAssemblies)
{
if (ReferenceAssemblyPackage is null)
{
throw new InvalidOperationException($"Cannot resolve assembly '{assembly}' without a reference assembly package");
}

var installedPath = GetInstalledPath(localPathResolver, globalPathResolver, ReferenceAssemblyPackage.ToNuGetIdentity());
if (File.Exists(Path.Combine(installedPath, ReferenceAssemblyPath, assembly + ".dll")))
if (File.Exists(Path.Combine(referenceAssemblyInstalledPath!, ReferenceAssemblyPath!, assembly + ".dll")))
{
resolvedAssemblies.Add(Path.GetFullPath(Path.Combine(installedPath, ReferenceAssemblyPath, assembly + ".dll")));
resolvedAssemblies.Add(Path.GetFullPath(Path.Combine(referenceAssemblyInstalledPath!, ReferenceAssemblyPath!, assembly + ".dll")));
}
}

// Prefer assemblies from the reference assembly package to ones otherwise provided
if (ReferenceAssemblyPackage is object)
{
var installedPath = GetInstalledPath(localPathResolver, globalPathResolver, ReferenceAssemblyPackage.ToNuGetIdentity());
var referenceAssemblies = new HashSet<string>(resolvedAssemblies.Where(resolved => resolved.StartsWith(installedPath)));
var referenceAssemblyNames = new HashSet<string>(referenceAssemblies.Select(Path.GetFileNameWithoutExtension));
var referenceAssemblies = new HashSet<string>(resolvedAssemblies.Where(resolved => resolved.StartsWith(referenceAssemblyInstalledPath!)));

// Suppression due to https://github.com/dotnet/roslyn/issues/44735
var referenceAssemblyNames = new HashSet<string>(referenceAssemblies.Select((Func<string, string>)Path.GetFileNameWithoutExtension!));
resolvedAssemblies.RemoveWhere(resolved => referenceAssemblyNames.Contains(Path.GetFileNameWithoutExtension(resolved)) && !referenceAssemblies.Contains(resolved));
}

// Add the facade assemblies
if (ReferenceAssemblyPackage is object)
{
var installedPath = GetInstalledPath(localPathResolver, globalPathResolver, ReferenceAssemblyPackage.ToNuGetIdentity());
var facadesPath = Path.Combine(installedPath, ReferenceAssemblyPath, "Facades");
var facadesPath = Path.Combine(referenceAssemblyInstalledPath!, ReferenceAssemblyPath!, "Facades");
if (Directory.Exists(facadesPath))
{
foreach (var path in Directory.GetFiles(facadesPath, "*.dll"))
Expand All @@ -425,10 +438,10 @@ await PackageExtractor.ExtractPackageAsync(

foreach (var assembly in FacadeAssemblies)
{
if (File.Exists(Path.Combine(installedPath, ReferenceAssemblyPath, assembly + ".dll")))
if (File.Exists(Path.Combine(referenceAssemblyInstalledPath!, ReferenceAssemblyPath!, assembly + ".dll")))
{
resolvedAssemblies.RemoveWhere(existingAssembly => Path.GetFileNameWithoutExtension(existingAssembly) == assembly);
resolvedAssemblies.Add(Path.GetFullPath(Path.Combine(installedPath, ReferenceAssemblyPath, assembly + ".dll")));
resolvedAssemblies.Add(Path.GetFullPath(Path.Combine(referenceAssemblyInstalledPath!, ReferenceAssemblyPath!, assembly + ".dll")));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.CodeAnalysis.Testing
{
internal static class RoslynDebug
{
/// <inheritdoc cref="Debug.Assert(bool)"/>
[Conditional("DEBUG")]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1405:Debug.Assert should provide message text", Justification = "This is a wrapper for Debug.Assert.")]
public static void Assert([DoesNotReturnIf(false)] bool b)
=> Debug.Assert(b);

/// <inheritdoc cref="Debug.Assert(bool, string)"/>
[Conditional("DEBUG")]
public static void Assert([DoesNotReturnIf(false)] bool b, string message)
=> Debug.Assert(b, message);

[Conditional("DEBUG")]
public static void AssertNotNull<T>([NotNull] T value)
where T : class?
{
Assert(value is object, "Unexpected null reference");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.MSTest</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.MSTest</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.NUnit</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.XUnit</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.Analyzer.Testing</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.MSTest</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.MSTest</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.NUnit</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.NUnit</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.XUnit</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<AssemblyName>Microsoft.CodeAnalysis.CSharp.CodeFix.Testing</AssemblyName>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.MSTest</RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.NUnit</RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>$(TestingLibraryTargetFrameworks)</TargetFrameworks>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.Testing.XUnit</RootNamespace>
</PropertyGroup>

Expand Down
Loading

0 comments on commit 2f00c29

Please sign in to comment.