Skip to content

Commit

Permalink
Merging servicing fixes for 16.9.4 (#2837)
Browse files Browse the repository at this point in the history
* Dynamic corelib.net loading (#2762) (#2803)
  • Loading branch information
Haplois committed Mar 30, 2021
1 parent 6a858a3 commit 99b911a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
15 changes: 15 additions & 0 deletions scripts/build.ps1
Expand Up @@ -573,6 +573,14 @@ function Publish-Package
Copy-Loc-Files $eventLogDataCollectorNetFull $coreCLRExtensionsDir "Microsoft.TestPlatform.Extensions.EventLogCollector.resources.dll"
}

# Copy Coverage.CoreLib.Net dlls
$codeCoverageExternalsVersion = ([xml](Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props)).Project.PropertyGroup.CodeCoverageExternalsVersion
$codeCoverageCoreLibPackagesDir = Join-Path $env:TP_PACKAGES_DIR "microsoft.visualstudio.coverage.corelib.net\$codeCoverageExternalsVersion\lib\$TPB_TargetFrameworkStandard"
Copy-Item $codeCoverageCoreLibPackagesDir\Microsoft.VisualStudio.Coverage.CoreLib.Net.dll $coreCLR20PackageDir -Force
if($TPB_LocalizedBuild) {
Copy-Loc-Files $codeCoverageCoreLibPackagesDir $coreCLR20PackageDir "Microsoft.VisualStudio.Coverage.CoreLib.Net.resources.dll"
}

# If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
$runtimeproviders = @("Microsoft.TestPlatform.TestHostRuntimeProvider.dll", "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb")
foreach($file in $runtimeproviders) {
Expand Down Expand Up @@ -736,6 +744,13 @@ function Create-VsixPackage
if($TPB_LocalizedBuild) {
Copy-Loc-Files $traceDataCollectorPackageDirectory $extensionsPackageDir "Microsoft.VisualStudio.TraceDataCollector.resources.dll"
}

# Copy Microsoft.VisualStudio.CoreLib.Net
$codeCoverageCoreLibPackagesDir = Join-Path $env:TP_PACKAGES_DIR "microsoft.visualstudio.coverage.corelib.net\$codeCoverageExternalsVersion\lib\$TPB_TargetFramework451"
Copy-Item $codeCoverageCoreLibPackagesDir\Microsoft.VisualStudio.Coverage.CoreLib.Net.dll $packageDir -Force
if($TPB_LocalizedBuild) {
Copy-Loc-Files $codeCoverageCoreLibPackagesDir $packageDir "Microsoft.VisualStudio.Coverage.CoreLib.Net.resources.dll"
}

$codeCoverageInterprocessPackageDirectory = Join-Path $env:TP_PACKAGES_DIR "Microsoft.VisualStudio.Coverage.Interprocess\$codeCoverageExternalsVersion\lib\$TPB_TargetFrameworkNS20"
Copy-Item $codeCoverageInterprocessPackageDirectory\Microsoft.VisualStudio.Coverage.Interprocess.dll $extensionsPackageDir -Force
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/TestPlatform.Dependencies.props
Expand Up @@ -11,7 +11,7 @@
<!-- this version also needs to be "statically" readable because the test fixture will inspect this file for the version
and because during the test `dotnet test` will run and re-build some of the test projects and at that time the version
from a build parameter would not be available, so I am writing this version from the build.ps1 script to keep it in sync -->
<NETTestSdkVersion>16.9.1-dev</NETTestSdkVersion>
<NETTestSdkVersion>16.9.4-dev</NETTestSdkVersion>

<MSTestFrameworkVersion>2.1.0</MSTestFrameworkVersion>
<MSTestAdapterVersion>2.1.0</MSTestAdapterVersion>
Expand All @@ -32,7 +32,7 @@
<JsonNetVersion>9.0.1</JsonNetVersion>
<MoqVersion>4.7.63</MoqVersion>
<TestPlatformExternalsVersion>16.9.0-preview-4267359</TestPlatformExternalsVersion>
<CodeCoverageExternalsVersion>16.9.0-beta.21119.4</CodeCoverageExternalsVersion>
<CodeCoverageExternalsVersion>16.9.0-beta.21158.1</CodeCoverageExternalsVersion>
<MicrosoftFakesVersion>16.9.0-beta.20628.1</MicrosoftFakesVersion>

<MicrosoftBuildPackageVersion>16.0.461</MicrosoftBuildPackageVersion>
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/TestPlatform.Settings.targets
Expand Up @@ -5,7 +5,7 @@
<!-- This version is read by vsts-prebuild.ps1 and is a base for the current version, this should be updated
at the start of new iteration to the goal number. This is also used to version the local packages. This version needs to be statically
readable when we read the file as xml, don't move it to a .props file, unless you change the build server process -->
<TPVersionPrefix>16.9.1</TPVersionPrefix>
<TPVersionPrefix>16.9.4</TPVersionPrefix>
</PropertyGroup>
<PropertyGroup>
<!-- Versioning is defined from the build script. Use a default dev build if it's not defined.
Expand Down
2 changes: 1 addition & 1 deletion scripts/verify-nupkgs.ps1
Expand Up @@ -16,7 +16,7 @@ function Verify-Nuget-Packages($packageDirectory, $version)
"Microsoft.NET.Test.Sdk" = 27;
"Microsoft.TestPlatform" = 515;
"Microsoft.TestPlatform.Build" = 21;
"Microsoft.TestPlatform.CLI" = 381;
"Microsoft.TestPlatform.CLI" = 366;
"Microsoft.TestPlatform.Extensions.TrxLogger" = 35;
"Microsoft.TestPlatform.ObjectModel" = 180;
"Microsoft.TestPlatform.AdapterUtilities" = 48;
Expand Down
Expand Up @@ -8,28 +8,34 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.VisualStudio.Coverage.CoreLib.Net;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;

public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachmentProcessor
{
private const string CoverageUri = "datacollector://microsoft/CodeCoverage/2.0";
private const string CoverageFileExtension = ".coverage";
private const string CoverageFriendlyName = "Code Coverage";

private const string CodeCoverageCoreLibNetAssemblyName = "Microsoft.VisualStudio.Coverage.CoreLib.Net";
private const string CoverageFileUtilityTypeName = "CoverageFileUtility";
private const string MergeMethodName = "MergeCoverageFilesAsync";
private const string WriteMethodName = "WriteCoverageFile";

private static readonly Uri CodeCoverageDataCollectorUri = new Uri(CoverageUri);

public bool SupportsIncrementalProcessing => true;

public IEnumerable<Uri> GetExtensionUris()
{
yield return CodeCoverageDataCollectorUri;
}
}

public async Task<ICollection<AttachmentSet>> ProcessAttachmentSetsAsync(ICollection<AttachmentSet> attachments, IProgress<int> progressReporter, IMessageLogger logger, CancellationToken cancellationToken)
{
Expand All @@ -53,7 +59,7 @@ public async Task<ICollection<AttachmentSet>> ProcessAttachmentSetsAsync(ICollec
}
}

if(coverageReportFilePaths.Count > 1)
if (coverageReportFilePaths.Count > 1)
{
var mergedCoverageReportFilePath = await this.MergeCodeCoverageFilesAsync(coverageReportFilePaths, progressReporter, cancellationToken).ConfigureAwait(false);
if (!string.IsNullOrEmpty(mergedCoverageReportFilePath))
Expand Down Expand Up @@ -106,15 +112,25 @@ private async Task<string> MergeCodeCoverageFilesAsync(IList<string> files, IPro

private async Task<string> MergeCodeCoverageFilesAsync(IList<string> files, CancellationToken cancellationToken)
{
var coverageUtility = new CoverageFileUtility();

var coverageData = await coverageUtility.MergeCoverageFilesAsync(
files,
cancellationToken).ConfigureAwait(false);

coverageUtility.WriteCoverageFile(files[0], coverageData);

foreach(var file in files.Skip(1))
cancellationToken.ThrowIfCancellationRequested();

var assemblyPath = Path.Combine(Path.GetDirectoryName(typeof(CodeCoverageDataAttachmentsHandler).GetTypeInfo().Assembly.GetAssemblyLocation()), CodeCoverageCoreLibNetAssemblyName + ".dll");

// Get assembly, type and methods
Assembly assembly = new PlatformAssemblyLoadContext().LoadAssemblyFromPath(assemblyPath);
var classType = assembly.GetType($"{CodeCoverageCoreLibNetAssemblyName}.{CoverageFileUtilityTypeName}");
var classInstance = Activator.CreateInstance(classType);
var mergeMethodInfo = classType?.GetMethod(MergeMethodName, new[] { typeof(IList<string>), typeof(CancellationToken) });
var writeMethodInfo = classType?.GetMethod(WriteMethodName);

// Invoke methods
var task = (Task)mergeMethodInfo.Invoke(classInstance, new object[] { files, cancellationToken });
await task.ConfigureAwait(false);
var coverageData = task.GetType().GetProperty("Result").GetValue(task, null);
writeMethodInfo.Invoke(classInstance, new object[] { files[0], coverageData });

// Delete original files and keep merged file only
foreach (var file in files.Skip(1))
{
try
{
Expand Down
Expand Up @@ -15,7 +15,6 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj" />
<ProjectReference Include="..\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
<PackageReference Include="Microsoft.VisualStudio.Coverage.CoreLib.Net" Version="$(CodeCoverageExternalsVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
Expand Down

0 comments on commit 99b911a

Please sign in to comment.