From 062b47ac8d6f1e4c19f8cf2f274893265450baa6 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Sun, 13 May 2012 21:31:40 -0400 Subject: [PATCH] better invalidation of interface version.properties file --- project/Sbt.scala | 3 +-- project/Util.scala | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/project/Sbt.scala b/project/Sbt.scala index 7d81c0d15..b2431d3f8 100644 --- a/project/Sbt.scala +++ b/project/Sbt.scala @@ -1,4 +1,3 @@ -// TODO(high): proper incremental xsbt.version.properties generation // TODO(low): proper generated API sources caching: doesn't detect output directory change import sbt._ @@ -192,7 +191,7 @@ object Sbt extends Build exportJars := true, componentID := Some("xsbti"), watchSources <++= apiDefinitions, - resourceGenerators in Compile <+= (version, resourceManaged, streams) map generateVersionFile, + resourceGenerators in Compile <+= (version, resourceManaged, streams, compile in Compile) map generateVersionFile, apiDefinitions <<= baseDirectory map { base => (base / "definition") :: (base / "other") :: (base / "type") :: Nil }, sourceGenerators in Compile <+= (cacheDirectory, apiDefinitions, fullClasspath in Compile in datatypeSub, sourceManaged in Compile, mainClass in datatypeSub in Compile, runner, streams) map generateAPICached ) diff --git a/project/Util.scala b/project/Util.scala index b9531d9b8..4059ed695 100644 --- a/project/Util.scala +++ b/project/Util.scala @@ -55,7 +55,12 @@ object Util toError(run.run(mainClass, cp.files, args, s.log)) (out ** "*.java").get } - def generateVersionFile(version: String, dir: File, s: TaskStreams): Seq[File] = + def lastCompilationTime(analysis: sbt.inc.Analysis): Long = + { + val times = analysis.apis.internal.values.map(_.compilation.startTime) + if(times.isEmpty) 0L else times.max + } + def generateVersionFile(version: String, dir: File, s: TaskStreams, analysis: sbt.inc.Analysis): Seq[File] = { import java.util.{Date, TimeZone} val formatter = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss") @@ -63,7 +68,7 @@ object Util val timestamp = formatter.format(new Date) val content = "version=" + version + "\ntimestamp=" + timestamp val f = dir / "xsbt.version.properties" - if(!f.exists) { // TODO: properly handle this + if(!f.exists || f.lastModified < lastCompilationTime(analysis)) { s.log.info("Writing version information to " + f + " :\n" + content) IO.write(f, content) }