Skip to content
Browse files

always build if we never built before

  • Loading branch information...
1 parent 0a856a3 commit 8bbef56ae3516d8f75463f93658fc1c286df73f8 Lucas Meijer committed Apr 14, 2012
Showing with 55 additions and 43 deletions.
  1. +3 −1 BuildHistory.cs
  2. +8 −2 DependencyGraph.cs
  3. +5 −0 GenerationRecord.cs
  4. +19 −3 Tests/SimpleCopyDepGraph.cs
  5. +20 −37 Tests/TargetWithoutSources.cs
View
4 BuildHistory.cs
@@ -14,7 +14,9 @@ public void AddRecord(GenerationRecord record)
public GenerationRecord FindRecordFor(string targetFile)
{
- return _records[targetFile];
+ GenerationRecord result = null;
+ _records.TryGetValue(targetFile,out result);
+ return result;
}
}
}
View
10 DependencyGraph.cs
@@ -24,10 +24,16 @@ public void RequestTarget(string targetFile)
private bool NeedToGenerate(string targetFile, TargetBuildInstructions instructions)
{
- if (!File.Exists(targetFile))
+ var recordOfLastBuild = _buildHistory.FindRecordFor(targetFile);
+
+ if (recordOfLastBuild == null)
return true;
- var recordOfLastBuild = _buildHistory.FindRecordFor(targetFile);
+ if (!File.Exists(targetFile))
+ return true;
+
+ if (File.GetLastWriteTimeUtc(targetFile) < recordOfLastBuild.ModificationTimeOfTargetFile())
+ return true;
return instructions.SourceFiles.Any(sourceFile => recordOfLastBuild.ModificationTimeOf(sourceFile) != File.GetLastWriteTimeUtc(sourceFile));
}
View
5 GenerationRecord.cs
@@ -32,5 +32,10 @@ public DateTime ModificationTimeOf(string file)
{
return _modificationDates[file];
}
+
+ public DateTime ModificationTimeOfTargetFile()
+ {
+ return ModificationTimeOf(TargetFile);
+ }
}
}
View
22 Tests/SimpleCopyDepGraph.cs
@@ -9,17 +9,22 @@ namespace bs.Tests
{
class SimpleCopyDepGraph : DependencyGraphTests
{
+ [SetUp]
+ public void Setup()
+ {
+ SetupSimpleCopyDepGraph();
+ }
+
+
[Test]
public void ThrowsIfDependencyDoesNotExist()
{
- SetupSimpleCopyDepGraph();
Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
}
[Test]
public void RegeneratesWhenSourceChanges()
{
- SetupSimpleCopyDepGraph();
Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
WriteToSourceRunDepGraphAndVerifyTarget("One");
@@ -36,7 +41,6 @@ private void WriteToSourceRunDepGraphAndVerifyTarget(string contents)
[Test]
public void WillNotRegeneratesWhenSourceDidNotChange()
{
- SetupSimpleCopyDepGraph();
Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
WriteToSourceRunDepGraphAndVerifyTarget("One");
@@ -45,6 +49,18 @@ public void WillNotRegeneratesWhenSourceDidNotChange()
_depGraph.RequestTarget(defaulttargetFile);
}
+ [Test]
+ public void WillNotRegeneratesWhenTargetGotManuallyUpdated()
+ {
+ Assert.Throws<MissingDependencyException>(() => _depGraph.RequestTarget(defaulttargetFile));
+
+ WriteToSourceRunDepGraphAndVerifyTarget("One");
+
+ File.WriteAllText(defaulttargetFile, "Three");
+ ThrowIfDepgraphGenerates();
+ _depGraph.RequestTarget(defaulttargetFile);
+ }
+
private void SetupSimpleCopyDepGraph()
{
_depGraph.RegisterTarget(defaulttargetFile, new TargetBuildInstructions()
View
57 Tests/TargetWithoutSources.cs
@@ -1,65 +1,48 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
+using System.IO;
using System.Linq;
-using System.Text;
using NUnit.Framework;
namespace bs.Tests
{
class TargetWithoutSources : DependencyGraphTests
{
+ [SetUp]
+ public void Setup()
+ {
+ SetupGraphWithOneTargetWithoutSources();
+ }
+
[Test]
public void WillGenerateTargetWithoutSources()
{
- DependencyGraph depGraph = SetupGraphWithOneTargetWithoutSources();
-
- depGraph.RequestTarget(defaulttargetFile);
+ _depGraph.RequestTarget(defaulttargetFile);
FileAssert.Contains(defaulttargetFile, "Hello");
}
[Test]
public void WontGenerateTargetWithoutSourcesTwice()
{
- DependencyGraph depGraph = SetupGraphWithOneTargetWithoutSources();
-
- depGraph.RequestTarget(defaulttargetFile);
+ _depGraph.RequestTarget(defaulttargetFile);
FileAssert.Contains(defaulttargetFile, "Hello");
ThrowIfDepgraphGenerates();
- depGraph.RequestTarget(defaulttargetFile);
- }
-
- private static DependencyGraph SetupGraphWithOneTargetWithoutSources()
- {
- var depGraph = new DependencyGraph();
- depGraph.RegisterTarget(defaulttargetFile, new TargetBuildInstructions()
- {
- Action = (target,sources) => File.WriteAllText(target, "Hello"),
- SourceFiles = new string[0],
- });
- return depGraph;
+ _depGraph.RequestTarget(defaulttargetFile);
}
[Test]
- public void ThrowsIfDependencyDoesNotExist()
+ public void WillGenerateTargetIfItWasNeverBuiltBefore()
{
- DependencyGraph depGraph = SetupSimpleCopyDepGraph();
- Assert.Throws<MissingDependencyException>(() => depGraph.RequestTarget(defaulttargetFile));
+ File.WriteAllText(defaulttargetFile, "One");
+ _depGraph.RequestTarget(defaulttargetFile);
+ FileAssert.Contains(defaulttargetFile, "Hello");
}
- [Test]
- public void RegeneratesWhenSourceChanges()
+ private void SetupGraphWithOneTargetWithoutSources()
{
- DependencyGraph depGraph = SetupSimpleCopyDepGraph();
- Assert.Throws<MissingDependencyException>(() => depGraph.RequestTarget(defaulttargetFile));
-
- File.WriteAllText(defaultSourceFile, "One");
- depGraph.RequestTarget(defaulttargetFile);
- FileAssert.Contains(defaultSourceFile, "One");
-
- File.WriteAllText(defaultSourceFile, "Two");
- depGraph.RequestTarget(defaulttargetFile);
- FileAssert.Contains(defaultSourceFile, "Two");
+ _depGraph.RegisterTarget(defaulttargetFile, new TargetBuildInstructions()
+ {
+ Action = (target,sources) => File.WriteAllText(target, "Hello"),
+ SourceFiles = new string[0],
+ });
}
private static DependencyGraph SetupSimpleCopyDepGraph()

0 comments on commit 8bbef56

Please sign in to comment.
Something went wrong with that request. Please try again.