Add KeptByAttribute to validate an item was kept due to a specific dependency (dotnet...
authorJackson Schuster <36744439+jtschuster@users.noreply.github.com>
Mon, 7 Nov 2022 22:47:42 +0000 (16:47 -0600)
committerGitHub <noreply@github.com>
Mon, 7 Nov 2022 22:47:42 +0000 (22:47 +0000)
commit381f14bcc9be5e321732d2fef8af114a374230ca
treeda0c8bb68d4959b566231d9aa0ced09886ed1bde
parentd67748d7a38d41d987320e7ca25d1f3638edde80
Add KeptByAttribute to validate an item was kept due to a specific dependency (dotnet/linker#3096)

The tests we have in the linker try to ensure that something can only be kept for a certain reason, but it can be hard to ensure it's not being kept for another reason. For example, sometimes we use typeof(TestType) to mark a type, but that also makes it relevant to variant casting, which can cause parts of TestType to be kept for unintended reasons.

This PR creates the KeptByAttribute which accepts a fully qualified string in Cecil format to indicate depenency provider (the thing that is creating the dependency that marks the item with the attribute), as well as a string representing the DependencyKind to specify the "reason" there was a dependency between the two. It also can accept a System.Type, or a System.Type + name of the member to indicate the dependency provider.

Commit migrated from https://github.com/dotnet/linker/commit/dc5e60f5f2becf0b462d37ad918443126e80b49b
src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptByAttribute.cs [new file with mode: 0644]
src/tools/illink/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/VirtualMethodGetsPreservedIfBaseMethodGetsInvoked.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/VirtualMethodGetsStrippedIfImplementingMethodGetsInvokedDirectly.cs
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestDependencyRecorder.cs