Skip to content

Commit

Permalink
add a file and move some code upwards
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Nov 23, 2024
1 parent 982b847 commit d370820
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 30 deletions.
60 changes: 30 additions & 30 deletions build-support/caching.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
54 changes: 54 additions & 0 deletions build-support/graph.coffee
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d370820

Please sign in to comment.