Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define repl as an alias of scala-compiler-bootstrapped/console #11742

Merged
merged 1 commit into from
Mar 15, 2021
Merged
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
94 changes: 43 additions & 51 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ object Build {
// Run tests with filter through vulpix test suite
val testCompilation = inputKey[Unit]("runs integration test with the supplied filter")

// Spawns a repl with the correct classpath
val repl = inputKey[Unit]("run the REPL with correct classpath")

// Used to compile files similar to ./bin/scalac script
val scalac = inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath")

Expand Down Expand Up @@ -171,7 +168,9 @@ object Build {

// enable verbose exception messages for JUnit
testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "-a", "-v"),
)
) ++
// Spawns a repl with the correct classpath
addCommandAlias("repl", "scala3-compiler-bootstrapped/console")

// Settings shared globally (scoped in Global). Used in build.sbt
lazy val globalSettings = Def.settings(
Expand Down Expand Up @@ -387,9 +386,6 @@ object Build {

// Settings shared between scala3-compiler and scala3-compiler-bootstrapped
lazy val commonDottyCompilerSettings = Seq(
// set system in/out for repl
connectInput in run := true,

// Generate compiler.properties, used by sbt
resourceGenerators in Compile += Def.task {
import java.util._
Expand Down Expand Up @@ -531,8 +527,46 @@ object Build {
},

run := scalac.evaluated,
scalac := runCompilerMain().evaluated,
repl := runCompilerMain(repl = true).evaluated,
scalac := Def.inputTaskDyn {
val log = streams.value.log
val externalDeps = externalCompilerClasspathTask.value
val jars = packageAll.value
val scalaLib = findArtifactPath(externalDeps, "scala-library")
val dottyLib = jars("scala3-library")
val dottyCompiler = jars("scala3-compiler")
val args0: List[String] = spaceDelimited("<arg>").parsed.toList
val decompile = args0.contains("-decompile")
val printTasty = args0.contains("-print-tasty")
val debugFromTasty = args0.contains("-Ythrough-tasty")
val args = args0.filter(arg => arg != "-repl" && arg != "-decompile" &&
arg != "-with-compiler" && arg != "-Ythrough-tasty")

val main =
if (decompile || printTasty) "dotty.tools.dotc.decompiler.Main"
else if (debugFromTasty) "dotty.tools.dotc.fromtasty.Debug"
else "dotty.tools.dotc.Main"

var extraClasspath = Seq(scalaLib, dottyLib)

if ((decompile || printTasty) && !args.contains("-classpath"))
extraClasspath ++= Seq(".")

if (args0.contains("-with-compiler")) {
if (scalaVersion.value == referenceVersion) {
log.error("-with-compiler should only be used with a bootstrapped compiler")
}
val dottyInterfaces = jars("scala3-interfaces")
val dottyStaging = jars("scala3-staging")
val dottyTastyInspector = jars("scala3-tasty-inspector")
val tastyCore = jars("tasty-core")
val asm = findArtifactPath(externalDeps, "scala-asm")
extraClasspath ++= Seq(dottyCompiler, dottyInterfaces, asm, dottyStaging, dottyTastyInspector, tastyCore)
}

val fullArgs = main :: insertClasspathInArgs(args, extraClasspath.mkString(File.pathSeparator))

(runMain in Compile).toTask(fullArgs.mkString(" ", " ", ""))
}.evaluated,

/* Add the sources of scalajs-ir.
* To guarantee that dotty can bootstrap without depending on a version
Expand Down Expand Up @@ -569,48 +603,6 @@ object Build {
}.taskValue,
)

def runCompilerMain(repl: Boolean = false) = Def.inputTaskDyn {
val log = streams.value.log
val externalDeps = externalCompilerClasspathTask.value
val jars = packageAll.value
val scalaLib = findArtifactPath(externalDeps, "scala-library")
val dottyLib = jars("scala3-library")
val dottyCompiler = jars("scala3-compiler")
val args0: List[String] = spaceDelimited("<arg>").parsed.toList
val decompile = args0.contains("-decompile")
val printTasty = args0.contains("-print-tasty")
val debugFromTasty = args0.contains("-Ythrough-tasty")
val args = args0.filter(arg => arg != "-repl" && arg != "-decompile" &&
arg != "-with-compiler" && arg != "-Ythrough-tasty")

val main =
if (repl) "dotty.tools.repl.Main"
else if (decompile || printTasty) "dotty.tools.dotc.decompiler.Main"
else if (debugFromTasty) "dotty.tools.dotc.fromtasty.Debug"
else "dotty.tools.dotc.Main"

var extraClasspath = Seq(scalaLib, dottyLib)

if ((decompile || printTasty) && !args.contains("-classpath"))
extraClasspath ++= Seq(".")

if (args0.contains("-with-compiler")) {
if (scalaVersion.value == referenceVersion) {
log.error("-with-compiler should only be used with a bootstrapped compiler")
}
val dottyInterfaces = jars("scala3-interfaces")
val dottyStaging = jars("scala3-staging")
val dottyTastyInspector = jars("scala3-tasty-inspector")
val tastyCore = jars("tasty-core")
val asm = findArtifactPath(externalDeps, "scala-asm")
extraClasspath ++= Seq(dottyCompiler, dottyInterfaces, asm, dottyStaging, dottyTastyInspector, tastyCore)
}

val fullArgs = main :: insertClasspathInArgs(args, extraClasspath.mkString(File.pathSeparator))

(runMain in Compile).toTask(fullArgs.mkString(" ", " ", ""))
}

def insertClasspathInArgs(args: List[String], cp: String): List[String] = {
val (beforeCp, fromCp) = args.span(_ != "-classpath")
val classpath = fromCp.drop(1).headOption.fold(cp)(_ + File.pathSeparator + cp)
Expand Down