提交 851e4843 编写于 作者: T Ty Overby

Merge pull request #6330 from TyOverby/6329-caller-file-path

Fixes /pathmap for the unix root ("/") directory.  Adds diagnostics for pathmap failed parsing.
......@@ -104,7 +104,6 @@ EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Test\Utilities\Shared\TestUtilities.projitems*{6ff42825-5464-4151-ac55-ed828168c192}*SharedItemsImports = 13
src\Test\Utilities\Shared\TestUtilities.projitems*{f7712928-1175-47b3-8819-ee086753dee2}*SharedItemsImports = 4
src\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems*{d0bc9be7-24f6-40ca-8dc6-fcb93bd44b34}*SharedItemsImports = 13
src\Compilers\Core\SharedCollections\SharedCollections.projitems*{afde6bea-5038-4a4a-a88e-dbd2e4088eed}*SharedItemsImports = 4
src\Compilers\Core\SharedCollections\SharedCollections.projitems*{1ee8cad3-55f9-4d91-96b2-084641da9a6c}*SharedItemsImports = 4
......
......@@ -5245,6 +5245,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to The pathmap option was incorrectly formatted.
/// </summary>
internal static string ERR_InvalidPathMap {
get {
return ResourceManager.GetString("ERR_InvalidPathMap", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid preprocessor expression.
/// </summary>
......
......@@ -4657,4 +4657,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_SourceFileReferencesNotSupported" xml:space="preserve">
<value>Source file references are not supported.</value>
</data>
</root>
\ No newline at end of file
<data name="ERR_InvalidPathMap" xml:space="preserve">
<value>The pathmap option was incorrectly formatted.</value>
</data>
</root>
......@@ -932,7 +932,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
if (value == null)
break;
pathMap = pathMap.Concat(ParsePathMap(value));
pathMap = pathMap.Concat(ParsePathMap(value, diagnostics));
}
continue;
......
......@@ -1316,5 +1316,6 @@ internal enum ErrorCode
ERR_PPLoadFollowsToken = 8098,
ERR_SourceFileReferencesNotSupported = 8099,
ERR_BadAwaitInStaticVariableInitializer = 8100,
ERR_InvalidPathMap = 8101,
}
}
......@@ -126,6 +126,7 @@ public override ReportDiagnostic GetDiagnosticReport(DiagnosticInfo diagnosticIn
// command line:
public override int ERR_ExpectedSingleScript { get { return (int)ErrorCode.ERR_ExpectedSingleScript; } }
public override int ERR_OpenResponseFile { get { return (int)ErrorCode.ERR_OpenResponseFile; } }
public override int ERR_InvalidPathMap { get { return (int)ErrorCode.ERR_InvalidPathMap; } }
public override int FTL_InputFileNameTooLong { get { return (int)ErrorCode.FTL_InputFileNameTooLong; } }
public override int ERR_FileNotFound { get { return (int)ErrorCode.ERR_FileNotFound; } }
public override int ERR_NoSourceFile { get { return (int)ErrorCode.ERR_NoSourceFile; } }
......
......@@ -7927,12 +7927,20 @@ public void PathMapParser()
Assert.Equal(KeyValuePair.Create("K2", "V2"), parsedArgs.PathMap[1]);
parsedArgs = DefaultParse(new [] { "/pathmap:,,,", "a.cs" }, _baseDirectory);
parsedArgs.Errors.Verify();
Assert.Equal(0, parsedArgs.PathMap.Length);
Assert.Equal(4, parsedArgs.Errors.Count());
Assert.Equal((int)ErrorCode.ERR_InvalidPathMap, parsedArgs.Errors[0].Code);
Assert.Equal((int)ErrorCode.ERR_InvalidPathMap, parsedArgs.Errors[1].Code);
Assert.Equal((int)ErrorCode.ERR_InvalidPathMap, parsedArgs.Errors[2].Code);
Assert.Equal((int)ErrorCode.ERR_InvalidPathMap, parsedArgs.Errors[3].Code);
parsedArgs = DefaultParse(new [] { "/pathmap:k=,=v", "a.cs" }, _baseDirectory);
parsedArgs.Errors.Verify();
Assert.Equal(0, parsedArgs.PathMap.Length);
Assert.Equal(2, parsedArgs.Errors.Count());
Assert.Equal((int)ErrorCode.ERR_InvalidPathMap, parsedArgs.Errors[0].Code);
Assert.Equal((int)ErrorCode.ERR_InvalidPathMap, parsedArgs.Errors[1].Code);
parsedArgs = DefaultParse(new [] { "/pathmap:k=v=bad", "a.cs" }, _baseDirectory);
Assert.Equal(1, parsedArgs.Errors.Count());
Assert.Equal((int)ErrorCode.ERR_InvalidPathMap, parsedArgs.Errors[0].Code);
}
}
......
......@@ -188,17 +188,33 @@ internal static string RemoveTrailingSpacesAndDots(string path)
return string.Empty;
}
protected ImmutableArray<KeyValuePair<string, string>> ParsePathMap(string pathMap)
protected ImmutableArray<KeyValuePair<string, string>> ParsePathMap(string pathMap, IList<Diagnostic> errors)
{
var pathMapBuilder = ArrayBuilder<KeyValuePair<string, string>>.GetInstance();
if (pathMap.IsEmpty())
{
return pathMapBuilder.ToImmutableAndFree();
}
foreach (var kEqualsV in pathMap.Split(','))
{
var kv = kEqualsV.Split('=');
if (kv.Length != 2) continue;
if (kv.Length != 2)
{
errors.Add(Diagnostic.Create(_messageProvider, _messageProvider.ERR_InvalidPathMap, kEqualsV));
continue;
}
var from = PathUtilities.TrimTrailingSeparators(kv[0]);
var to = PathUtilities.TrimTrailingSeparators(kv[1]);
if (from.Length == 0 || to.Length == 0) continue;
pathMapBuilder.Add(new KeyValuePair<string, string>(from, to));
if (from.Length == 0 || (to.Length == 0 && kv[1] != "/"))
{
errors.Add(Diagnostic.Create(_messageProvider, _messageProvider.ERR_InvalidPathMap, kEqualsV));
}
else
{
pathMapBuilder.Add(new KeyValuePair<string, string>(from, to));
}
}
return pathMapBuilder.ToImmutableAndFree();
......
......@@ -138,6 +138,7 @@ public DiagnosticInfo FilterDiagnosticInfo(DiagnosticInfo diagnosticInfo, Compil
// command line:
public abstract int ERR_ExpectedSingleScript { get; }
public abstract int ERR_OpenResponseFile { get; }
public abstract int ERR_InvalidPathMap { get; }
public abstract int FTL_InputFileNameTooLong { get; }
public abstract int ERR_FileNotFound { get; }
public abstract int ERR_NoSourceFile { get; }
......
......@@ -19,7 +19,7 @@ class EndToEndDeterminismTest: TestBase
/// <param name="source"> The source code for the program that will be compiled </param>
/// <param name="additionalFlags"> A string containing any additional compiler flags </param>
/// <returns> An array of bytes that were read from the compiled DLL</returns>
private byte[] CompileAndGetBytes(string source, string additionalFlags)
private byte[] CompileAndGetBytes(string source, string additionalFlags, out string finalFlags)
{
var tempRoot = new TempRoot();
......@@ -27,12 +27,14 @@ private byte[] CompileAndGetBytes(string source, string additionalFlags)
var tempDir = tempRoot.CreateDirectory();
var srcFile = tempDir.CreateFile("test.cs").WriteAllText(source).Path;
var outFile = srcFile.Replace("test.cs", "test.dll");
finalFlags = $"{ _flags } { additionalFlags } /pathmap:{tempDir.Path}=/";
try
{
var errorsFile = srcFile + ".errors";
// Compile
var result = ProcessUtilities.Run("cmd", $"/C {CompilerServerUnitTests.s_csharpCompilerExecutableSrc} { _flags } { additionalFlags } { srcFile } /out:{ outFile } > { errorsFile }");
var result = ProcessUtilities.Run("cmd", $"/C {CompilerServerUnitTests.s_csharpCompilerExecutableSrc} { finalFlags } { srcFile } /out:{ outFile } > { errorsFile }");
if (result.ExitCode != 0)
{
var errors = File.ReadAllText(errorsFile);
......@@ -58,14 +60,17 @@ private byte[] CompileAndGetBytes(string source, string additionalFlags)
/// <param name="additionalFlags"> A string containing any additional compiler flags </param>
private void RunDeterministicTest(string source, string additionalFlags = "")
{
var first = CompileAndGetBytes(source, additionalFlags);
var second = CompileAndGetBytes(source, additionalFlags);
string finalFlags1;
string finalFlags2;
var first = CompileAndGetBytes(source, additionalFlags, out finalFlags1);
var second = CompileAndGetBytes(source, additionalFlags, out finalFlags2);
Assert.Equal(first.Length, second.Length);
for (int i = 0; i < first.Length; i++)
{
if (first[i] != second[i])
{
AssertEx.Fail($"Bytes were different at position { i } ({ first[i] } vs { second[i] }). Flags used were '{ _flags } { additionalFlags }'");
AssertEx.Fail($"Bytes were different at position { i } ({ first[i] } vs { second[i] }). Flags used were (\"{ finalFlags1 }\" vs \"{ finalFlags2 }\")");
}
}
}
......@@ -85,8 +90,7 @@ static void Main()
RunDeterministicTest(source);
}
// Waiting on PathMap support
[Fact(Skip = "https://github.com/dotnet/roslyn/pull/6008")]
[Fact]
public void CallerInfo()
{
var source = @"using System;
......
......@@ -989,7 +989,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Exit Select
End If
pathMap = pathMap.Concat(ParsePathMap(value))
pathMap = pathMap.Concat(ParsePathMap(value, diagnostics))
Continue For
Case "reportanalyzer"
......
......@@ -1679,6 +1679,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_InterpolationAlignmentOutOfRange = 37250
ERR_InterpolatedStringFactoryError = 37251
ERR_DebugEntryPointNotSourceMethodDefinition = 37252
ERR_InvalidPathMap = 37253
ERR_LastPlusOne
......
......@@ -160,6 +160,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Public Overrides ReadOnly Property ERR_InvalidPathMap As Integer
Get
Return ERRID.ERR_InvalidPathMap
End Get
End Property
Public Overrides ReadOnly Property FTL_InputFileNameTooLong As Integer
Get
Return ERRID.FTL_InputFileNameTooLong
......
......@@ -6107,6 +6107,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to The pathmap option was incorrectly formatted.
'''</summary>
Friend ReadOnly Property ERR_InvalidPathMap() As String
Get
Return ResourceManager.GetString("ERR_InvalidPathMap", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Invalid signature public key specified in AssemblySignatureKeyAttribute..
'''</summary>
......
......@@ -5332,4 +5332,7 @@
<data name="ERR_DebugEntryPointNotSourceMethodDefinition" xml:space="preserve">
<value>Debug entry point must be a definition of a method declared in the current compilation.</value>
</data>
</root>
\ No newline at end of file
<data name="ERR_InvalidPathMap" xml:space="preserve">
<value>The pathmap option was incorrectly formatted.</value>
</data>
</root>
......@@ -29,6 +29,11 @@ public override ReportDiagnostic GetDiagnosticReport(DiagnosticInfo diagnosticIn
throw new NotImplementedException();
}
public override int ERR_InvalidPathMap
{
get { throw new NotImplementedException(); }
}
public override int ERR_FailedToCreateTempFile
{
get { throw new NotImplementedException(); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册