Skip to content

Commit

Permalink
Add exclusion support to source-build SDK tests (#15650)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaMilosavljevic authored Feb 28, 2023
2 parents 4c9bc74 + 93d517d commit 86543a0
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1,188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Enumeration;
using System.Linq;
using System.Text.RegularExpressions;
using Xunit.Abstractions;
Expand All @@ -27,15 +28,15 @@ public void CompareMsftToSb()
{
const string msftFileListingFileName = "msftSdkFiles.txt";
const string sbFileListingFileName = "sbSdkFiles.txt";
WriteTarballFileList(Config.MsftSdkTarballPath, msftFileListingFileName, isPortable: true);
WriteTarballFileList(Config.SdkTarballPath, sbFileListingFileName, isPortable: false);
WriteTarballFileList(Config.MsftSdkTarballPath, msftFileListingFileName, isPortable: true, "msft");
WriteTarballFileList(Config.SdkTarballPath, sbFileListingFileName, isPortable: false, "sb");

string diff = BaselineHelper.DiffFiles(msftFileListingFileName, sbFileListingFileName, OutputHelper);
diff = RemoveDiffMarkers(diff);
BaselineHelper.CompareContents("MsftToSbSdk.diff", diff, OutputHelper, Config.WarnOnSdkContentDiffs);
}

private void WriteTarballFileList(string? tarballPath, string outputFileName, bool isPortable)
private void WriteTarballFileList(string? tarballPath, string outputFileName, bool isPortable, string sdkType)
{
if (!File.Exists(tarballPath))
{
Expand All @@ -46,10 +47,32 @@ private void WriteTarballFileList(string? tarballPath, string outputFileName, bo
fileListing = BaselineHelper.RemoveRids(fileListing, isPortable);
fileListing = BaselineHelper.RemoveVersions(fileListing);
IEnumerable<string> files = fileListing.Split(Environment.NewLine).OrderBy(path => path);
files = RemoveExclusions(
files,
GetExclusionFilters(
Path.Combine(BaselineHelper.GetAssetsDirectory(), "SdkDiffExclusions.txt"),
sdkType));

File.WriteAllLines(outputFileName, files);
}

private static IEnumerable<string> RemoveExclusions(IEnumerable<string> files, IEnumerable<string> exclusions) =>
files.Where(item => !exclusions.Any(p => FileSystemName.MatchesSimpleExpression(p, item)));

private static IEnumerable<string> GetExclusionFilters(string exclusionsFilePath, string sdkType)
{
int prefixSkip = sdkType.Length + 1;
return File.ReadAllLines(exclusionsFilePath)
.Where(line => line.StartsWith(sdkType + ",")) // process only specific sdk exclusions
.Select(line =>
{
// Ignore comments
var index = line.IndexOf('#');
return index >= 0 ? line[prefixSkip..index].TrimEnd() : line[prefixSkip..];
})
.ToList();
}

private static string RemoveDiffMarkers(string source)
{
Regex indexRegex = new("^index .*", RegexOptions.Multiline);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This list is processed using FileSystemName.MatchesSimpleExpression
#
# Format
# {msft|sb},<path> [# comment]
# msft = Microsoft built SDK
# sb = source-built SDK
#
# Examples
# 'folder/*' matches 'folder/' and 'folder/abc'
# 'folder/?*' matches 'folder/abc' but not 'folder/'
#
# We do not want to filter-out folder entries, therefore, we should use: '?*' and not just '*'

msft,./sdk/x.y.z/TestHostNetFramework/?* # Intentional - MSFT build includes test-host that targets netcoreapp3.1
msft,./sdk/x.y.z/Sdks/Microsoft.NET.Sdk.Publish/tools/net472/?* # Intentional - source-build includes SDK Publishing package that target latest .NET TFM
msft,./sdk/x.y.z/Sdks/Microsoft.NET.Sdk.WindowsDesktop/?* # Intentional - explicitly excluded from source-build
sb,./sdk/x.y.z/TestHost/?* # Intentional - source-build includes test-host that targets latest .NET TFM

# vstest localization is disabled in Linux builds - https://github.com/microsoft/vstest/issues/4305
msft,./sdk/x.y.z/*?/Microsoft.CodeCoverage.IO.resources.dll
msft,./sdk/x.y.z/*?/Microsoft.TestPlatform.*?.resources.dll
msft,./sdk/x.y.z/*?/Microsoft.VisualStudio.TestPlatform.*?.resources.dll
msft,./sdk/x.y.z/*?/Test.Utility.resources.dll
msft,./sdk/x.y.z/*?/vstest.console.resources.dll
msft,./sdk/x.y.z/Extensions/*?/Microsoft.TestPlatform.*?.resources.dll
msft,./sdk/x.y.z/Extensions/*?/Microsoft.VisualStudio.TestPlatform.*?.resources.dll

# nuget localization is not available for Linux builds - https://github.com/NuGet/Home/issues/12440
msft,./sdk/x.y.z/*?/NuGet.*?.resources.dll
msft,./sdk/x.y.z/*?/Microsoft.Build.NuGetSdkResolver.resources.dll

# ILMerge is not supported in Linux builds - excluding the whole NuGet.Build.Tasks.Pack directory, to avoid a noisy diff
msft,./sdk/x.y.z/Sdks/NuGet.Build.Tasks.Pack/*?
sb,./sdk/x.y.z/Sdks/NuGet.Build.Tasks.Pack/*?

# missing workload manifests - https://github.com/dotnet/source-build/issues/3242
msft,./sdk-manifests/x.y.z/microsoft.net.sdk.android/*
msft,./sdk-manifests/x.y.z/microsoft.net.sdk.ios/*
msft,./sdk-manifests/x.y.z/microsoft.net.sdk.maccatalyst/*
msft,./sdk-manifests/x.y.z/microsoft.net.sdk.macos/*
msft,./sdk-manifests/x.y.z/microsoft.net.sdk.maui/*
msft,./sdk-manifests/x.y.z/microsoft.net.sdk.tvos/*
Loading

0 comments on commit 86543a0

Please sign in to comment.