Skip to content

Commit

Permalink
[msbuild] Merge the Ditto[TaskBase] classes. (#19661)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Dec 19, 2023
1 parent 2a1f9ee commit 0a7c732
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 53 deletions.
52 changes: 0 additions & 52 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/Ditto.cs

This file was deleted.

39 changes: 38 additions & 1 deletion msbuild/Xamarin.MacDev.Tasks/Tasks/DittoTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

using Xamarin.Messaging.Build.Client;

namespace Xamarin.MacDev.Tasks {
public abstract class DittoTaskBase : XamarinToolTask {
public class Ditto : XamarinToolTask, ITaskCallback {
#region Inputs

public string? AdditionalArguments { get; set; }
Expand Down Expand Up @@ -65,6 +68,14 @@ protected override string GenerateCommandLineCommands ()

public override bool Execute ()
{
if (ShouldExecuteRemotely ()) {
var taskRunner = new TaskRunner (SessionId, BuildEngine4);

taskRunner.FixReferencedItems (new ITaskItem [] { Source! });

return taskRunner.RunAsync (this).Result;
}

if (!base.Execute ())
return false;

Expand All @@ -90,5 +101,31 @@ protected override void LogEventsFromTextOutput (string singleLine, MessageImpor
// TODO: do proper parsing of error messages and such
Log.LogMessage (messageImportance, "{0}", singleLine);
}

public override void Cancel ()
{
base.Cancel ();

if (ShouldExecuteRemotely ())
BuildConnection.CancelAsync (BuildEngine4).Wait ();
}

public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied ()
{
if (!Directory.Exists (Source!.ItemSpec))
return Enumerable.Empty<ITaskItem> ();

if (!CopyFromWindows)
return Enumerable.Empty<ITaskItem> ();

// TaskRunner doesn't know how to copy directories to Mac but `ditto` can take directories (and that's why we use ditto often).
// If Source is a directory path, let's add each file within it as an TaskItem, as TaskRunner knows how to copy files to Mac.
return Directory.GetFiles (Source.ItemSpec, "*", SearchOption.AllDirectories)
.Select (f => new TaskItem (f));
}

public bool ShouldCopyToBuildServer (ITaskItem item) => true;

public bool ShouldCreateOutputFile (ITaskItem item) => true;
}
}

6 comments on commit 0a7c732

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.