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] Enable nullability and improve error reporting in the PackLibraryResources task. #19998

Merged
Merged
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
39 changes: 16 additions & 23 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/PackLibraryResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@
using Xamarin.Localization.MSBuild;
using Xamarin.Messaging.Build.Client;

// Disable until we get around to enable + fix any issues.
#nullable disable

namespace Xamarin.MacDev.Tasks {
public class PackLibraryResources : XamarinTask, ITaskCallback, ICancelableTask {
#region Inputs

[Required]
public string Prefix { get; set; }
public string Prefix { get; set; } = string.Empty;

public ITaskItem [] BundleResourcesWithLogicalNames { get; set; }
public ITaskItem [] BundleResourcesWithLogicalNames { get; set; } = Array.Empty<ITaskItem> ();

#endregion

#region Outputs

[Output]
public ITaskItem [] EmbeddedResources { get; set; }
public ITaskItem [] EmbeddedResources { get; set; } = Array.Empty<ITaskItem> ();

#endregion

Expand All @@ -48,13 +45,11 @@ static string EscapeMangledResource (string name)
bool ExecuteRemotely ()
{
// Fix LogicalName path for the Mac
if (BundleResourcesWithLogicalNames is not null) {
foreach (var resource in BundleResourcesWithLogicalNames) {
var logicalName = resource.GetMetadata ("LogicalName");
foreach (var resource in BundleResourcesWithLogicalNames) {
var logicalName = resource.GetMetadata ("LogicalName");

if (!string.IsNullOrEmpty (logicalName)) {
resource.SetMetadata ("LogicalName", logicalName.Replace ("\\", "/"));
}
if (!string.IsNullOrEmpty (logicalName)) {
resource.SetMetadata ("LogicalName", logicalName.Replace ("\\", "/"));
}
}

Expand Down Expand Up @@ -86,21 +81,19 @@ public override bool Execute ()

var results = new List<ITaskItem> ();

if (BundleResourcesWithLogicalNames is not null) {
foreach (var item in BundleResourcesWithLogicalNames) {
var logicalName = item.GetMetadata ("LogicalName");
foreach (var item in BundleResourcesWithLogicalNames) {
var logicalName = item.GetMetadata ("LogicalName");

if (string.IsNullOrEmpty (logicalName)) {
Log.LogError (MSBStrings.E0161);
return false;
}
if (string.IsNullOrEmpty (logicalName)) {
Log.LogError (null, null, null, item.ItemSpec, 0, 0, 0, 0, MSBStrings.E0161);
continue;
}

var embedded = new TaskItem (item);
var embedded = new TaskItem (item);

embedded.SetMetadata ("LogicalName", "__" + Prefix + "_content_" + EscapeMangledResource (logicalName));
embedded.SetMetadata ("LogicalName", "__" + Prefix + "_content_" + EscapeMangledResource (logicalName));

results.Add (embedded);
}
results.Add (embedded);
}

EmbeddedResources = results.ToArray ();
Expand Down
Loading