aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Petrashko <dark@d-d.me>2016-06-12 18:11:58 +0200
committerGitHub <noreply@github.com>2016-06-12 18:11:58 +0200
commitc7d1826cf0456e5efad5cb66ae06e7273c8a8e2a (patch)
tree83d508f03ab8af65012fc65f169003fae331b2e1
parent002ed8e1ccaf6e821c75da3a4bfad3b3c12da0ab (diff)
parent42030aad5ad62296286f2d1ec785377ba550cb89 (diff)
downloaddotty-c7d1826cf0456e5efad5cb66ae06e7273c8a8e2a.tar.gz
dotty-c7d1826cf0456e5efad5cb66ae06e7273c8a8e2a.tar.bz2
dotty-c7d1826cf0456e5efad5cb66ae06e7273c8a8e2a.zip
Merge pull request #1314 from dotty-staging/topic/bridge-repl
Add console to bridge
-rw-r--r--bridge/src/main/scala/xsbt/ConsoleInterface.scala73
-rw-r--r--project/Build.scala57
-rw-r--r--project/VersionUtil.scala18
-rwxr-xr-xscripts/build/get-scala-commit-date16
-rw-r--r--scripts/build/get-scala-commit-date.bat9
-rwxr-xr-xscripts/build/get-scala-commit-sha18
-rw-r--r--scripts/build/get-scala-commit-sha.bat9
-rw-r--r--src/dotty/tools/dotc/repl/CompilingInterpreter.scala14
-rw-r--r--src/dotty/tools/dotc/repl/REPL.scala10
9 files changed, 210 insertions, 14 deletions
diff --git a/bridge/src/main/scala/xsbt/ConsoleInterface.scala b/bridge/src/main/scala/xsbt/ConsoleInterface.scala
new file mode 100644
index 000000000..f56918113
--- /dev/null
+++ b/bridge/src/main/scala/xsbt/ConsoleInterface.scala
@@ -0,0 +1,73 @@
+/* sbt -- Simple Build Tool
+ * Copyright 2008, 2009 Mark Harrah
+ */
+package xsbt
+
+import xsbti.Logger
+import scala.tools.nsc.{ GenericRunnerCommand, Interpreter, InterpreterLoop, ObjectRunner, Settings }
+import scala.tools.nsc.interpreter.InteractiveReader
+import scala.tools.nsc.reporters.Reporter
+import scala.tools.nsc.util.ClassPath
+
+import dotty.tools.dotc.core.Contexts.Context
+import dotty.tools.dotc.repl.REPL
+import dotty.tools.dotc.repl.REPL.Config
+
+class ConsoleInterface {
+ def commandArguments(
+ args: Array[String],
+ bootClasspathString: String,
+ classpathString: String,
+ log: Logger
+ ): Array[String] = args
+
+ def run(args: Array[String],
+ bootClasspathString: String,
+ classpathString: String,
+ initialCommands: String,
+ cleanupCommands: String,
+ loader: ClassLoader,
+ bindNames: Array[String],
+ bindValues: Array[Any],
+ log: Logger
+ ): Unit = {
+ val completeArgs =
+ args :+
+ "-bootclasspath" :+ bootClasspathString :+
+ "-classpath" :+ classpathString
+
+ println("Starting dotty interpreter...")
+ val repl = ConsoleInterface.customRepl(
+ initialCommands :: Nil,
+ cleanupCommands :: Nil,
+ bindNames zip bindValues,
+ loader
+ )
+ repl.process(completeArgs)
+ }
+}
+
+object ConsoleInterface {
+ def customConfig(
+ initCmds: List[String],
+ cleanupCmds: List[String],
+ boundVals: Array[(String, Any)],
+ loader: ClassLoader
+ ) = new Config {
+ override val initialCommands: List[String] = initCmds
+ override val cleanupCommands: List[String] = cleanupCmds
+ override val boundValues: Array[(String, Any)] = boundVals
+ override val classLoader: Option[ClassLoader] = Option(loader)
+ }
+
+ def customRepl(cfg: Config): REPL = new REPL {
+ override lazy val config = cfg
+ }
+
+ def customRepl(
+ initCmds: List[String],
+ cleanupCmds: List[String],
+ boundVals: Array[(String, Any)],
+ loader: ClassLoader
+ ): REPL = customRepl(customConfig(initCmds, cleanupCmds, boundVals, loader))
+}
diff --git a/project/Build.scala b/project/Build.scala
index db3587772..fc452f7f6 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -25,7 +25,8 @@ object DottyBuild extends Build {
override def settings: Seq[Setting[_]] = {
super.settings ++ Seq(
scalaVersion in Global := "2.11.5",
- version in Global := "0.1-SNAPSHOT",
+ version in Global :=
+ "0.1-" + VersionUtil.commitDate + "-" + VersionUtil.gitHash + "-SNAPSHOT",
organization in Global := "ch.epfl.lamp",
organizationName in Global := "LAMP/EPFL",
organizationHomepage in Global := Some(url("http://lamp.epfl.ch")),
@@ -50,7 +51,8 @@ object DottyBuild extends Build {
autoScalaLibrary := false,
//Remove javac invalid options in Compile doc
javacOptions in (Compile, doc) --= Seq("-Xlint:unchecked", "-Xlint:deprecation")
- )
+ ).
+ settings(publishing)
lazy val dotty = project.in(file(".")).
dependsOn(`dotty-interfaces`).
@@ -207,11 +209,15 @@ object DottyBuild extends Build {
"org.scala-sbt" % "api" % sbtVersion.value % "test",
"org.specs2" %% "specs2" % "2.3.11" % "test"
),
- version := "0.1.1-SNAPSHOT",
- // The sources should be published with crossPaths := false, the binaries
- // are unused so it doesn't matter.
+ version :=
+ "0.1.1-" + VersionUtil.commitDate + "-" + VersionUtil.gitHash + "-SNAPSHOT",
+ // The sources should be published with crossPaths := false since they
+ // need to be compiled by the project using the bridge.
crossPaths := false,
+ // Don't publish any binaries for the bridge because of the above
+ publishArtifact in (Compile, packageBin) := false,
+
fork in Test := true,
parallelExecution in Test := false
).
@@ -244,7 +250,8 @@ object DottyInjectedPlugin extends AutoPlugin {
""")
}
*/
- )
+ ).
+ settings(publishing)
/** A sandbox to play with the Scala.js back-end of dotty.
@@ -330,8 +337,8 @@ object DottyInjectedPlugin extends AutoPlugin {
lazy val publishing = Seq(
publishMavenStyle := true,
- publishMavenStyle := true,
publishArtifact := true,
+ isSnapshot := version.value.contains("SNAPSHOT"),
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
@@ -341,11 +348,47 @@ object DottyInjectedPlugin extends AutoPlugin {
},
publishArtifact in Test := false,
homepage := Some(url("https://github.com/lampepfl/dotty")),
+ licenses += ("BSD New",
+ url("https://github.com/lampepfl/dotty/blob/master/LICENSE.md")),
scmInfo := Some(
ScmInfo(
url("https://github.com/lampepfl/dotty"),
"scm:git:git@github.com:lampepfl/dotty.git"
)
+ ),
+ pomExtra := (
+ <developers>
+ <developer>
+ <id>odersky</id>
+ <name>Martin Odersky</name>
+ <email>martin.odersky@epfl.ch</email>
+ <url>https://github.com/odersky</url>
+ </developer>
+ <developer>
+ <id>DarkDimius</id>
+ <name>Dmitry Petrashko</name>
+ <email>me@d-d.me</email>
+ <url>https://d-d.me</url>
+ </developer>
+ <developer>
+ <id>smarter</id>
+ <name>Guillaume Martres</name>
+ <email>smarter@ubuntu.com</email>
+ <url>http://guillaume.martres.me</url>
+ </developer>
+ <developer>
+ <id>felixmulder</id>
+ <name>Felix Mulder</name>
+ <email>felix.mulder@gmail.com</email>
+ <url>http://felixmulder.com</url>
+ </developer>
+ <developer>
+ <id>liufengyun</id>
+ <name>Liu Fengyun</name>
+ <email>liufengyun@chaos-lab.com</email>
+ <url>http://chaos-lab.com</url>
+ </developer>
+ </developers>
)
)
diff --git a/project/VersionUtil.scala b/project/VersionUtil.scala
new file mode 100644
index 000000000..338cf2d95
--- /dev/null
+++ b/project/VersionUtil.scala
@@ -0,0 +1,18 @@
+import scala.sys.process.Process
+
+object VersionUtil {
+ def executeScript(scriptName: String) = {
+ val cmd =
+ if (System.getProperty("os.name").toLowerCase.contains("windows"))
+ s"cmd.exe /c scripts\\build\\$scriptName.bat -p"
+ else s"scripts/build/$scriptName"
+ Process(cmd).lines.head.trim
+ }
+
+ /** Seven letters of the SHA hash is considered enough to uniquely identify a
+ * commit, albeit extremely large projects - such as the Linux kernel - need
+ * more letters to stay unique
+ */
+ def gitHash = executeScript("get-scala-commit-sha").substring(0, 7)
+ def commitDate = executeScript("get-scala-commit-date")
+}
diff --git a/scripts/build/get-scala-commit-date b/scripts/build/get-scala-commit-date
new file mode 100755
index 000000000..ef5b0f540
--- /dev/null
+++ b/scripts/build/get-scala-commit-date
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+#
+# Usage: get-scala-commit-date [dir]
+# Figures out current commit date of a git clone.
+# If no dir is given, current working dir is used.
+#
+# Example build version string:
+# 20120312
+#
+
+[[ $# -eq 0 ]] || cd "$1"
+
+lastcommitdate=$(git log --format="%ci" HEAD | head -n 1 | cut -d ' ' -f 1)
+
+# 20120324
+echo "${lastcommitdate//-/}"
diff --git a/scripts/build/get-scala-commit-date.bat b/scripts/build/get-scala-commit-date.bat
new file mode 100644
index 000000000..735a80b92
--- /dev/null
+++ b/scripts/build/get-scala-commit-date.bat
@@ -0,0 +1,9 @@
+@echo off
+for %%X in (bash.exe) do (set FOUND=%%~$PATH:X)
+if defined FOUND (
+ bash "%~dp0\get-scala-commit-date" 2>NUL
+) else (
+ rem echo this script does not work with cmd.exe. please, install bash
+ echo unknown
+ exit 1
+)
diff --git a/scripts/build/get-scala-commit-sha b/scripts/build/get-scala-commit-sha
new file mode 100755
index 000000000..eab90a421
--- /dev/null
+++ b/scripts/build/get-scala-commit-sha
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+#
+# Usage: get-scala-commit-sha [dir]
+# Figures out current commit sha of a git clone.
+# If no dir is given, current working dir is used.
+#
+# Example build version string:
+# 6f1c486d0ba
+#
+
+[[ $# -eq 0 ]] || cd "$1"
+
+# printf %016s is not portable for 0-padding, has to be a digit.
+# so we're stuck disassembling it.
+hash=$(git log -1 --format="%H" HEAD)
+hash=${hash#g}
+hash=${hash:0:10}
+echo "$hash"
diff --git a/scripts/build/get-scala-commit-sha.bat b/scripts/build/get-scala-commit-sha.bat
new file mode 100644
index 000000000..6559a1912
--- /dev/null
+++ b/scripts/build/get-scala-commit-sha.bat
@@ -0,0 +1,9 @@
+@echo off
+for %%X in (bash.exe) do (set FOUND=%%~$PATH:X)
+if defined FOUND (
+ bash "%~dp0\get-scala-commit-sha" 2>NUL
+) else (
+ rem echo this script does not work with cmd.exe. please, install bash
+ echo unknown
+ exit 1
+)
diff --git a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
index b6a3e388e..897011be2 100644
--- a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
+++ b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
@@ -60,7 +60,11 @@ import printing.SyntaxHighlighting
* @param ictx The context to use for initialization of the interpreter,
* needed to access the current classpath.
*/
-class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler with Interpreter {
+class CompilingInterpreter(
+ out: PrintWriter,
+ ictx: Context,
+ parentClassLoader: Option[ClassLoader]
+) extends Compiler with Interpreter {
import ast.untpd._
import CompilingInterpreter._
@@ -136,8 +140,6 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
/** the compiler's classpath, as URL's */
val compilerClasspath: List[URL] = ictx.platform.classPath(ictx).asURLs
- protected def parentClassLoader: ClassLoader = classOf[Interpreter].getClassLoader
-
/* A single class loader is used for all commands interpreted by this Interpreter.
It would also be possible to create a new class loader for each command
to interpret. The advantages of the current approach are:
@@ -153,8 +155,10 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
*/
/** class loader used to load compiled code */
val classLoader: ClassLoader = {
- val parent = new URLClassLoader(compilerClasspath.toArray, parentClassLoader)
- new AbstractFileClassLoader(virtualDirectory, parent)
+ lazy val parent = new URLClassLoader(compilerClasspath.toArray,
+ classOf[Interpreter].getClassLoader)
+
+ new AbstractFileClassLoader(virtualDirectory, parentClassLoader.getOrElse(parent))
}
// Set the current Java "context" class loader to this interpreter's class loader
diff --git a/src/dotty/tools/dotc/repl/REPL.scala b/src/dotty/tools/dotc/repl/REPL.scala
index 1fcb055d6..cca5e8d6b 100644
--- a/src/dotty/tools/dotc/repl/REPL.scala
+++ b/src/dotty/tools/dotc/repl/REPL.scala
@@ -4,7 +4,10 @@ package repl
import core.Contexts.Context
import reporting.Reporter
-import java.io.{BufferedReader, File, FileReader, PrintWriter}
+import io.{AbstractFile, PlainFile, VirtualDirectory}
+import scala.reflect.io.{PlainDirectory, Directory}
+import java.io.{BufferedReader, File => JFile, FileReader, PrintWriter}
+import java.net.{URL, URLClassLoader}
/** A compiler which stays resident between runs.
* Usage:
@@ -31,7 +34,7 @@ class REPL extends Driver {
}
override def newCompiler(implicit ctx: Context): Compiler =
- new repl.CompilingInterpreter(config.output, ctx)
+ new repl.CompilingInterpreter(config.output, ctx, config.classLoader)
override def sourcesRequired = false
@@ -80,6 +83,9 @@ object REPL {
*/
val boundValues: Array[(String, Any)] = Array.empty[(String, Any)]
+ /** To pass a custom ClassLoader to the Dotty REPL, overwride this value */
+ val classLoader: Option[ClassLoader] = None
+
/** The default input reader */
def input(in: Interpreter)(implicit ctx: Context): InteractiveReader = {
val emacsShell = System.getProperty("env.emacs", "") != ""