Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

start modestly using the ActionScheduler

  • Loading branch information...
commit 0bf1459dffad8d4ebe4203fe6e44f150de0e0b25 1 parent 4df7360
Lucas Meijer authored
View
4 ActionScheduler.cs
@@ -8,9 +8,9 @@ public class ActionScheduler
{
private readonly Dictionary<TargetGenerateSettings, HashSet<string>> _scheduledActions = new Dictionary<TargetGenerateSettings, HashSet<string>>();
- public void Add(IEnumerable<string> dependenciesRequiringRegeneration, TargetGenerateSettings tgs)
+ public void Add(SchedulableAction schedulableAction)
{
- _scheduledActions.Add(tgs, new HashSet<string>(dependenciesRequiringRegeneration));
+ _scheduledActions.Add(schedulableAction.Settings, new HashSet<string>(schedulableAction.InputFilesRequiringGeneration));
}
public TargetGenerateSettings FindJobToRun()
View
42 DependencyGraph.cs
@@ -22,17 +22,44 @@ public DependencyGraph(BuildHistory history)
public void RequestTarget(string targetFile)
{
- var instructions = _graph[targetFile];
+ var actionScheduler = new ActionScheduler();
+
+ var action = ActionRequiredToGetTargetUpdated(targetFile);
+ if (action == null)
+ return;
- if (instructions.InputFiles.Any(inputFile => !File.Exists(inputFile)))
+ actionScheduler.Add(action);
+
+ var job = actionScheduler.FindJobToRun();
+
+ Generate(job);
+ }
+
+ SchedulableAction ActionRequiredToGetTargetUpdated(string target)
+ {
+ TargetGenerateSettings generateSettings;
+ if (!_graph.TryGetValue(target, out generateSettings))
+ {
+ if (File.Exists(target))
+ return null;
throw new MissingDependencyException();
+ }
- if (NeedToGenerate(targetFile, instructions))
- Generate(instructions);
+ var inputFilesRequiringGeneration = generateSettings.InputFiles.Where(inputfile => ActionRequiredToGetTargetUpdated(inputfile) != null);
+
+ if (inputFilesRequiringGeneration.Any())
+ return new SchedulableAction(generateSettings, inputFilesRequiringGeneration);
+
+ if (NeedToGenerate(target))
+ return new SchedulableAction(generateSettings);
+
+ return null;
}
- private bool NeedToGenerate(string targetFile, TargetGenerateSettings generateSettings)
+ private bool NeedToGenerate(string targetFile)
{
+ TargetGenerateSettings generateSettings = _graph[targetFile];
+
var recordOfLastBuild = _buildHistory.FindRecordFor(targetFile);
if (recordOfLastBuild == null)
@@ -47,7 +74,10 @@ private bool NeedToGenerate(string targetFile, TargetGenerateSettings generateSe
if (File.GetLastWriteTimeUtc(targetFile) < recordOfLastBuild.ModificationTimeOfTargetFile())
return true;
- return generateSettings.InputFiles.Any(sourceFile => recordOfLastBuild.ModificationTimeOf(sourceFile) != File.GetLastWriteTimeUtc(sourceFile));
+ if (generateSettings.InputFiles.Any(inputFile => File.GetLastWriteTimeUtc(inputFile) > recordOfLastBuild.ModificationTimeOf(inputFile)))
+ return true;
+
+ return false;
}
private void Generate(TargetGenerateSettings settings)
View
21 SchedulableAction.cs
@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+
+namespace cake
+{
+ public class SchedulableAction
+ {
+ public TargetGenerateSettings Settings;
+ public IEnumerable<string> InputFilesRequiringGeneration;
+
+ public SchedulableAction(TargetGenerateSettings generateSettings)
+ :this(generateSettings,new List<string>())
+ {
+ }
+
+ public SchedulableAction(TargetGenerateSettings generateSettings, IEnumerable<string> inputFilesRequiringGeneration)
+ {
+ Settings = generateSettings;
+ InputFilesRequiringGeneration = inputFilesRequiringGeneration;
+ }
+ }
+}
View
8 Tests/ActionSchedulerTest.cs
@@ -24,7 +24,7 @@ public void Setup()
public void SingleActionWithoutDependenciesRequiringGenerationCanBeRun()
{
var tgs = new TargetGenerateSettings(_action, new[] {"input"}, "output");
- _scheduler.Add(new string[0], tgs);
+ _scheduler.Add(new SchedulableAction(tgs));
Assert.AreEqual(tgs,_scheduler.FindJobToRun());
}
@@ -33,7 +33,7 @@ public void SingleActionWithoutDependenciesRequiringGenerationCanBeRun()
public void DoesNotProvideSameJobTwice()
{
var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
- _scheduler.Add(new string[0], tgs);
+ _scheduler.Add(new SchedulableAction(tgs));
Assert.AreEqual(tgs, _scheduler.FindJobToRun());
Assert.IsNull(_scheduler.FindJobToRun());
@@ -43,7 +43,7 @@ public void DoesNotProvideSameJobTwice()
public void SingleActionWithDependenciesRequiringGenerationCannotBeRun()
{
var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
- _scheduler.Add(new[]{"input"}, tgs);
+ _scheduler.Add(new SchedulableAction(tgs,new[] { "input"}));
Assert.IsNull(_scheduler.FindJobToRun());
}
@@ -52,7 +52,7 @@ public void SingleActionWithDependenciesRequiringGenerationCannotBeRun()
public void ActionWithDependenciesRequiringGenerationCanBeRanWhenDependencyIsGenerated()
{
var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
- _scheduler.Add(new[] { "input" }, tgs);
+ _scheduler.Add(new SchedulableAction(tgs, new[] { "input" }));
Assert.IsNull(_scheduler.FindJobToRun());
View
6 Tests/SimpleCopyDepGraph.cs
@@ -24,8 +24,6 @@ public void ThrowsIfDependencyDoesNotExist()
[Test]
public void RegeneratesWhenSourceChanges()
{
- Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
-
WriteToSourceRunDepGraphAndVerifyTarget("One");
WriteToSourceRunDepGraphAndVerifyTarget("Two");
}
@@ -40,8 +38,6 @@ private void WriteToSourceRunDepGraphAndVerifyTarget(string contents)
[Test]
public void WillNotRegeneratesWhenSourceDidNotChange()
{
- Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
-
WriteToSourceRunDepGraphAndVerifyTarget("One");
ThrowIfDepgraphGenerates();
@@ -51,8 +47,6 @@ public void WillNotRegeneratesWhenSourceDidNotChange()
[Test]
public void WillNotRegeneratesWhenTargetGotManuallyUpdated()
{
- Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
-
WriteToSourceRunDepGraphAndVerifyTarget("One");
File.WriteAllText(defaulttargetFile, "Three");
View
206 cake.5.1.ReSharper.user
@@ -0,0 +1,206 @@
+<Configuration>
+ <SettingsComponent>
+ <string />
+ <integer />
+ <boolean>
+ <setting name="SolutionAnalysisEnabled">False</setting>
+ </boolean>
+ </SettingsComponent>
+ <CompletionStatisticsManager>
+ <ItemStatistics item="Default">
+ <Item value="action" priority="10" />
+ <Item value="if" priority="7" />
+ <Item value="Action" priority="1" />
+ <Item value="return" priority="9" />
+ <Item value="else" priority="1" />
+ <Item value="new" priority="31" />
+ <Item value="HashSet&lt;string&gt;" priority="3" />
+ <Item value="inputFiles" priority="1" />
+ <Item value="simpleAction" priority="0" />
+ <Item value="_actionHash" priority="0" />
+ <Item value="IEnumerable" priority="5" />
+ <Item value="string" priority="7" />
+ <Item value="defaulttargetFile" priority="2" />
+ <Item value="foreach" priority="6" />
+ <Item value="var" priority="22" />
+ <Item value="in" priority="4" />
+ <Item value="settings" priority="9" />
+ <Item value="this" priority="3" />
+ <Item value="outputFile" priority="1" />
+ <Item value="ActionHash" priority="0" />
+ <Item value="s" priority="2" />
+ <Item value="TestAttribute`0" priority="0" />
+ <Item value="public" priority="5" />
+ <Item value="void" priority="3" />
+ <Item value="TargetGenerateSettings`0" priority="7" />
+ <Item value="SimpleAction`0" priority="1" />
+ <Item value="FileAssert" priority="0" />
+ <Item value="CCompilerTask`0" priority="0" />
+ <Item value="File`0" priority="2" />
+ <Item value="_depGraph" priority="2" />
+ <Item value="compilecppfile" priority="0" />
+ <Item value="DependencyGraph`0" priority="1" />
+ <Item value="depGraph" priority="0" />
+ <Item value="TargetGenerateSettings" priority="0" />
+ <Item value="GetInputFiles`0" priority="0" />
+ <Item value="FileAssert`0" priority="0" />
+ <Item value="_sourceFile" priority="0" />
+ <Item value="_targetFile" priority="0" />
+ <Item value="ActionSchedulerTest`0" priority="0" />
+ <Item value="scheduler" priority="2" />
+ <Item value="IgnoreAttribute`0" priority="1" />
+ <Item value="Assert`0" priority="2" />
+ <Item value="tgs" priority="2" />
+ <Item value="jobToRun" priority="0" />
+ <Item value="List" priority="4" />
+ <Item value="Dictionary&lt;TargetGenerateSettings,List&lt;string&gt;&gt;" priority="0" />
+ <Item value="_scheduledActions" priority="3" />
+ <Item value="KeyValuePair" priority="1" />
+ <Item value="kvp" priority="0" />
+ <Item value="SetUpAttribute`0" priority="0" />
+ <Item value="ActionScheduler" priority="0" />
+ <Item value="SimpleAction" priority="0" />
+ <Item value="findJobToRun" priority="1" />
+ <Item value="_scheduler" priority="1" />
+ <Item value="_action" priority="0" />
+ <Item value="inputGenerator" priority="1" />
+ <Item value="deps" priority="0" />
+ <Item value="HashSet" priority="0" />
+ <Item value="ActionScheduler`0" priority="0" />
+ <Item value="_graph" priority="2" />
+ <Item value="target" priority="3" />
+ <Item value="jobs" priority="2" />
+ <Item value="GetJobsRequiredToGenerateTarget`0" priority="0" />
+ <Item value="jobsToGenerateInputFile" priority="0" />
+ <Item value="Count`1" priority="0" />
+ <Item value="Any`1" priority="0" />
+ <Item value="String`0" priority="1" />
+ <Item value="inputFile" priority="0" />
+ <Item value="bool" priority="0" />
+ <Item value="JobsRequiredToGetTargetUpdated`0" priority="0" />
+ <Item value="inputFilesAboutToBecomeRegenerated" priority="4" />
+ <Item value="yield return" priority="0" />
+ <Item value="System" priority="0" />
+ <Item value="Tuple`0" priority="0" />
+ <Item value="Tuple&lt;TargetGenerateSettings,IEnumerable&lt;string&gt;&gt;" priority="0" />
+ <Item value="SchedulableAction`0" priority="1" />
+ <Item value="SchedulableAction" priority="1" />
+ <Item value="generateSettings" priority="4" />
+ <Item value="Settings" priority="0" />
+ <Item value="NeedToGenerate`0" priority="0" />
+ <Item value="null" priority="1" />
+ <Item value="false" priority="0" />
+ <Item value="schedulableAction" priority="3" />
+ <Item value="actionScheduler" priority="2" />
+ <Item value="ActionRequiredToGetTargetUpdated`0" priority="0" />
+ <Item value="targetFile" priority="0" />
+ <Item value="throw" priority="0" />
+ <Item value="MissingDependencyException" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:cake.ITargetGeneratingAction">
+ <Item value="GetActionHash`0" priority="1" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:cake.TargetGenerateSettings">
+ <Item value="OutputFiles" priority="6" />
+ <Item value="InputFiles" priority="2" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:System.Collections.Generic.HashSet`1">
+ <Item value="Single`1" priority="3" />
+ <Item value="Where`1" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:@System.IO.File">
+ <Item value="WriteAllText`0" priority="1" />
+ <Item value="Exists`0" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:cake.DependencyGraph">
+ <Item value="RegisterTarget`0" priority="1" />
+ <Item value="RequestTarget`0" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:@NUnit.Framework.Assert">
+ <Item value="AreEqual`0" priority="1" />
+ <Item value="IsNull`0" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:System.Collections.Generic.Dictionary`2">
+ <Item value="Add`0" priority="0" />
+ <Item value="Remove`0" priority="0" />
+ <Item value="TryGetValue`0" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:System.Collections.Generic.List`1">
+ <Item value="Count" priority="1" />
+ <Item value="Remove`0" priority="0" />
+ <Item value="AddRange`0" priority="0" />
+ <Item value="Add`0" priority="1" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:System.Collections.Generic.IEnumerable`1">
+ <Item value="FirstOrDefault`1" priority="0" />
+ <Item value="ToArray`1" priority="0" />
+ <Item value="Any`1" priority="1" />
+ <Item value="Concat`1" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:System.Collections.Generic.KeyValuePair`2">
+ <Item value="Key" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:cake.ActionScheduler">
+ <Item value="FindJobToRun`0" priority="1" />
+ <Item value="Add`0" priority="0" />
+ </ItemStatistics>
+ <ItemStatistics item="Qualified:cake.SchedulableAction">
+ <Item value="Settings" priority="0" />
+ <Item value="InputFilesRequiringGeneration" priority="0" />
+ </ItemStatistics>
+ </CompletionStatisticsManager>
+ <RecentFiles>
+ <RecentFiles>
+ <File id="d:Miscellaneous Files/f:Microsoft.Common.targets/l:C!?Windows?Microsoft.NET?Framework?v4.0.30319?Microsoft.Common.targets" caret="66787" fromTop="23" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:SimpleAction.cs" caret="493" fromTop="22" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:SchedulableAction.cs" caret="323" fromTop="12" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:ActionScheduler.cs" caret="973" fromTop="30" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:ActionSchedulerTest.cs" caret="673" fromTop="18" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1759" fromTop="17" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:FileAssert.cs" caret="162" fromTop="9" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:SimpleCopyDepGraph.cs" caret="816" fromTop="14" />
+ </RecentFiles>
+ <RecentEdits>
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:ActionScheduler.cs" caret="672" fromTop="16" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:ActionSchedulerTest.cs" caret="1765" fromTop="28" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:ActionSchedulerTest.cs" caret="1671" fromTop="28" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:ActionScheduler.cs" caret="955" fromTop="25" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:ActionScheduler.cs" caret="461" fromTop="9" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1647" fromTop="20" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1506" fromTop="10" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1506" fromTop="17" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1506" fromTop="27" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1506" fromTop="26" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1506" fromTop="18" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1517" fromTop="0" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="2527" fromTop="29" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="2527" fromTop="18" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="2527" fromTop="24" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="2527" fromTop="5" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="2044" fromTop="26" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1410" fromTop="15" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:ActionSchedulerTest.cs" caret="859" fromTop="16" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:ActionScheduler.cs" caret="176" fromTop="8" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:ActionScheduler.cs" caret="310" fromTop="10" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:ActionSchedulerTest.cs" caret="1204" fromTop="10" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:ActionSchedulerTest.cs" caret="1515" fromTop="19" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:ActionSchedulerTest.cs" caret="614" fromTop="15" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="844" fromTop="18" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="639" fromTop="9" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/f:DependencyGraph.cs" caret="1131" fromTop="17" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:SimpleCopyDepGraph.cs" caret="947" fromTop="13" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:SimpleCopyDepGraph.cs" caret="1167" fromTop="13" />
+ <File id="F2546F61-0181-4E7D-AD26-5F20F9D2F888/d:Tests/f:SimpleCopyDepGraph.cs" caret="527" fromTop="6" />
+ </RecentEdits>
+ </RecentFiles>
+ <NAntValidationSettings>
+ <NAntPath value="" />
+ </NAntValidationSettings>
+ <UnitTestRunner>
+ <Providers />
+ </UnitTestRunner>
+ <UnitTestRunnerNUnit>
+ <NUnitInstallDir>C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\</NUnitInstallDir>
+ <UseAddins>Never</UseAddins>
+ </UnitTestRunnerNUnit>
+</Configuration>
View
1  cake.csproj
@@ -57,6 +57,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecursiveIncludeScanner.cs" />
+ <Compile Include="SchedulableAction.cs" />
<Compile Include="TargetGenerateSettings.cs" />
<Compile Include="CCompilerTask.cs" />
<Compile Include="GenerationReason.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.