diff --git a/build-support/caching.coffee b/build-support/caching.coffee index f1889a127e..79bf7baf7f 100644 --- a/build-support/caching.coffee +++ b/build-support/caching.coffee @@ -48,11 +48,39 @@ exports.Checksummed = class Checksummed exports.ChecksumFiles = class ChecksumFiles constructor: (paths) -> - @inputs = paths.map (p) -> path.resolve p + @sources = paths.map (p) -> path.resolve p .sort() .map (p) -> new FileContent p - digestAll: -> await Promise.all @inputs.map (f) -> await Checksummed.digestContent f + digestAll: -> await Promise.all @sources.map (f) -> await Checksummed.digestContent f + + +exports.TaskFailed = class TaskFailed extends Error + constructor: (task, cause) -> + message = "task failed: #{task.print()}\n#{cause.message}" + super message, {cause} + @task = task + + title: -> @task.print() + operation: -> @cause.operation?() + reason: -> @cause.reason?() + inner: -> @cause.inner?() + + print: (console, {useColors}) -> + console.error "task failed: #{@title()}" + + operation = "operation: #{@operation()}" + if useColors + operation = util.styleText 'yellow', operation + console.info operation + + reason = "reason: #{@reason()}" + if useColors + reason = util.styleText 'cyan', reason + console.info reason + + if (inner = @inner())? + console.error util.styleText 'reset', inner class Attestation @@ -125,34 +153,6 @@ class Attestation @constructor.objectEquals cached, generated -exports.TaskFailed = class TaskFailed extends Error - constructor: (task, cause) -> - message = "task failed: #{task.print()}\n#{cause.message}" - super message, {cause} - @task = task - - title: -> @task.print() - operation: -> @cause.operation?() - reason: -> @cause.reason?() - inner: -> @cause.inner?() - - print: (console, {useColors}) -> - console.error "task failed: #{@title()}" - - operation = "operation: #{@operation()}" - if useColors - operation = util.styleText 'yellow', operation - console.info operation - - reason = "reason: #{@reason()}" - if useColors - reason = util.styleText 'cyan', reason - console.info reason - - if (inner = @inner())? - console.error util.styleText 'reset', inner - - exports.BuildTask = class BuildTask identifier: -> throw new TypeError "unimplemented: #{@constructor.name}" inputSources: -> throw new TypeError "unimplemented: #{@constructor.name}" diff --git a/build-support/graph.coffee b/build-support/graph.coffee new file mode 100644 index 0000000000..9215715e97 --- /dev/null +++ b/build-support/graph.coffee @@ -0,0 +1,54 @@ +assert = require 'assert' + + +class ProductRelations + constructor: -> + @in = new Set + @out = new Set + + addInput: (taskId) -> + assert (not @in.has taskId), taskId + @in.add taskId + + addOutput: (taskId) -> + assert (not @out.has taskId), taskId + @out.add taskId + + +class ProductRegistry + constructor: -> + @graph = new Map + @knownTasks = new Map + @knownContent = new Map + + ensureNewTask: (task) -> + taskId = task.identifier() + assert (not @knownTasks.has taskId), taskId + @knownTasks.set taskId, task + taskId + + maybeNewContent: (content) -> + contentId = content.identifier() + @knownContent.set contentId, content + contentId + + setupRelations: (contentId) -> + if @graph.has contentId + return @graph.get contentId + relations = new ProductRelations + @graph.set contentId, relations + relations + + registerTask: (task) -> + taskId = @ensureNewTask task + + for {sources} in task.inputSources() + for i in sources + contentId = @maybeNewContent i + relations = @setupRelations contentId + relations.addInput taskId + for {sources} in task.outputSources() + for o in sources + contentId = @maybeNewContent o + relations = @setupRelations contentId + relations.addOutput taskId