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

Adding net9/c#13 support. Drop support for net6/7 #1362

Merged
merged 2 commits into from
Oct 26, 2024
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: 1 addition & 1 deletion .github/workflows/format_repositories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
repository: belav/csharpier-repos
path: csharpier-repos
- run: dotnet build csharpier/Src/CSharpier.Cli/CSharpier.Cli.csproj -c release
- run: dotnet csharpier/Src/CSharpier.Cli/bin/release/net8.0/dotnet-csharpier.dll csharpier-repos --skip-write
- run: dotnet csharpier/Src/CSharpier.Cli/bin/release/net9.0/dotnet-csharpier.dll csharpier-repos --skip-write
2 changes: 1 addition & 1 deletion .run/Playground.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Playground" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/Src/CSharpier.Playground/CSharpier.Playground.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_TFM" value="net9.0" />
<option name="LAUNCH_PROFILE_NAME" value="Watch" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
4 changes: 2 additions & 2 deletions Scripts/RunLinuxTests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# running this seems to screw up the nuget restore, but provides a way to figure out why a test is failing on linux while working on windows.
# you have to run this from the root, IE powershell ./Scripts/RunLinuxTests.ps1
# also a lot of these tests fail due to line endings in your local files being \r\n but the writeLine using \n
docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app/tests mcr.microsoft.com/dotnet/sdk:7.0 dotnet test /app/Src/CSharpier.Tests/CSharpier.Tests.csproj --logger:trx
docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app/tests mcr.microsoft.com/dotnet/sdk:9.0 dotnet test /app/Src/CSharpier.Tests/CSharpier.Tests.csproj --logger:trx

