From 823be71afc55d3ed664aec0be637bd412df436a0 Mon Sep 17 00:00:00 2001 From: Pieter Bos Date: Thu, 12 Oct 2023 09:39:23 +0200 Subject: [PATCH] fix #1050: set git buildinfos for caching properly --- build.sc | 13 +++++++++---- src/main/vct/cache/VerificationCache.scala | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/build.sc b/build.sc index a038c7a48f..ffce17e624 100644 --- a/build.sc +++ b/build.sc @@ -681,6 +681,11 @@ object vercors extends Module { object test extends Tests object buildInfo extends BuildInfo with ScalaModule { + def gitBranch() = T.command { os.proc("git", "rev-parse", "--abbrev", "HEAD").call().out.text() } + def gitCommit() = T.command { os.proc("git", "rev-parse", "HEAD").call().out.text() } + def gitShortCommit() = T.command { os.proc("git", "rev-parse", "--short=8", "HEAD").call().out.text() } + def gitHasChanges() = T.command { os.proc("git", "diff-index", "--name-only", "HEAD").call().out.text().nonEmpty } + def buildInfoPackageName = "vct.main" override def buildInfoMembers = T { Seq( @@ -688,10 +693,10 @@ object vercors extends Module { BuildInfo.Value("version", "2.0.0"), BuildInfo.Value("scalaVersion", scalaVersion()), BuildInfo.Value("sbtVersion", "-"), - BuildInfo.Value("currentBranch", "unknown branch"), - BuildInfo.Value("currentCommit", "unknown commit"), - BuildInfo.Value("currentShortCommit", "unknown commit"), - BuildInfo.Value("gitHasChanges", ""), + BuildInfo.Value("currentBranch", gitBranch()()), + BuildInfo.Value("currentCommit", gitCommit()()), + BuildInfo.Value("currentShortCommit", gitShortCommit()()), + BuildInfo.Value("gitHasChanges", gitHasChanges()().toString), BuildInfo.Value("silverCommit", viper.silver.repo.commitish()), BuildInfo.Value("siliconCommit", viper.silicon.repo.commitish()), BuildInfo.Value("carbonCommit", viper.carbon.repo.commitish()), diff --git a/src/main/vct/cache/VerificationCache.scala b/src/main/vct/cache/VerificationCache.scala index c56d987be3..6d495c1465 100644 --- a/src/main/vct/cache/VerificationCache.scala +++ b/src/main/vct/cache/VerificationCache.scala @@ -11,7 +11,7 @@ case object VerificationCache extends LazyLogging { def getSiliconDirectory: Path = getViperDirectory(BuildInfo.siliconCommit).resolve("silicon").resolve("verified") private def getViperDirectory(backendCommit: String): Path = { - val variate = BuildInfo.gitHasChanges == "false" + val variate = BuildInfo.gitHasChanges != "false" if(variate) { logger.warn("Caching is enabled, but results will be discarded, since there were uncommitted changes at compilation time.")