Skip to content

Commit

Permalink
[msbuild] Fix duplicate resources when bundling original resources. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Feb 12, 2025
1 parent 4c1667e commit e5b7863
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
7 changes: 7 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/PackLibraryResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ public override bool Execute ()
{
var results = new List<ITaskItem> ();

var hashOriginalResources = new HashSet<string> (BundleOriginalResourcesWithLogicalNames.Select (v => v.ItemSpec));

foreach (var item in BundleResourcesWithLogicalNames) {
if (hashOriginalResources.Contains (item.ItemSpec)) {
Log.LogMessage (MessageImportance.Low, $"Skipping BundleResourcesWithLogicalNames={item.ItemSpec}, because it's also specified in BundleOriginalResourcesWithLogicalNames");
continue;
}

var logicalName = item.GetMetadata ("LogicalName");

if (string.IsNullOrEmpty (logicalName)) {
Expand Down
13 changes: 9 additions & 4 deletions tests/BundledResources/ResourcesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using System;
using System.IO;
using System.Linq;
using NUnit.Framework;

using Foundation;
Expand Down Expand Up @@ -41,10 +42,14 @@ public void Bundled ()
if (!hasResources) {
Assert.That (resources.Length, Is.EqualTo (0), "No resources");
} else {
Assert.That (resources.Length, Is.GreaterThanOrEqualTo (2), "Resources");
Assert.That (resources, Contains.Item ("__monotouch_content_basn3p08.png"), "res-basn3p08.png");
Assert.That (resources, Contains.Item ("__monotouch_content_basn3p08__with__loc.png"), "res-basn3p08_with_loc.png");
Assert.That (resources, Contains.Item ("__monotouch_content_xamvideotest.mp4"), "res-xamvideotest.mp4");
var expectedResources = new string [] {
"basn3p08.png",
"basn3p08__with__loc.png",
"xamvideotest.mp4",
};
var oldPrefixed = expectedResources.Select (v => $"__monotouch_content_{v}").ToArray ();
var newPrefixed = expectedResources.Select (v => $"__monotouch_item_BundleResource_{v}").ToArray ();
Assert.That (resources, Is.EquivalentTo (oldPrefixed).Or.EquivalentTo (newPrefixed), "Resources");
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,19 @@ public void BuildBindingsTest2 (ApplePlatform platform)
Assert.That (resourceBundle, Does.Exist, "Bundle existence");
}

[TestCase ("iOS", "monotouch")]
[TestCase ("tvOS", "monotouch")]
[TestCase ("macOS", "xammac")]
[TestCase ("MacCatalyst", "monotouch")]
public void BuildBundledResources (string platform, string prefix)
[TestCase ("iOS", "monotouch", true)]
[TestCase ("tvOS", "monotouch", true)]
[TestCase ("macOS", "xammac", true)]
[TestCase ("MacCatalyst", "monotouch", true)]
[TestCase ("iOS", "monotouch", false)]
[TestCase ("tvOS", "monotouch", false)]
[TestCase ("macOS", "xammac", false)]
[TestCase ("MacCatalyst", "monotouch", false)]
[TestCase ("iOS", "monotouch", null)]
[TestCase ("tvOS", "monotouch", null)]
[TestCase ("macOS", "xammac", null)]
[TestCase ("MacCatalyst", "monotouch", null)]
public void BuildBundledResources (string platform, string prefix, bool? bundleOriginalResources)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var assemblyName = "BundledResources";
Expand Down Expand Up @@ -877,9 +885,6 @@ public void LibraryWithResources (ApplePlatform platform, bool? bundleOriginalRe
var platformPrefix = (platform == ApplePlatform.MacOSX) ? "xammac" : "monotouch";
if (actualBundleOriginalResources) {
expectedResources = new string [] {
$"__{platformPrefix}_content_A.ttc",
$"__{platformPrefix}_content_B.otf",
$"__{platformPrefix}_content_C.ttf",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0001.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0002.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0003.png",
Expand Down

0 comments on commit e5b7863

Please sign in to comment.