Implement diag feature
authorNick Downing <downing.nick@gmail.com>
Mon, 8 Oct 2018 23:44:21 +0000 (10:44 +1100)
committerNick Downing <downing.nick@gmail.com>
Mon, 8 Oct 2018 23:44:21 +0000 (10:44 +1100)
build_cache.js

index 15918ff..a2e31d5 100644 (file)
@@ -7,11 +7,14 @@ let BuildCache = function() {
   if (!this instanceof BuildCache)
     throw Error('BuildCache is a constructor')
   this.map = new Map()
+  this.diag = false
 }
 
 BuildCache.prototype.get = async function(key, build_func) {
   let result = this.map.get(key)
   if (result === undefined) {
+    if (this.diag)
+      console.log('building', key)
     result = {deps: [key], time: Date.now()}
     result.done = build_func(result)
     this.map.set(key, result)
@@ -19,11 +22,15 @@ BuildCache.prototype.get = async function(key, build_func) {
     delete result.done
   }
   else if (result.done === undefined) {
+    if (this.diag)
+      console.log('checking', key)
     result.done = (
       async () => {
         for (let i = 0; i < result.deps.length; ++i) {
           stats = await fs_stat(result.deps[i])
           if (stats.mtimeMs > result.time) {
+            if (this.diag)
+              console.log('rebuilding', key)
             result.deps = [key]
             result.time = Date.now()
             await build_func(result)