Skip to content

Commit

Permalink
Fix (#85400)
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Apr 27, 2023
1 parent 0b30b3b commit bc84bd3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ public void BugRegression_60479_WithRazorClassLib()
.ExecuteWithCapturedOutput("new razorclasslib")
.EnsureSuccessful();

AddItemsPropertiesToProject(wasmProjectFile, extraItems:@"
AddItemsPropertiesToProject(wasmProjectFile, extraItems: UseWebcil ? @"
<ProjectReference Include=""..\RazorClassLibrary\RazorClassLibrary.csproj"" />
<BlazorWebAssemblyLazyLoad Include=""RazorClassLibrary.webcil"" />
" : @"
<ProjectReference Include=""..\RazorClassLibrary\RazorClassLibrary.csproj"" />
<BlazorWebAssemblyLazyLoad Include=""RazorClassLibrary.dll"" />
");
Expand All @@ -223,7 +226,7 @@ public void BugRegression_60479_WithRazorClassLib()
throw new XunitException($"Could not find resources.lazyAssembly object in {bootJson}");
}

Assert.Contains("RazorClassLibrary.dll", lazyVal.EnumerateObject().Select(jp => jp.Name));
Assert.Contains("RazorClassLibrary.webcil", lazyVal.EnumerateObject().Select(jp => jp.Name));
}

[ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ private List<ITaskItem> ComputeUpdatedAssemblies(
assetsToUpdate.Add(satelliteAssembly.ItemSpec, satelliteAssembly);
var culture = satelliteAssembly.GetMetadata("AssetTraitValue");
var fileName = Path.GetFileName(satelliteAssembly.GetMetadata("RelativePath"));
if (IsWebCilEnabled)
fileName = Path.ChangeExtension(fileName, ".dll");

if (satelliteAssemblies.TryGetValue((culture, fileName), out var existing))
{
filesToRemove.Add(existing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public override bool Execute()
var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: filePath, outputPath: tmpWebcil, logger: Log);
webcilWriter.ConvertToWebcil();

var finalWebcil = Path.Combine(OutputPath, Path.GetFileNameWithoutExtension(filePath) + ".webcil");
string candicatePath = Path.Combine(OutputPath, candidate.GetMetadata("Culture"));
if (!Directory.Exists(candicatePath))
Directory.CreateDirectory(candicatePath);

var finalWebcil = Path.Combine(candicatePath, Path.GetFileNameWithoutExtension(filePath) + ".webcil");
if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true))
Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} .");
else
Expand All @@ -72,10 +76,16 @@ public override bool Execute()

var webcilItem = new TaskItem(finalWebcil, candidate.CloneCustomMetadata());
webcilItem.SetMetadata("RelativePath", Path.ChangeExtension(candidate.GetMetadata("RelativePath"), ".webcil"));
webcilItem.SetMetadata("AssetTraitName", "WasmResource");
webcilItem.SetMetadata("AssetTraitValue", "runtime");
webcilItem.SetMetadata("OriginalItemSpec", finalWebcil);

if (webcilItem.GetMetadata("AssetTraitName") == "Culture")
{
string relatedAsset = webcilItem.GetMetadata("RelatedAsset");
relatedAsset = Path.ChangeExtension(relatedAsset, ".webcil");
webcilItem.SetMetadata("RelatedAsset", relatedAsset);
Log.LogMessage(MessageImportance.Low, $"Changing related asset of {webcilItem} to {relatedAsset}.");
}

webCilCandidates.Add(webcilItem);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName)
}
else if (string.Equals("symbol", assetTraitValue, StringComparison.OrdinalIgnoreCase))
{
if (TryGetLazyLoadedAssembly($"{fileName}.dll", out _))
if (TryGetLazyLoadedAssembly($"{fileName}.dll", out _) || TryGetLazyLoadedAssembly($"{fileName}.webcil", out _))
{
Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as a lazy loaded symbols file.", resource.ItemSpec);
resourceData.lazyAssembly ??= new ResourceHashesByNameDictionary();
Expand Down

0 comments on commit bc84bd3

Please sign in to comment.