-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add KeptByAttribute to validate an item was kept due to a specific de…
…pendency (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 dotnet/linker@dc5e60f
- Loading branch information
1 parent
d67748d
commit 381f14b
Showing
7 changed files
with
128 additions
and
12 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptByAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Mono.Linker.Tests.Cases.Expectations.Assertions | ||
{ | ||
[AttributeUsage (AttributeTargets.All, Inherited = false)] | ||
public class KeptByAttribute : KeptAttribute | ||
{ | ||
private KeptByAttribute () { } | ||
|
||
/// <summary> | ||
/// Place on an type member to indicate that the linker should log that the member is kept as a depenendency of <paramref name="dependencyProvider"/> with reason <paramref name="reason"/>. | ||
/// </summary> | ||
/// <param name="dependencyProvider">Cecil's FullName property of the item that provides the dependency that keeps the item</param> | ||
/// <param name="reason">The string representation of the DependencyKind that is recorded as the reason for the dependency</param> | ||
public KeptByAttribute (string dependencyProvider, string reason) { } | ||
|
||
/// <summary> | ||
/// Place on an type member to indicate that the linker should log that the member is kept as a depenendency of <paramref name="dependencyProviderType"/> with reason <paramref name="reason"/>. | ||
/// </summary> | ||
/// <param name="dependencyProviderType">The type that is providing the dependency that keeps the item</param> | ||
/// <param name="reason">The string representation of the DependencyKind that is recorded as the reason for the dependency</param> | ||
public KeptByAttribute (Type dependencyProviderType, string reason) { } | ||
|
||
/// <summary> | ||
/// Place on an type member to indicate that the linker should log that the member is kept as a depenendency of <paramref name="dependencyProviderType"/>.<paramref name="memberName"/> with reason <paramref name="reason"/>. | ||
/// </summary> | ||
/// <param name="dependencyProviderType">The declaring type of the member that is providing the dependency that keeps the item</param> | ||
/// <param name="memberName">Cecil's 'Name' property of the member that provides the dependency that keeps the item</param> | ||
/// <param name="reason">The string representation of the DependencyKind that is recorded as the reason for the dependency</param> | ||
public KeptByAttribute (Type dependencyProviderType, string memberName, string reason) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters