-
Notifications
You must be signed in to change notification settings - Fork 0
/
DependencyGraph.cs
70 lines (57 loc) · 1.73 KB
/
DependencyGraph.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace cake
{
public delegate bool WillFileBeGeneratedAtPath(string path);
public class DependencyGraph
{
public readonly Dictionary<string, TargetGenerateSettings> _graph = new Dictionary<string, TargetGenerateSettings>();
public Action<TargetGenerateSettings> GenerateCallback = s => { };
public readonly BuildHistory _buildHistory;
public DependencyGraph() : this(new BuildHistory())
{
}
public DependencyGraph(BuildHistory history)
{
_buildHistory = history;
}
public void RequestTarget(string targetFile)
{
var actionScheduler = new ActionScheduler();
var c = new SchedulableActionCollector(this);
var actions = c.CollectActionsToGenerate(targetFile);
foreach(var action in actions)
actionScheduler.Add(action);
actionScheduler.VerifyAllInputFilesArePresentOrWillBeGenerated();
while (actionScheduler.AnyJobsLeft)
{
var job = actionScheduler.FindJobToRun();
if (job==null)
throw new InvalidOperationException("No job is available to run, while there are still scheduled jobs left.");
Generate(job);
actionScheduler.JobFinished(job);
}
}
private void Generate(TargetGenerateSettings settings)
{
GenerateCallback(settings);
settings.Action.Invoke(settings);
foreach (var outputFile in settings.OutputFiles)
{
var record = new GenerationRecord(outputFile, settings);
_buildHistory.AddRecord(record);
}
}
public void RegisterTarget(TargetGenerateSettings settings)
{
foreach(var targetFile in settings.OutputFiles)
_graph.Add(targetFile,settings);
}
public bool IsTargetRegistered(string file)
{
return _graph.Keys.Contains(file);
}
}
}