提交 399a0b9d 编写于 作者: J Jared Parsons

Added diagnostics to the determinism testing

上级 63063347
param ([string]$buildDir = $(throw "Need a directory containing a compiler build to test with"))
$rootDir = split-path -parent (split-path -parent $PSScriptRoot)
$debugDir = resolve-path (join-path $rootDir "Binaries\Debug")
if (-not ([IO.Path]::IsPathRooted($buildDir))) {
write-error "The build path must be absolute"
exit 1
}
$rootDir = resolve-path (split-path -parent (split-path -parent $PSScriptRoot))
$sln = join-path $rootDir "Compilers.sln"
$debugDir = join-path $rootDir "Binaries\Debug"
# Create directories that may or may not exist to make the script execution below
# clean in either case.
mkdir $debugDir -errorAction SilentlyContinue | out-null
mkdir (join-path $rootDir "Binaries\Obj") -errorAction SilentlyContinue | out-null
pushd $rootDir
$skipList = @(
"Microsoft.CodeAnalysis.Test.Resources.Proprietary.dll"
)
$allGood = $true
$map = @{}
$i = 0;
......@@ -13,25 +27,32 @@ while ($i -lt 3 -and $allGood) {
# Clean out the previous run
write-host "Cleaning the Binaries"
rm -re -fo "Binaries\Debug"
rm -re -fo "Binaries\Debug"
rm -re -fo "Binaries\Obj"
msbuild /nologo /v:m /t:clean $sln
& msbuild /nologo /v:m /t:clean $sln
write-host "Building the Solution"
msbuild /nologo /v:m /m $sln
& msbuild /nologo /v:m /m /p:BootstrapBuildPath=$buildDir /p:Features="debug-determinism=$debugDir" /p:UseRoslynAnalyzers=false $sln
pushd $debugDir
write-host "Testing the binaries"
foreach ($dll in gci -re -in Microsoft.CodeAnalysis.*dll,Roslyn.*dll,cs*exe,vb*exe) {
foreach ($dll in gci Microsoft.CodeAnalysis.*dll,Roslyn.*dll,cs*exe,vb*exe) {
$dllFullName = $dll.FullName
$dllName = split-path -leaf $dllFullName
$dllHash = get-md5 $dll
$dllKeyName = $dllFullName + ".key"
if ($skipList.Contains($dllName)) {
continue;
}
if ($i -eq 0) {
write-host "`tRecording $dllName = $dllHash"
$data = @{}
$data["Hash"] = $dllHash
$data["Content"] = [IO.File]::ReadAllBytes($dllFullName)
$data["Key"] = [IO.File]::ReadAllBytes($dllFullName + ".key")
$map[$dllFullName] = $data
}
else {
......@@ -43,6 +64,7 @@ while ($i -lt 3 -and $allGood) {
else {
write-host "`tERROR! $dllName changed ($dllFullName)"
[IO.File]::WriteAllBytes($dllFullName + ".baseline", $data.Content)
[IO.File]::WriteAllBytes($dllFullName + ".baseline.key", $data.Key)
$allGood = $false
}
}
......@@ -62,6 +84,8 @@ while ($i -lt 3 -and $allGood) {
popd
& $buildDir\VBCSCompiler.exe -shutdown
if (-not $allGood) {
exit 1
}
......
......@@ -67,7 +67,7 @@ msbuild %MSBuildAdditionalCommandLineArgs% /t:Clean build/Toolset.sln /p:Configu
call :TerminateBuildProcesses
if defined TestDeterminism (
powershell -noprofile -executionPolicy RemoteSigned -command "%RoslynRoot%\build\scripts\test-determinism.ps1 %bindir%\Bootstrap" || goto :BuildFailed
powershell -noprofile -executionPolicy RemoteSigned -command "%RoslynRoot%\build\scripts\test-determinism.ps1 %RoslynRoot%\%bindir%\Bootstrap" || goto :BuildFailed
exit /b 0
)
......
......@@ -58,6 +58,14 @@ public CommonCompiler(CommandLineParser parser, string responseFile, string[] ar
this.Arguments = parser.Parse(allArgs, baseDirectory, sdkDirectoryOpt, additionalReferenceDirectories);
this.MessageProvider = parser.MessageProvider;
this.AnalyzerLoader = analyzerLoader;
#if DEBUG
string value;
if (Arguments.ParseOptions.Features.TryGetValue("debug-determinism", out value))
{
EmitDeterminismKey(Arguments, args, baseDirectory, parser, value);
}
#endif
}
internal abstract bool SuppressDefaultResponseFile(IEnumerable<string> args);
......@@ -847,5 +855,58 @@ protected virtual CultureInfo Culture
return Arguments.PreferredUILang ?? CultureInfo.CurrentUICulture;
}
}
private static void EmitDeterminismKey(CommandLineArguments args, string[] rawArgs, string baseDirectory, CommandLineParser parser, string outputDirectory)
{
var key = CreateDeterminismKey(args, rawArgs, baseDirectory, parser);
var filePath = Path.Combine(outputDirectory, args.OutputFileName + ".key");
using (var stream = PortableShim.File.Create(filePath))
{
var bytes = Encoding.UTF8.GetBytes(key);
stream.Write(bytes, 0, bytes.Length);
}
}
private static string CreateDeterminismKey(CommandLineArguments args, string[] rawArgs, string baseDirectory, CommandLineParser parser)
{
List<Diagnostic> diagnostics = new List<Diagnostic>();
List<string> flattenedArgs = new List<string>();
parser.FlattenArgs(rawArgs, diagnostics, flattenedArgs, null, baseDirectory);
var builder = new StringBuilder();
var name = !string.IsNullOrEmpty(args.OutputFileName)
? Path.GetFileNameWithoutExtension(Path.GetFileName(args.OutputFileName))
: $"no-output-name-{Guid.NewGuid().ToString()}";
builder.AppendLine($"{name}");
builder.AppendLine($"Command Line:");
foreach (var current in flattenedArgs)
{
builder.AppendLine($"\t{current}");
}
builder.AppendLine("Source Files:");
var hash = new MD5CryptoServiceProvider();
foreach (var sourceFile in args.SourceFiles)
{
var sourceFileName = Path.GetFileName(sourceFile.Path);
string hashValue;
try
{
var bytes = PortableShim.File.ReadAllBytes(sourceFile.Path);
var hashBytes = hash.ComputeHash(bytes);
var data = BitConverter.ToString(hashBytes);
hashValue = data.Replace("-", "");
}
catch (Exception ex)
{
hashValue = $"Could not compute {ex.Message}";
}
builder.AppendLine($"\t{sourceFileName} - {hashValue}");
}
return builder.ToString();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册