# gross way to run csharpier against the csharpier-repos
#docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app mcr.microsoft.com/dotnet/sdk:5.0 dotnet ./csharpier/Src/CSharpier/bin/Debug/net6.0/dotnet-csharpier.dll csharpier-repos --skip-write
#docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app mcr.microsoft.com/dotnet/sdk:9.0 dotnet ./csharpier/Src/CSharpier/bin/Debug/net9.0/dotnet-csharpier.dll csharpier-repos --skip-write
2 changes: 1 addition & 1 deletion Src/CSharpier.Cli/CSharpier.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<PackageId>CSharpier</PackageId>
<AssemblyName>dotnet-csharpier</AssemblyName>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<ToolCommandName>csharpier</ToolCommandName>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private CompareResult Compare(
sourceBuilder.AppendLine(
$"""
case {syntaxNodeType.Name} {lowerCaseName}:
if (this.IgnoreDisabledText)
if (this.ReorderedUsingsWithDisabledText)
return Equal;
return this.Compare{syntaxNodeType.Name}({lowerCaseName}, formattedNode as {syntaxNodeType.Name});
"""
Expand Down
4 changes: 2 additions & 2 deletions Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../Nuget/Build.props"/>
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<PackageId>CSharpier.MsBuild</PackageId>
<DevelopmentDependency>true</DevelopmentDependency>
<CSharpierOutputDir>../CSharpier.Cli/bin/$(Configuration)/$(TargetFramework)</CSharpierOutputDir>
Expand All @@ -10,7 +10,7 @@
<!--
Note: There is no <ProjectReference /> here because that would cause msbuild to
make it a dependency in the output package, which causes all sorts of issues as
CSharpier is a net6.0 project with <PackAsTool> and this is neither.
CSharpier is a net9.0 project with <PackAsTool> and this is neither.
-->
<Target Name="BuildCSharpier" BeforeTargets="Restore">
<Exec command="dotnet build -c $(Configuration)" WorkingDirectory="../CSharpier.Cli" />
Expand Down
3 changes: 1 addition & 2 deletions Src/CSharpier.MsBuild/build/CSharpier.MsBuild.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project>
<PropertyGroup>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '9.0'))">net9.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '8.0'))">net8.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '7.0'))">net7.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '6.0'))">net6.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == ''" Label="Fallback">net8.0</CSharpier_FrameworkVersion>
<CSharpierDllPath>$(MSBuildThisFileDirectory)../tools/csharpier/$(CSharpier_FrameworkVersion)/dotnet-csharpier.dll</CSharpierDllPath>
<CSharpierArgs Condition="'$(CSharpier_Check)' == 'true'">$(CSharpierArgs) --check</CSharpierArgs>
Expand Down
2 changes: 2 additions & 0 deletions Src/CSharpier.Tests/CSharpier.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
<SignAssembly>True</SignAssembly>
<!-- DiffEngine references older packages and vulnerabilities on tests isn't a big deal -->
<NuGetAuditMode>direct</NuGetAuditMode>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DiffEngine" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class C<T>
where T : allows ref struct
{
// Use T as a ref struct:
public void M(scoped T p)
{
// The parameter p must follow ref safety rules
}
}
2 changes: 1 addition & 1 deletion Src/CSharpier/CSharpier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="../../Nuget/Build.props" />
<PropertyGroup>
<PackageId>CSharpier.Core</PackageId>
<TargetFrameworks>net6.0;net7.0;net8.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;netstandard2.0</TargetFrameworks>
<RootNamespace>CSharpier</RootNamespace>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
Expand Down
28 changes: 28 additions & 0 deletions Src/CSharpier/SyntaxNodeComparer.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private CompareResult Compare(
return this.CompareAccessorListSyntax(accessorListSyntax, formattedNode as AccessorListSyntax);
case AliasQualifiedNameSyntax aliasQualifiedNameSyntax:
return this.CompareAliasQualifiedNameSyntax(aliasQualifiedNameSyntax, formattedNode as AliasQualifiedNameSyntax);
case AllowsConstraintClauseSyntax allowsConstraintClauseSyntax:
return this.CompareAllowsConstraintClauseSyntax(allowsConstraintClauseSyntax, formattedNode as AllowsConstraintClauseSyntax);
case AnonymousMethodExpressionSyntax anonymousMethodExpressionSyntax:
return this.CompareAnonymousMethodExpressionSyntax(anonymousMethodExpressionSyntax, formattedNode as AnonymousMethodExpressionSyntax);
case AnonymousObjectCreationExpressionSyntax anonymousObjectCreationExpressionSyntax:
Expand Down Expand Up @@ -390,6 +392,8 @@ private CompareResult Compare(
return this.CompareReferenceDirectiveTriviaSyntax(referenceDirectiveTriviaSyntax, formattedNode as ReferenceDirectiveTriviaSyntax);
case RefExpressionSyntax refExpressionSyntax:
return this.CompareRefExpressionSyntax(refExpressionSyntax, formattedNode as RefExpressionSyntax);
case RefStructConstraintSyntax refStructConstraintSyntax:
return this.CompareRefStructConstraintSyntax(refStructConstraintSyntax, formattedNode as RefStructConstraintSyntax);
case RefTypeExpressionSyntax refTypeExpressionSyntax:
return this.CompareRefTypeExpressionSyntax(refTypeExpressionSyntax, formattedNode as RefTypeExpressionSyntax);
case RefTypeSyntax refTypeSyntax:
Expand Down Expand Up @@ -473,6 +477,8 @@ private CompareResult Compare(
case UnsafeStatementSyntax unsafeStatementSyntax:
return this.CompareUnsafeStatementSyntax(unsafeStatementSyntax, formattedNode as UnsafeStatementSyntax);
case UsingDirectiveSyntax usingDirectiveSyntax:
if (this.ReorderedUsingsWithDisabledText)
return Equal;
return this.CompareUsingDirectiveSyntax(usingDirectiveSyntax, formattedNode as UsingDirectiveSyntax);
case UsingStatementSyntax usingStatementSyntax:
return this.CompareUsingStatementSyntax(usingStatementSyntax, formattedNode as UsingStatementSyntax);
Expand Down Expand Up @@ -576,6 +582,18 @@ private CompareResult CompareAliasQualifiedNameSyntax(AliasQualifiedNameSyntax o
formattedStack.Push((formattedNode.Name, formattedNode));
return Equal;
}
private CompareResult CompareAllowsConstraintClauseSyntax(AllowsConstraintClauseSyntax originalNode, AllowsConstraintClauseSyntax formattedNode)
{
CompareResult result;
result = this.Compare(originalNode.AllowsKeyword, formattedNode.AllowsKeyword, originalNode, formattedNode);
if (result.IsInvalid) return result;
result = this.CompareLists(originalNode.Constraints, formattedNode.Constraints, null, o => o.Span, originalNode.Span, formattedNode.Span);
if (result.IsInvalid) return result;
result = this.CompareLists(originalNode.Constraints.GetSeparators().Take(originalNode.Constraints.Count() - 1).ToList(), formattedNode.Constraints.GetSeparators().Take(formattedNode.Constraints.Count() - 1).ToList(), Compare, o => o.Span, originalNode.Span, formattedNode.Span);
if (result.IsInvalid) return result;
if (originalNode.IsMissing != formattedNode.IsMissing) return NotEqual(originalNode, formattedNode);
return Equal;
}
private CompareResult CompareAnonymousMethodExpressionSyntax(AnonymousMethodExpressionSyntax originalNode, AnonymousMethodExpressionSyntax formattedNode)
{
CompareResult result;
Expand Down Expand Up @@ -3127,6 +3145,16 @@ private CompareResult CompareRefExpressionSyntax(RefExpressionSyntax originalNod
if (result.IsInvalid) return result;
return Equal;
}
private CompareResult CompareRefStructConstraintSyntax(RefStructConstraintSyntax originalNode, RefStructConstraintSyntax formattedNode)
{
CompareResult result;
if (originalNode.IsMissing != formattedNode.IsMissing) return NotEqual(originalNode, formattedNode);
result = this.Compare(originalNode.RefKeyword, formattedNode.RefKeyword, originalNode, formattedNode);
if (result.IsInvalid) return result;
result = this.Compare(originalNode.StructKeyword, formattedNode.StructKeyword, originalNode, formattedNode);
if (result.IsInvalid) return result;
return Equal;
}
private CompareResult CompareRefTypeExpressionSyntax(RefTypeExpressionSyntax originalNode, RefTypeExpressionSyntax formattedNode)
{
CompareResult result;
Expand Down
58 changes: 58 additions & 0 deletions Src/CSharpier/SyntaxNodeJsonWriter.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static void WriteSyntaxNode(StringBuilder builder, SyntaxNode syntaxNode)
if (syntaxNode is AccessorDeclarationSyntax) WriteAccessorDeclarationSyntax(builder, syntaxNode as AccessorDeclarationSyntax);
if (syntaxNode is AccessorListSyntax) WriteAccessorListSyntax(builder, syntaxNode as AccessorListSyntax);
if (syntaxNode is AliasQualifiedNameSyntax) WriteAliasQualifiedNameSyntax(builder, syntaxNode as AliasQualifiedNameSyntax);
if (syntaxNode is AllowsConstraintClauseSyntax) WriteAllowsConstraintClauseSyntax(builder, syntaxNode as AllowsConstraintClauseSyntax);
if (syntaxNode is AnonymousMethodExpressionSyntax) WriteAnonymousMethodExpressionSyntax(builder, syntaxNode as AnonymousMethodExpressionSyntax);
if (syntaxNode is AnonymousObjectCreationExpressionSyntax) WriteAnonymousObjectCreationExpressionSyntax(builder, syntaxNode as AnonymousObjectCreationExpressionSyntax);
if (syntaxNode is AnonymousObjectMemberDeclaratorSyntax) WriteAnonymousObjectMemberDeclaratorSyntax(builder, syntaxNode as AnonymousObjectMemberDeclaratorSyntax);
Expand Down Expand Up @@ -188,6 +189,7 @@ public static void WriteSyntaxNode(StringBuilder builder, SyntaxNode syntaxNode)
if (syntaxNode is RecursivePatternSyntax) WriteRecursivePatternSyntax(builder, syntaxNode as RecursivePatternSyntax);
if (syntaxNode is ReferenceDirectiveTriviaSyntax) WriteReferenceDirectiveTriviaSyntax(builder, syntaxNode as ReferenceDirectiveTriviaSyntax);
if (syntaxNode is RefExpressionSyntax) WriteRefExpressionSyntax(builder, syntaxNode as RefExpressionSyntax);
if (syntaxNode is RefStructConstraintSyntax) WriteRefStructConstraintSyntax(builder, syntaxNode as RefStructConstraintSyntax);
if (syntaxNode is RefTypeExpressionSyntax) WriteRefTypeExpressionSyntax(builder, syntaxNode as RefTypeExpressionSyntax);
if (syntaxNode is RefTypeSyntax) WriteRefTypeSyntax(builder, syntaxNode as RefTypeSyntax);
if (syntaxNode is RefValueExpressionSyntax) WriteRefValueExpressionSyntax(builder, syntaxNode as RefValueExpressionSyntax);
Expand Down Expand Up @@ -375,6 +377,32 @@ public static void WriteAliasQualifiedNameSyntax(StringBuilder builder, AliasQua
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteAllowsConstraintClauseSyntax(StringBuilder builder, AllowsConstraintClauseSyntax syntaxNode)
{
builder.Append("{");
var properties = new List<string>();
properties.Add($"\"nodeType\":\"{GetNodeType(syntaxNode.GetType())}\"");
properties.Add($"\"kind\":\"{syntaxNode.Kind().ToString()}\"");
if (syntaxNode.AllowsKeyword != default(SyntaxToken))
{
var allowsKeywordBuilder = new StringBuilder();
WriteSyntaxToken(allowsKeywordBuilder, syntaxNode.AllowsKeyword);
properties.Add($"\"allowsKeyword\":{allowsKeywordBuilder.ToString()}");
}
var constraints = new List<string>();
foreach(var node in syntaxNode.Constraints)
{
var innerBuilder = new StringBuilder();
WriteSyntaxNode(innerBuilder, node);
constraints.Add(innerBuilder.ToString());
}
properties.Add($"\"constraints\":[{string.Join(",", constraints)}]");
properties.Add(WriteBoolean("hasLeadingTrivia", syntaxNode.HasLeadingTrivia));
properties.Add(WriteBoolean("hasTrailingTrivia", syntaxNode.HasTrailingTrivia));
properties.Add(WriteBoolean("isMissing", syntaxNode.IsMissing));
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteAnonymousMethodExpressionSyntax(StringBuilder builder, AnonymousMethodExpressionSyntax syntaxNode)
{
builder.Append("{");
Expand Down Expand Up @@ -2078,6 +2106,12 @@ public static void WriteCrefParameterSyntax(StringBuilder builder, CrefParameter
properties.Add(WriteBoolean("hasLeadingTrivia", syntaxNode.HasLeadingTrivia));
properties.Add(WriteBoolean("hasTrailingTrivia", syntaxNode.HasTrailingTrivia));
properties.Add(WriteBoolean("isMissing", syntaxNode.IsMissing));
if (syntaxNode.ReadOnlyKeyword != default(SyntaxToken))
{
var readOnlyKeywordBuilder = new StringBuilder();
WriteSyntaxToken(readOnlyKeywordBuilder, syntaxNode.ReadOnlyKeyword);
properties.Add($"\"readOnlyKeyword\":{readOnlyKeywordBuilder.ToString()}");
}
if (syntaxNode.RefKindKeyword != default(SyntaxToken))
{
var refKindKeywordBuilder = new StringBuilder();
Expand Down Expand Up @@ -6940,6 +6974,30 @@ public static void WriteRefExpressionSyntax(StringBuilder builder, RefExpression
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteRefStructConstraintSyntax(StringBuilder builder, RefStructConstraintSyntax syntaxNode)
{
builder.Append("{");
var properties = new List<string>();
properties.Add($"\"nodeType\":\"{GetNodeType(syntaxNode.GetType())}\"");
properties.Add($"\"kind\":\"{syntaxNode.Kind().ToString()}\"");
properties.Add(WriteBoolean("hasLeadingTrivia", syntaxNode.HasLeadingTrivia));
properties.Add(WriteBoolean("hasTrailingTrivia", syntaxNode.HasTrailingTrivia));
properties.Add(WriteBoolean("isMissing", syntaxNode.IsMissing));
if (syntaxNode.RefKeyword != default(SyntaxToken))
{
var refKeywordBuilder = new StringBuilder();
WriteSyntaxToken(refKeywordBuilder, syntaxNode.RefKeyword);
properties.Add($"\"refKeyword\":{refKeywordBuilder.ToString()}");
}
if (syntaxNode.StructKeyword != default(SyntaxToken))
{
var structKeywordBuilder = new StringBuilder();
WriteSyntaxToken(structKeywordBuilder, syntaxNode.StructKeyword);
properties.Add($"\"structKeyword\":{structKeywordBuilder.ToString()}");
}
builder.Append(string.Join(",", properties.Where(o => o != null)));
builder.Append("}");
}
public static void WriteRefTypeExpressionSyntax(StringBuilder builder, RefTypeExpressionSyntax syntaxNode)
{
builder.Append("{");
Expand Down
2 changes: 1 addition & 1 deletion Src/SyntaxFinder/SyntaxFinder.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions docs/MSBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ Valid options are:
- Debug

### Target Frameworks
CSharpier.MSBuild will be run with net6.0, net7.0 or net8.0 if the project targets one of the three frameworks. In cases where the project targets something else (net48, netstandard2.0) `CSharpier_FrameworkVersion` will default to net7.0
This can be controlled with the following property. This property is required if the csproj is targeting < net6.0 (netstandard2.0, net48, etc) and net7.0 is not installed.
CSharpier.MSBuild will be run with net8.0 or net9.0 if the project targets one of the three frameworks. In cases where the project targets something else (net48, netstandard2.0) `CSharpier_FrameworkVersion` will default to net8.0
This can be controlled with the following property. This property is required if the csproj is targeting < net8.0 (netstandard2.0, net48, etc) and net8.0 is not installed.
```xml
<PropertyGroup>
<CSharpier_FrameworkVersion>net6.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion>net8.0</CSharpier_FrameworkVersion>
</PropertyGroup>
```
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.401",
"version": "9.0.100-rc.2",
"rollForward": "latestFeature"
},
"msbuild-sdks": {
Expand Down
Loading