-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add --make-repro-path option to crossgen2 #57543
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
|
@@ -75,6 +77,8 @@ internal class CommandLineOptions | |
|
||
public IReadOnlyList<string> CodegenOptions; | ||
|
||
public string MakeReproPath; | ||
|
||
public bool CompositeOrInputBubble => Composite || InputBubble; | ||
|
||
public CommandLineOptions(string[] args) | ||
|
@@ -169,6 +173,8 @@ public CommandLineOptions(string[] args) | |
syntax.DefineOption("verify-type-and-field-layout", ref VerifyTypeAndFieldLayout, SR.VerifyTypeAndFieldLayoutOption); | ||
syntax.DefineOption("callchain-profile", ref CallChainProfileFile, SR.CallChainProfileFile); | ||
|
||
syntax.DefineOption("make-repro-path", ref MakeReproPath, SR.MakeReproPathHelp); | ||
|
||
syntax.DefineOption("h|help", ref Help, SR.HelpOption); | ||
|
||
syntax.DefineParameterList("in", ref InputFilePaths, SR.InputFilesToCompile); | ||
|
@@ -230,6 +236,162 @@ public CommandLineOptions(string[] args) | |
|
||
HelpText = argSyntax.GetHelpText(); | ||
} | ||
|
||
if (MakeReproPath != null) | ||
{ | ||
// Create a repro package in the specified path | ||
// This package will have the set of input files needed for compilation | ||
// + the original command line arguments | ||
// + a rsp file that should work to directly run out of the zip file | ||
|
||
string makeReproPath = MakeReproPath; | ||
Directory.CreateDirectory(makeReproPath); | ||
|
||
List<string> crossgenDetails = new List<string>(); | ||
crossgenDetails.Add("CrossGen2 version"); | ||
try | ||
{ | ||
crossgenDetails.Add(Environment.GetCommandLineArgs()[0]); | ||
} catch {} | ||
try | ||
{ | ||
crossgenDetails.Add(System.Diagnostics.FileVersionInfo.GetVersionInfo(Environment.GetCommandLineArgs()[0]).ToString()); | ||
} catch {} | ||
|
||
crossgenDetails.Add("------------------------"); | ||
crossgenDetails.Add("Actual Command Line Args"); | ||
crossgenDetails.Add("------------------------"); | ||
crossgenDetails.AddRange(args); | ||
foreach (string arg in args) | ||
{ | ||
if (arg.StartsWith('@')) | ||
{ | ||
string rspFileName = arg.Substring(1); | ||
crossgenDetails.Add("------------------------"); | ||
crossgenDetails.Add(rspFileName); | ||
crossgenDetails.Add("------------------------"); | ||
try | ||
{ | ||
crossgenDetails.AddRange(File.ReadAllLines(rspFileName)); | ||
} catch {} | ||
} | ||
} | ||
|
||
HashCode hashCodeOfArgs = new HashCode(); | ||
foreach (string s in crossgenDetails) | ||
hashCodeOfArgs.Add(s); | ||
|
||
string zipFileName = ((uint)hashCodeOfArgs.ToHashCode()).ToString(); | ||
|
||
if (OutputFilePath != null) | ||
zipFileName = zipFileName + "_" + Path.GetFileName(OutputFilePath); | ||
|
||
zipFileName = Path.Combine(MakeReproPath, Path.ChangeExtension(zipFileName, ".zip")); | ||
|
||
Console.WriteLine($"Creating {zipFileName}"); | ||
using (var archive = ZipFile.Open(zipFileName, ZipArchiveMode.Create)) | ||
{ | ||
ZipArchiveEntry commandEntry = archive.CreateEntry("crossgen2command.txt"); | ||
using (StreamWriter writer = new StreamWriter(commandEntry.Open())) | ||
{ | ||
foreach (string s in crossgenDetails) | ||
writer.WriteLine(s); | ||
} | ||
|
||
HashSet<string> inputOptionNames = new HashSet<string>(); | ||
inputOptionNames.Add("-r"); | ||
inputOptionNames.Add("-u"); | ||
inputOptionNames.Add("-m"); | ||
inputOptionNames.Add("--inputbubbleref"); | ||
Dictionary<string, string> inputToReproPackageFileName = new Dictionary<string, string>(); | ||
|
||
List<string> rspFile = new List<string>(); | ||
foreach (var option in argSyntax.GetOptions()) | ||
{ | ||
if (option.GetDisplayName() == "--make-repro-path") | ||
{ | ||
continue; | ||
} | ||
|
||
if (option.Value != null && !option.Value.Equals(option.DefaultValue)) | ||
{ | ||
if (option.IsList) | ||
{ | ||
if (inputOptionNames.Contains(option.GetDisplayName())) | ||
{ | ||
Dictionary<string, string> dictionary = new Dictionary<string, string>(); | ||
foreach (string optInList in (IEnumerable)option.Value) | ||
{ | ||
Helpers.AppendExpandedPaths(dictionary, optInList, false); | ||
} | ||
foreach (string inputFile in dictionary.Values) | ||
{ | ||
rspFile.Add($"{option.GetDisplayName()}:{ConvertFromInputPathToReproPackagePath(inputFile)}"); | ||
} | ||
} | ||
else | ||
{ | ||
foreach (object optInList in (IEnumerable)option.Value) | ||
{ | ||
rspFile.Add($"{option.GetDisplayName()}:{optInList}"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
rspFile.Add($"{option.GetDisplayName()}:{option.Value}"); | ||
} | ||
} | ||
} | ||
|
||
foreach (var parameter in argSyntax.GetParameters()) | ||
{ | ||
if (parameter.Value != null) | ||
{ | ||
if (parameter.IsList) | ||
{ | ||
foreach (object optInList in (IEnumerable)parameter.Value) | ||
{ | ||
rspFile.Add($"{ConvertFromInputPathToReproPackagePath((string)optInList)}"); | ||
} | ||
} | ||
else | ||
{ | ||
rspFile.Add($"{ConvertFromInputPathToReproPackagePath((string)parameter.Value.ToString())}"); | ||
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. Nit: I guess casting to |
||
} | ||
} | ||
} | ||
|
||
ZipArchiveEntry rspEntry = archive.CreateEntry("crossgen2repro.rsp"); | ||
using (StreamWriter writer = new StreamWriter(rspEntry.Open())) | ||
{ | ||
foreach (string s in rspFile) | ||
writer.WriteLine(s); | ||
} | ||
|
||
string ConvertFromInputPathToReproPackagePath(string inputPath) | ||
{ | ||
if (inputToReproPackageFileName.TryGetValue(inputPath, out string reproPackagePath)) | ||
{ | ||
return reproPackagePath; | ||
} | ||
|
||
try | ||
{ | ||
string inputFileDir = inputToReproPackageFileName.Count.ToString(); | ||
reproPackagePath = Path.Combine(inputFileDir, Path.GetFileName(inputPath)); | ||
archive.CreateEntryFromFile(inputPath, reproPackagePath); | ||
inputToReproPackageFileName.Add(inputPath, reproPackagePath); | ||
|
||
return reproPackagePath; | ||
} | ||
catch | ||
{ | ||
return inputPath; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: If there are multiple repro files in the same directory, it might be easier to search through them if we put
OutputFilePath
at the beginning.