aboutsummaryrefslogtreecommitdiff
path: root/sbt-bridge/src/xsbt/ConsoleInterface.scala
blob: b34eb8a4d66388110196a1b7563adf8bd372837a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* sbt -- Simple Build Tool
 * Copyright 2008, 2009 Mark Harrah
 */
package xsbt

import xsbti.Logger

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))
}