Skip to content
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

[pack] [EMG] fixing infinite loop issue with typeforwarders #8772

Merged
merged 4 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mono.Cecil" Version="0.11.1" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static bool IsWebJobsStartupAttributeType(TypeReference attributeType, Co

public static IEnumerable<ExtensionReference> GenerateExtensionReferences(string fileName, ConsoleLogger logger)
{
BaseAssemblyResolver resolver = new DefaultAssemblyResolver();
var resolver = new FunctionsAssemblyResolver();
brettsam marked this conversation as resolved.
Show resolved Hide resolved
resolver.AddSearchDirectory(Path.GetDirectoryName(fileName));

ReaderParameters readerParams = new ReaderParameters { AssemblyResolver = resolver };
Expand Down Expand Up @@ -183,5 +183,38 @@ public static string GetReflectionFullName(TypeReference typeRef)
{
return typeRef.FullName.Replace("/", "+");
}

public class FunctionsAssemblyResolver : DefaultAssemblyResolver
{
private static readonly HashSet<string> _trustedPlatformAssemblies = GetTrustedPlatformAssemblies();

private static HashSet<string> GetTrustedPlatformAssemblies()
{
var data = AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES");
var tpaArr = data.ToString().Split(Path.PathSeparator);
var tpaHash = new HashSet<string>(tpaArr.Length, StringComparer.OrdinalIgnoreCase);

foreach (var tpa in tpaArr)
{
tpaHash.Add(tpa);
}

return tpaHash;
}

public override AssemblyDefinition Resolve(AssemblyNameReference name)
{
var assemblyDef = base.Resolve(name);

// As soon as we get to a TPA we can stop. This helps prevent the odd circular reference
// with type forwarders as well.
if (_trustedPlatformAssemblies.Contains(assemblyDef.MainModule.FileName))
brettsam marked this conversation as resolved.
Show resolved Hide resolved
{
return null;
}

return assemblyDef;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" InitialTargets="UpdateRuntimeAssemblies">
<Import Project="..\..\build\metadatagenerator.props" />
<PropertyGroup>
<Version>4.0.1</Version>
<Version>4.0.2</Version>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
<AssemblyName>Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator</AssemblyName>
Expand All @@ -21,8 +21,8 @@

<Target Name="BuildGeneratorConsole" Condition="'$(TargetFramework)' == 'netstandard2.0'" AfterTargets="Build">
<MSBuild Projects="@(ConsoleProject)" Targets="Restore;Build" Properties="Configuration=$(Configuration);Platform=$(Platform);TargetFramework=netcoreapp2.0;OutputPath=$(MSBuildProjectDirectory)\$(OutputPath)\generator" />
</Target>
</Target>

<ItemGroup>
<Content Include="Targets\**\*">
<Pack>true</Pack>
Expand All @@ -34,7 +34,7 @@
<Exec Command="pwsh ./updateruntimeassemblies.ps1" Condition=" '$(OS)' == 'Unix' "/>
<Exec Command="powershell.exe –command .\updateruntimeassemblies.ps1" Condition=" '$(OS)' == 'Windows_NT' "/>
</Target>

<Target Name="PackReferenceAssemblies">
<ItemGroup>
<Content Include="$(OutputPath)\netstandard2.0\generator\*">
Expand Down Expand Up @@ -69,7 +69,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Runtime.Loader">
<Version>4.3.0</Version>
Expand Down