Skip to content

Commit

Permalink
Leverage the shipping, roslyn based ApiCompat in dotnet/runtime (#73263)
Browse files Browse the repository at this point in the history
* ApiCompat infra changes

* Convert baseline to suppression files

* ApiCompat.proj

* update suppressions

* sorted suppressions

* rebase and update suppressions

* enable attribute and param rules

* Enable optional rules

* WebAssemblyThreading proj

* CompatSuppression for XmlREaderWriter

* Enable optional rules correctly...

* ThreadPool UnsupportedOSPlatformAttribute

* VBCore CP0017

* Migrate all CoreLibs over

* Update ApiCompat.proj

* Add ApiCompat.proj baselines

* Update ApiCompat.proj

* Clean-up suppression files with nint/IntPtr fix

* Clean-up CoreLib suppression

* Update suppression files with latest apicompat fix

* Update suppression files

* update suppressions

* Update suppression files

* Clean-up obsolete suppression files

* Update suppression files

* update suppressions

* huge reduction in suppression file size

* update suppressions

* more suppressions removed

* update suppressions

* Update dependencies and clean-up

* Add suppression files for CoreLib and fix path

* Update CoreLib coreclr suppression file

* Update coreclr suppression files

* Suppression file fixes and Linux path fixes

* Update coreclr suppression again)

* Fix suppression file path calculation

* Fix previous mistake

* Diagnostics.Tracing suppression file

* Threading suppression file fix

* use global suppression for CryptoSignedXmlRecursionException

* Add Specification.Tests suppression

* Disable NoTargets ref copying

* Fix for coreclr build

* Avoid duplicate project evals

Co-authored-by: smasher164 <akhilindurti@microsoft.com>
Co-authored-by: Akhil Indurti <aindurti@gmail.com>
  • Loading branch information
3 people committed Oct 16, 2022
1 parent 8ed6b13 commit 960e4d7
Show file tree
Hide file tree
Showing 99 changed files with 8,421 additions and 1,575 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@

<PropertyGroup>
<CustomBeforeNoTargets>$(RepositoryEngineeringDir)NoTargetsSdk.BeforeTargets.targets</CustomBeforeNoTargets>
<CustomAfterNoTargets>$(RepositoryEngineeringDir)NoTargetsSdk.AfterTargets.targets</CustomAfterNoTargets>
<CustomAfterTraversalTargets>$(RepositoryEngineeringDir)TraversalSdk.AfterTargets.targets</CustomAfterTraversalTargets>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion docs/coding-guidelines/updating-ref-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This document provides the steps you need to take to update the reference assemb

## For most assemblies within libraries

