Skip to content

Commit

Permalink
Rebuild artifacts if they change
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Mar 9, 2024
1 parent 4a8d30c commit 8b9e02e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/engine/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import galilei.*, filesystemOptions.{createNonexistent,
import gastronomy.*, alphabets.base32.zBase32Unpadded
import gossamer.*
import acyclicity.*
import hieroglyph.*, charEncoders.utf8, charDecoders.utf8, badEncodingHandlers.skip
import guillotine.*
import hellenism.*
import hypotenuse.*
Expand Down Expand Up @@ -149,14 +150,20 @@ class Builder():
async:
val outputName = hash.bytes.encodeAs[Base32]
val output = installation.build / PathName(outputName.take(2)) / PathName(outputName.drop(2))
val checkFile = output / p"checksum"
val inputAsyncs = phase.classpath.map(run)

phase.destination.let: path =>
if !path.exists() then
def checksumsDiffer(): Boolean =
val currentHash = path.as[File].stream[Bytes].digest[Sha2[256]].bytes.encodeAs[Base32]
checkFile.as[File].readAs[Text] != currentHash

if !path.exists() || checkFile.exists() && checksumsDiffer() then
info(t"Building file $path")
val tmpPath = unsafely(installation.work / PathName(Uuid().show))
val zipFile = phase.basis.lay(ZipFile.create(tmpPath)): basis =>
basis().copyTo(path)
ZipFile(path.as[File])
basis().copyTo(tmpPath)
ZipFile(tmpPath.as[File])

(dag(hash) - phase).sorted.map(_.digest).each: hash =>
tasks(hash).await().let: directory =>
Expand All @@ -165,7 +172,10 @@ class Builder():

zipFile.append(entries, Epoch)

tmpPath.as[File].moveTo(path)
tmpPath.as[File].tap: file =>
output.as[Directory]
file.stream[Bytes].digest[Sha2[256]].bytes.encodeAs[Base32].writeTo(checkFile.as[File])
file.moveTo(path)

val inputs = inputAsyncs.map(_.await())

Expand Down
3 changes: 1 addition & 2 deletions src/model/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,11 @@ object Basis extends RefType(t"basis"):
given decoder(using Raises[InvalidRefError]): Decoder[Basis] =
case t"runtime" => Basis.Runtime
case t"tools" => Basis.Tools
case value => raise(InvalidRefError(value, this))(Basis.Runtime)
case value => raise(InvalidRefError(value, this))(Basis.Runtime)

enum Basis:
case Runtime, Tools


object Artifact:
given relabelling: CodlRelabelling[Artifact] = () =>
Map(t"kind" -> t"type", t"includes" -> t"include")
Expand Down

0 comments on commit 8b9e02e

Please sign in to comment.