diff --git a/src/Uno.Wasm.Bootstrap/GenerateUnoAssetsManifestTask.cs b/src/Uno.Wasm.Bootstrap/GenerateUnoAssetsManifestTask.cs new file mode 100644 index 000000000..952806a10 --- /dev/null +++ b/src/Uno.Wasm.Bootstrap/GenerateUnoAssetsManifestTask.cs @@ -0,0 +1,84 @@ + +// ****************************************************************** +// Copyright � 2015-2022 Uno Platform inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ****************************************************************** +// +// This file is based on the work from https://github.com/praeclarum/Ooui +// +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Runtime.InteropServices; +using System.Security.Cryptography; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using Uno.Wasm.Bootstrap.Extensions; + +namespace Uno.Wasm.Bootstrap; + +public class GenerateUnoAssetsManifest_v0 : Microsoft.Build.Utilities.Task +{ + private string _intermediateAssetsPath = ""; + + [Required] + public ITaskItem[] StaticWebAsset { get; set; } = []; + + [Required] + public string IntermediateOutputPath { get; set; } = ""; + + [Output] + public ITaskItem[] UnoAssetsFile { get; set; } = []; + + public override bool Execute() + { + _intermediateAssetsPath = Path.Combine(IntermediateOutputPath, "unowwwrootassets"); + + List assets = new(); + + // Grab the list of all the staticwebassets provided to be available in uno-assets.txt + foreach(var asset in StaticWebAsset) + { + var assetPath = Path.GetDirectoryName(asset.GetMetadata("RelativePath")) + "/" + Path.GetFileName(asset.GetMetadata("FullPath")); + assets.Add(assetPath.Replace("\\", "/")); + } + + var assetsFilePath = Path.Combine(_intermediateAssetsPath, "uno-assets.txt"); + File.WriteAllLines(assetsFilePath, assets); + AddStaticAsset(Path.GetFileName(assetsFilePath), assetsFilePath); + + return true; + } + + private void AddStaticAsset(string targetPath, string filePath) + { + var contentRoot = targetPath.StartsWith(_intermediateAssetsPath) + ? _intermediateAssetsPath + : Path.GetDirectoryName(filePath); + + TaskItem indexMetadata = new( + filePath, new Dictionary + { + ["CopyToOutputDirectory"] = "PreserveNewest", + ["ContentRoot"] = contentRoot, + ["Link"] = "wwwroot/" + targetPath, + }); + + UnoAssetsFile = UnoAssetsFile.Concat([indexMetadata]).ToArray(); + } +} diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index c24fdeaad..d8727693e 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -184,7 +184,7 @@ private void RemoveDuplicateAssets() foreach (var existingAsset in existingAssets) { Log.LogMessage(MessageImportance.Low, $"Existing asset to remove [{existingAsset.ItemSpec}]"); - } + } // remove existingAssets from StaticWebContent StaticWebContent = StaticWebContent @@ -319,23 +319,14 @@ private void CopyContent() deployMode = defaultDeployMode; } - var dest = Path.Combine(_intermediateAssetsPath, relativePath); - if (deployMode != DeployMode.None) { - // Add the file to the package assets manifest - assets.Add(relativePath.Replace(Path.DirectorySeparatorChar, '/')); - AddStaticAsset(relativePath, fullSourcePath); } - Log.LogMessage($"ContentFile {fullSourcePath} -> {dest ?? ""} [Mode={deployMode} / by {deployModeSource}, ]"); + Log.LogMessage($"ContentFile {fullSourcePath} -> [Mode={deployMode} / by {deployModeSource}, {relativePath}]"); } } - - var assetsFilePath = Path.Combine(_intermediateAssetsPath, "uno-assets.txt"); - File.WriteAllLines(assetsFilePath, assets); - AddStaticAsset(Path.GetFileName(assetsFilePath), assetsFilePath); } private void ExtractAdditionalJS() diff --git a/src/Uno.Wasm.Bootstrap/StaticWebAssetsResolverTask.cs b/src/Uno.Wasm.Bootstrap/StaticWebAssetsResolverTask.cs deleted file mode 100644 index 0f8e9d318..000000000 --- a/src/Uno.Wasm.Bootstrap/StaticWebAssetsResolverTask.cs +++ /dev/null @@ -1,67 +0,0 @@ - -// ****************************************************************** -// Copyright � 2015-2022 Uno Platform inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ****************************************************************** -// -// This file is based on the work from https://github.com/praeclarum/Ooui -// -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; -using Uno.Wasm.Bootstrap.Extensions; - -namespace Uno.Wasm.Bootstrap; - -public class ValidateStaticAssets_v0 : Microsoft.Build.Utilities.Task -{ - [Required] - public ITaskItem[] CandidateAssets { get; set; } = []; - - [Required] - public ITaskItem[] ExistingEndpoints { get; set; } = []; - - [Required] - public ITaskItem[] ContentTypeMappings { get; set; } = []; - - public override bool Execute() - { - var staticWebAssets = CandidateAssets.ToDictionary(a => a.GetMetadata("FullPath")); - var existingEndpoints = ExistingEndpoints; - var existingEndpointsByAssetFile = existingEndpoints - .GroupBy(e => e.GetMetadata("AssetFile"), OSPath.PathComparer) - .ToDictionary(g => g.Key); - - return true; - } - - internal static class OSPath - { - public static StringComparer PathComparer { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) - ? StringComparer.OrdinalIgnoreCase : - StringComparer.Ordinal; - - public static StringComparison PathComparison { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) - ? StringComparison.OrdinalIgnoreCase : - StringComparison.Ordinal; - } -} diff --git a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets index 38cf47f61..c0d39be03 100644 --- a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets +++ b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets @@ -15,7 +15,7 @@ true browser - + false @@ -37,7 +37,7 @@ false - + @@ -167,10 +167,10 @@ $(WasmShellEnableJiterpreter) - + $(EmccFlags);@(WasmShellExtraEmccFlags) - + $(EmccFlags);--profiling @@ -220,20 +220,49 @@ - + - + - - + + + $(UnoGenerateAssetsManifestDependsOn); + + + + + + + + + + + + + + + + WebAppBasePath="$(WasmShellWebAppBasePath)"> @@ -305,7 +333,7 @@ AssetMergeSource="$(StaticWebAssetMergeTarget)"> - + $(_FilteredAotProfile) - +