1. Implement the API in the source assembly and [build it](../workflow/building/libraries/README.md#building-individual-libraries). Note that when adding new public types, this might fail with a `TypeMustExist` error. The deadlock can be worked around by disabling the `RunApiCompat` property: `dotnet build /p:RunApiCompat=false`.
1. Implement the API in the source assembly and [build it](../workflow/building/libraries/README.md#building-individual-libraries). Note that when adding new public types, this might fail with a `TypeMustExist` error. The deadlock can be worked around by disabling ApiCompat's assembly validation: `dotnet build /p:ApiCompatValidateAssemblies=false`.
2. Run the following command (from the src directory) `dotnet msbuild /t:GenerateReferenceAssemblySource` to update the reference assembly**.
3. Navigate to the ref directory and build the reference assembly.
4. Add, build, and run tests.
Expand Down
7 changes: 7 additions & 0 deletions eng/NoTargetsSdk.AfterTargets.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>

<!-- Reset the following target to avoid copying references to an output directory.
TODO: Remove when https://github.com/microsoft/MSBuildSdks/pull/395 is merged. -->
<Target Name="CopyFilesToOutputDirectory" />

</Project>
4 changes: 4 additions & 0 deletions eng/TraversalSdk.AfterTargets.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project>

<PropertyGroup>
<TraversalGlobalProperties>BuildAllProjects=true</TraversalGlobalProperties>
</PropertyGroup>

<!-- Uses the Microsoft.DotNet.Build.Tasks.TargetFramework package to filter out target frameworks from ProjectReferences. -->
<PropertyGroup Condition="'$(FilterTraversalProjectReferences)' == 'true'">
<BuildDependsOn>$(BuildDependsOn);ResolveP2PReferences</BuildDependsOn>
Expand Down
8 changes: 2 additions & 6 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>d2d39276af2db3da7816ee2dc543e120d7e5781e</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.ApiCompat" Version="8.0.0-beta.22503.1">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>d2d39276af2db3da7816ee2dc543e120d7e5781e</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.GenAPI" Version="8.0.0-beta.22503.1">
<Dependency Name="Microsoft.DotNet.GenAPI" Version="8.0.0-beta.22480.2">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>d2d39276af2db3da7816ee2dc543e120d7e5781e</Sha>
</Dependency>
Expand Down Expand Up @@ -322,7 +318,7 @@
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
<Sha>ea9fb45000311153bfc91690f306cca2b80e6b83</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.ApiCompat.Task" Version="8.0.100-alpha.1.22462.3">
<Dependency Name="Microsoft.DotNet.ApiCompat.Task" Version="8.0.100-alpha.1.22511.23">
<Uri>https://github.com/dotnet/sdk</Uri>
<Sha>3f2524bd65a6ab77b9160bcc23824dbc03990f3d</Sha>
</Dependency>
Expand Down
33 changes: 16 additions & 17 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,23 @@
<PropertyGroup>
<StaticCsVersion>0.2.0</StaticCsVersion>
<!-- SDK dependencies -->
<MicrosoftDotNetApiCompatTaskVersion>8.0.100-alpha.1.22462.3</MicrosoftDotNetApiCompatTaskVersion>
<MicrosoftDotNetApiCompatTaskVersion>8.0.100-alpha.1.22511.23</MicrosoftDotNetApiCompatTaskVersion>
<!-- Arcade dependencies -->
<MicrosoftDotNetApiCompatVersion>8.0.0-beta.22503.1</MicrosoftDotNetApiCompatVersion>
<MicrosoftDotNetBuildTasksFeedVersion>8.0.0-beta.22503.1</MicrosoftDotNetBuildTasksFeedVersion>
<MicrosoftDotNetCodeAnalysisVersion>8.0.0-beta.22503.1</MicrosoftDotNetCodeAnalysisVersion>
<MicrosoftDotNetGenAPIVersion>8.0.0-beta.22503.1</MicrosoftDotNetGenAPIVersion>
<MicrosoftDotNetGenFacadesVersion>8.0.0-beta.22503.1</MicrosoftDotNetGenFacadesVersion>
<MicrosoftDotNetXUnitExtensionsVersion>8.0.0-beta.22503.1</MicrosoftDotNetXUnitExtensionsVersion>
<MicrosoftDotNetXUnitConsoleRunnerVersion>2.5.1-beta.22503.1</MicrosoftDotNetXUnitConsoleRunnerVersion>
<MicrosoftDotNetBuildTasksArchivesVersion>8.0.0-beta.22503.1</MicrosoftDotNetBuildTasksArchivesVersion>
<MicrosoftDotNetBuildTasksInstallersVersion>8.0.0-beta.22503.1</MicrosoftDotNetBuildTasksInstallersVersion>
<MicrosoftDotNetBuildTasksPackagingVersion>8.0.0-beta.22503.1</MicrosoftDotNetBuildTasksPackagingVersion>
<MicrosoftDotNetBuildTasksTargetFrameworkVersion>8.0.0-beta.22503.1</MicrosoftDotNetBuildTasksTargetFrameworkVersion>
<MicrosoftDotNetBuildTasksTemplatingVersion>8.0.0-beta.22503.1</MicrosoftDotNetBuildTasksTemplatingVersion>
<MicrosoftDotNetBuildTasksWorkloadsPackageVersion>8.0.0-beta.22503.1</MicrosoftDotNetBuildTasksWorkloadsPackageVersion>
<MicrosoftDotNetRemoteExecutorVersion>8.0.0-beta.22503.1</MicrosoftDotNetRemoteExecutorVersion>
<MicrosoftDotNetVersionToolsTasksVersion>8.0.0-beta.22503.1</MicrosoftDotNetVersionToolsTasksVersion>
<MicrosoftDotNetPackageTestingVersion>8.0.0-beta.22503.1</MicrosoftDotNetPackageTestingVersion>
<MicrosoftDotNetBuildTasksFeedVersion>8.0.0-beta.22480.2</MicrosoftDotNetBuildTasksFeedVersion>
<MicrosoftDotNetCodeAnalysisVersion>8.0.0-beta.22480.2</MicrosoftDotNetCodeAnalysisVersion>
<MicrosoftDotNetGenAPIVersion>8.0.0-beta.22480.2</MicrosoftDotNetGenAPIVersion>
<MicrosoftDotNetGenFacadesVersion>8.0.0-beta.22480.2</MicrosoftDotNetGenFacadesVersion>
<MicrosoftDotNetXUnitExtensionsVersion>8.0.0-beta.22480.2</MicrosoftDotNetXUnitExtensionsVersion>
<MicrosoftDotNetXUnitConsoleRunnerVersion>2.5.1-beta.22480.2</MicrosoftDotNetXUnitConsoleRunnerVersion>
<MicrosoftDotNetBuildTasksArchivesVersion>8.0.0-beta.22480.2</MicrosoftDotNetBuildTasksArchivesVersion>
<MicrosoftDotNetBuildTasksInstallersVersion>8.0.0-beta.22480.2</MicrosoftDotNetBuildTasksInstallersVersion>
<MicrosoftDotNetBuildTasksPackagingVersion>8.0.0-beta.22480.2</MicrosoftDotNetBuildTasksPackagingVersion>
<MicrosoftDotNetBuildTasksTargetFrameworkVersion>8.0.0-beta.22480.2</MicrosoftDotNetBuildTasksTargetFrameworkVersion>
<MicrosoftDotNetBuildTasksTemplatingVersion>8.0.0-beta.22480.2</MicrosoftDotNetBuildTasksTemplatingVersion>
<MicrosoftDotNetBuildTasksWorkloadsPackageVersion>8.0.0-beta.22480.2</MicrosoftDotNetBuildTasksWorkloadsPackageVersion>
<MicrosoftDotNetRemoteExecutorVersion>8.0.0-beta.22480.2</MicrosoftDotNetRemoteExecutorVersion>
<MicrosoftDotNetVersionToolsTasksVersion>8.0.0-beta.22480.2</MicrosoftDotNetVersionToolsTasksVersion>
<MicrosoftDotNetPackageTestingVersion>8.0.0-beta.22480.2</MicrosoftDotNetPackageTestingVersion>
<!-- NuGet dependencies -->
<NuGetBuildTasksPackVersion>6.0.0-preview.1.102</NuGetBuildTasksPackVersion>
<!-- Installer dependencies -->
Expand Down
4 changes: 2 additions & 2 deletions eng/illink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<IsTrimmable Condition="'$(IsTrimmable)' == ''">true</IsTrimmable>
<PrepareResourcesDependsOn>_EmbedILLinkXmls;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
<TargetsTriggeredByCompilation Condition="'$(DesignTimeBuild)' != 'true'">$(TargetsTriggeredByCompilation);ILLinkTrimAssembly</TargetsTriggeredByCompilation>
<!-- ApiCompat should perform compatibility checks on the trimmed assemblies. -->
<ApiCompatDependsOn>$(ApiCompatDependsOn);ILLinkTrimAssembly</ApiCompatDependsOn>
<!-- ApiCompat's assembly validation should use the trimmed assemblies as an input, so we make sure that ILLink runs first. -->
<ApiCompatValidateAssembliesDependsOn Condition="'$(IsCrossTargetingBuild)' != 'true'">$(ApiCompatValidateAssembliesDependsOn);ILLinkTrimAssembly</ApiCompatValidateAssembliesDependsOn>
</PropertyGroup>

<!-- Flow the IsTrimmable property down to consuming projects, in order for oob.proj
Expand Down
7 changes: 4 additions & 3 deletions eng/resolveContract.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project>
<!-- ApiCompat setting -->
<PropertyGroup>
<RunApiCompatForSrc>$([MSBuild]::ValueOrDefault('$(IsSourceProject)', 'false'))</RunApiCompatForSrc>
<RunMatchingRefApiCompat>$([MSBuild]::ValueOrDefault('$(IsSourceProject)', 'false'))</RunMatchingRefApiCompat>
<ApiCompatEnforceOptionalRules>true</ApiCompatEnforceOptionalRules>
<ApiCompatValidateAssemblies Condition="'$(IsSourceProject)' == 'true'">true</ApiCompatValidateAssemblies>
<!-- Optional rules -->
<ApiCompatEnableRuleAttributesMustMatch>true</ApiCompatEnableRuleAttributesMustMatch>
<ApiCompatEnableRuleCannotChangeParameterName>true</ApiCompatEnableRuleCannotChangeParameterName>
</PropertyGroup>

<ItemGroup>
Expand Down
43 changes: 33 additions & 10 deletions eng/resolveContract.targets
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
<Project>
<PropertyGroup>
<!-- Use implementation referencepath if no contract dependency path is set.
This item transform is executed at the time this property is evaluated in the API Compat targets. -->
<ContractDependencyPaths Condition="'$(ContractDependencyPaths)' == ''">@(ReferencePath->'%(RelativeDir)'->Distinct())</ContractDependencyPaths>
<!-- Fall back to the targeting pack dir for NetCoreAppCurrent to avoid passing through dependencies from ref to src. -->
<ContractDependencyPaths Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)'))">$(ContractDependencyPaths);$(MicrosoftNetCoreAppRefPackRefDir)</ContractDependencyPaths>
</PropertyGroup>
<ApiCompatContractItemName>ResolvedMatchingContract</ApiCompatContractItemName>
<ApiCompatStrictMode Condition="'$(ApiCompatStrictMode)' == ''">true</ApiCompatStrictMode>
<_ApiCompatCaptureGroupPattern>.+%5C$([System.IO.Path]::DirectorySeparatorChar)(.+)%5C$([System.IO.Path]::DirectorySeparatorChar)(.+)</_ApiCompatCaptureGroupPattern>
<_ApiCompatRuntimePrefixPattern>(.+)/(net%5Cd.%5Cd)-(.+)/(.+)</_ApiCompatRuntimePrefixPattern>
<_ApiCompatLibReplacementString>lib/$1/$2</_ApiCompatLibReplacementString>
<!-- CoreLib source projects have different output paths. -->
<_ApiCompatLibReplacementString Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib'">lib/$(NetCoreAppCurrent)/$2</_ApiCompatLibReplacementString>

<PropertyGroup>
<GenAPIExcludeAttributesList>$(RepositoryEngineeringDir)DefaultGenApiDocIds.txt</GenAPIExcludeAttributesList>
<GenAPIHeaderFile>$(RepositoryEngineeringDir)LicenseHeader.txt</GenAPIHeaderFile>
<GenAPITargetPath>$([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '..', 'ref', '$(AssemblyName).cs'))</GenAPITargetPath>
<GenAPILangVersion Condition="'$(LangVersion)' != ''">$(LangVersion)</GenAPILangVersion>
<ProjectForGenAPIDocIdGeneration Condition="'$(IsSourceProject)' == 'true' and '$(ProjectForGenAPIDocIdGeneration)' == ''">$(CoreLibProject)</ProjectForGenAPIDocIdGeneration>
</PropertyGroup>

<ItemGroup>
<!-- Transform the API Compat assemblies passed in to log-able strings. -->
<ApiCompatLeftAssembliesTransformationPattern Include="$(_ApiCompatCaptureGroupPattern)" ReplacementString="ref/$1/$2" />
<ApiCompatLeftAssembliesTransformationPattern Include="$(_ApiCompatRuntimePrefixPattern)" ReplacementString="runtimes/$3/$1/$2/$4" />
<ApiCompatLeftAssembliesTransformationPattern Include="runtimes/windows/" ReplacementString="runtimes/win/" />

<ApiCompatRightAssembliesTransformationPattern Include="$(_ApiCompatCaptureGroupPattern)" ReplacementString="$(_ApiCompatLibReplacementString)" />
<ApiCompatRightAssembliesTransformationPattern Include="$(_ApiCompatRuntimePrefixPattern)" ReplacementString="runtimes/$3/$1/$2/$4" />
<ApiCompatRightAssembliesTransformationPattern Include="runtimes/windows/" ReplacementString="runtimes/win/" />

<!-- Fall back to the targeting pack dir for NetCoreAppCurrent to avoid passing through dependencies from ref to src. -->
<ApiCompatContractAssemblyReferences Include="$(MicrosoftNetCoreAppRefPackRefDir)"
Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)'))" />
</ItemGroup>

