-
Notifications
You must be signed in to change notification settings - Fork 295
Make AOT-incompatible code paths a no-op at runtime in MTP/Native AOT mode #8688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Evangelink
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
Evangelink:dev/amauryleve/aot-friendliness-mtp-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4f54c3c
Make AOT-incompatible code paths a no-op at runtime in MTP/Native AOT…
6b53b02
Address review: clarify wording — dynamic code generation, not "Nativ…
51a44a9
Fix CS1574: `RuntimeFeature.IsDynamicCodeSupported` cref unresolved o…
faba143
Address review: update stale 'source gen mode' comments
11debde
Merge branch 'main' into dev/amauryleve/aot-friendliness-mtp-mode
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/Adapter/MSTestAdapter.PlatformServices/Helpers/AssemblyFileLocator.cs
This file contains hidden or 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,71 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Helpers; | ||
|
|
||
| /// <summary> | ||
| /// Centralizes access to <see cref="Assembly.Location"/> so that single-file / Native AOT | ||
| /// scenarios (where <c>Assembly.Location</c> returns an empty string) are handled once instead | ||
| /// of being scattered across many call sites with individual <c>IL3000</c> suppressions. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// All members tolerate <see cref="Assembly.Location"/> returning an empty string — that is the | ||
| /// documented behavior for assemblies embedded in single-file or Native AOT executables. | ||
| /// Callers receive <see langword="null"/> (for try-style getters) or fall back to | ||
| /// <see cref="AppContext.BaseDirectory"/> / the assembly simple name when appropriate. | ||
| /// </remarks> | ||
| internal static class AssemblyFileLocator | ||
| { | ||
| /// <summary> | ||
| /// Returns the file path of the given assembly, or <see langword="null"/> when the | ||
| /// assembly is embedded in a single-file or Native AOT executable (and therefore has no | ||
| /// on-disk location). | ||
| /// </summary> | ||
| [UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file", Justification = "Empty return is the documented contract; callers are expected to handle null.")] | ||
| public static string? TryGetLocation(Assembly assembly) | ||
| { | ||
| string location = assembly.Location; | ||
| return string.IsNullOrEmpty(location) ? null : location; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the directory containing the given assembly, falling back to | ||
| /// <see cref="AppContext.BaseDirectory"/> when <see cref="Assembly.Location"/> is empty | ||
| /// (single-file / Native AOT). | ||
| /// </summary> | ||
| [UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file", Justification = "Falls back to AppContext.BaseDirectory when Assembly.Location is empty (single-file/Native AOT case).")] | ||
| public static string GetDirectoryOrAppContextBase(Assembly assembly) | ||
| { | ||
| string location = assembly.Location; | ||
| if (!string.IsNullOrEmpty(location)) | ||
| { | ||
| string? directory = Path.GetDirectoryName(location); | ||
| if (!string.IsNullOrEmpty(directory)) | ||
| { | ||
| return directory; | ||
| } | ||
| } | ||
|
|
||
| return AppContext.BaseDirectory; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the file name (with extension) of the given assembly, falling back to the | ||
| /// assembly simple name with a <c>.dll</c> suffix when <see cref="Assembly.Location"/> | ||
| /// is empty (single-file / Native AOT). | ||
| /// </summary> | ||
| [UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file", Justification = "Falls back to assembly simple name when Assembly.Location is empty (single-file/Native AOT case).")] | ||
| public static string GetFileNameOrSimpleName(Assembly assembly) | ||
| { | ||
| string location = assembly.Location; | ||
| if (!string.IsNullOrEmpty(location)) | ||
| { | ||
| return Path.GetFileName(location); | ||
| } | ||
|
|
||
| string? simpleName = assembly.GetName().Name; | ||
| return string.IsNullOrEmpty(simpleName) | ||
| ? string.Empty | ||
| : simpleName + ".dll"; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.