Permalink
Browse files

work towards having an ActionScheduler. add Moq

  • Loading branch information...
1 parent 8d6600d commit 2b57288a450f68f898adff514f312d26063b4ff0 Lucas Meijer committed Apr 15, 2012
View
@@ -0,0 +1,18 @@
+using System;
+using cake;
+
+namespace bs
+{
+ public class ActionScheduler
+ {
+ public void Add(string target, TargetGenerateSettings tgs, string[] dependenciesRequiringRegeneration)
+ {
+ throw new NotImplementedException();
+ }
+
+ public TargetGenerateSettings FindJobToRun()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
View
@@ -1,4 +1,6 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
+using System.IO;
using cake.Tests;
namespace cake
@@ -23,5 +25,18 @@ public IEnumerable<string> GetInputFiles()
foreach (var file in scanner.GetFilesIncludedBy(_sourceFile))
yield return file;
}
+
+ public void RegisterWithDepGraph(DependencyGraph depGraph)
+ {
+ var action = new SimpleAction(Execute, "todo");
+ var settings = new TargetGenerateSettings(action, GetInputFiles(), _targetFile);
+ depGraph.RegisterTarget(settings);
+ }
+
+ public void Execute(TargetGenerateSettings settings)
+ {
+ //todo
+ File.Copy(_sourceFile, _targetFile, true);
+ }
}
}
View
@@ -8,7 +8,7 @@ namespace cake
public class DependencyGraph
{
readonly Dictionary<string, TargetGenerateSettings> _graph = new Dictionary<string, TargetGenerateSettings>();
- public Action<string, TargetGenerateSettings> GenerateCallback = (s, i) => { };
+ public Action<TargetGenerateSettings> GenerateCallback = s => { };
private readonly BuildHistory _buildHistory;
public DependencyGraph() : this(new BuildHistory())
@@ -28,7 +28,7 @@ public void RequestTarget(string targetFile)
throw new MissingDependencyException();
if (NeedToGenerate(targetFile, instructions))
- Generate(targetFile, instructions);
+ Generate(instructions);
}
private bool NeedToGenerate(string targetFile, TargetGenerateSettings generateSettings)
@@ -50,13 +50,16 @@ private bool NeedToGenerate(string targetFile, TargetGenerateSettings generateSe
return generateSettings.InputFiles.Any(sourceFile => recordOfLastBuild.ModificationTimeOf(sourceFile) != File.GetLastWriteTimeUtc(sourceFile));
}
- private void Generate(string targetFile, TargetGenerateSettings settings)
+ private void Generate(TargetGenerateSettings settings)
{
- GenerateCallback(targetFile, settings);
+ GenerateCallback(settings);
settings.Action.Invoke(settings);
- var record = new GenerationRecord(targetFile, settings);
- _buildHistory.AddRecord(record);
+ foreach (var outputFile in settings.OutputFiles)
+ {
+ var record = new GenerationRecord(outputFile, settings);
+ _buildHistory.AddRecord(record);
+ }
}
public void RegisterTarget(TargetGenerateSettings settings)
View
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace bs
+{
+ enum GenerationReason
+ {
+ NeverBuilt,
+ Missing,
+ InputFilesWereModifiedSinceLastGeneration,
+ DifferentSettingsThanLastGeneration
+ }
+}
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using cake;
+using cake.Tests;
+using NUnit.Framework;
+
+namespace bs.Tests
+{
+ [TestFixture]
+ public class ActionSchedulerTest
+ {
+ [Test]
+ [Ignore]
+ public void Test()
+ {
+ var scheduler = new ActionScheduler();
+
+ var action = new SimpleAction(s => { });
+ var tgs = new TargetGenerateSettings(action, new[] {"input"}, "output");
+ scheduler.Add("output", tgs, new string[0]);
+
+ var jobToRun = scheduler.FindJobToRun();
+
+ }
+ }
+}
@@ -30,7 +30,7 @@ public void Setup()
protected void ThrowIfDepgraphGenerates()
{
- _depGraph.GenerateCallback += (target, instructions) => { throw new InvalidOperationException(); };
+ _depGraph.GenerateCallback += settings => { throw new InvalidOperationException(); };
}
View
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace cake.Tests
+{
+ [TestFixture]
+ public class GeneratedHeader : DependencyGraphTests
+ {
+ [Test]
+ [Ignore]
+ public void Test()
+ {
+ var generateHeaderAction = new SimpleAction(s => File.Copy(s.InputFiles.Single(), s.OutputFiles.Single(), true));
+ var generateHeaderSettings = new TargetGenerateSettings(generateHeaderAction, new[] { "file1" }, "myheader.h");
+
+ File.WriteAllText("file1","//theboss");
+ File.WriteAllText("test.c","#include <myheader.h>");
+ var compilecppfile = new CCompilerTask("test.o", "test.c", new string[] {});
+
+ _depGraph.RegisterTarget(generateHeaderSettings);
+ compilecppfile.RegisterWithDepGraph(_depGraph);
+
+ _depGraph.RequestTarget("test.o");
+ }
+ }
+}
View
@@ -7,6 +7,11 @@ class SimpleAction : ITargetGeneratingAction
private readonly Action<TargetGenerateSettings> _invoke;
private readonly string _actionHash;
+ public SimpleAction(Action<TargetGenerateSettings> invoke)
+ : this(invoke,"defaulthash")
+ {
+ }
+
public SimpleAction(Action<TargetGenerateSettings> invoke, string actionHash)
{
_invoke = invoke;
View
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
View
@@ -11,7 +11,8 @@
<RootNamespace>bs</RootNamespace>
<AssemblyName>bs</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -34,7 +35,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+ <Reference Include="Moq">
+ <HintPath>libs\Moq.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>libs\nunit.framework.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -52,18 +59,25 @@
<Compile Include="RecursiveIncludeScanner.cs" />
<Compile Include="TargetGenerateSettings.cs" />
<Compile Include="CCompilerTask.cs" />
+ <Compile Include="GenerationReason.cs" />
+ <Compile Include="ActionScheduler.cs" />
+ <Compile Include="Tests\ActionSchedulerTest.cs" />
<Compile Include="Tests\CCompilerTests.cs" />
<Compile Include="Tests\DependencyGraphTests.cs" />
<Compile Include="DependencyGraph.cs" />
<Compile Include="MissingDependencyException.cs" />
<Compile Include="Tests\DifferentInputFiles.cs" />
<Compile Include="IncludeScanner.cs" />
+ <Compile Include="Tests\GeneratedHeader.cs" />
<Compile Include="Tests\IncludeScannerTest.cs" />
<Compile Include="Tests\SimpleAction.cs" />
<Compile Include="Tests\SimpleCopyDepGraph.cs" />
<Compile Include="ITargetGeneratingAction.cs" />
<Compile Include="Tests\TargetWithoutSources.cs" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
Binary file not shown.
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit 2b57288

Please sign in to comment.