Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Delay uno-assets.txt generation #891

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions src/Uno.Wasm.Bootstrap/GenerateUnoAssetsManifestTask.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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<string, string>
{
["CopyToOutputDirectory"] = "PreserveNewest",
["ContentRoot"] = contentRoot,
["Link"] = "wwwroot/" + targetPath,
});

UnoAssetsFile = UnoAssetsFile.Concat([indexMetadata]).ToArray();
}
}
13 changes: 2 additions & 11 deletions src/Uno.Wasm.Bootstrap/ShellTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ?? "<null>"} [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()
Expand Down
67 changes: 0 additions & 67 deletions src/Uno.Wasm.Bootstrap/StaticWebAssetsResolverTask.cs

This file was deleted.

58 changes: 43 additions & 15 deletions src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<WasmEnableThreads Condition=" '$(WasmShellEnableThreads)' == 'true' ">true</WasmEnableThreads>

<WasmShellMode Condition="'$(WasmShellMode)'==''">browser</WasmShellMode>

<BlazorWebAssemblyJiterpreter Condition=" $(NETCoreSdkVersion.Contains('rc.1')) ">false</BlazorWebAssemblyJiterpreter>
</PropertyGroup>

Expand All @@ -37,7 +37,7 @@
<PublishTrimmed>false</PublishTrimmed>

</PropertyGroup>

<!-- Log profiler support -->
<PropertyGroup Condition=" '$(WasmShellEnableLogProfiler)' == 'true' ">
<!-- Enable AOT profiling using a single property -->
Expand Down Expand Up @@ -167,10 +167,10 @@

<!-- Jiterpreter compatibility -->
<BlazorWebAssemblyJiterpreter Condition=" '$(WasmShellEnableJiterpreter)' != '' AND '$(BlazorWebAssemblyJiterpreter)' == '' ">$(WasmShellEnableJiterpreter)</BlazorWebAssemblyJiterpreter>

<!-- EMCC flags compatibility -->
<EmccFlags>$(EmccFlags);@(WasmShellExtraEmccFlags)</EmccFlags>

<EmccFlags Condition=" '$(WasmShellEnableEmccProfiling)' == 'true' ">$(EmccFlags);--profiling</EmccFlags>

<!-- Threading compatibility -->
Expand Down Expand Up @@ -220,20 +220,49 @@
</Target>

<UsingTask Condition="!$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.ShellTask_v0" />
<UsingTask Condition="!$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.ValidateStaticAssets_v0" />
<UsingTask Condition="!$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.GenerateUnoAssetsManifest_v0" />
<UsingTask Condition="!$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.StaticWebAssetsResolverTask_v0" />
<UsingTask Condition="!$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.RemoveDirTask_v0" />

<UsingTask Condition="$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.ShellTask_v0" TaskFactory="TaskHostFactory" />
<UsingTask Condition="$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.ValidateStaticAssets_v0" TaskFactory="TaskHostFactory" />
<UsingTask Condition="$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.GenerateUnoAssetsManifest_v0" TaskFactory="TaskHostFactory" />
<UsingTask Condition="$(_WasmShellTasksPathIsDevMode)" AssemblyFile="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.StaticWebAssetsResolverTask_v0" TaskFactory="TaskHostFactory" />
<UsingTask Condition="$(_WasmShellTasksPathIsDevMode)" AssemblyFile ="$(WasmShellTasksPath)/Uno.Wasm.Bootstrap.v0.dll" TaskName="Uno.Wasm.Bootstrap.RemoveDirTask_v0" TaskFactory="TaskHostFactory" />

<Target Name="ValidateAssets" BeforeTargets="_GenerateBuildWasmBootJson">
<ValidateStaticAssets_v0
CandidateAssets="@(WasmStaticWebAsset)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)" />
<PropertyGroup>
<UnoGenerateAssetsManifestDependsOn>
$(UnoGenerateAssetsManifestDependsOn);
</UnoGenerateAssetsManifestDependsOn>
</PropertyGroup>

<Target Name="UnoGenerateAssetsManifest"
BeforeTargets="ResolveStaticWebAssetsInputs"
DependsOnTargets="$(UnoGenerateAssetsManifestDependsOn)">
<GenerateUnoAssetsManifest_v0
StaticWebAsset="@(StaticWebAsset)"
IntermediateOutputPath="$(IntermediateOutputPath)">
<Output TaskParameter="UnoAssetsFile" ItemName="_UnoAssetsManifest" />
</GenerateUnoAssetsManifest_v0>

<DefineStaticWebAssets
CandidateAssets="@(_UnoAssetsManifest)"
FingerprintCandidates="$(StaticWebAssetsFingerprintContent)"
FingerprintPatterns="@(StaticWebAssetFingerprintPattern)"
RelativePathPattern="wwwroot/**"
SourceType="Discovered"
SourceId="$(PackageId)"
ContentRoot="$(MSBuildProjectDirectory)\wwwroot\"
BasePath="$(StaticWebAssetBasePath)"
AssetMergeSource="$(StaticWebAssetMergeTarget)">
<Output TaskParameter="Assets" ItemName="StaticWebAsset" />
</DefineStaticWebAssets>

<DefineStaticWebAssetEndpoints
CandidateAssets="@(StaticWebAsset)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)">
<Output TaskParameter="Endpoints" ItemName="StaticWebAssetEndpoint" />
</DefineStaticWebAssetEndpoints>
</Target>

<Target Name="GenerateUnoWasmAssets"
Expand Down Expand Up @@ -286,8 +315,7 @@
Optimize="$(Optimize)"
WasmBuildNative="$(WasmBuildNative)"
WasmShellMode="$(WasmShellMode)"
WebAppBasePath="$(WasmShellWebAppBasePath)"
>
WebAppBasePath="$(WasmShellWebAppBasePath)">
<Output TaskParameter="StaticWebContent" ItemName="_UnoStaticWebContent" />
<Output TaskParameter="NativeFileReference" ItemName="NativeFileReference" />
<Output TaskParameter="FilteredAotProfile" PropertyName="_FilteredAotProfile" />
Expand All @@ -305,7 +333,7 @@
AssetMergeSource="$(StaticWebAssetMergeTarget)">
<Output TaskParameter="Assets" ItemName="StaticWebAsset" />
</DefineStaticWebAssets>

<DefineStaticWebAssetEndpoints
CandidateAssets="@(StaticWebAsset)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
Expand All @@ -318,7 +346,7 @@
<!-- Override the user's profile with the filtered one -->
<WasmAotProfilePath>$(_FilteredAotProfile)</WasmAotProfilePath>
</PropertyGroup>

</Target>

</Project>
Loading