Skip to content
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

Fix repro package creation #78924

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions src/coreclr/tools/Common/CommandLineHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static TargetArchitecture GetTargetArchitecture(string token)
throw new CommandLineException($"Target architecture '{token}' is not supported");
}

public static void MakeReproPackage(string makeReproPath, string outputFilePath, string[] args, ParseResult res, IEnumerable<string> inputOptions)
public static void MakeReproPackage(string makeReproPath, string outputFilePath, string[] args, ParseResult res, IEnumerable<string> inputOptions, IEnumerable<string> outputOptions = null)
{
Directory.CreateDirectory(makeReproPath);

Expand Down Expand Up @@ -169,6 +169,8 @@ public static void MakeReproPackage(string makeReproPath, string outputFilePath,

HashSet<string> inputOptionNames = new HashSet<string>(inputOptions);
Dictionary<string, string> inputToReproPackageFileName = new();
HashSet<string> outputOptionNames = outputOptions == null ? new HashSet<string>() : new HashSet<string>(outputOptions);
Dictionary<string, string> outputToReproPackageFileName = new();

List<string> rspFile = new List<string>();
foreach (var option in res.CommandResult.Command.Options)
Expand All @@ -182,48 +184,68 @@ public static void MakeReproPackage(string makeReproPath, string outputFilePath,
object val = res.CommandResult.GetValue(option);
if (val is not null && !(descriptor.HasDefaultValue && descriptor.GetDefaultValue().Equals(val)))
{
if (val is IEnumerable<string> values)
if (val is IEnumerable<string> || val is IDictionary<string, string>)
{
if (!(val is IEnumerable<string> values))
MichalStrehovsky marked this conversation as resolved.
Show resolved Hide resolved
values = ((IDictionary<string, string>)val).Values;
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved

if (inputOptionNames.Contains(option.Name))
{
Dictionary<string, string> dictionary = new();
foreach (string optInList in values)
{
AppendExpandedPaths(dictionary, optInList, false);
if (!string.IsNullOrEmpty(optInList))
AppendExpandedPaths(dictionary, optInList, false);
}
foreach (string inputFile in dictionary.Values)
{
rspFile.Add($"--{option.Name}:{ConvertFromInputPathToReproPackagePath(inputFile)}");
rspFile.Add($"--{option.Name}:{ConvertFromOriginalPathToReproPackagePath(input: true, inputFile)}");
}
}
else
{
foreach (string optInList in values)
{
rspFile.Add($"--{option.Name}:{optInList}");
if (!string.IsNullOrEmpty(optInList))
rspFile.Add($"--{option.Name}:{optInList}");
}
}
}
else
{
rspFile.Add($"--{option.Name}:{val}");
if (val is string stringVal && !string.IsNullOrEmpty(stringVal))
{
if (outputOptionNames.Contains(option.Name))
{
// if output option is used, overwrite the path to the repro package
stringVal = ConvertFromOriginalPathToReproPackagePath(input: false, stringVal);
}
rspFile.Add($"--{option.Name}:{stringVal}");
}
else
{
rspFile.Add($"--{option.Name}:{val}");
}
}
}
}

foreach (var argument in res.CommandResult.Command.Arguments)
{
object val = res.CommandResult.GetValue(argument);
if (val is IEnumerable<string> values)
if (val is IEnumerable<string> || val is IDictionary<string, string>)
{
if (!(val is IEnumerable<string> values))
MichalStrehovsky marked this conversation as resolved.
Show resolved Hide resolved
values = ((IDictionary<string, string>)val).Values;
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved

foreach (string optInList in values)
{
rspFile.Add($"{ConvertFromInputPathToReproPackagePath((string)optInList)}");
rspFile.Add($"{ConvertFromOriginalPathToReproPackagePath(input: true, optInList)}");
}
}
else
{
rspFile.Add($"{ConvertFromInputPathToReproPackagePath((string)val)}");
rspFile.Add($"{ConvertFromOriginalPathToReproPackagePath(input: true, (string)val)}");
}
}

Expand All @@ -234,25 +256,30 @@ public static void MakeReproPackage(string makeReproPath, string outputFilePath,
writer.WriteLine(s);
}

string ConvertFromInputPathToReproPackagePath(string inputPath)
string ConvertFromOriginalPathToReproPackagePath(bool input, string originalPath)
{
if (inputToReproPackageFileName.TryGetValue(inputPath, out string reproPackagePath))
var originalToReproPackageFileName = input ? inputToReproPackageFileName : outputToReproPackageFileName;
if (originalToReproPackageFileName.TryGetValue(originalPath, 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);
string prefix = input ? "_in_" : "_out_";
string reproFileDir = prefix + originalToReproPackageFileName.Count.ToString() + Path.DirectorySeparatorChar;
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
reproPackagePath = Path.Combine(reproFileDir, Path.GetFileName(originalPath));
if (!input)
archive.CreateEntry(reproFileDir); // for outputs just create output directory
else
archive.CreateEntryFromFile(originalPath, reproPackagePath);
originalToReproPackageFileName.Add(originalPath, reproPackagePath);

return reproPackagePath;
}
catch
{
return inputPath;
return originalPath;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ public ILCompilerRootCommand(string[] args) : base(".NET Native IL Compiler")
// + the original command line arguments
// + a rsp file that should work to directly run out of the zip file

Helpers.MakeReproPackage(makeReproPath, context.ParseResult.GetValue(OutputFilePath), args,
context.ParseResult, new[] { "r", "reference", "m", "mibc", "rdxml", "directpinvokelist", "descriptor" });
Helpers.MakeReproPackage(makeReproPath, context.ParseResult.GetValue(OutputFilePath), args, context.ParseResult,
inputOptions : new[] { "r", "reference", "m", "mibc", "rdxml", "directpinvokelist", "descriptor", "root", "conditionalroot", "trim" },
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
outputOptions : new[] { "o", "out", "exportsfile" });
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
}

context.ExitCode = new Program(this).Run();
Expand Down