Skip to content

Support multiple unique assembly ids in packages and tasks - #27203

Merged
mmitche merged 3 commits into
dotnet:mainfrom
ViktorHofer:MultiAssemblyMode
Aug 17, 2022
Merged

mmitche merged 3 commits into
dotnet:mainfrom
ViktorHofer:MultiAssemblyMode

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Aug 16, 2022 •

Copy link
Copy Markdown
Member

Fixes #17364
Fixes #23393
Fixes dotnet/runtime#65260
Contributes to #18165

Support multiple assemblies in package and task

This change updates the ApiCompatibility and the PackageValidation
backend to allow comparing assembly sets with each other instead of only
single assemblies.

This enables api compatibility checks on packages
that contain more than a single assembly and also unblocks packages that
are named differently than the underlying assembly.

Update tests because of the multi assembly mode

Tests need to be updated as the CompatDifference type now stores the
metadata information of the left and right that triggered the
difference.

Also updating the styling to follow the arrance-act-assert pattern that
makes reading these tests easier.

This change updates the ApiCompatibility and the PackageValidation
backend to allow comparing assembly sets with each other instead of only
single assemblies.

This enables api compatibility checks on packages
that contain more than a single assembly and also unblocks packages that
are named differently than the underlying assembly.
Tests need to be updated as the CompatDifference type now stores the
metadata information of the left and right that triggered the
difference.

Also updating the styling to follow the arrance-act-assert pattern that
makes reading these tests easier.
@ViktorHofer
ViktorHofer requested review from a team, ericstj and joperezr as code owners August 16, 2022 17:06
@ghost

ghost commented Aug 16, 2022

Copy link
Copy Markdown

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ViktorHofer ViktorHofer changed the title Multi assembly mode Support multiple assemblies in package and task Aug 16, 2022
@ViktorHofer ViktorHofer changed the title Support multiple assemblies in package and task Support multiple unique assembly ids in packages and tasks Aug 16, 2022
Comment on lines +30 to +34
if (symbol is IAssemblySymbol assembly)
{
// When mapping assemblies, we must ignore the version, culture and token.
return assembly.Identity.Name;
}

@ViktorHofer ViktorHofer Aug 16, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very interesting change. Before, an assembly with the same identity but different version, culture or public key didn't not map together when resolved from an assembly set. As an example, System.Runtime/6.0.0.0 didn't map with System.Runtime/7.0.0.0.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where this is used, but maybe you can test these scenarios to make sure we catch them?

  1. Error when changing public key.
  2. Error when version is lower on right than left.
  3. Ensure we compare newer versions of the same assembly and find compatibility problems in them.
  4. Either error when changing culture, or support mapping multiple assemblies with different cultures. I'm not sure there's a scenario for API compat on culture-specific assemblies since they typically have no code in them just embedded resources.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, what you describe is already being validated by the AssemblyIdentityMustMatch rule here:

if (left == null && right != null)
{
differences.Add(new CompatDifference(
leftMetadata,
rightMetadata,
DiagnosticIds.MatchingAssemblyDoesNotExist,
string.Format(Resources.AssemblyNameDoesNotExist, leftMetadata, right.Identity.Name),
DifferenceType.Removed,
right.Identity.GetDisplayName()));
return;
}
if (left != null && right == null)
{
differences.Add(new CompatDifference(
leftMetadata,
rightMetadata,
DiagnosticIds.MatchingAssemblyDoesNotExist,
string.Format(Resources.AssemblyNameDoesNotExist, rightMetadata, left.Identity.Name),
DifferenceType.Added,
left.Identity.GetDisplayName()));
return;
}
// At this point, left and right are both not null.
AssemblyIdentity leftIdentity = left!.Identity;
AssemblyIdentity rightIdentity = right!.Identity;
string leftAssemblyName = leftIdentity.Name;
string leftAssemblyCulture = string.IsNullOrEmpty(leftIdentity.CultureName) ? "neutral" : leftIdentity.CultureName;
Version leftAssemblyVersion = leftIdentity.Version;
ReadOnlySpan<byte> leftAssemblyPublicKeyToken = leftIdentity.PublicKeyToken.AsSpan();
string rightAssemblyName = rightIdentity.Name;
string rightAssemblyCulture = string.IsNullOrEmpty(rightIdentity.CultureName) ? "neutral" : rightIdentity.CultureName;
Version rightAssemblyVersion = rightIdentity.Version;
ReadOnlySpan<byte> rightAssemblyPublicKeyToken = rightIdentity.PublicKeyToken.AsSpan();
if (leftAssemblyName != rightAssemblyName)
{
differences.Add(CreateIdentityDifference(
leftMetadata,
rightMetadata,
Resources.AssemblyNameDoesNotMatch,
leftAssemblyName,
rightAssemblyName,
leftMetadata.DisplayString,
rightMetadata.DisplayString,
rightIdentity));
}
if (leftAssemblyCulture != rightAssemblyCulture)
{
differences.Add(CreateIdentityDifference(
leftMetadata,
rightMetadata,
Resources.AssembyCultureDoesNotMatch,
leftAssemblyCulture,
rightAssemblyCulture,
leftMetadata.DisplayString,
rightMetadata.DisplayString,
rightIdentity));
}
if (rightAssemblyVersion < leftAssemblyVersion)
{
differences.Add(CreateIdentityDifference(
leftMetadata,
rightMetadata,
Resources.AssembyVersionIsNotCompatible,
rightAssemblyVersion.ToString(),
leftAssemblyVersion.ToString(),
rightMetadata.DisplayString,
leftMetadata.DisplayString,
rightIdentity));
}
else if (_settings.StrictMode && leftAssemblyVersion < rightAssemblyVersion)
{
differences.Add(CreateIdentityDifference(
leftMetadata,
rightMetadata,
Resources.AssembyVersionDoesNotMatch,
leftAssemblyVersion.ToString(),
rightAssemblyVersion.ToString(),
leftMetadata.DisplayString,
rightMetadata.DisplayString,
leftIdentity));
}
if (!leftAssemblyPublicKeyToken.IsEmpty && !leftIdentity.IsRetargetable && !leftAssemblyPublicKeyToken.SequenceEqual(rightAssemblyPublicKeyToken))
{
differences.Add(CreateIdentityDifference(
leftMetadata,
rightMetadata,
Resources.AssemblyPublicKeyTokenDoesNotMatch,
GetStringRepresentation(leftAssemblyPublicKeyToken),
GetStringRepresentation(rightAssemblyPublicKeyToken),
leftMetadata.DisplayString,
rightMetadata.DisplayString,
rightIdentity));
}
else if (_settings.StrictMode && !rightAssemblyPublicKeyToken.IsEmpty && !rightIdentity.IsRetargetable && !rightAssemblyPublicKeyToken.SequenceEqual(leftAssemblyPublicKeyToken))
{
differences.Add(CreateIdentityDifference(
leftMetadata,
rightMetadata,
Resources.AssemblyPublicKeyTokenDoesNotMatch,
GetStringRepresentation(rightAssemblyPublicKeyToken),
GetStringRepresentation(leftAssemblyPublicKeyToken),
rightMetadata.DisplayString,
leftMetadata.DisplayString,
leftIdentity));
}
.

