2017-01-19 14:42:27 +03:00
|
|
|
using System.Collections.Generic;
|
2017-01-25 19:14:28 +03:00
|
|
|
using System.Linq;
|
2017-01-19 14:42:27 +03:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace Xamarin.Bundler
|
|
|
|
{
|
|
|
|
public class BuildTasks : List<BuildTask>
|
|
|
|
{
|
|
|
|
static void Execute (List<BuildTask> added, BuildTask v)
|
|
|
|
{
|
2017-01-25 14:25:47 +03:00
|
|
|
var next = v.Run ();
|
2017-01-19 14:42:27 +03:00
|
|
|
if (next != null) {
|
|
|
|
lock (added)
|
|
|
|
added.AddRange (next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ExecuteInParallel ()
|
|
|
|
{
|
|
|
|
if (Count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var build_list = new List<BuildTask> (this);
|
|
|
|
var added = new List<BuildTask> ();
|
|
|
|
while (build_list.Count > 0) {
|
|
|
|
added.Clear ();
|
|
|
|
Parallel.ForEach (build_list, new ParallelOptions () { MaxDegreeOfParallelism = Driver.Concurrency }, (v) =>
|
|
|
|
{
|
|
|
|
Execute (added, v);
|
|
|
|
});
|
|
|
|
build_list.Clear ();
|
|
|
|
build_list.AddRange (added);
|
|
|
|
}
|
|
|
|
|
|
|
|
Clear ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract class BuildTask
|
|
|
|
{
|
|
|
|
public IEnumerable<BuildTask> NextTasks;
|
|
|
|
|
2017-01-25 14:25:47 +03:00
|
|
|
protected abstract void Execute ();
|
2017-01-25 18:38:24 +03:00
|
|
|
|
|
|
|
// A list of input files (not a list of all the dependencies that would make this task rebuild).
|
|
|
|
public abstract IEnumerable<string> Inputs { get; }
|
2017-01-19 14:42:27 +03:00
|
|
|
|
2017-01-25 14:25:47 +03:00
|
|
|
public IEnumerable<BuildTask> Run ()
|
2017-01-19 14:42:27 +03:00
|
|
|
{
|
2017-01-25 14:25:47 +03:00
|
|
|
Execute ();
|
2017-01-19 14:42:27 +03:00
|
|
|
return NextTasks;
|
|
|
|
}
|
|
|
|
|
2017-01-25 18:38:24 +03:00
|
|
|
public virtual bool IsUptodate {
|
|
|
|
get {
|
|
|
|
return Application.IsUptodate (FileDependencies, Outputs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A list of all the files that causes the task to rebuild.
|
|
|
|
// This should at least include all the 'Inputs', and potentially other files as well.
|
|
|
|
public virtual IEnumerable<string> FileDependencies {
|
|
|
|
get {
|
|
|
|
return Inputs;
|
|
|
|
}
|
2017-01-19 14:42:27 +03:00
|
|
|
}
|
2017-01-25 18:38:24 +03:00
|
|
|
|
|
|
|
// A list of files that this task outputs.
|
|
|
|
public abstract IEnumerable<string> Outputs { get; }
|
2017-01-25 19:14:28 +03:00
|
|
|
|
|
|
|
public bool CheckIsUptodate ()
|
|
|
|
{
|
|
|
|
if (!IsUptodate)
|
|
|
|
return false;
|
|
|
|
var outputs = Outputs;
|
|
|
|
if (outputs.Count () > 1) {
|
|
|
|
Driver.Log (3, "Targets '{0}' are up-to-date.", string.Join ("', '", outputs));
|
|
|
|
} else {
|
|
|
|
Driver.Log (3, "Target '{0}' is up-to-date.", outputs.First ());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-19 14:42:27 +03:00
|
|
|
}
|
|
|
|
}
|