From 9bd7f49a81c36e768d95ba7232fa7571f6b6841d Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Mon, 26 Apr 2021 05:48:29 -0700 Subject: [PATCH 1/4] TrimTrailingSeparators on GetRelativePath fixes #51602 --- .../CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs | 8 ++++++++ src/Compilers/Core/Portable/FileSystem/PathUtilities.cs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs b/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs index 16ecf206029d7..260d1093490d3 100644 --- a/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs @@ -383,5 +383,13 @@ public void CombinePaths_DifferentFromPathCombine(string expected, string path1, { Assert.Equal(expected, PathUtilities.CombinePaths(path1, path2)); } + + [Fact, WorkItem(51602, @"https://github.com/dotnet/roslyn/issues/51602")] + public void GetRelativePath_IndexOutOfRangeException() + { + var expected = ""; + var result = PathUtilities.GetRelativePath(@"C:\A\B\", @"C:\A\B"); + Assert.Equal(expected, result); + } } } diff --git a/src/Compilers/Core/Portable/FileSystem/PathUtilities.cs b/src/Compilers/Core/Portable/FileSystem/PathUtilities.cs index 297dec288f528..b3b7cedccfe78 100644 --- a/src/Compilers/Core/Portable/FileSystem/PathUtilities.cs +++ b/src/Compilers/Core/Portable/FileSystem/PathUtilities.cs @@ -534,6 +534,9 @@ public static string GetRelativePath(string directory, string fullPath) { string relativePath = string.Empty; + directory = TrimTrailingSeparators(directory); + fullPath = TrimTrailingSeparators(fullPath); + if (IsChildPath(directory, fullPath)) { return GetRelativeChildPath(directory, fullPath); From 22c6bd233da2d858be14a41e56e9152c2dfeff2b Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Mon, 26 Apr 2021 08:21:01 -0700 Subject: [PATCH 2/4] only run on windows --- .../Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs b/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs index 260d1093490d3..526e2f2b4bd37 100644 --- a/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs @@ -384,7 +384,7 @@ public void CombinePaths_DifferentFromPathCombine(string expected, string path1, Assert.Equal(expected, PathUtilities.CombinePaths(path1, path2)); } - [Fact, WorkItem(51602, @"https://github.com/dotnet/roslyn/issues/51602")] + [ConditionalFact(typeof(WindowsOnly)), WorkItem(51602, @"https://github.com/dotnet/roslyn/issues/51602")] public void GetRelativePath_IndexOutOfRangeException() { var expected = ""; From 4558a7569961f64621c00b840afcb478ac2a4e5f Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Mon, 26 Apr 2021 14:43:38 -0700 Subject: [PATCH 3/4] add unix tests --- .../CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs b/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs index 526e2f2b4bd37..c660ffa62b568 100644 --- a/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/FileSystem/PathUtilitiesTests.cs @@ -385,11 +385,19 @@ public void CombinePaths_DifferentFromPathCombine(string expected, string path1, } [ConditionalFact(typeof(WindowsOnly)), WorkItem(51602, @"https://github.com/dotnet/roslyn/issues/51602")] - public void GetRelativePath_IndexOutOfRangeException() + public void GetRelativePath_EnsureNo_IndexOutOfRangeException_Windows() { var expected = ""; var result = PathUtilities.GetRelativePath(@"C:\A\B\", @"C:\A\B"); Assert.Equal(expected, result); } + + [ConditionalFact(typeof(UnixLikeOnly)), WorkItem(51602, @"https://github.com/dotnet/roslyn/issues/51602")] + public void GetRelativePath_EnsureNo_IndexOutOfRangeException_Unix() + { + var expected = ""; + var result = PathUtilities.GetRelativePath(@"/A/B/", @"/A/B"); + Assert.Equal(expected, result); + } } } From 77919271a5e796b3ad51f48a6794a4fc07c02ae5 Mon Sep 17 00:00:00 2001 From: Fred Silberberg Date: Tue, 1 Jun 2021 13:11:59 -0700 Subject: [PATCH 4/4] Restore writing OperationKind during generation (#53812) Thanks @alrz for pointing this out. --- .../Portable/Generated/OperationKind.Generated.cs | 3 ++- .../IOperationGenerator/IOperationClassWriter.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Compilers/Core/Portable/Generated/OperationKind.Generated.cs b/src/Compilers/Core/Portable/Generated/OperationKind.Generated.cs index c9700d1aaf961..54e5d98317ec5 100644 --- a/src/Compilers/Core/Portable/Generated/OperationKind.Generated.cs +++ b/src/Compilers/Core/Portable/Generated/OperationKind.Generated.cs @@ -1,7 +1,8 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. // < auto-generated /> +#nullable enable using System; using System.ComponentModel; using Microsoft.CodeAnalysis.FlowAnalysis; diff --git a/src/Tools/Source/CompilerGeneratorTools/Source/IOperationGenerator/IOperationClassWriter.cs b/src/Tools/Source/CompilerGeneratorTools/Source/IOperationGenerator/IOperationClassWriter.cs index 698fb13621295..a894d43850f08 100644 --- a/src/Tools/Source/CompilerGeneratorTools/Source/IOperationGenerator/IOperationClassWriter.cs +++ b/src/Tools/Source/CompilerGeneratorTools/Source/IOperationGenerator/IOperationClassWriter.cs @@ -156,6 +156,21 @@ private void WriteFiles() } } + using (_writer = new StreamWriter(File.Open(Path.Combine(_location, "OperationKind.Generated.cs"), FileMode.Create), Encoding.UTF8)) + { + writeHeader(); + WriteUsing("System"); + WriteUsing("System.ComponentModel"); + WriteUsing("Microsoft.CodeAnalysis.FlowAnalysis"); + WriteUsing("Microsoft.CodeAnalysis.Operations"); + + WriteStartNamespace(namespaceSuffix: null); + + WriteOperationKind(); + + WriteEndNamespace(); + } + void writeHeader() { WriteLine("// Licensed to the .NET Foundation under one or more agreements.");