Permalink
Browse files

make chained dependencies work

  • Loading branch information...
Lucas Meijer
Lucas Meijer committed Apr 15, 2012
1 parent 9bc54cb commit 84ea5e61d68bae1d6b63f396107f8e48f46d9401
View
@@ -18,18 +18,18 @@ public CCompilerTask(string targetFile, string sourceFile, string[] includePaths
_includePaths = includePaths;
}
- public IEnumerable<string> GetInputFiles()
+ public IEnumerable<string> GetInputFiles(DependencyGraph depGraph)
{
var scanner = new RecursiveIncludeScanner(_includePaths, new IncludeScanner());
yield return _sourceFile;
- foreach (var file in scanner.GetFilesIncludedBy(_sourceFile))
+ foreach (var file in scanner.GetFilesIncludedBy(_sourceFile, depGraph))
yield return file;
}
public void RegisterWithDepGraph(DependencyGraph depGraph)
{
var action = new SimpleAction(Execute, "todo");
- var settings = new TargetGenerateSettings(action, GetInputFiles(), _targetFile);
+ var settings = new TargetGenerateSettings(action, GetInputFiles(depGraph), _targetFile);
depGraph.RegisterTarget(settings);
}
View
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
namespace cake
{
@@ -14,20 +15,22 @@ public RecursiveIncludeScanner(string[] includePaths, IncludeScanner scanner)
_includeScanner = scanner;
}
- public IEnumerable<string> GetFilesIncludedBy(string file)
+ public IEnumerable<string> GetFilesIncludedBy(string file, DependencyGraph depGraph)
{
foreach (var includedFile in _includeScanner.Scan(file))
{
- var foundIncludeFile = FindSpecifiedIncludeFileInSearchDirs(includedFile);
+ var foundIncludeFile = FindSpecifiedIncludeFileInSearchDirs(depGraph,includedFile);
if (foundIncludeFile == null)
throw new InvalidOperationException("unable to find the header file: " + includedFile + " in the header search paths.");
yield return foundIncludeFile;
- foreach (var file2 in GetFilesIncludedBy(foundIncludeFile))
+ if (!File.Exists(foundIncludeFile))
+ continue;
+ foreach (var file2 in GetFilesIncludedBy(foundIncludeFile, depGraph))
yield return file2;
}
}
- private string FindSpecifiedIncludeFileInSearchDirs(string includedFile)
+ private string FindSpecifiedIncludeFileInSearchDirs(DependencyGraph depGraph, string includedFile)
{
return includedFile;
}
View
@@ -8,7 +8,7 @@ public class SchedulableAction
public IEnumerable<string> InputFilesRequiringGeneration;
public SchedulableAction(TargetGenerateSettings generateSettings)
- :this(generateSettings,new List<string>())
+ : this(generateSettings, new List<string>())
{
}
@@ -18,19 +18,22 @@ 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;
- //if (File.Exists(target))
- // return null;
- //throw new MissingDependencyException();
- }
var inputFilesRequiringGeneration = generateSettings.InputFiles.Where(inputfile => ActionRequiredToGetTargetUpdated(inputfile) != null).ToArray();
View
@@ -35,8 +35,14 @@ public override bool Equals(object obj)
if (ActionHash != other.ActionHash)
return false;
-
- return other.InputFiles.SetEquals(InputFiles);
+
+ if (!other.InputFiles.SetEquals(InputFiles))
+ return false;
+
+ if (!other.OutputFiles.SetEquals(OutputFiles))
+ return false;
+
+ return true;
}
public override int GetHashCode()
View
@@ -1,4 +1,5 @@
using System.IO;
+using Moq;
using NUnit.Framework;
namespace cake.Tests
@@ -13,7 +14,8 @@ public void GetInputFilesFindsRecursiveHeaderDependencies()
File.WriteAllText("test.h", "#include <shared.h>");
File.WriteAllText("shared.h", "//like a boss");
var task = new CCompilerTask("test.o", "test.c", new[] {""});
- var inputfiles = task.GetInputFiles();
+ var depGraph = new Mock<DependencyGraph>().Object;
+ var inputfiles = task.GetInputFiles(depGraph);
CollectionAssert.AreEquivalent(new [] {"test.c","test.h","shared.h"}, inputfiles);
}
@@ -5,7 +5,6 @@
namespace cake.Tests
{
- [TestFixture]
public class DependencyGraphTests
{
[SetUp]
@@ -32,9 +31,5 @@ protected void ThrowIfDepgraphGenerates()
{
_depGraph.GenerateCallback += settings => { throw new InvalidOperationException(); };
}
-
-
-
-
}
}
View
@@ -11,7 +11,6 @@ namespace cake.Tests
public class GeneratedHeader : DependencyGraphTests
{
[Test]
- [Ignore]
public void Test()
{
var generateHeaderAction = new SimpleAction(s => File.Copy(s.InputFiles.Single(), s.OutputFiles.Single(), true));
@@ -20,8 +19,6 @@ public void Test()
File.WriteAllText("file1","//theboss");
File.WriteAllText("test.c","#include <myheader.h>");
- //temp:
- File.WriteAllText("myheader.h","doesalreadyexisttemporary" );
var compilecppfile = new CCompilerTask("test.o", "test.c", new string[] {});
_depGraph.RegisterTarget(generateHeaderSettings);
@@ -1,28 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using cake;
-using cake.Tests;
using NUnit.Framework;
-namespace bs.Tests
+namespace cake.Tests
{
[TestFixture]
class SchedulableActionCollectorTest
{
+ DependencyGraph _depGraph;
+ SchedulableActionCollector _collector;
+
+ [SetUp]
+ public void Setup()
+ {
+ _depGraph = new DependencyGraph();
+ _collector = new SchedulableActionCollector(_depGraph);
+ }
+
[Test]
public void CanCollectSingleAction()
{
- var depGraph = new DependencyGraph();
- var a = new SchedulableActionCollector(depGraph);
-
var settings = new TargetGenerateSettings(new SimpleAction(s=> { }), new[] {"input"}, "output");
- depGraph.RegisterTarget(settings);
- var result = a.CollectActionsToGenerate("output").ToArray();
+ _depGraph.RegisterTarget(settings);
+ var result = _collector.CollectActionsToGenerate("output").ToArray();
Assert.AreEqual(1, result.Length);
- Assert.AreEqual(settings,result[0].Settings);
+ Assert.AreEqual(settings, result[0].Settings);
+ }
+
+ [Test]
+ public void CanCollectMultipleActions()
+ {
+ var settings1 = new TargetGenerateSettings(new SimpleAction(s => { }), new[] { "file1" }, "file2");
+ _depGraph.RegisterTarget(settings1);
+
+ var settings2 = new TargetGenerateSettings(new SimpleAction(s => { }), new[] { "file2" }, "file3");
+ _depGraph.RegisterTarget(settings2);
+
+ var result = _collector.CollectActionsToGenerate("file3").ToArray();
+
+ Assert.AreEqual(2, result.Length);
+
+ //HALP! how to do a more reasonable equivalenec test?
+ CollectionAssert.AreEquivalent(result.Select(r=>r.Settings), new[] { settings1,settings2});
+ CollectionAssert.AreEquivalent(result.Select(r => r.InputFilesRequiringGeneration), new[] { new string[0], new[]{"file2"}});
}
}
}

0 comments on commit 84ea5e6

Please sign in to comment.