Skip to content

Commit

Permalink
[browser] Fix filtering compressed assets for pdb during publish (#10…
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf authored Mar 21, 2024
1 parent d9b9eb9 commit 3caa596
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
26 changes: 25 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Wasm.Build.Tests
{
public class WasmTemplateTests : WasmTemplateTestBase
public class WasmTemplateTests : BlazorWasmTestBase
{
public WasmTemplateTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext)
Expand Down Expand Up @@ -603,5 +603,29 @@ internal static void TestWasmStripILAfterAOTOutput(string objBuildDir, string fr
}
}
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void PublishPdb(bool copyOutputSymbolsToPublishDirectory)
{
string config = "Release";
string id = $"publishpdb_{copyOutputSymbolsToPublishDirectory.ToString().ToLower()}_{GetRandomId()}";
CreateWasmTemplateProject(id, "wasmbrowser");

(CommandResult result, _) = BlazorPublish(new BlazorBuildOptions(id, config), $"-p:CopyOutputSymbolsToPublishDirectory={copyOutputSymbolsToPublishDirectory.ToString().ToLower()}");
result.EnsureSuccessful();

string publishFrameworkPath = Path.GetFullPath(FindBlazorBinFrameworkDir(config, forPublish: true));
AssertFile(".pdb");
AssertFile(".pdb.gz");
AssertFile(".pdb.br");

void AssertFile(string suffix)
{
var fileName = $"{id}{suffix}";
Assert.True(copyOutputSymbolsToPublishDirectory == File.Exists(Path.Combine(publishFrameworkPath, fileName)), $"The {fileName} file {(copyOutputSymbolsToPublishDirectory ? "should" : "shouldn't")} exist in publish folder");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ private List<ITaskItem> ProcessSymbolAssets(
{
var symbolStaticWebAssets = new List<ITaskItem>();
var updateMap = new Dictionary<string, ITaskItem>();
var existingToRemove = new Dictionary<string, ITaskItem>();

foreach (var kvp in symbolAssets)
{
Expand All @@ -339,9 +340,14 @@ private List<ITaskItem> ProcessSymbolAssets(
resolvedPublishFilesToRemove.Remove(existing.ItemSpec);
}
}
else
{
Log.LogMessage(MessageImportance.Low, "Marking '{0}' as removed for filtering compressed assets.", kvp.Key);
existingToRemove.Add(kvp.Key, kvp.Value);
}
}

var compressedFiles = ProcessCompressedAssets(compressedRepresentations, symbolAssets, updateMap);
var compressedFiles = ProcessCompressedAssets(compressedRepresentations, symbolAssets, updateMap, existingToRemove);

foreach (var file in compressedFiles)
{
Expand Down Expand Up @@ -460,7 +466,8 @@ private List<ITaskItem> ComputeUpdatedAssemblies(
private List<ITaskItem> ProcessCompressedAssets(
Dictionary<string, ITaskItem> compressedRepresentations,
Dictionary<string, ITaskItem> assetsToUpdate,
Dictionary<string, ITaskItem> updatedAssets)
Dictionary<string, ITaskItem> updatedAssets,
Dictionary<string, ITaskItem> existingToRemove = null)
{
var processed = new List<string>();
var runtimeAssetsToUpdate = new List<ITaskItem>();
Expand All @@ -470,7 +477,11 @@ private List<ITaskItem> ProcessCompressedAssets(
var relatedAsset = compressedAsset.GetMetadata("RelatedAsset");
if (assetsToUpdate.ContainsKey(relatedAsset))
{
if (!updatedAssets.ContainsKey(relatedAsset))
if (existingToRemove?.ContainsKey(relatedAsset) == true)
{
Log.LogMessage(MessageImportance.Low, "Removing compressed '{0}' because related '{1}' is not published.", compressedAsset.ItemSpec, relatedAsset);
}
else if (!updatedAssets.ContainsKey(relatedAsset))
{
Log.LogMessage(MessageImportance.Low, "Related assembly for '{0}' was not updated and the compressed asset can be reused.", relatedAsset);
var newCompressedAsset = new TaskItem(compressedAsset);
Expand Down

0 comments on commit 3caa596

Please sign in to comment.