This specific change here affects the mapping of assemblies (before the rule is even invoked) and resulted in assemblies with different full qualified names (i.e. the version) not being mapped together.

@ViktorHofer

Copy link
Copy Markdown
Member Author

@dotnet/dnceng can you please take a look at the following AzDO failures? Are those related to the known outage?

Chunk '6' attempt '2' of file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip' fail to send request to server. Error: Microsoft.VisualStudio.Services.WebApi.VssServiceResponseException: Bad Request
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.HandleResponseAsync(HttpResponseMessage response, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.SendAsync(HttpRequestMessage message, HttpCompletionOption completionOption, Object userState, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.FileContainer.Client.FileContainerHttpClient.UploadFileAsync(Int64 containerId, String itemPath, Stream fileStream, Byte[] contentId, Int64 fileLength, Boolean isGzipped, Guid scopeIdentifier, CancellationToken cancellationToken, Int32 chunkSize, Int32 chunkRetryTimes, Boolean uploadFirstChunk, Object userState).
Backoff 7.5 seconds before attempt '3' chunk '6' of file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip'.
Attempt '3' for uploading chunk '6' of file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip'.
Generate new HttpRequest for uploading file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip', chunk '6' of '24'.
Start uploading file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip' to server, chunk '6'.
Async Command End: Upload Artifact
##[error]File upload failed even after retry.

@MattGal

MattGal commented Aug 16, 2022

Copy link
Copy Markdown
Member

@dotnet/dnceng can you please take a look at the following AzDO failures? Are those related to the known outage?

Chunk '6' attempt '2' of file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip' fail to send request to server. Error: Microsoft.VisualStudio.Services.WebApi.VssServiceResponseException: Bad Request
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.HandleResponseAsync(HttpResponseMessage response, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.SendAsync(HttpRequestMessage message, HttpCompletionOption completionOption, Object userState, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.FileContainer.Client.FileContainerHttpClient.UploadFileAsync(Int64 containerId, String itemPath, Stream fileStream, Byte[] contentId, Int64 fileLength, Boolean isGzipped, Guid scopeIdentifier, CancellationToken cancellationToken, Int32 chunkSize, Int32 chunkRetryTimes, Boolean uploadFirstChunk, Object userState).
Backoff 7.5 seconds before attempt '3' chunk '6' of file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip'.
Attempt '3' for uploading chunk '6' of file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip'.
Generate new HttpRequest for uploading file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip', chunk '6' of '24'.
Start uploading file 'BlobArtifacts/dotnet-toolset-internal-7.0.100-ci.zip' to server, chunk '6'.
Async Command End: Upload Artifact
##[error]File upload failed even after retry.

This one happens semi-regularly, and it's always the same root cause; the same build artifact being uploaded by different agents at the same time. Somewhere you have name duplication and it's causing a collision, surfaced by these strange storage API loggings.

@ViktorHofer

Copy link
Copy Markdown
Member Author

/azp run dotnet-sdk-public-ci

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@smasher164 smasher164 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmitche
mmitche merged commit b413c0c into dotnet:main Aug 17, 2022
@ViktorHofer
ViktorHofer deleted the MultiAssemblyMode branch August 17, 2022 19:00
ViktorHofer added a commit to ViktorHofer/sdk that referenced this pull request Sep 12, 2022
)

* Support multiple assemblies in package and task

This change updates the ApiCompatibility and the PackageValidation
backend to allow comparing assembly sets with each other instead of only
single assemblies.

This enables api compatibility checks on packages
that contain more than a single assembly and also unblocks packages that
are named differently than the underlying assembly.

* Update tests because of the multi assembly mode

Tests need to be updated as the CompatDifference type now stores the
metadata information of the left and right that triggered the
difference.

Also updating the styling to follow the arrance-act-assert pattern that
makes reading these tests easier.

* Update AssemblyMapper.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

5 participants