Skip to content
Browse files

Modified Prerequisites are being computed.

  • Loading branch information...
1 parent 5819eab commit f148e990bfe6d3104f64bf3b0b96d0a01e7f36c4 @KrisJordan committed Jan 5, 2011
Showing with 86 additions and 37 deletions.
  1. +4 −1 Cakefile
  2. +10 −10 docs/icing.html
  3. +33 −10 docs/rules.html
  4. +7 −5 src/icing.coffee
  5. +32 −11 src/rules.coffee
View
5 Cakefile
@@ -12,7 +12,10 @@ task 'test', ['spec/*'], (options) ->
this.exec command
task 'docs', 'Generate docco documentation', ['src/*'],
- exec: (options) -> this.exec "docco #{this.prereqs.join(' ')}"
+ exec: (options) ->
+ modified = this.modifiedPrereqs
+ console.log modified
+ this.exec "docco #{modified.join(' ')}"
outputs: ->
for prereq in this.prereqs
prereq.replace /src\/(.*).coffee/,"docs/$1.html"
View
20 docs/icing.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>icing.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="dag.html"> dag.coffee </a> <a class="source" href="icing.html"> icing.coffee </a> <a class="source" href="rules.html"> rules.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> icing.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><strong>icing</strong> adds dependency management to Cakefiles by extending and
+<!DOCTYPE html> <html> <head> <title>icing.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="icing.html"> icing.coffee </a> <a class="source" href="rules.html"> rules.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> icing.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><strong>icing</strong> adds dependency management to Cakefiles by extending and
slightly modifying cake's "task" function. Add icing to your Cakefiles by adding
a single line:</p>
@@ -67,8 +67,7 @@
<span class="nv">description = </span><span class="nx">target</span>
<span class="k">else</span>
<span class="nv">recipe = </span><span class="nx">prereqs</span>
- <span class="nv">prereqs = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Add a rule to the rule graph.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">graph</span><span class="p">.</span><span class="nx">rule</span> <span class="k">new</span> <span class="nx">Rule</span> <span class="nx">target</span><span class="p">,</span> <span class="nx">prereqs</span><span class="p">,</span> <span class="nx">recipe</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Bootstrap into cake's task book keeping</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">cakeTask</span> <span class="nx">target</span><span class="p">,</span> <span class="nx">description</span><span class="p">,</span> <span class="nf">(options) -&gt;</span>
- <span class="nv">recipeNodes = </span><span class="nx">graph</span><span class="p">.</span><span class="nx">recipeNodesTo</span> <span class="nx">target</span>
+ <span class="nv">prereqs = </span><span class="p">[]</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Add a rule to the rule graph.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">graph</span><span class="p">.</span><span class="nx">rule</span> <span class="k">new</span> <span class="nx">Rule</span> <span class="nx">target</span><span class="p">,</span> <span class="nx">prereqs</span><span class="p">,</span> <span class="nx">recipe</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Bootstrap into cake's task book keeping</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">cakeTask</span> <span class="nx">target</span><span class="p">,</span> <span class="nx">description</span><span class="p">,</span> <span class="nf">(options) -&gt;</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>TODO add watch support</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">recipeNodes = </span><span class="nx">graph</span><span class="p">.</span><span class="nx">recipeNodesTo</span> <span class="nx">target</span>
<span class="nv">aRecipeRan = </span><span class="kc">false</span>
<span class="nv">allRecipesRan = </span><span class="kc">false</span>
<span class="nv">recipeNode = </span><span class="p">{}</span>
@@ -89,7 +88,7 @@
<span class="nx">do</span> <span class="nx">runNextRecipeCallback</span>
<span class="k">else</span>
<span class="nv">allRecipesRan = </span><span class="kc">true</span>
- <span class="k">if</span> <span class="o">not</span> <span class="nx">aRecipeRan</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Homage</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;cake: Nothing to be done for `#{target}&#39;.&quot;</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">aRecipeRan</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Homage</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;cake: Nothing to be done for `#{target}&#39;.&quot;</span>
<span class="nx">do</span> <span class="nx">runNextRecipeCallback</span>
@@ -98,7 +97,7 @@
<span class="nv">tasksLeft = </span><span class="nx">recipeNodes</span><span class="p">.</span><span class="nx">pluck</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="s2">&quot;\nError: task `#{recipeNode.name}` did not complete.\n&quot;</span> <span class="o">+</span>
<span class="s2">&quot;Tasks [#{tasksLeft}] should have run, but did not.\n&quot;</span> <span class="o">+</span>
- <span class="s2">&quot;Task `#{recipeNode.name}` should call this.finished() or this.failed(message).\n&quot;</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>Helpers</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Set-up the context that a recipe exec is run in.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">runRecipeContext = </span><span class="nf">(graph, recipeNode, runNextRecipeCallback, options) -&gt;</span>
+ <span class="s2">&quot;Task `#{recipeNode.name}` should call this.finished() or this.failed(message).\n&quot;</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <h3>Helpers</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Set-up the context that a recipe exec is run in.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">runRecipeContext = </span><span class="nf">(graph, recipeNode, runNextRecipeCallback, options) -&gt;</span>
<span class="nv">finishedFn = </span><span class="o">-&gt;</span> <span class="nx">do</span> <span class="nx">runNextRecipeCallback</span>
@@ -126,11 +125,12 @@
<span class="nx">do</span> <span class="nx">runNextCommandCallback</span>
<span class="k">return</span> <span class="p">{</span>
- <span class="nv">callback: </span> <span class="nx">runNextRecipeCallback</span>
- <span class="nv">finished: </span> <span class="nx">finishedFn</span>
- <span class="nv">failed: </span> <span class="nx">failedFn</span>
- <span class="nv">prereqs: </span> <span class="nx">recipeNode</span><span class="p">.</span><span class="nx">prereqs</span><span class="p">(</span><span class="nx">graph</span><span class="p">).</span><span class="nx">names</span><span class="p">()</span>
- <span class="nv">exec: </span> <span class="nx">execFn</span>
+ <span class="nv">callback: </span> <span class="nx">runNextRecipeCallback</span>
+ <span class="nv">finished: </span> <span class="nx">finishedFn</span>
+ <span class="nv">failed: </span> <span class="nx">failedFn</span>
+ <span class="nv">prereqs: </span> <span class="nx">recipeNode</span><span class="p">.</span><span class="nx">prereqs</span><span class="p">(</span><span class="nx">graph</span><span class="p">).</span><span class="nx">names</span><span class="p">()</span>
+ <span class="nv">modifiedPrereqs: </span> <span class="nx">recipeNode</span><span class="p">.</span><span class="nx">modifiedPrereqs</span><span class="p">(</span><span class="nx">graph</span><span class="p">).</span><span class="nx">names</span><span class="p">()</span>
+ <span class="nv">exec: </span> <span class="nx">execFn</span>
<span class="p">}</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
43 docs/rules.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>rules.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="dag.html"> dag.coffee </a> <a class="source" href="icing.html"> icing.coffee </a> <a class="source" href="rules.html"> rules.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> rules.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><strong>rules</strong> models task pipelines using directed acyclic graph (<strong>dag.coffee</strong>) primitives.
+<!DOCTYPE html> <html> <head> <title>rules.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> rules.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><strong>rules</strong> models task pipelines using directed acyclic graph (<strong>dag.coffee</strong>) primitives.
Following in the heritage of <em>make</em>, rules have a target, prerequisites, and a recipe.
Unlike <em>make</em> target is a symbolic name and prerequisites can refer to other rules or to
files on disk.</p>
@@ -82,18 +82,41 @@
<span class="nv">clone: </span><span class="nf">(node) -&gt;</span> <span class="k">new</span> <span class="nx">RecipeNode</span> <span class="nx">@name</span><span class="p">,</span> <span class="nx">@recipe</span>
<span class="nv">prereqs: </span><span class="nf">(graph) -&gt;</span> <span class="nx">graph</span><span class="p">.</span><span class="nx">arcs</span><span class="p">.</span><span class="nx">to</span><span class="p">(</span><span class="nx">graph</span><span class="p">.</span><span class="nx">node</span> <span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">).</span><span class="nx">from</span><span class="p">().</span><span class="nx">ofType</span> <span class="nx">FileNode</span>
<span class="nv">outputs: </span><span class="nf">(graph) -&gt;</span> <span class="nx">graph</span><span class="p">.</span><span class="nx">arcs</span><span class="p">.</span><span class="nx">from</span><span class="p">(</span><span class="nx">graph</span><span class="p">.</span><span class="nx">node</span> <span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">).</span><span class="nx">to</span><span class="p">().</span><span class="nx">ofType</span> <span class="nx">FileNode</span>
- <span class="nv">shouldRun: </span><span class="nf">(graph) -&gt;</span>
- <span class="nv">prereqs = </span><span class="k">this</span><span class="p">.</span><span class="nx">prereqs</span> <span class="nx">graph</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Recipes without prereqs always run</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">prereqs</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">()</span> <span class="k">then</span> <span class="k">return</span> <span class="kc">true</span>
-
- <span class="nv">outputs = </span><span class="k">this</span><span class="p">.</span><span class="nx">outputs</span> <span class="nx">graph</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Recipes without file outputs always run</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">outputs</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">()</span> <span class="k">then</span> <span class="k">return</span> <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>There are file inputs and outputs. If there is the same number of inputs
+ <span class="nv">modifiedPrereqs: </span><span class="nf">(graph) -&gt;</span>
+ <span class="nv">prereqs = </span><span class="k">this</span><span class="p">.</span><span class="nx">prereqs</span> <span class="nx">graph</span>
+ <span class="nv">outputs = </span><span class="k">this</span><span class="p">.</span><span class="nx">outputs</span> <span class="nx">graph</span>
+ <span class="k">if</span> <span class="nx">prereqs</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">()</span> <span class="o">or</span> <span class="nx">outputs</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">()</span> <span class="k">then</span> <span class="k">return</span> <span class="nx">prereqs</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>There are file inputs and outputs. If there is the same number of inputs
as outputs we take a special case and compare them 1 by 1. If there are
a different number of inputs and outputs we check to see if the greatest
modified time of the inputs is greater than the oldest output. If so we
-should run.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">prereqs</span><span class="p">.</span><span class="nx">count</span><span class="p">()</span> <span class="o">==</span> <span class="nx">outputs</span><span class="p">.</span><span class="nx">count</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>TODO: special case</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="kc">true</span>
+should run.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">prereqs</span><span class="p">.</span><span class="nx">count</span><span class="p">()</span> <span class="o">==</span> <span class="nx">outputs</span><span class="p">.</span><span class="nx">count</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">new</span> <span class="nx">NodeList</span> <span class="nx">_</span><span class="p">(</span><span class="nx">_</span><span class="p">.</span><span class="nx">zip</span> <span class="nx">prereqs</span><span class="p">.</span><span class="nx">items</span><span class="p">,</span><span class="nx">outputs</span><span class="p">.</span><span class="nx">items</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">chain</span><span class="p">()</span>
+ <span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nf">(pair) -&gt;</span>
+ <span class="p">[</span><span class="nx">input</span><span class="p">,</span><span class="nx">output</span><span class="p">]</span> <span class="o">=</span> <span class="nx">pair</span>
+ <span class="nv">inputTime = </span><span class="nx">input</span><span class="p">.</span><span class="nx">mtime</span> <span class="o">||</span> <span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">()</span>
+ <span class="nv">outputTime = </span><span class="nx">output</span><span class="p">.</span><span class="nx">mtime</span> <span class="o">||</span> <span class="mi">0</span>
+ <span class="k">if</span> <span class="nx">inputTime</span> <span class="o">&gt;</span> <span class="nx">outputTime</span>
+ <span class="nx">input</span>
+ <span class="k">else</span>
+ <span class="kc">false</span>
+ <span class="p">)</span>
+ <span class="p">.</span><span class="nx">compact</span><span class="p">()</span>
+ <span class="p">.</span><span class="nx">value</span><span class="p">()</span>
<span class="k">else</span>
- <span class="nv">prereqMax = </span><span class="nx">_</span><span class="p">(</span><span class="nx">prereqs</span><span class="p">.</span><span class="nx">items</span><span class="p">).</span><span class="nx">max</span> <span class="nf">(fileNode) -&gt;</span> <span class="nx">fileNode</span><span class="p">.</span><span class="nx">mtime</span> <span class="o">||</span> <span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">()</span>
- <span class="nv">outputMin = </span><span class="nx">_</span><span class="p">(</span><span class="nx">outputs</span><span class="p">.</span><span class="nx">items</span><span class="p">).</span><span class="nx">min</span> <span class="nf">(fileNode) -&gt;</span> <span class="nx">fileNode</span><span class="p">.</span><span class="nx">mtime</span> <span class="o">||</span> <span class="mi">0</span>
- <span class="k">return</span> <span class="nx">prereqMax</span><span class="p">.</span><span class="nx">mtime</span> <span class="o">&gt;</span> <span class="nx">outputMin</span><span class="p">.</span><span class="nx">mtime</span>
+ <span class="nv">prereqMax = </span><span class="nx">_</span><span class="p">(</span><span class="nx">prereqs</span><span class="p">.</span><span class="nx">items</span><span class="p">).</span><span class="nx">max</span> <span class="nf">(fileNode) -&gt;</span> <span class="nx">fileNode</span><span class="p">.</span><span class="nx">mtime</span> <span class="o">||=</span> <span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">()</span>
+ <span class="nv">outputMin = </span><span class="nx">_</span><span class="p">(</span><span class="nx">outputs</span><span class="p">.</span><span class="nx">items</span><span class="p">).</span><span class="nx">min</span> <span class="nf">(fileNode) -&gt;</span> <span class="nx">fileNode</span><span class="p">.</span><span class="nx">mtime</span> <span class="o">||=</span> <span class="mi">0</span>
+ <span class="k">if</span> <span class="nx">prereqMax</span><span class="p">.</span><span class="nx">mtime</span> <span class="o">&gt;</span> <span class="nx">outputMin</span><span class="p">.</span><span class="nx">mtime</span>
+ <span class="k">return</span> <span class="nx">prereqs</span>
+ <span class="k">else</span>
+ <span class="k">return</span> <span class="k">new</span> <span class="nx">NodeList</span>
+
+ <span class="nv">shouldRun: </span><span class="nf">(graph) -&gt;</span>
+ <span class="nv">prereqs = </span><span class="k">this</span><span class="p">.</span><span class="nx">prereqs</span> <span class="nx">graph</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Recipes without prereqs always run</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">prereqs</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">()</span> <span class="k">then</span> <span class="k">return</span> <span class="kc">true</span>
+
+ <span class="nv">outputs = </span><span class="k">this</span><span class="p">.</span><span class="nx">outputs</span> <span class="nx">graph</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Recipes without file outputs always run</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">outputs</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">()</span> <span class="k">then</span> <span class="k">return</span> <span class="kc">true</span>
+
+ <span class="k">return</span> <span class="o">not</span> <span class="k">this</span><span class="p">.</span><span class="nx">modifiedPrereqs</span><span class="p">(</span><span class="nx">graph</span><span class="p">).</span><span class="nx">isEmpty</span><span class="p">()</span>
<span class="nv">run: </span><span class="nf">(context, options) -&gt;</span> <span class="nx">@recipe</span><span class="p">.</span><span class="nx">exec</span><span class="p">.</span><span class="nx">call</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">options</span>
@@ -107,6 +130,6 @@
<span class="vi">@mtime = </span><span class="kc">undefined</span>
<span class="nv">equals: </span><span class="nf">(node) -&gt;</span>
<span class="k">super</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">node</span> <span class="k">instanceof</span> <span class="nx">FileNode</span>
- <span class="nv">clone: </span><span class="nf">(node) -&gt;</span> <span class="k">new</span> <span class="nx">FileNode</span> <span class="nx">@name</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <h3>Exports</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nx">_</span><span class="p">(</span><span class="nx">exports</span><span class="p">).</span><span class="nx">extend</span> <span class="p">{</span> <span class="nx">RuleGraph</span><span class="p">,</span> <span class="nx">Rule</span><span class="p">,</span> <span class="nx">RecipeNode</span><span class="p">,</span> <span class="nx">FileNode</span><span class="p">,</span> <span class="nx">Recipe</span> <span class="p">}</span>
+ <span class="nv">clone: </span><span class="nf">(node) -&gt;</span> <span class="k">new</span> <span class="nx">FileNode</span> <span class="nx">@name</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <h3>Exports</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nx">_</span><span class="p">(</span><span class="nx">exports</span><span class="p">).</span><span class="nx">extend</span> <span class="p">{</span> <span class="nx">RuleGraph</span><span class="p">,</span> <span class="nx">Rule</span><span class="p">,</span> <span class="nx">RecipeNode</span><span class="p">,</span> <span class="nx">FileNode</span><span class="p">,</span> <span class="nx">Recipe</span> <span class="p">}</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
12 src/icing.coffee
@@ -78,6 +78,7 @@ global.task = (target, description, prereqs=undefined, recipe=undefined) ->
# Bootstrap into cake's task book keeping
cakeTask target, description, (options) ->
+ # TODO add watch support
recipeNodes = graph.recipeNodesTo target
aRecipeRan = false
allRecipesRan = false
@@ -143,9 +144,10 @@ runRecipeContext = (graph, recipeNode, runNextRecipeCallback, options) ->
do runNextCommandCallback
return {
- callback: runNextRecipeCallback
- finished: finishedFn
- failed: failedFn
- prereqs: recipeNode.prereqs(graph).names()
- exec: execFn
+ callback: runNextRecipeCallback
+ finished: finishedFn
+ failed: failedFn
+ prereqs: recipeNode.prereqs(graph).names()
+ modifiedPrereqs: recipeNode.modifiedPrereqs(graph).names()
+ exec: execFn
}
View
43 src/rules.coffee
@@ -98,27 +98,48 @@ class RecipeNode extends Node
clone: (node) -> new RecipeNode @name, @recipe
prereqs: (graph) -> graph.arcs.to(graph.node this.name).from().ofType FileNode
outputs: (graph) -> graph.arcs.from(graph.node this.name).to().ofType FileNode
- shouldRun: (graph) ->
+ modifiedPrereqs: (graph) ->
prereqs = this.prereqs graph
- # Recipes without prereqs always run
- if prereqs.isEmpty() then return true
-
outputs = this.outputs graph
- # Recipes without file outputs always run
- if outputs.isEmpty() then return true
+ if prereqs.isEmpty() or outputs.isEmpty() then return prereqs
# There are file inputs and outputs. If there is the same number of inputs
# as outputs we take a special case and compare them 1 by 1. If there are
# a different number of inputs and outputs we check to see if the greatest
# modified time of the inputs is greater than the oldest output. If so we
# should run.
if prereqs.count() == outputs.count()
- # TODO: special case
- return true
+ return new NodeList _(_.zip prereqs.items,outputs.items)
+ .chain()
+ .map((pair) ->
+ [input,output] = pair
+ inputTime = input.mtime || Date.now()
+ outputTime = output.mtime || 0
+ if inputTime > outputTime
+ input
+ else
+ false
+ )
+ .compact()
+ .value()
else
- prereqMax = _(prereqs.items).max (fileNode) -> fileNode.mtime || Date.now()
- outputMin = _(outputs.items).min (fileNode) -> fileNode.mtime || 0
- return prereqMax.mtime > outputMin.mtime
+ prereqMax = _(prereqs.items).max (fileNode) -> fileNode.mtime ||= Date.now()
+ outputMin = _(outputs.items).min (fileNode) -> fileNode.mtime ||= 0
+ if prereqMax.mtime > outputMin.mtime
+ return prereqs
+ else
+ return new NodeList
+
+ shouldRun: (graph) ->
+ prereqs = this.prereqs graph
+ # Recipes without prereqs always run
+ if prereqs.isEmpty() then return true
+
+ outputs = this.outputs graph
+ # Recipes without file outputs always run
+ if outputs.isEmpty() then return true
+
+ return not this.modifiedPrereqs(graph).isEmpty()
run: (context, options) -> @recipe.exec.call context, options

0 comments on commit f148e99

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