Skip to content

Commit

Permalink
Allow Fable to skip some DLL when scanning for plugins
Browse files Browse the repository at this point in the history
See #3511 for more info
  • Loading branch information
Maxime Mangel committed Aug 22, 2023
1 parent 25344a2 commit 7c7c732
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
27 changes: 24 additions & 3 deletions src/Fable.Transforms/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Assemblies(getPlugin, fsharpAssemblies: FSharpAssembly list) =

let plugins =
let plugins = Dictionary<Fable.EntityRef, System.Type>()
let mutable hasSkippedAssembly = false

for asm in fsharpAssemblies do
match asm.FileName with
| Some path ->
Expand All @@ -28,8 +30,23 @@ type Assemblies(getPlugin, fsharpAssemblies: FSharpAssembly list) =
coreAssemblies.Add(asmName, asm)
else
let scanForPlugins =
asm.Contents.Attributes |> Seq.exists (fun attr ->
attr.AttributeType.TryFullName = Some "Fable.ScanForPluginsAttribute")
try
asm.Contents.Attributes |> Seq.exists (fun attr ->
attr.AttributeType.TryFullName = Some "Fable.ScanForPluginsAttribute")
with
| _ ->
// To help identify problem, log information about the exception
// but keep the process going to mimic previous Fable behavior
// and because these exception seems harmless
let errorMessage =
$"Could not scan {path} for Fable plugins, skipping this assembly"

Console.ForegroundColor <- ConsoleColor.Gray
Console.Error.WriteLine(errorMessage)
Console.ResetColor()
hasSkippedAssembly <- true
false

if scanForPlugins then
for e in asm.Contents.Entities do
if e.IsAttributeType && FSharp2Fable.Util.inherits e "Fable.PluginAttribute" then
Expand All @@ -42,7 +59,7 @@ type Assemblies(getPlugin, fsharpAssemblies: FSharpAssembly list) =
$"Error while loading plugin: {e.FullName}"
""
"This error often happens if you are trying to use a plugin that is not compatible with the current version of Fable."
""

"If you see this error please open an issue at https://github.com/fable-compiler/Fable/"
"so we can check if we can improve the plugin detection mechanism."
]
Expand All @@ -60,6 +77,10 @@ type Assemblies(getPlugin, fsharpAssemblies: FSharpAssembly list) =
assemblies.Add(path, asm)
| None -> ()

// Add a blank line to separate the error message from the rest of the output
if hasSkippedAssembly then
Console.WriteLine()

({ MemberDeclarationPlugins = Map.empty }, plugins)
||> Seq.fold (fun acc kv ->
if kv.Value.IsSubclassOf(typeof<MemberDeclarationPluginAttribute>) then
Expand Down
8 changes: 3 additions & 5 deletions tests/Python/Fable.Tests.Python.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="XUnit" Version="2.4.2" />
<PackageReference Include="XUnit" Version="2.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FSharp.UMX" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Fable.Core/Fable.Core.fsproj" />
<ProjectReference Include="../../tests_external/Fable.Tests.External.fsproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.UMX" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="../Js/Main/Globs/*.fs" />
<Compile Include="Util.fs" />
Expand Down

0 comments on commit 7c7c732

Please sign in to comment.