<PropertyGroup Condition="'$(IsSourceProject)' == 'true'">
<ContractProject Condition="'$(ContractProject)' == ''">$(LibrariesProjectRoot)$(MSBuildProjectName)\ref\$(MSBuildProjectName).csproj</ContractProject>
<HasMatchingContract Condition="'$(HasMatchingContract)' == '' and Exists('$(ContractProject)')">true</HasMatchingContract>
</PropertyGroup>

<PropertyGroup Condition="'$(IsSourceProject)' == 'true' and '$(IsCrossTargetingBuild)' != 'true'">
<!-- Disable API compat if the project doesn't have reference assembly -->
<RunApiCompat Condition="'$(HasMatchingContract)' != 'true'">false</RunApiCompat>
<ApiCompatValidateAssemblies Condition="'$(HasMatchingContract)' != 'true'">false</ApiCompatValidateAssemblies>
<!-- TODO: Move into Microsoft.DotNet.GenFacadesNotSupported.targets. -->
<!-- Not supported sources are created from the ref assembly, we currently don't produce finalizers in dummy assemblies, so we disable ApiCompat to not fail. -->
<ApiCompatValidateAssemblies Condition="'$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">false</ApiCompatValidateAssemblies>
</PropertyGroup>

<ItemGroup Condition="'$(IsSourceProject)' == 'true' or '$(IsReferenceAssemblyProject)' == 'true' or '$(IsPartialFacadeAssembly)' == 'true'">
<PackageReference Include="Microsoft.DotNet.ApiCompat" Condition="'$(DotNetBuildFromSource)' != 'true'" Version="$(MicrosoftDotNetApiCompatVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
<!-- Use the apicompat task package instead of the in-built SDK functionality to consume newer features. -->
<ItemGroup Condition="'$(EnablePackageValidation)' == 'true' or
'$(ApiCompatValidateAssemblies)' == 'true'">
<PackageReference Include="Microsoft.DotNet.ApiCompat.Task" Version="$(MicrosoftDotNetApiCompatTaskVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
</ItemGroup>

