Fix issue where compiler interface was poorly cached

This commit is contained in:
Mark Harrah 2009-11-09 22:02:53 -05:00
parent 4023e10fd6
commit 9516e54e0a
5 changed files with 26 additions and 17 deletions

View File

@ -1,11 +0,0 @@
/* sbt -- Simple Build Tool
* Copyright 2009 Mark Harrah
*/
package xsbti;
public interface Versions
{
public static final String Sbt = "0.7.0_13"; // keep in sync with LauncherProject in the XSbt project definition;
public static final int Interface = 1;
public static final int BootInterface = 1;
}

View File

@ -55,7 +55,7 @@ class ComponentManager(globalLock: xsbti.GlobalLock, provider: xsbti.ComponentPr
/** Retrieve the file for component 'id' from the local repository. */
private def update(id: String): Unit = IvyCache.withCachedJar(sbtModuleID(id), log)(jar => define(id, Seq(jar)) )
private def sbtModuleID(id: String) = ModuleID("org.scala-tools.sbt", id, xsbti.Versions.Sbt)
private def sbtModuleID(id: String) = ModuleID("org.scala-tools.sbt", id, ComponentManager.stampedVersion)
/** Install the files for component 'id' to the local repository. This is usually used after writing files to the directory returned by 'location'. */
def cache(id: String): Unit = IvyCache.cacheJar(sbtModuleID(id), file(id)(IfMissing.Fail), log)
def clearCache(id: String): Unit = lockGlobalCache { IvyCache.clearCachedJar(sbtModuleID(id), log) }
@ -69,4 +69,15 @@ object IfMissing
{
object Fail extends IfMissing
final class Define(val cache: Boolean, define: => Unit) extends IfMissing { def apply() = define }
}
object ComponentManager
{
lazy val (version, timestamp) =
{
val properties = new java.util.Properties
val propertiesStream = getClass.getResourceAsStream("/xsbt.version.properties")
try { properties.load(propertiesStream) } finally { propertiesStream.close() }
(properties.getProperty("version"), properties.getProperty("timestamp"))
}
lazy val stampedVersion = version + "_" + timestamp
}

View File

@ -52,8 +52,7 @@ object IvyCache
copyTo
}
/** Get the location of the cached jar for the given ID in the Ivy cache. If the jar is not in the cache, NotInCache is thrown
* TODO: locking.*/
/** Get the location of the cached jar for the given ID in the Ivy cache. If the jar is not in the cache, NotInCache is thrown .*/
def withCachedJar[T](id: ModuleID, log: IvyLogger)(f: File => T): T =
{
val cachedFile =

View File

@ -73,7 +73,7 @@ package test
{
object MainTest
{
val Version = "test-" + xsbti.Versions.Sbt
val Version = "test-" + System.currentTimeMillis
}
class Exit(val code: Int) extends xsbti.Exit
final class MainException(message: String) extends RuntimeException(message)

View File

@ -119,11 +119,21 @@ class XSbt(info: ProjectInfo) extends ParentProject(info)
val ivy = "org.apache.ivy" % "ivy" % "2.0.0"
override def deliverProjectDependencies = Set(super.deliverProjectDependencies.toSeq : _*) - launchInterfaceSub.projectID
}
class InterfaceProject(info: ProjectInfo) extends DefaultProject(info) with ManagedBase with TestWithLog with Component with JavaProject
abstract class BaseInterfaceProject(info: ProjectInfo) extends DefaultProject(info) with ManagedBase with TestWithLog with Component with JavaProject
class InterfaceProject(info: ProjectInfo) extends BaseInterfaceProject(info)
{
override def componentID: Option[String] = Some("xsbti")
override def packageAction = super.packageAction dependsOn generateVersions
def versionPropertiesPath = mainResourcesPath / "xsbt.version.properties"
lazy val generateVersions = task {
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)
FileUtilities.write(versionPropertiesPath.asFile, "version=" + version + "\ntimestamp=" + timestamp, log)
}
}
class LaunchInterfaceProject(info: ProjectInfo) extends InterfaceProject(info)
class LaunchInterfaceProject(info: ProjectInfo) extends BaseInterfaceProject(info)
{
override def componentID = None
}