Skip to content

Commit 533d70c

Browse files
authored
Remove unnecessary suppressions in APICompat files (#87094)
* Remove unnecessary suppressions in APICompat files - Remove unnecessary suppressions in APICompat files. This is in preparation for dotnet/sdk#32964 which will validate the existing suppressions going forward. - Set the required APICompat properties for the future tooling support. * Add suppressions back for two CoreLib flavors * Fix CoreLib suppression because of API attribute difference
1 parent a9f3262 commit 533d70c

File tree

9 files changed

+30
-284
lines changed

9 files changed

+30
-284
lines changed

eng/resolveContract.targets

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<Project>
2+
23
<!--
34
##### Contract project settings #####
45
- Allows referencing contract projects for passing matching reference assemblies to tooling like ApiCompat.
@@ -62,6 +63,22 @@
6263
<_ApiCompatLibReplacementString Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib'">lib/$(NetCoreAppCurrent)/$2</_ApiCompatLibReplacementString>
6364
</PropertyGroup>
6465

66+
<PropertyGroup>
67+
<IsRuntimeAndReferenceAssembly Condition="'$(IsRuntimeAndReferenceAssembly)' == '' and
68+
'$(HasMatchingContract)' != 'true' and
69+
'$(IsPrivateAssembly)' != 'true'">true</IsRuntimeAndReferenceAssembly>
70+
</PropertyGroup>
71+
72+
<!-- Disable suppression validation for packable projects that have a corresponding reference source project.
73+
That is necessary as APICompat is invoked twice, once for the ref <-> src comparision and then again
74+
for the package validation (which doesn't include reference assemblies). As both operations don't have
75+
all the inputs available, some suppressions might only apply to one or the other and hence unnecessary
76+
suppressions can't be determined. -->
77+
<PropertyGroup Condition="'$(IsPackable)' == 'true' and '$(IsRuntimeAndReferenceAssembly)' != 'true'">
78+
<ApiCompatPreserveUnnecessarySuppressions>true</ApiCompatPreserveUnnecessarySuppressions>
79+
<ApiCompatPermitUnnecessarySuppressions>true</ApiCompatPermitUnnecessarySuppressions>
80+
</PropertyGroup>
81+
6582
<PropertyGroup Condition="'$(IsCrossTargetingBuild)' != 'true'">
6683
<!-- Disable API compat if the project doesn't have a reference assembly. -->
6784
<ApiCompatValidateAssemblies Condition="'$(HasMatchingContract)' != 'true'">false</ApiCompatValidateAssemblies>

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Com.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : not
5050

5151
[SupportedOSPlatform("windows")]
5252
[EditorBrowsable(EditorBrowsableState.Never)]
53+
[return: NotNullIfNotNull(nameof(o))]
5354
public static object? CreateWrapperOfType(object? o, Type t)
5455
{
5556
throw new NotSupportedException(SR.PlatformNotSupported_ComInterop);

src/libraries/Directory.Build.targets

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@
4747
-->
4848
<WarningsAsErrors>$(WarningsAsErrors.Replace('NU1605', ''))</WarningsAsErrors>
4949

50-
<IsRuntimeAndReferenceAssembly Condition="'$(IsRuntimeAndReferenceAssembly)' == '' and
51-
'$(IsSourceProject)' == 'true' and
52-
Exists('$(LibrariesProjectRoot)$(MSBuildProjectName)') and
53-
!Exists('$(LibrariesProjectRoot)$(MSBuildProjectName)$([System.IO.Path]::DirectorySeparatorChar)ref') and
54-
!$(MSBuildProjectName.StartsWith('System.Private'))">true</IsRuntimeAndReferenceAssembly>
55-
5650
<!-- The source of truth for these IsNETCoreApp* properties is NetCoreAppLibrary.props. -->
57-
<IsNETCoreAppSrc Condition="('$(IsSourceProject)' == 'true' or '$(IsRuntimeAndReferenceAssembly)' == 'true') and
51+
<IsNETCoreAppSrc Condition="'$(IsSourceProject)' == 'true' and
5852
$(NetCoreAppLibrary.Contains('$(AssemblyName);'))">true</IsNETCoreAppSrc>
5953
<IsNETCoreAppRef Condition="('$(IsReferenceAssemblyProject)' == 'true' or '$(IsRuntimeAndReferenceAssembly)' == 'true') and
6054
$(NetCoreAppLibrary.Contains('$(AssemblyName);')) and
@@ -82,7 +76,7 @@
8276
<!-- Libraries-specific binplacing properties -->
8377
<PropertyGroup>
8478
<BinPlaceRef Condition="'$(BinPlaceRef)' == '' and ('$(IsReferenceAssemblyProject)' == 'true' or '$(IsRuntimeAndReferenceAssembly)' == 'true')">true</BinPlaceRef>
85-
<BinPlaceRuntime Condition="'$(BinPlaceRuntime)' == '' and ('$(IsSourceProject)' == 'true' or '$(IsRuntimeAndReferenceAssembly)' == 'true')">true</BinPlaceRuntime>
79+
<BinPlaceRuntime Condition="'$(BinPlaceRuntime)' == '' and '$(IsSourceProject)' == 'true'">true</BinPlaceRuntime>
8680
<BinPlaceForTargetVertical Condition="'$(BinPlaceForTargetVertical)' == ''">true</BinPlaceForTargetVertical>
8781
</PropertyGroup>
8882

src/libraries/Microsoft.Extensions.DependencyInjection.Specification.Tests/src/CompatibilitySuppressions.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
23
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3-
<!-- StructWithPublicDefaultConstructor test re-enabled in .NET 7 that added a new parameter to the ctor. -->
4-
<Suppression>
5-
<DiagnosticId>CP0002</DiagnosticId>
6-
<Target>M:Microsoft.Extensions.DependencyInjection.Specification.ClassWithOptionalArgsCtorWithStructs.#ctor(System.DateTime,System.DateTime,System.TimeSpan,System.TimeSpan,System.DateTimeOffset,System.DateTimeOffset,System.Guid,System.Guid,Microsoft.Extensions.DependencyInjection.Specification.ClassWithOptionalArgsCtorWithStructs.CustomStruct,Microsoft.Extensions.DependencyInjection.Specification.ClassWithOptionalArgsCtorWithStructs.CustomStruct,System.Nullable{System.ConsoleColor},System.Nullable{System.ConsoleColor},System.Nullable{System.Int32},System.Nullable{System.Int32})</Target>
7-
<IsBaselineSuppression>true</IsBaselineSuppression>
8-
</Suppression>
9-
<!-- Typo fixed in the .NET 7 version of the package. -->
10-
<Suppression>
11-
<DiagnosticId>CP0002</DiagnosticId>
12-
<Target>M:Microsoft.Extensions.DependencyInjection.Specification.DependencyInjectionSpecificationTests.ExplictServiceRegisterationWithIsService</Target>
13-
<IsBaselineSuppression>true</IsBaselineSuppression>
14-
</Suppression>
154
<!-- Test renamed to TypeActivatorCreateInstanceUsesLongestAvailableConstructor. -->
165
<Suppression>
176
<DiagnosticId>CP0002</DiagnosticId>

src/libraries/System.Private.CoreLib/src/CompatibilitySuppressions.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,4 @@
1717
<DiagnosticId>CP0002</DiagnosticId>
1818
<Target>F:System.Resources.ResourceSet.Reader</Target>
1919
</Suppression>
20-
<Suppression>
21-
<DiagnosticId>CP0014</DiagnosticId>
22-
<Target>M:System.Runtime.InteropServices.Marshal.CreateWrapperOfType(System.Object,System.Type)-&gt;object?:[T:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute]</Target>
23-
</Suppression>
2420
</Suppressions>

src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : not
4646

4747
[SupportedOSPlatform("windows")]
4848
[EditorBrowsable(EditorBrowsableState.Never)]
49+
[return: NotNullIfNotNull(nameof(o))]
4950
public static object? CreateWrapperOfType(object? o, Type t)
5051
{
5152
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);

0 commit comments

Comments
 (0)