Split Mono files provider into "Js" and "Bcl" parts, as they are used for different things
This commit is contained in:
parent
4b247e8050
commit
667f2cc007
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Blazor.Mono;
|
||||
using Microsoft.Blazor.Server.ClientFilesystem;
|
||||
using Mono.Cecil;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
|
@ -19,7 +20,7 @@ namespace Microsoft.Blazor.Server.Test
|
|||
var provider = new ReferencedAssemblyFileProvider(
|
||||
entrypoint,
|
||||
entrypointData,
|
||||
MonoStaticFileProvider.Instance);
|
||||
MonoStaticFileProvider.BclFiles);
|
||||
Assert.Collection(provider.GetDirectoryContents("/"), item =>
|
||||
{
|
||||
Assert.Equal("/bin", item.PhysicalPath);
|
||||
|
|
@ -34,7 +35,7 @@ namespace Microsoft.Blazor.Server.Test
|
|||
var provider = new ReferencedAssemblyFileProvider(
|
||||
entrypoint,
|
||||
entrypointData,
|
||||
MonoStaticFileProvider.Instance);
|
||||
MonoStaticFileProvider.BclFiles);
|
||||
var contents = provider.GetDirectoryContents("/bin").OrderBy(i => i.Name).ToList();
|
||||
Assert.Collection(contents,
|
||||
item => { Assert.Equal("/bin/mscorlib.dll", item.PhysicalPath); },
|
||||
|
|
@ -51,7 +52,7 @@ namespace Microsoft.Blazor.Server.Test
|
|||
var provider = new ReferencedAssemblyFileProvider(
|
||||
AssemblyDefinition.ReadAssembly(standaloneAppAssemblyLocation),
|
||||
File.ReadAllBytes(standaloneAppAssemblyLocation),
|
||||
MonoStaticFileProvider.Instance);
|
||||
MonoStaticFileProvider.BclFiles);
|
||||
var expectedContents = new[]
|
||||
{
|
||||
/*
|
||||
|
|
@ -104,7 +105,7 @@ namespace Microsoft.Blazor.Server.Test
|
|||
{
|
||||
var possibleFilenames = new[] { $"/bcl/{name}.dll", $"/bcl/Facades/{name}.dll" };
|
||||
var fileInfo = possibleFilenames
|
||||
.Select(MonoStaticFileProvider.Instance.GetFileInfo)
|
||||
.Select(MonoStaticFileProvider.BclFiles.GetFileInfo)
|
||||
.First(item => item.Exists);
|
||||
using (var data = new MemoryStream())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,9 +12,17 @@
|
|||
|
||||
<Target Name="EmbedMonoResources" BeforeTargets="PreBuildEvent" DependsOnTargets="OptimizeMono">
|
||||
<ItemGroup>
|
||||
<MonoResourcesToEmbed Include="$(MonoOptimizedDir)**" />
|
||||
<EmbeddedResource Include="@(MonoResourcesToEmbed)">
|
||||
<LogicalName>mono.$([System.String]::Copy('/%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '/'))</LogicalName>
|
||||
<MonoWasmResourcesToEmbed Include="$(MonoOptimizedDir)wasm/**" />
|
||||
<MonoAsmJsResourcesToEmbed Include="$(MonoOptimizedDir)asmjs/**" />
|
||||
<MonoBclResourcesToEmbed Include="$(MonoOptimizedDir)bcl/**" />
|
||||
<EmbeddedResource Include="@(MonoWasmResourcesToEmbed)">
|
||||
<LogicalName>mono.js./wasm$([System.String]::Copy('/%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '/'))</LogicalName>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="@(MonoAsmJsResourcesToEmbed)">
|
||||
<LogicalName>mono.js./asmjs$([System.String]::Copy('/%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '/'))</LogicalName>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="@(MonoBclResourcesToEmbed)">
|
||||
<LogicalName>mono.bcl./bcl$([System.String]::Copy('/%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '/'))</LogicalName>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@ namespace Microsoft.Blazor.Mono
|
|||
{
|
||||
public static class MonoStaticFileProvider
|
||||
{
|
||||
public readonly static IFileProvider Instance = new EmbeddedResourceFileProvider(
|
||||
typeof(MonoStaticFileProvider).Assembly, "mono.");
|
||||
public readonly static IFileProvider JsFiles = new EmbeddedResourceFileProvider(
|
||||
typeof(MonoStaticFileProvider).Assembly, "mono.js.");
|
||||
|
||||
public readonly static IFileProvider BclFiles = new EmbeddedResourceFileProvider(
|
||||
typeof(MonoStaticFileProvider).Assembly, "mono.bcl.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,17 @@ using Microsoft.Blazor.Internal.Common.FileProviders;
|
|||
using System.Reflection;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Blazor.Server
|
||||
namespace Microsoft.Blazor.Server.ClientFilesystem
|
||||
{
|
||||
internal class ReferencedAssemblyFileProvider : InMemoryFileProvider
|
||||
{
|
||||
public ReferencedAssemblyFileProvider(Assembly assembly, IFileProvider clientBcl) : this(
|
||||
AssemblyDefinition.ReadAssembly(assembly.Location),
|
||||
File.ReadAllBytes(assembly.Location),
|
||||
clientBcl)
|
||||
{
|
||||
}
|
||||
|
||||
public ReferencedAssemblyFileProvider(
|
||||
AssemblyDefinition entrypoint,
|
||||
byte[] entrypointData,
|
||||
|
|
@ -8,48 +8,40 @@ namespace Microsoft.Blazor.Mono.Test
|
|||
public class MonoStaticFileProviderTest
|
||||
{
|
||||
[Fact]
|
||||
public void SuppliesMonoFiles()
|
||||
public void SuppliesJsFiles()
|
||||
{
|
||||
// This is not an exhaustive list. The set of BCL facade types is long and
|
||||
// will probably change. This test is just to verify the resource embedding
|
||||
// and filename mapping is working correctly.
|
||||
var expectedFiles = new[]
|
||||
{
|
||||
"/asmjs/mono.asm.js",
|
||||
"/asmjs/mono.js.mem",
|
||||
"/wasm/mono.wasm",
|
||||
"/bcl/mscorlib.dll",
|
||||
"/bcl/Facades/System.Collections.dll",
|
||||
};
|
||||
// The collection is small enough that we can assert the exact full list
|
||||
|
||||
foreach (var name in expectedFiles)
|
||||
{
|
||||
var fileInfo = MonoStaticFileProvider.Instance.GetFileInfo(name);
|
||||
Assert.True(fileInfo.Exists);
|
||||
Assert.False(fileInfo.IsDirectory);
|
||||
Assert.True(fileInfo.Length > 0);
|
||||
}
|
||||
Assert.Collection(MonoStaticFileProvider.JsFiles.GetDirectoryContents("/"),
|
||||
item => Assert.Equal("/asmjs", item.PhysicalPath),
|
||||
item => Assert.Equal("/wasm", item.PhysicalPath));
|
||||
|
||||
Assert.Collection(MonoStaticFileProvider.JsFiles.GetDirectoryContents("/asmjs"),
|
||||
item => Assert.Equal("/asmjs/mono.asm.js", item.PhysicalPath),
|
||||
item => Assert.Equal("/asmjs/mono.js", item.PhysicalPath),
|
||||
item => Assert.Equal("/asmjs/mono.js.mem", item.PhysicalPath));
|
||||
|
||||
Assert.Collection(MonoStaticFileProvider.JsFiles.GetDirectoryContents("/wasm"),
|
||||
item => Assert.Equal("/wasm/mono.js", item.PhysicalPath),
|
||||
item => Assert.Equal("/wasm/mono.wasm", item.PhysicalPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DoesNotSupplyUnexpectedFiles()
|
||||
public void SuppliesBclFiles()
|
||||
{
|
||||
var notExpectedFiles = new[]
|
||||
{
|
||||
"",
|
||||
"mono",
|
||||
"wasm",
|
||||
"/wasm",
|
||||
"/wasm/",
|
||||
"wasm/mono.wasm",
|
||||
"/wasm/../wasm/mono.wasm",
|
||||
};
|
||||
Assert.Collection(MonoStaticFileProvider.BclFiles.GetDirectoryContents("/"),
|
||||
item => Assert.Equal("/bin", item.PhysicalPath));
|
||||
|
||||
foreach (var name in notExpectedFiles)
|
||||
{
|
||||
var fileInfo = MonoStaticFileProvider.Instance.GetFileInfo(name);
|
||||
Assert.False(fileInfo.Exists);
|
||||
}
|
||||
Assert.Collection(MonoStaticFileProvider.BclFiles.GetDirectoryContents("/bin"),
|
||||
item => Assert.Equal("/bin/mscorlib.dll", item.PhysicalPath),
|
||||
item => Assert.Equal("/bin/System.Core.dll", item.PhysicalPath),
|
||||
item => Assert.Equal("/bin/System.dll", item.PhysicalPath),
|
||||
item => Assert.Equal("/bin/Facades", item.PhysicalPath));
|
||||
|
||||
// Not an exhaustive list. The full list is long.
|
||||
var actualFacades = MonoStaticFileProvider.BclFiles.GetDirectoryContents("/bin/Facades");
|
||||
Assert.Contains(actualFacades, item => item.PhysicalPath == "/bin/Facades/netstandard.dll");
|
||||
Assert.Contains(actualFacades, item => item.PhysicalPath == "/bin/Facades/System.Console.dll");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue