Fix boot json on mac/linux (#19332)

This commit is contained in:
Steve Sanderson 2020-02-25 11:48:31 +00:00 committed by GitHub
parent 461051ec78
commit bfcf72dfdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 44 deletions

View File

@ -70,10 +70,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
{
foreach (var resource in Resources)
{
var resourceTypeMetadata = resource.GetMetadata("BootResourceType");
var resourceTypeMetadata = resource.GetMetadata("BootManifestResourceType");
if (!Enum.TryParse<ResourceType>(resourceTypeMetadata, out var resourceType))
{
throw new NotSupportedException($"Unsupported BootResourceType metadata value: {resourceTypeMetadata}");
throw new NotSupportedException($"Unsupported BootManifestResourceType metadata value: {resourceTypeMetadata}");
}
if (!result.resources.TryGetValue(resourceType, out var resourceList))
@ -82,10 +82,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
result.resources.Add(resourceType, resourceList);
}
var resourceFileRelativePath = GetResourceFileRelativePath(resource);
if (!resourceList.ContainsKey(resourceFileRelativePath))
var resourceName = GetResourceName(resource);
if (!resourceList.ContainsKey(resourceName))
{
resourceList.Add(resourceFileRelativePath, $"sha256-{resource.GetMetadata("FileHash")}");
resourceList.Add(resourceName, $"sha256-{resource.GetMetadata("FileHash")}");
}
}
}
@ -99,21 +99,16 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
serializer.WriteObject(writer, result);
}
private static string GetResourceFileRelativePath(ITaskItem item)
private static string GetResourceName(ITaskItem item)
{
// The build targets use RelativeOutputPath in the case of satellite assemblies, which
// will have relative paths like "fr\\SomeAssembly.resources.dll". If RelativeOutputPath
// is specified, we want to use all of it.
var outputPath = item.GetMetadata("RelativeOutputPath");
var name = item.GetMetadata("BootManifestResourceName");
if (string.IsNullOrEmpty(outputPath))
if (string.IsNullOrEmpty(name))
{
// If RelativeOutputPath was not specified, we assume the item will be placed at the
// root of whatever directory is used for its resource type (e.g., assemblies go in _bin)
outputPath = Path.GetFileName(item.GetMetadata("TargetOutputPath"));
throw new Exception($"No BootManifestResourceName was specified for item '{item.ItemSpec}'");
}
return outputPath.Replace('\\', '/');
return name.Replace('\\', '/');
}
#pragma warning disable IDE1006 // Naming Styles

View File

@ -83,17 +83,18 @@
<_BlazorCopyLocalPaths Remove="@(_BlazorManagedRuntimeAssemby)" />
<_BlazorOutputWithTargetPath Include="@(_BlazorCopyLocalPaths)">
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BlazorBootManifestResourceType>
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BlazorBootManifestResourceType>
<!-- This group is for satellite assemblies. We set the resource name to include a path, e.g. "fr\\SomeAssembly.resources.dll" -->
<BootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BootManifestResourceType>
<BootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BootManifestResourceType>
<BootManifestResourceName>%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</BootManifestResourceName>
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</TargetOutputPath>
<RelativeOutputPath>%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</RelativeOutputPath>
</_BlazorOutputWithTargetPath>
<_BlazorOutputWithTargetPath Include="@(_BlazorResolvedAssembly)">
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BlazorBootManifestResourceType>
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BlazorBootManifestResourceType>
<BootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BootManifestResourceType>
<BootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BootManifestResourceType>
<BootManifestResourceName>%(FileName)%(Extension)</BootManifestResourceName>
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(FileName)%(Extension)</TargetOutputPath>
<RelativeOutputPath>%(FileName)%(Extension)</RelativeOutputPath>
</_BlazorOutputWithTargetPath>
</ItemGroup>
@ -120,10 +121,10 @@
<_BlazorCopyLocalPaths Remove="@(_BlazorManagedRuntimeAssemby)" Condition="'%(Extension)' == '.dll'" />
<_BlazorOutputWithTargetPath Include="@(_BlazorCopyLocalPaths)">
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BlazorBootManifestResourceType>
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BlazorBootManifestResourceType>
<BootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BootManifestResourceType>
<BootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BootManifestResourceType>
<BootManifestResourceName>%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</BootManifestResourceName>
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</TargetOutputPath>
<RelativeOutputPath>%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</RelativeOutputPath>
</_BlazorOutputWithTargetPath>
</ItemGroup>
@ -144,13 +145,15 @@
<_DotNetWasmRuntimeFile Include="$(ComponentsWebAssemblyRuntimePath)*.wasm" />
<_BlazorOutputWithTargetPath Include="@(_DotNetWasmRuntimeFile)">
<TargetOutputPath>$(_BlazorRuntimeWasmOutputPath)%(FileName)%(Extension)</TargetOutputPath>
<BlazorBootManifestResourceType>runtime</BlazorBootManifestResourceType>
<BootManifestResourceType>runtime</BootManifestResourceType>
<BootManifestResourceName>%(FileName)%(Extension)</BootManifestResourceName>
</_BlazorOutputWithTargetPath>
<_DotNetWasmJsFile Include="$(ComponentsWebAssemblyRuntimePath)*.js" />
<_BlazorOutputWithTargetPath Include="@(_DotNetWasmJsFile)">
<TargetOutputPath>$(_BlazorRuntimeWasmOutputPath)%(FileName).$(TemporaryDotNetJsFileVersion)%(Extension)</TargetOutputPath>
<BlazorBootManifestResourceType>runtime</BlazorBootManifestResourceType>
<BootManifestResourceType>runtime</BootManifestResourceType>
<BootManifestResourceName>%(FileName).$(TemporaryDotNetJsFileVersion)%(Extension)</BootManifestResourceName>
</_BlazorOutputWithTargetPath>
<_BlazorJSFile Include="$(_BlazorJSPath)" />
@ -329,9 +332,7 @@
Inputs="$(MSBuildAllProjects);@(_BlazorOutputWithTargetPath)"
Outputs="$(_BlazorBootJsonIntermediateOutputPath)">
<ItemGroup>
<_BlazorBootResource Include="@(_BlazorOutputWithTargetPath->HasMetadata('BlazorBootManifestResourceType'))">
<BootResourceType>%(_BlazorOutputWithTargetPath.BlazorBootManifestResourceType)</BootResourceType>
</_BlazorBootResource>
<_BlazorBootResource Include="@(_BlazorOutputWithTargetPath->HasMetadata('BootManifestResourceType'))" />
</ItemGroup>
<GetFileHash Files="@(_BlazorBootResource)" Algorithm="SHA256" HashEncoding="base64">

View File

@ -24,26 +24,22 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
{
CreateResourceTaskItem(
ResourceType.assembly,
itemSpec: Path.Combine("dir", "My.Assembly1.ext"), // Can specify item spec
relativeOutputPath: null,
name: "My.Assembly1.ext", // Can specify filename with no dir
fileHash: "abcdefghikjlmnopqrstuvwxyz"),
CreateResourceTaskItem(
ResourceType.assembly,
itemSpec: "Ignored",
relativeOutputPath: Path.Combine("dir", "My.Assembly2.ext2"), // Can specify relative path
name: "dir\\My.Assembly2.ext2", // Can specify Windows-style path
fileHash: "012345678901234567890123456789"),
CreateResourceTaskItem(
ResourceType.pdb,
itemSpec: "SomePdb.pdb",
relativeOutputPath: null,
name: "otherdir/SomePdb.pdb", // Can specify Linux-style path
fileHash: "pdbhashpdbhashpdbhash"),
CreateResourceTaskItem(
ResourceType.runtime,
itemSpec: "some-runtime-file",
relativeOutputPath: null,
name: "some-runtime-file", // Can specify path with no extension
fileHash: "runtimehashruntimehash")
}
};
@ -63,14 +59,14 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
Assert.Equal(ResourceType.assembly, resourceListKey);
Assert.Equal(2, resources.Count);
Assert.Equal("sha256-abcdefghikjlmnopqrstuvwxyz", resources["My.Assembly1.ext"]);
Assert.Equal("sha256-012345678901234567890123456789", resources["dir/My.Assembly2.ext2"]); // For relative paths, we preserve the whole relative path, but use URL-style separators
Assert.Equal("sha256-012345678901234567890123456789", resources["dir/My.Assembly2.ext2"]); // Paths are converted to use URL-style separators
},
resourceListKey =>
{
var resources = parsedContent.resources[resourceListKey];
Assert.Equal(ResourceType.pdb, resourceListKey);
Assert.Single(resources);
Assert.Equal("sha256-pdbhashpdbhashpdbhash", resources["SomePdb.pdb"]);
Assert.Equal("sha256-pdbhashpdbhashpdbhash", resources["otherdir/SomePdb.pdb"]);
},
resourceListKey =>
{
@ -141,13 +137,11 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
return (BootJsonData)serializer.ReadObject(stream);
}
private static ITaskItem CreateResourceTaskItem(ResourceType type, string itemSpec, string relativeOutputPath, string fileHash)
private static ITaskItem CreateResourceTaskItem(ResourceType type, string name, string fileHash)
{
var mock = new Mock<ITaskItem>();
mock.Setup(m => m.ItemSpec).Returns(itemSpec);
mock.Setup(m => m.GetMetadata("TargetOutputPath")).Returns(itemSpec);
mock.Setup(m => m.GetMetadata("BootResourceType")).Returns(type.ToString());
mock.Setup(m => m.GetMetadata("RelativeOutputPath")).Returns(relativeOutputPath);
mock.Setup(m => m.GetMetadata("BootManifestResourceType")).Returns(type.ToString());
mock.Setup(m => m.GetMetadata("BootManifestResourceName")).Returns(name);
mock.Setup(m => m.GetMetadata("FileHash")).Returns(fileHash);
return mock.Object;
}