-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C#: Early identification of duplicate extraction #1851
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
C#: Early identification of duplicate extraction #1851
Conversation
a68bad1
to
a369db9
Compare
f9260b1
to
e63e791
Compare
e63e791
to
8f3f940
Compare
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.
Nice sleuthing. This is an extremely reasonable solution. I'm sorry that it wasn't clear enough that the args-files should have been the verbatim command line arguments that can be passed by @ to the extractor command line.
/// Logs information about the extractor, as well as the arguments to Roslyn. | ||
/// </summary> | ||
/// <param name="roslynArgs">The arguments passed to Roslyn.</param> | ||
/// <returns>A Boolean indicating whether to proceed with extraction.</returns> |
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.
Perhaps, "A Boolean indicating whether the same arguments have been logged previously." The decision about extraction is taken elsewhere.
|
||
layout = new Layout(); | ||
this.options = options; | ||
|
||
extractor = new Extraction.Extractor(false, GetOutputName(compilation, commandLineArguments), Logger); | ||
finalizeInit = comp => |
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.
I think it would be clearer to just pull this out into a method FinalizeInitialization(CSharpCompilation comp ...)
, and to remove the finalizeInit
argument on line 51. Then just call FinalizeInitialization
explicitly.
@@ -259,7 +260,7 @@ void DoAnalyseAssembly(PortableExecutableReference r) | |||
var projectLayout = layout.LookupProjectOrDefault(assemblyPath); | |||
using (var trapWriter = projectLayout.CreateTrapWriter(Logger, assemblyPath, true, options.TrapCompression)) | |||
{ | |||
var skipExtraction = FileIsCached(assemblyPath, trapWriter.TrapFile); | |||
var skipExtraction = options.Cache && File.Exists(trapWriter.TrapFile); |
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.
Optionally, push logic into FileIsCached
.
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.
FileIsCached
actually does more, it also checks for timestamps, which is what didn't work for Mono and CoreFX.
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.
I meant, change FileIsCached
to use File.Exists
and not timestamps.
{ | ||
Logger.Log(Severity.Info, $" Arguments to Roslyn: {string.Join(' ', roslynArgs)}"); | ||
streamWriter.WriteLine($"Arguments to Roslyn: {string.Join(' ', roslynArgs)}"); |
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.
I don't think we want this, because we want to be able to @-include the arguments file on the command line arguments for debugging purposes, if we need to reproduce extraction of a particular compilation command.
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.
The reason it is there is because we need the hash of the file to include all arguments to Roslyn, not just the ones from the response file, in order to identify identical compilations. However, it appears that response files can contain comments, so adding this line as a comment should work.
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.
The comment worked beautifully, nice find. However, the hash of the file and the contents of the file could be different. You hash all the "inputs" (i.e. the command line), and could even have an empty file just to indicate that the arguments have been seen.
@@ -259,7 +260,7 @@ void DoAnalyseAssembly(PortableExecutableReference r) | |||
var projectLayout = layout.LookupProjectOrDefault(assemblyPath); | |||
using (var trapWriter = projectLayout.CreateTrapWriter(Logger, assemblyPath, true, options.TrapCompression)) | |||
{ | |||
var skipExtraction = FileIsCached(assemblyPath, trapWriter.TrapFile); | |||
var skipExtraction = options.Cache && File.Exists(trapWriter.TrapFile); |
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.
I meant, change FileIsCached
to use File.Exists
and not timestamps.
{ | ||
Logger.Log(Severity.Info, $" Arguments to Roslyn: {string.Join(' ', roslynArgs)}"); | ||
streamWriter.WriteLine($"Arguments to Roslyn: {string.Join(' ', roslynArgs)}"); |
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.
The comment worked beautifully, nice find. However, the hash of the file and the contents of the file could be different. You hash all the "inputs" (i.e. the command line), and could even have an empty file just to indicate that the arguments have been seen.
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.
A small suggestion but the overall approach LGTM.
@@ -456,7 +456,7 @@ public bool LogRoslynArgs(string[] roslynArgs, string extractorVersion) | |||
bool argsWritten; | |||
using (var streamWriter = new StreamWriter(new FileStream(tempFile, FileMode.Append, FileAccess.Write))) | |||
{ | |||
streamWriter.WriteLine($"# Arguments to Roslyn: {string.Join(' ', roslynArgs)}"); | |||
streamWriter.WriteLine($"# Arguments to Roslyn: {string.Join(' ', roslynArgs.Where(arg => arg[0] != '@'))}"); |
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.
!arg.StartsWith("@")
and fix CommandLineExtensions.cs:19 as well?
It's just possible that arg
is empty.
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.
Yeah, that is better.
804521d
to
61bd9f2
Compare
This change makes a big impact on CoreFX and Mono: