Skip to content

Commit

Permalink
better invalidation of interface version.properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
harrah committed May 14, 2012
1 parent 7bed381 commit 062b47a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions project/Sbt.scala
Original file line number Diff line number Diff line change
@@ -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._
Expand Down Expand Up @@ -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
)
Expand Down
9 changes: 7 additions & 2 deletions project/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ 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")
formatter.setTimeZone(TimeZone.getTimeZone("GMT"))
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)
}
Expand Down

0 comments on commit 062b47a

Please sign in to comment.