Skip to content
Snippets Groups Projects
Commit 9c422817 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Fix the classpath mess for good.

sbt now generates two scripts,
  - ./leon
  - ./setupenv
setupenv needs to be evaluated before doing "sbt test". Make sure you
run it using "source ./setupenv" and not "./setupenv" so that the
exports contained in setupenv have an effect on the outer shell
context.

setupenv is used within ./leon as well
parent 1721a865
Branches
Tags
No related merge requests found
...@@ -4,7 +4,11 @@ import Keys._ ...@@ -4,7 +4,11 @@ import Keys._
object Leon extends Build { object Leon extends Build {
private val scriptName = "leon" private val scriptName = "leon"
def scriptFile = file(".") / scriptName private val setupScriptName = "setupenv"
def scriptFile = file(".") / scriptName
def setupScriptFile = file(".") / setupScriptName
def is64 = System.getProperty("sun.arch.data.model") == "64" def is64 = System.getProperty("sun.arch.data.model") == "64"
def ldLibraryDir32 = file(".") / "lib-bin" / "32" def ldLibraryDir32 = file(".") / "lib-bin" / "32"
def ldLibraryDir64 = file(".") / "lib-bin" / "64" def ldLibraryDir64 = file(".") / "lib-bin" / "64"
...@@ -16,7 +20,7 @@ object Leon extends Build { ...@@ -16,7 +20,7 @@ object Leon extends Build {
} }
} }
val scriptTask = TaskKey[Unit]("script", "Generate the " + scriptName + " Bash script") <<= (streams, dependencyClasspath in Compile, classDirectory in Compile) map { (s, deps, out) => val scriptTask = TaskKey[Unit]("script", "Generate the " + scriptName + " and " + setupScriptName + " Bash scriptes") <<= (streams, dependencyClasspath in Compile, classDirectory in Compile) map { (s, deps, out) =>
if(scriptFile.exists) { if(scriptFile.exists) {
s.log.info("Re-generating script ("+(if(is64) "64b" else "32b")+")...") s.log.info("Re-generating script ("+(if(is64) "64b" else "32b")+")...")
scriptFile.delete scriptFile.delete
...@@ -36,13 +40,13 @@ object Leon extends Build { ...@@ -36,13 +40,13 @@ object Leon extends Build {
val nl = System.getProperty("line.separator") val nl = System.getProperty("line.separator")
val fw = new java.io.FileWriter(scriptFile) val fw = new java.io.FileWriter(scriptFile)
fw.write("#!/bin/bash --posix" + nl) fw.write("#!/bin/bash --posix" + nl)
if (is64) { val ldLibPath = if (is64) {
fw.write("SCALACLASSPATH=\"") fw.write("SCALACLASSPATH=\"")
fw.write((out.absolutePath +: depsPaths).mkString(":")) fw.write((out.absolutePath +: depsPaths).mkString(":"))
fw.write("\"" + nl + nl) fw.write("\"" + nl + nl)
// Setting the dynamic lib path // Setting the dynamic lib path
fw.write("LIBRARY_PATH=\"" + ldLibraryDir64.absolutePath + "\"" + nl) ldLibraryDir64.absolutePath
} else { } else {
fw.write("if [ `uname -m` == \"x86_64\" ]; then "+nl) fw.write("if [ `uname -m` == \"x86_64\" ]; then "+nl)
...@@ -56,12 +60,18 @@ object Leon extends Build { ...@@ -56,12 +60,18 @@ object Leon extends Build {
fw.write("\"" + nl) fw.write("\"" + nl)
// Setting the dynamic lib path // Setting the dynamic lib path
fw.write(" LIBRARY_PATH=\"" + ldLibraryDir32.absolutePath + "\"" + nl)
fw.write("fi" + nl + nl) fw.write("fi" + nl + nl)
ldLibraryDir32.absolutePath
} }
val leonLibPath = depsPaths.find(_.endsWith("/library/target/scala-2.9.2/classes")) match {
case None => throw new Exception("Couldn't find leon-library in the classpath.")
case Some(p) => p
}
fw.write("source "+setupScriptFile.getAbsolutePath()+nl)
// the Java command that uses sbt's local Scala to run the whole contraption. // the Java command that uses sbt's local Scala to run the whole contraption.
fw.write("LD_LIBRARY_PATH=\"$LIBRARY_PATH\" \\"+nl)
fw.write("java -Xmx2G -Xms512M -classpath ${SCALACLASSPATH} -Dscala.home=\"") fw.write("java -Xmx2G -Xms512M -classpath ${SCALACLASSPATH} -Dscala.home=\"")
fw.write(scalaHomeDir) fw.write(scalaHomeDir)
fw.write("\" -Dscala.usejavacp=true ") fw.write("\" -Dscala.usejavacp=true ")
...@@ -69,6 +79,16 @@ object Leon extends Build { ...@@ -69,6 +79,16 @@ object Leon extends Build {
fw.write("leon.Main $@" + nl) fw.write("leon.Main $@" + nl)
fw.close fw.close
scriptFile.setExecutable(true) scriptFile.setExecutable(true)
s.log.info("Generating setup script ("+(if(is64) "64b" else "32b")+")...")
val sfw = new java.io.FileWriter(setupScriptFile)
sfw.write("#!/bin/bash --posix" + nl)
sfw.write("export LD_LIBRARY_PATH=\""+ldLibPath+"\"" + nl)
sfw.write("export LEON_LIBRARY_PATH=\""+leonLibPath+"\"" + nl)
sfw.write("export SCALA_HOME=\""+scalaHomeDir+"\"" + nl)
sfw.close
setupScriptFile.setExecutable(true)
} catch { } catch {
case e => s.log.error("There was an error while generating the script file: " + e.getLocalizedMessage) case e => s.log.error("There was an error while generating the script file: " + e.getLocalizedMessage)
} }
......
...@@ -9,12 +9,26 @@ object Settings { ...@@ -9,12 +9,26 @@ object Settings {
var silentlyTolerateNonPureBodies: Boolean = false var silentlyTolerateNonPureBodies: Boolean = false
def defaultClassPath() = { def defaultClassPath() = {
val env = System.getenv("SCALA_HOME") val leonLib = System.getenv("LEON_LIBRARY_PATH")
if (env != "") { if (leonLib == "" || leonLib == null) {
List(env+"/lib") sys.error("LEON_LIBRARY_PATH env variable is undefined")
}
val leonCPs = leonLib
val scalaHome = System.getenv("SCALA_HOME")
val scalaCPs = if (scalaHome != "") {
val f = new java.io.File(scalaHome+"/lib")
f.listFiles().collect {
case f if f.getPath().endsWith(".jar") => f.getAbsolutePath()
}.toList
} else { } else {
Nil Nil
} }
leonCPs :: scalaCPs
} }
} }
......
...@@ -13,8 +13,7 @@ object ExtractionPhase extends LeonPhase[List[String], Program] { ...@@ -13,8 +13,7 @@ object ExtractionPhase extends LeonPhase[List[String], Program] {
val settings = new NSCSettings val settings = new NSCSettings
//settings.extdirs.value = ctx.settings.classPath.mkString(":") settings.classpath.value = ctx.settings.classPath.mkString(":")
settings.usejavacp.value = true
val compilerOpts = args.filterNot(_.startsWith("--")) val compilerOpts = args.filterNot(_.startsWith("--"))
...@@ -26,7 +25,7 @@ object ExtractionPhase extends LeonPhase[List[String], Program] { ...@@ -26,7 +25,7 @@ object ExtractionPhase extends LeonPhase[List[String], Program] {
// Debugging code for classpath crap // Debugging code for classpath crap
// new scala.tools.util.PathResolver(settings).Calculated.basis.foreach { cp => // new scala.tools.util.PathResolver(settings).Calculated.basis.foreach { cp =>
// cp.foreach( p => // cp.foreach( p =>
// ctx.reporter.info(" => "+p.toString) // println(" => "+p.toString)
// ) // )
// } // }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment