Skip to content

Commit 2df5115

Browse files
authored
Fix generation of SourceKey path in RDG (#48017)
* Reproduce bug in CI * Change how SourceKey path is derived * Remove RequiresDynamicCode attribute on MapIdentityApi
1 parent 2860263 commit 2df5115

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

eng/TrimmableProjects.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<TrimmableProject Include="Microsoft.AspNetCore.Routing" />
3333
<TrimmableProject Include="Microsoft.AspNetCore.WebUtilities" />
3434
<TrimmableProject Include="Microsoft.AspNetCore.Html.Abstractions" />
35+
<TrimmableProject Include="Microsoft.AspNetCore.Identity" />
3536
<TrimmableProject Include="Microsoft.Extensions.Identity.Core" />
3637
<TrimmableProject Include="Microsoft.Extensions.Identity.Stores" />
3738
<TrimmableProject Include="Microsoft.AspNetCore.Connections.Abstractions" />

src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<Compile Include="$(SharedSourceRoot)RoslynUtils\WellKnownTypeData.cs" LinkBase="Shared" />
2828
<Compile Include="$(SharedSourceRoot)RoslynUtils\WellKnownTypes.cs" LinkBase="Shared" />
2929
<Compile Include="$(SharedSourceRoot)RoslynUtils\SymbolExtensions.cs" LinkBase="Shared" />
30+
<Compile Include="$(SharedSourceRoot)RoslynUtils\SyntaxTreeExtensions.cs" LinkBase="Shared" />
3031
<Compile Include="$(SharedSourceRoot)RoslynUtils\ParsabilityHelper.cs" LinkBase="Shared" />
3132
<Compile Include="$(SharedSourceRoot)RoslynUtils\CodeWriter.cs" LinkBase="Shared" />
3233
</ItemGroup>

src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ public static int GetSignatureHashCode(Endpoint endpoint)
163163

164164
private static (string, int) GetLocation(IInvocationOperation operation)
165165
{
166-
var filePath = operation.Syntax.SyntaxTree.FilePath;
167-
var span = operation.Syntax.SyntaxTree.GetLineSpan(operation.Syntax.Span);
166+
var operationSpan = operation.Syntax.Span;
167+
var filePath = operation.Syntax.SyntaxTree.GetDisplayPath(operationSpan, operation.SemanticModel?.Compilation.Options.SourceReferenceResolver);
168+
var span = operation.Syntax.SyntaxTree.GetLineSpan(operationSpan);
168169
var lineNumber = span.StartLinePosition.Line + 1;
169170
return (filePath, lineNumber);
170171
}

src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Diagnostics.CodeAnalysis;
54
using System.Linq;
65
using Microsoft.AspNetCore.Authentication.BearerToken.DTO;
76
using Microsoft.AspNetCore.Builder;
@@ -28,8 +27,6 @@ public static class IdentityApiEndpointRouteBuilderExtensions
2827
/// Call <see cref="EndpointRouteBuilderExtensions.MapGroup(IEndpointRouteBuilder, string)"/> to add a prefix to all the endpoints.
2928
/// </param>
3029
/// <returns>An <see cref="IEndpointConventionBuilder"/> to further customize the added endpoints.</returns>
31-
// TODO: Remove RequiresDynamicCode when https://github.com/dotnet/aspnetcore/issues/47918 is fixed and RDG is enabled.
32-
[RequiresDynamicCode("This API requires generated code that is not compatible with native AOT applications.")]
3330
public static IEndpointConventionBuilder MapIdentityApi<TUser>(this IEndpointRouteBuilder endpoints) where TUser : class, new()
3431
{
3532
ArgumentNullException.ThrowIfNull(endpoints);

src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<PackageTags>aspnetcore;identity;membership</PackageTags>
99
<IsPackable>false</IsPackable>
10-
<!-- TODO: Re-enable trimming once https://github.com/dotnet/aspnetcore/issues/47918 is fixed and RDG is enabled. -->
11-
<!--<IsTrimmable>true</IsTrimmable>-->
10+
<IsTrimmable>true</IsTrimmable>
11+
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
1212
</PropertyGroup>
1313

1414
<ItemGroup>
@@ -31,7 +31,6 @@
3131
</ItemGroup>
3232

3333
<ItemGroup>
34-
<!-- TODO: Re-enable RDG once https://github.com/dotnet/aspnetcore/issues/47918 is fixed. -->
35-
<!--<ProjectReference Include="$(RepoRoot)/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />-->
34+
<ProjectReference Include="$(RepoRoot)/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
3635
</ItemGroup>
3736
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.CodeAnalysis;
5+
using Microsoft.CodeAnalysis.Text;
6+
7+
internal static class SyntaxTreeExtensions
8+
{
9+
// Utilize the same logic used by the `CallerLinePathAttribute` for generating
10+
// a file path for a given syntax tree.
11+
// Source copied from https://github.com/dotnet/roslyn/blob/5b47c7fe326faa35940f220c14f718cd0b820c38/src/Compilers/Core/Portable/Syntax/SyntaxTree.cs#L274-L293 until
12+
// public APIs are available.
13+
internal static string GetDisplayPath(this SyntaxTree tree, TextSpan span, SourceReferenceResolver? resolver)
14+
{
15+
var mappedSpan = tree.GetMappedLineSpan(span);
16+
if (resolver == null || mappedSpan.Path.Length == 0)
17+
{
18+
return mappedSpan.Path;
19+
}
20+
21+
return resolver.NormalizePath(mappedSpan.Path, baseFilePath: mappedSpan.HasMappedPath ? tree.FilePath : null) ?? mappedSpan.Path;
22+
}
23+
}

0 commit comments

Comments
 (0)