-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchedulableActionCollector.cs
74 lines (57 loc) · 2.03 KB
/
SchedulableActionCollector.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
71
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace cake
{
public class SchedulableActionCollector
{
private readonly DependencyGraph _dependencyGraph;
public SchedulableActionCollector(DependencyGraph dependencyGraph)
{
_dependencyGraph = dependencyGraph;
}
public IEnumerable<SchedulableAction> CollectActionsToGenerate(string targetFile)
{
var result = ActionRequiredToGetTargetUpdated(targetFile);
if (result != null)
{
yield return result;
foreach(var inputFileRequiringGeneration in result.InputFilesRequiringGeneration)
{
var theirAction = ActionRequiredToGetTargetUpdated(inputFileRequiringGeneration);
if (theirAction != null)
yield return theirAction;
}
}
}
SchedulableAction ActionRequiredToGetTargetUpdated(string target)
{
TargetGenerateSettings generateSettings;
if (!_dependencyGraph._graph.TryGetValue(target, out generateSettings))
return null;
var inputFilesRequiringGeneration = generateSettings.InputFiles.Where(inputfile => ActionRequiredToGetTargetUpdated(inputfile) != null).ToArray();
if (inputFilesRequiringGeneration.Any())
return new SchedulableAction(generateSettings, inputFilesRequiringGeneration);
if (NeedToGenerate(target))
return new SchedulableAction(generateSettings);
return null;
}
private bool NeedToGenerate(string targetFile)
{
TargetGenerateSettings generateSettings = _dependencyGraph._graph[targetFile];
var recordOfLastBuild = _dependencyGraph._buildHistory.FindRecordFor(targetFile);
if (recordOfLastBuild == null)
return true;
if (!File.Exists(targetFile))
return true;
if (!generateSettings.Equals(recordOfLastBuild.Settings))
return true;
if (File.GetLastWriteTimeUtc(targetFile) < recordOfLastBuild.ModificationTimeOfTargetFile())
return true;
if (generateSettings.InputFiles.Any(inputFile => File.GetLastWriteTimeUtc(inputFile) > recordOfLastBuild.ModificationTimeOf(inputFile)))
return true;
return false;
}
}
}