Skip to content

Instantly share code, notes, and snippets.

@dcsobral
Created December 13, 2011 18:44
Show Gist options
  • Save dcsobral/1473297 to your computer and use it in GitHub Desktop.
Save dcsobral/1473297 to your computer and use it in GitHub Desktop.
Build.scala
import sbt._
import Keys._
object MyBuild extends Build {
val distPath = "/home/dcs/github/scala/dists" // Set this to your environment
override def projects = root +: benchProjects
lazy val root = (
Project("root", file("."), settings = Nil)
aggregate(benchProjects map Reference.projectToRef: _*)
//settings(sources in Compile := Nil) //, run in Compile <<= inputTask { (argTask: TaskKey[Seq[String]]) => argTask.map(_ => () )})
)
lazy val benchProjects: Seq[Project] = (
normalAndOptimised("latest")
++ normalAndOptimised("former")
++ normalAndOptimised("dcs5286")
)
def normalAndOptimised(dir: String) = Seq(
benchProject(dir, scalaAt(dir)),
benchProject(dir + "Opt", scalaAt(dir) ++ optimise)
)
def benchProject(name: String, extraSettings: Seq[Setting[_]] = Seq.empty) =
Project(name, file(".")) settings(myDefaultSettings:_*) settings(extraSettings ++ targetDir(name): _*)
def targetDir(projectName: String) = Seq(target <<= (baseDirectory, name) apply (_ / "target" / projectName / _))
def scalaAt(dir: String) = Seq(scalaHome := Some(file(distPath) / dir))
val optimise = scalacOptions += "-optimise"
val myDefaultSettings: Seq[Setting[_]] = Seq(
organization := "com.example",
name := "scala-benchmarking-template",
version := "1.0.0-SNAPSHOT",
scalaVersion := "2.9.1",
libraryDependencies ++= Seq(
"com.google.code.java-allocation-instrumenter" % "java-allocation-instrumenter" % "2.0",
"com.google.code.caliper" % "caliper" % "1.0-SNAPSHOT",
"com.google.code.gson" % "gson" % "1.7.1"
),
resolvers += "sonatypeSnapshots" at "http://oss.sonatype.org/content/repositories/snapshots",
// enable forking in run
fork in run := true/*,
//javaOptions in run <<= fullClasspath in Compile map ( s => Seq("-cp", s.files mkString ":") )
// custom kludge to get caliper to see the right classpath
// define the onLoad hook
onLoad in Global <<= (onLoad in Global) ?? identity[State],
{
// attribute key to prevent circular onLoad hook
val key = AttributeKey[Boolean]("loaded")
val f = (s: State) => {
val loaded: Boolean = s get key getOrElse false
if (!loaded) {
var cpString: String = ""
// get the runtime classpath
Project.evaluateTask(fullClasspath.in(Runtime), s) match {
// make a colon-delimited string of the classpath
case Some(Value(cp)) => cpString = cp.files.mkString(":")
// probably should handle an error here, but not sure you can
// ever get here with a working sbt
case _ => Nil
}
val extracted: Extracted = Project.extract(s)
// return a state with loaded = true and javaOptions set correctly
extracted.append(Seq(javaOptions in run ++= Seq("-cp", cpString)),
s.put(key, true))
} else {
// return the state, unmodified
s
}
} // f
onLoad in Global ~= (f compose _)
} // onLoad
*/
) // myDefaultSettings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment