Skip to content

Commit 209fc4c

Browse files
author
Bartosz Krasiński
committed
Report git-hash used to package the distribution - Closes scala#1319
1 parent c4f2024 commit 209fc4c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

project/Build.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import scala.reflect.io.Path
66

77
import org.scalajs.sbtplugin.ScalaJSPlugin
88
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
9+
import sbt.Package.ManifestAttributes
910

1011
object DottyBuild extends Build {
1112

@@ -172,6 +173,9 @@ object DottyBuild extends Build {
172173
fork in Test := true,
173174
parallelExecution in Test := false,
174175

176+
// Add git-hash used to package the distribution to the manifest to know it in runtime and report it in REPL
177+
packageOptions += ManifestAttributes(("Git-Hash", VersionUtil.gitHash)),
178+
175179
// http://grokbase.com/t/gg/simple-build-tool/135ke5y90p/sbt-setting-jvm-boot-paramaters-for-scala
176180
javaOptions <++= (dependencyClasspath in Runtime, packageBin in Compile) map { (attList, bin) =>
177181
// put the Scala {library, reflect} in the classpath

src/dotty/tools/dotc/repl/InterpreterLoop.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con
6666
output.flush()
6767
}
6868

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

7172
/** The main read-eval-print loop for the interpreter. It calls
7273
* `command()` for each line of input.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package dotty.tools.dotc.repl
2+
3+
import java.net.JarURLConnection
4+
import scala.collection.JavaConversions._
5+
6+
object ManifestInfo {
7+
8+
val attributes: Map[String, String] = {
9+
for {
10+
resourceUrl <- Option(getClass.getResource(getClass.getSimpleName + ".class"))
11+
urlConnection = resourceUrl.openConnection() if urlConnection.isInstanceOf[JarURLConnection]
12+
manifest <- Option(urlConnection.asInstanceOf[JarURLConnection].getManifest)
13+
} yield {
14+
manifest.getMainAttributes.foldLeft(Map[String, String]())(
15+
(map, attribute) => map + (attribute._1.toString -> attribute._2.toString)
16+
)
17+
}
18+
}.getOrElse(Map())
19+
20+
}

0 commit comments

Comments
 (0)