Skip to content

Commit c81c79c

Browse files
committed
Add basic cli for semanticdb
1 parent 6a5d6f0 commit c81c79c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

semanticdb/src/dotty/semanticdb/Main.scala

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,55 @@ import scala.tasty.Reflection
44
import scala.tasty.file._
55
import scala.NotImplementedError
66

7+
import dotty.tools.dotc.Driver
8+
79
object Main {
10+
def parseArguments(args: Array[String]): (Map[String, String], Boolean) = {
11+
def nextArgument(optionMap: Map[String, String], args: List[String]): Map[String, String] = args match {
12+
case "--out" :: file :: tail => nextArgument(optionMap + ("outfile" -> file), tail)
13+
case "-o" :: file :: tail => nextArgument(optionMap + ("outfile" -> file), tail)
14+
case "--help" :: tail => nextArgument(optionMap + ("help" -> ""), tail)
15+
case "-h" :: tail => nextArgument(optionMap + ("help" -> ""), tail)
16+
case "--temp" :: folder :: tail => nextArgument(optionMap + ("temp" -> folder), tail)
17+
case "-t" :: folder :: tail => nextArgument(optionMap + ("temp" -> folder), tail)
18+
case file :: tail => nextArgument(optionMap + ("input" -> file), tail)
19+
case Nil => optionMap
20+
}
21+
22+
val help = """Usage semanticdb [options] [file]
23+
|Generate semanticdb's information related to the source file [file]
24+
|Options are:
25+
| -h,--help Show help
26+
| -o <file>, --out <file> Place the output into <file>
27+
| -t <folder>, --temp <folder> Use <folder> as the temp directory to store build artifacts
28+
""".stripMargin
29+
30+
var optionMap = nextArgument(Map(), args.toList)
31+
if (optionMap.contains("help") || !optionMap.contains("input")) {
32+
println(help)
33+
return (optionMap, false)
34+
} else {
35+
if (!optionMap.contains("temp")) {
36+
optionMap += ("temp" -> "/home/pierre/epfl/semester/dotty/semanticdb/testClass/")
37+
}
38+
val driver = new Driver
39+
val compilerParams : List[String] =
40+
optionMap("input") ::
41+
"-Yno-inline" ::
42+
"-d" :: optionMap("temp") ::
43+
"-classpath" :: "/home/pierre/epfl/semester/dotty/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.12/dotty-library_0.12-0.12.0-bin-SNAPSHOT.jar" ::
44+
Nil
45+
46+
val foo = driver.process(compilerParams.toArray)
47+
return (optionMap, true)
48+
}
49+
}
50+
51+
852
def main(args: Array[String]): Unit = {
953
val extraClasspath = "." // TODO allow to set it from the args with -classpath XYZ
1054
val classes = args.toList
55+
val (optionMap, canTreat) = parseArguments(args)
1156
if (args.isEmpty) {
1257
println("Dotty Semantic DB: No classes where passed as argument")
1358
} else {

semanticdb/test/dotty/semanticdb/Tests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ class Tests {
209209
@Test def testSuper(): Unit = checkFile("example/Super.scala")
210210
@Test def testTypeBug(): Unit = checkFile("example/TypeBug.scala")*/
211211
//@Test def testTraits(): Unit = checkFile("example/Traits.scala")
212-
//@Test def testSynthetic(): Unit = checkFile("example/Synthetic.scala")
212+
@Test def testSynthetic(): Unit = checkFile("example/Synthetic.scala")
213213
//@Test def testBinaryOp(): Unit = checkFile("example/BinaryOp.scala")
214214
//@Test def testAnonymous(): Unit = checkFile("example/Anonymous.scala")
215215
@Test def testDottyPredef(): Unit = checkFile("example/DottyPredef.scala")
216216
@Test def testCase(): Unit = checkFile("example/Case.scala")
217217

218+
218219
}

0 commit comments

Comments
 (0)