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.
|
// 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.Mono;
|
||||||
|
using Microsoft.Blazor.Server.ClientFilesystem;
|
||||||
using Mono.Cecil;
|
using Mono.Cecil;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
@ -19,7 +20,7 @@ namespace Microsoft.Blazor.Server.Test
|
||||||
var provider = new ReferencedAssemblyFileProvider(
|
var provider = new ReferencedAssemblyFileProvider(
|
||||||
entrypoint,
|
entrypoint,
|
||||||
entrypointData,
|
entrypointData,
|
||||||
MonoStaticFileProvider.Instance);
|
MonoStaticFileProvider.BclFiles);
|
||||||
Assert.Collection(provider.GetDirectoryContents("/"), item =>
|
Assert.Collection(provider.GetDirectoryContents("/"), item =>
|
||||||
{
|
{
|
||||||
Assert.Equal("/bin", item.PhysicalPath);
|
Assert.Equal("/bin", item.PhysicalPath);
|
||||||
|
|
@ -34,7 +35,7 @@ namespace Microsoft.Blazor.Server.Test
|
||||||
var provider = new ReferencedAssemblyFileProvider(
|
var provider = new ReferencedAssemblyFileProvider(
|
||||||
entrypoint,
|
entrypoint,
|
||||||
entrypointData,
|
entrypointData,
|
||||||
MonoStaticFileProvider.Instance);
|
MonoStaticFileProvider.BclFiles);
|
||||||
var contents = provider.GetDirectoryContents("/bin").OrderBy(i => i.Name).ToList();
|
var contents = provider.GetDirectoryContents("/bin").OrderBy(i => i.Name).ToList();
|
||||||
Assert.Collection(contents,
|
Assert.Collection(contents,
|
||||||
item => { Assert.Equal("/bin/mscorlib.dll", item.PhysicalPath); },
|
item => { Assert.Equal("/bin/mscorlib.dll", item.PhysicalPath); },
|
||||||
|
|
@ -51,7 +52,7 @@ namespace Microsoft.Blazor.Server.Test
|
||||||
var provider = new ReferencedAssemblyFileProvider(
|
var provider = new ReferencedAssemblyFileProvider(
|
||||||
AssemblyDefinition.ReadAssembly(standaloneAppAssemblyLocation),
|
AssemblyDefinition.ReadAssembly(standaloneAppAssemblyLocation),
|
||||||
File.ReadAllBytes(standaloneAppAssemblyLocation),
|
File.ReadAllBytes(standaloneAppAssemblyLocation),
|
||||||
MonoStaticFileProvider.Instance);
|
MonoStaticFileProvider.BclFiles);
|
||||||
var expectedContents = new[]
|
var expectedContents = new[]
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
|
@ -104,7 +105,7 @@ namespace Microsoft.Blazor.Server.Test
|
||||||
{
|
{
|
||||||
var possibleFilenames = new[] { $"/bcl/{name}.dll", $"/bcl/Facades/{name}.dll" };
|
var possibleFilenames = new[] { $"/bcl/{name}.dll", $"/bcl/Facades/{name}.dll" };
|
||||||
var fileInfo = possibleFilenames
|
var fileInfo = possibleFilenames
|
||||||
.Select(MonoStaticFileProvider.Instance.GetFileInfo)
|
.Select(MonoStaticFileProvider.BclFiles.GetFileInfo)
|
||||||
.First(item => item.Exists);
|
.First(item => item.Exists);
|
||||||
using (var data = new MemoryStream())
|
using (var data = new MemoryStream())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,17 @@
|
||||||
|
|
||||||
<Target Name="EmbedMonoResources" BeforeTargets="PreBuildEvent" DependsOnTargets="OptimizeMono">
|
<Target Name="EmbedMonoResources" BeforeTargets="PreBuildEvent" DependsOnTargets="OptimizeMono">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<MonoResourcesToEmbed Include="$(MonoOptimizedDir)**" />
|
<MonoWasmResourcesToEmbed Include="$(MonoOptimizedDir)wasm/**" />
|
||||||
<EmbeddedResource Include="@(MonoResourcesToEmbed)">
|
<MonoAsmJsResourcesToEmbed Include="$(MonoOptimizedDir)asmjs/**" />
|
||||||
<LogicalName>mono.$([System.String]::Copy('/%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '/'))</LogicalName>
|
<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>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,10 @@ namespace Microsoft.Blazor.Mono
|
||||||
{
|
{
|
||||||
public static class MonoStaticFileProvider
|
public static class MonoStaticFileProvider
|
||||||
{
|
{
|
||||||
public readonly static IFileProvider Instance = new EmbeddedResourceFileProvider(
|
public readonly static IFileProvider JsFiles = new EmbeddedResourceFileProvider(
|
||||||
typeof(MonoStaticFileProvider).Assembly, "mono.");
|
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.Reflection;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.Blazor.Server
|
namespace Microsoft.Blazor.Server.ClientFilesystem
|
||||||
{
|
{
|
||||||
internal class ReferencedAssemblyFileProvider : InMemoryFileProvider
|
internal class ReferencedAssemblyFileProvider : InMemoryFileProvider
|
||||||
{
|
{
|
||||||
|
public ReferencedAssemblyFileProvider(Assembly assembly, IFileProvider clientBcl) : this(
|
||||||
|
AssemblyDefinition.ReadAssembly(assembly.Location),
|
||||||
|
File.ReadAllBytes(assembly.Location),
|
||||||
|
clientBcl)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public ReferencedAssemblyFileProvider(
|
public ReferencedAssemblyFileProvider(
|
||||||
AssemblyDefinition entrypoint,
|
AssemblyDefinition entrypoint,
|
||||||
byte[] entrypointData,
|
byte[] entrypointData,
|
||||||
|
|
@ -8,48 +8,40 @@ namespace Microsoft.Blazor.Mono.Test
|
||||||
public class MonoStaticFileProviderTest
|
public class MonoStaticFileProviderTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SuppliesMonoFiles()
|
public void SuppliesJsFiles()
|
||||||
{
|
{
|
||||||
// This is not an exhaustive list. The set of BCL facade types is long and
|
// The collection is small enough that we can assert the exact full list
|
||||||
// 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",
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (var name in expectedFiles)
|
Assert.Collection(MonoStaticFileProvider.JsFiles.GetDirectoryContents("/"),
|
||||||
{
|
item => Assert.Equal("/asmjs", item.PhysicalPath),
|
||||||
var fileInfo = MonoStaticFileProvider.Instance.GetFileInfo(name);
|
item => Assert.Equal("/wasm", item.PhysicalPath));
|
||||||
Assert.True(fileInfo.Exists);
|
|
||||||
Assert.False(fileInfo.IsDirectory);
|
Assert.Collection(MonoStaticFileProvider.JsFiles.GetDirectoryContents("/asmjs"),
|
||||||
Assert.True(fileInfo.Length > 0);
|
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]
|
[Fact]
|
||||||
public void DoesNotSupplyUnexpectedFiles()
|
public void SuppliesBclFiles()
|
||||||
{
|
{
|
||||||
var notExpectedFiles = new[]
|
Assert.Collection(MonoStaticFileProvider.BclFiles.GetDirectoryContents("/"),
|
||||||
{
|
item => Assert.Equal("/bin", item.PhysicalPath));
|
||||||
"",
|
|
||||||
"mono",
|
|
||||||
"wasm",
|
|
||||||
"/wasm",
|
|
||||||
"/wasm/",
|
|
||||||
"wasm/mono.wasm",
|
|
||||||
"/wasm/../wasm/mono.wasm",
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (var name in notExpectedFiles)
|
Assert.Collection(MonoStaticFileProvider.BclFiles.GetDirectoryContents("/bin"),
|
||||||
{
|
item => Assert.Equal("/bin/mscorlib.dll", item.PhysicalPath),
|
||||||
var fileInfo = MonoStaticFileProvider.Instance.GetFileInfo(name);
|
item => Assert.Equal("/bin/System.Core.dll", item.PhysicalPath),
|
||||||
Assert.False(fileInfo.Exists);
|
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