Merged PR 2946: make it possible to rewrite a folder full of assemblies

make it possible to rewrite a folder full of assemblies.
This commit is contained in:
Chris Lovett 2020-08-20 00:53:25 +00:00
Родитель 341cc52997
Коммит db9b30933c
5 изменённых файлов: 63 добавлений и 25 удалений

Просмотреть файл

@ -51,10 +51,10 @@ namespace Microsoft.Coyote
internal string AssemblyToBeAnalyzed;
/// <summary>
/// The path to the binary rewriting configuration file.
/// The path to the binary rewriting configuration file or a folder containing assemblies to rewrite.
/// </summary>
[DataMember]
internal string RewritingConfigurationFile;
internal string RewritingOptionsPath;
/// <summary>
/// Test method to be used.
@ -339,7 +339,7 @@ namespace Microsoft.Coyote
this.RuntimeGeneration = 0;
this.AssemblyToBeAnalyzed = string.Empty;
this.RewritingConfigurationFile = string.Empty;
this.RewritingOptionsPath = string.Empty;
this.TestMethodName = string.Empty;
this.SchedulingStrategy = "random";

Просмотреть файл

@ -68,6 +68,23 @@ namespace Microsoft.Coyote.Rewriting
new MonitorTransform(this.Log),
new ExceptionFilterTransform(this.Log)
};
// expand folder
if (this.Options.AssemblyPaths == null || this.Options.AssemblyPaths.Count == 0)
{
// Expand to include all .dll files in AssemblyPaths.
foreach (var file in Directory.GetFiles(this.Options.AssembliesDirectory, "*.dll"))
{
if (!this.DisallowedAssemblies.Contains(Path.GetFileName(file)))
{
this.Options.AssemblyPaths.Add(file);
}
else
{
Debug.WriteLine("Skipping " + file);
}
}
}
}
/// <summary>

Просмотреть файл

@ -114,11 +114,14 @@ namespace Microsoft.Coyote.Rewriting
outputDirectory = resolvedUri.LocalPath;
}
foreach (string assembly in configuration.Assemblies)
if (configuration.Assemblies != null)
{
resolvedUri = new Uri(Path.Combine(assembliesDirectory, assembly));
string assemblyFileName = resolvedUri.LocalPath;
assemblyPaths.Add(assemblyFileName);
foreach (string assembly in configuration.Assemblies)
{
resolvedUri = new Uri(Path.Combine(assembliesDirectory, assembly));
string assemblyFileName = resolvedUri.LocalPath;
assemblyPaths.Add(assemblyFileName);
}
}
}
}
@ -184,7 +187,7 @@ namespace Microsoft.Coyote.Rewriting
[DataMember(Name = "OutputPath")]
public string OutputPath { get; set; }
[DataMember(Name = "Assemblies", IsRequired = true)]
[DataMember(Name = "Assemblies")]
public IList<string> Assemblies { get; set; }
[DataMember(Name = "StrongNameKeyFile")]

Просмотреть файл

@ -185,23 +185,33 @@ namespace Microsoft.Coyote
{
try
{
if (string.IsNullOrEmpty(Configuration.RewritingConfigurationFile))
string assemblyDir = null;
var fileList = new HashSet<string>();
if (!string.IsNullOrEmpty(Configuration.AssemblyToBeAnalyzed))
{
// We are rewriting a dll directly, so we fake up a default configuration for doing this.
var fullPath = Path.GetFullPath(Configuration.AssemblyToBeAnalyzed);
var assemblyDir = Path.GetDirectoryName(fullPath);
Console.WriteLine($". Rewriting {fullPath}");
var config = RewritingOptions.Create(assemblyDir, assemblyDir,
new HashSet<string>(new string[] { fullPath }));
assemblyDir = Path.GetDirectoryName(fullPath);
fileList.Add(fullPath);
}
else if (Directory.Exists(Configuration.RewritingOptionsPath))
{
assemblyDir = Path.GetFullPath(Configuration.RewritingOptionsPath);
Console.WriteLine($". Rewriting the assemblies specified in {assemblyDir}");
}
if (!string.IsNullOrEmpty(assemblyDir))
{
// Create a new RewritingOptions object from scratch
var config = RewritingOptions.Create(assemblyDir, assemblyDir, fileList);
config.StrongNameKeyFile = Configuration.StrongNameKeyFile;
config.PlatformVersion = Configuration.PlatformVersion;
AssemblyRewriter.Rewrite(config);
}
else
{
Console.WriteLine($". Rewriting the assemblies specified in {Configuration.RewritingConfigurationFile}");
var config = RewritingOptions.ParseFromJSON(Configuration.RewritingConfigurationFile);
var config = RewritingOptions.ParseFromJSON(Configuration.RewritingOptionsPath);
Console.WriteLine($". Rewriting the assemblies specified in {config}");
config.PlatformVersion = Configuration.PlatformVersion;
if (string.IsNullOrEmpty(config.StrongNameKeyFile))
{

Просмотреть файл

@ -178,19 +178,27 @@ You can provide one or two unsigned integer values", typeof(uint)).IsMultiValue
// In the case of 'coyote rewrite', the path is the JSON configuration file
// with the binary rewriting options.
string filename = (string)option.Value;
string extension = Path.GetExtension(filename);
if (string.Compare(extension, ".json", StringComparison.OrdinalIgnoreCase) == 0)
if (Directory.Exists(filename))
{
configuration.RewritingConfigurationFile = filename;
}
else if (string.Compare(extension, ".dll", StringComparison.OrdinalIgnoreCase) == 0 ||
string.Compare(extension, ".exe", StringComparison.OrdinalIgnoreCase) == 0)
{
configuration.AssemblyToBeAnalyzed = filename;
// then we want to rewrite a whole folder full of dll's.
configuration.RewritingOptionsPath = filename;
}
else
{
Error.ReportAndExit("Please give a valid .dll or JSON configuration file for binary rewriting.");
string extension = Path.GetExtension(filename);
if (string.Compare(extension, ".json", StringComparison.OrdinalIgnoreCase) == 0)
{
configuration.RewritingOptionsPath = filename;
}
else if (string.Compare(extension, ".dll", StringComparison.OrdinalIgnoreCase) == 0 ||
string.Compare(extension, ".exe", StringComparison.OrdinalIgnoreCase) == 0)
{
configuration.AssemblyToBeAnalyzed = filename;
}
else
{
Error.ReportAndExit("Please give a valid .dll or JSON configuration file for binary rewriting.");
}
}
}