<ItemGroup Condition="'$(HasMatchingContract)' == 'true' and '$(ContractProject)' != '' and '@(ResolvedMatchingContract)' == ''">
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<Import Project="..\..\Directory.Build.targets" />

<ItemGroup>
<ItemGroup Condition="'$(UsingMicrosoftNoTargetsSdk)' != 'true'">
<_DebugSymbolToMove Include="@(DebugSymbolsProjectOutputGroupOutput->Metadata('FinalOutputPath'))"
FolderName="$([System.IO.Directory]::GetParent('%(Identity)').Name)" />
<_DebugSymbolToMoveToExclude Include="@(_DebugSymbolToMove->WithMetadataValue('FolderName', 'aotsdk'))" />
Expand Down
33 changes: 33 additions & 0 deletions src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Console</Target>
<Left>ref/net7.0/System.Private.CoreLib.dll</Left>
<Right>lib/net7.0/System.Private.CoreLib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Runtime.CompilerServices.ICastable</Target>
<Left>ref/net7.0/System.Private.CoreLib.dll</Left>
<Right>lib/net7.0/System.Private.CoreLib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:System.Resources.ResourceManager.BaseNameField</Target>
<Left>ref/net7.0/System.Private.CoreLib.dll</Left>
<Right>lib/net7.0/System.Private.CoreLib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:System.Resources.ResourceSet.Reader</Target>
<Left>ref/net7.0/System.Private.CoreLib.dll</Left>
<Right>lib/net7.0/System.Private.CoreLib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0014</DiagnosticId>
<Target>M:System.Runtime.InteropServices.Marshal.CreateWrapperOfType(System.Object,System.Type)-&gt;object?:[T:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute]</Target>
<Left>ref/net7.0/System.Private.CoreLib.dll</Left>
<Right>lib/net7.0/System.Private.CoreLib.dll</Right>
</Suppression>
</Suppressions>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@
<!-- Import refererence assembly and ApiCompat logic -->
<PropertyGroup>
<IsSourceProject>true</IsSourceProject>
<ApiCompatValidateBaseline>true</ApiCompatValidateBaseline>
</PropertyGroup>
<Import Project="$(RepositoryEngineeringDir)resolveContract.props" />
<Import Project="$(RepositoryEngineeringDir)resolveContract.targets" />
Expand Down
Loading

0 comments on commit 960e4d7

Please sign in to comment.