Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import scala.reflect.io.Path

import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt.Package.ManifestAttributes

object DottyBuild extends Build {

Expand Down Expand Up @@ -172,6 +173,9 @@ object DottyBuild extends Build {
fork in Test := true,
parallelExecution in Test := false,

// Add git-hash used to package the distribution to the manifest to know it in runtime and report it in REPL
packageOptions += ManifestAttributes(("Git-Hash", VersionUtil.gitHash)),

// http://grokbase.com/t/gg/simple-build-tool/135ke5y90p/sbt-setting-jvm-boot-paramaters-for-scala
javaOptions <++= (dependencyClasspath in Runtime, packageBin in Compile) map { (attList, bin) =>
// put the Scala {library, reflect} in the classpath
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/repl/InterpreterLoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con
output.flush()
}

val version = ".next (pre-alpha)"
val gitHash = ManifestInfo.attributes.getOrElse("Git-Hash", "unknown")
val version = s".next (pre-alpha, git-hash: $gitHash)"

/** The main read-eval-print loop for the interpreter. It calls
* `command()` for each line of input.
Expand Down
20 changes: 20 additions & 0 deletions src/dotty/tools/dotc/repl/ManifestInfo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dotty.tools.dotc.repl

import java.net.JarURLConnection
import scala.collection.JavaConversions._

object ManifestInfo {

val attributes: Map[String, String] = {
for {
resourceUrl <- Option(getClass.getResource(getClass.getSimpleName + ".class"))
urlConnection = resourceUrl.openConnection() if urlConnection.isInstanceOf[JarURLConnection]
manifest <- Option(urlConnection.asInstanceOf[JarURLConnection].getManifest)
} yield {
manifest.getMainAttributes.foldLeft(Map[String, String]())(
(map, attribute) => map + (attribute._1.toString -> attribute._2.toString)
)
}
}.getOrElse(Map())

}