-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[msbuild] Port the SpotlightIndexer task to subclass XamarinTask.
This has a few advantages: * We simplify and unify more of our code. * We have more control over the error reporting / logging behavior. Additionally: * Use 'xcrun' to invoke 'altool' (partial fix for #3931). * Allow for overriding the path to the command-line tool in question. * Add support for cancellation. * Fix nullability.
- Loading branch information
1 parent
377f0f0
commit c785d4b
Showing
3 changed files
with
36 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
using Xamarin.Messaging.Build.Client; | ||
|
||
#nullable enable | ||
|
||
namespace Xamarin.MacDev.Tasks { | ||
public class SpotlightIndexer : XamarinToolTask { | ||
public class SpotlightIndexer : XamarinTask, ICancelableTask { | ||
CancellationTokenSource? cancellationTokenSource; | ||
#region Inputs | ||
|
||
[Required] | ||
public string Input { get; set; } = string.Empty; | ||
|
||
#endregion | ||
public string MdimportPath { get; set; } = string.Empty; | ||
|
||
protected override string ToolName { | ||
get { return "mdimport"; } | ||
} | ||
#endregion | ||
|
||
protected override string GenerateFullPathToTool () | ||
static string GetExecutable (List<string> arguments, string toolName, string toolPathOverride) | ||
{ | ||
if (!string.IsNullOrEmpty (ToolPath)) | ||
return Path.Combine (ToolPath, ToolExe); | ||
|
||
var path = Path.Combine ("/usr/bin", ToolExe); | ||
|
||
return File.Exists (path) ? path : ToolExe; | ||
if (string.IsNullOrEmpty (toolPathOverride)) { | ||
arguments.Insert (0, toolName); | ||
return "xcrun"; | ||
} | ||
return toolPathOverride; | ||
} | ||
|
||
protected override string GenerateCommandLineCommands () | ||
List<string> GenerateCommandLineCommands () | ||
{ | ||
var args = new CommandLineBuilder (); | ||
var args = new List<string> (); | ||
|
||
args.AppendFileNameIfNotNull (Input); | ||
args.Add (Input); | ||
|
||
return args.ToString (); | ||
} | ||
|
||
protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance) | ||
{ | ||
// TODO: do proper parsing of error messages and such | ||
Log.LogMessage (messageImportance, "{0}", singleLine); | ||
return args; | ||
} | ||
|
||
public override bool Execute () | ||
{ | ||
if (ShouldExecuteRemotely ()) | ||
return new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result; | ||
|
||
return base.Execute (); | ||
var args = GenerateCommandLineCommands (); | ||
var executable = GetExecutable (args, "mdimport", MdimportPath); | ||
cancellationTokenSource = new CancellationTokenSource (); | ||
ExecuteAsync (Log, executable, args, cancellationToken: cancellationTokenSource.Token).Wait (); | ||
return !Log.HasLoggedErrors; | ||
} | ||
|
||
public override void Cancel () | ||
public void Cancel () | ||
{ | ||
if (ShouldExecuteRemotely ()) | ||
if (ShouldExecuteRemotely ()) { | ||
BuildConnection.CancelAsync (BuildEngine4).Wait (); | ||
|
||
base.Execute (); | ||
} else { | ||
cancellationTokenSource?.Cancel (); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters