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

[msbuild] Fix duplicate resources when bundling original resources. #21990

Merged
merged 3 commits into from
Jan 18, 2025
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
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 @@ -870,9 +878,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
Loading