better invalidation of interface version.properties file

This commit is contained in:
Mark Harrah 2012-05-13 21:31:40 -04:00
parent 7bed381bec
commit 062b47ac8d
2 changed files with 8 additions and 4 deletions

View File

@ -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
)

View File

@ -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)
}