-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Ensure generated trees have a full path #60095
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2451,13 +2451,14 @@ private static void ValidateEmbeddedSources_Windows(Dictionary<string, string> e | |
continue; | ||
} | ||
|
||
var sourceStr = Encoding.UTF8.GetString(sourceBlob.Array, sourceBlob.Offset, sourceBlob.Count); | ||
// offset by 3 to skip the BOM | ||
var sourceStr = Encoding.UTF8.GetString(sourceBlob.Array, sourceBlob.Offset + 3, sourceBlob.Count - 3); | ||
|
||
Assert.Equal(expectedEmbeddedMap[docPath], sourceStr); | ||
Assert.True(expectedEmbeddedMap.Remove(docPath)); | ||
} | ||
} | ||
catch | ||
finally | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out we were silently ignoring failures, but this function was not actually being used anyway :/ |
||
{ | ||
symReader?.Dispose(); | ||
} | ||
|
@@ -14324,6 +14325,123 @@ public void TestDuplicateAdditionalFiles(string additionalFilePath1, string addi | |
[InlineData("abc/a.txt", "./../ABC/a.txt", 2)] | ||
public void TestDuplicateAdditionalFiles_Linux(string additionalFilePath1, string additionalFilePath2, int expectedCount) => TestDuplicateAdditionalFiles(additionalFilePath1, additionalFilePath2, expectedCount); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this behavior interact with |
||
[Theory] | ||
[InlineData("/debug:embedded")] | ||
[InlineData("/debug:portable")] | ||
[InlineData("/debug:full")] | ||
public void Generated_Trees_Have_Full_Path(string debugSwitch) | ||
{ | ||
var dir = Temp.CreateDirectory(); | ||
var src = dir.CreateFile("temp.cs").WriteAllText("class C {}"); | ||
var generatedDir = dir.CreateDirectory("generated"); | ||
|
||
var generatedSource = "public class D { }"; | ||
var generator = new SingleFileTestGenerator(generatedSource, "generatedSource.cs"); | ||
|
||
VerifyOutput(dir, src, includeCurrentAssemblyAsAnalyzerReference: false, additionalFlags: new[] { "/generatedfilesout:" + generatedDir.Path, debugSwitch, "/out:embed.exe" }, generators: new[] { generator }, analyzers: null); | ||
|
||
var generatorPrefix = GeneratorDriver.GetFilePathPrefixForGenerator(generator); | ||
|
||
ValidateWrittenSources(new() { { Path.Combine(generatedDir.Path, generatorPrefix), new() { { "generatedSource.cs", generatedSource } } } }); | ||
|
||
Dictionary<string, string> expectedEmbeddedMap = new() { { Path.Combine(generatedDir.Path, generatorPrefix, "generatedSource.cs"), generatedSource } }; | ||
switch (debugSwitch) | ||
{ | ||
case "/debug:embedded": | ||
ValidateEmbeddedSources_Portable(expectedEmbeddedMap, dir, isEmbeddedPdb: true); | ||
break; | ||
case "/debug:portable": | ||
ValidateEmbeddedSources_Portable(expectedEmbeddedMap, dir, isEmbeddedPdb: false); | ||
break; | ||
case "/debug:full": | ||
ValidateEmbeddedSources_Windows(expectedEmbeddedMap, dir); | ||
break; | ||
} | ||
|
||
// Clean up temp files | ||
CleanupAllGeneratedFiles(src.Path); | ||
} | ||
|
||
[Theory] | ||
[InlineData("/debug:embedded")] | ||
[InlineData("/debug:portable")] | ||
[InlineData("/debug:full")] | ||
public void Generated_Trees_Have_Output_Path_When_No_GeneratedFilesOut(string debugSwitch) | ||
{ | ||
var dir = Temp.CreateDirectory(); | ||
var src = dir.CreateFile("temp.cs").WriteAllText("class C {}"); | ||
var generatedDir = dir.CreateDirectory("generated"); | ||
|
||
var generatedSource = "public class D { }"; | ||
var generator = new SingleFileTestGenerator(generatedSource, "generatedSource.cs"); | ||
|
||
VerifyOutput(dir, src, includeCurrentAssemblyAsAnalyzerReference: false, additionalFlags: new[] { debugSwitch, "/out:embed.exe" }, generators: new[] { generator }, analyzers: null); | ||
|
||
var generatorPrefix = GeneratorDriver.GetFilePathPrefixForGenerator(generator); | ||
|
||
// validate that *no* sources were written | ||
Assert.Empty(Directory.GetDirectories(generatedDir.Path)); | ||
|
||
// but we still have full paths (using output dir) in the PDBs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we verify the files were written to the expected directory?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we're not actually emitting any files here, which we check that on line 14384. |
||
Dictionary<string, string> expectedEmbeddedMap = new() { { Path.Combine(dir.Path, generatorPrefix, "generatedSource.cs"), generatedSource } }; | ||
switch (debugSwitch) | ||
{ | ||
case "/debug:embedded": | ||
ValidateEmbeddedSources_Portable(expectedEmbeddedMap, dir, isEmbeddedPdb: true); | ||
break; | ||
case "/debug:portable": | ||
ValidateEmbeddedSources_Portable(expectedEmbeddedMap, dir, isEmbeddedPdb: false); | ||
break; | ||
case "/debug:full": | ||
ValidateEmbeddedSources_Windows(expectedEmbeddedMap, dir); | ||
break; | ||
} | ||
|
||
// Clean up temp files | ||
CleanupAllGeneratedFiles(src.Path); | ||
} | ||
|
||
[Theory] | ||
[InlineData("/debug:embedded")] | ||
[InlineData("/debug:portable")] | ||
[InlineData("/debug:full")] | ||
public void Generated_Trees_Output_Path_Respects_PathMap(string debugSwitch) | ||
{ | ||
var dir = Temp.CreateDirectory(); | ||
var src = dir.CreateFile("temp.cs").WriteAllText("class C {}"); | ||
var generatedDir = dir.CreateDirectory("generated"); | ||
|
||
var generatedSource = "public class D { }"; | ||
var generator = new SingleFileTestGenerator(generatedSource, "generatedSource.cs"); | ||
|
||
var mappedPath = Path.Combine("mapped", "path"); | ||
|
||
VerifyOutput(dir, src, includeCurrentAssemblyAsAnalyzerReference: false, additionalFlags: new[] { debugSwitch, "/out:embed.exe", $"/pathmap:{dir.Path}={mappedPath}" }, generators: new[] { generator }, analyzers: null); | ||
|
||
var generatorPrefix = GeneratorDriver.GetFilePathPrefixForGenerator(generator); | ||
|
||
// validate that *no* sources were written | ||
Assert.Empty(Directory.GetDirectories(generatedDir.Path)); | ||
|
||
// but we still have full paths (using output dir) in the PDBs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we verify the files were written to the expected directory?
|
||
Dictionary<string, string> expectedEmbeddedMap = new() { { Path.Combine(mappedPath, generatorPrefix, "generatedSource.cs"), generatedSource } }; | ||
switch (debugSwitch) | ||
{ | ||
case "/debug:embedded": | ||
ValidateEmbeddedSources_Portable(expectedEmbeddedMap, dir, isEmbeddedPdb: true); | ||
break; | ||
case "/debug:portable": | ||
ValidateEmbeddedSources_Portable(expectedEmbeddedMap, dir, isEmbeddedPdb: false); | ||
break; | ||
case "/debug:full": | ||
ValidateEmbeddedSources_Windows(expectedEmbeddedMap, dir); | ||
break; | ||
} | ||
|
||
// Clean up temp files | ||
CleanupAllGeneratedFiles(src.Path); | ||
} | ||
} | ||
|
||
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odd to do this unconditionally. What if there is no BOM?