Skip to content

Commit 098afe1

Browse files
esarbeallanrenucci
authored andcommitted
Fix #3071: Create new directory setting and use it for '-d' parameter (#3120)
1 parent 51a317c commit 098afe1

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class GenBCode extends Phase {
4747
}
4848

4949
def outputDir(implicit ctx: Context): AbstractFile =
50-
new PlainDirectory(new Directory(new JFile(ctx.settings.d.value)))
50+
new PlainDirectory(ctx.settings.outputDir.value)
5151

5252
def run(implicit ctx: Context): Unit = {
5353
new GenBCodePipeline(entryPoints.toList,

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools.dotc
22
package config
33

44
import java.io.File
5+
import dotty.tools.io.{ Directory, Path }
56

67
import PathResolver.Defaults
78
import rewrite.Rewrites
@@ -17,7 +18,7 @@ class ScalaSettings extends Settings.SettingGroup {
1718
val javaextdirs = PathSetting("-javaextdirs", "Override java extdirs classpath.", Defaults.javaExtDirs)
1819
val sourcepath = PathSetting("-sourcepath", "Specify location(s) of source files.", "") // Defaults.scalaSourcePath
1920
val classpath = PathSetting("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp"
20-
val d = StringSetting("-d", "directory|jar", "destination for generated classfiles.", ".")
21+
val outputDir = DirectorySetting("-d", "directory|jar", "destination for generated classfiles.", Directory(Path(".")))
2122
val priorityclasspath = PathSetting("-priorityclasspath", "class path that takes precedence over all other paths (or testing only)", "")
2223

2324
/** Other settings */

compiler/src/dotty/tools/dotc/config/Settings.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import scala.util.{ Try, Success, Failure }
66
import reflect.ClassTag
77
import core.Contexts._
88
import scala.annotation.tailrec
9+
import dotty.tools.io.{ Directory, Path }
10+
911
// import annotation.unchecked
1012
// Dotty deviation: Imports take precedence over definitions in enclosing package
1113
// (Note that @unchecked is in scala, not annotation, so annotation.unchecked gives
@@ -20,6 +22,7 @@ object Settings {
2022
val ListTag = ClassTag(classOf[List[_]])
2123
val VersionTag = ClassTag(classOf[ScalaVersion])
2224
val OptionTag = ClassTag(classOf[Option[_]])
25+
val DirectoryTag = ClassTag(classOf[Directory])
2326

2427
class SettingsState(initialValues: Seq[Any]) {
2528
private var values = ArrayBuffer(initialValues: _*)
@@ -158,6 +161,10 @@ object Settings {
158161
case Success(v) => update(v, args)
159162
case Failure(ex) => fail(ex.getMessage, args)
160163
}
164+
case (DirectoryTag, arg :: args) =>
165+
val path = Path(arg)
166+
if (path.isDirectory) update(Directory(path), args)
167+
else fail(s"'$arg' does not exist or is not a directory", args)
161168
case (_, Nil) =>
162169
missingArg
163170
}
@@ -278,5 +285,8 @@ object Settings {
278285

279286
def OptionSetting[T: ClassTag](name: String, descr: String): Setting[Option[T]] =
280287
publish(Setting(name, descr, None, propertyClass = Some(implicitly[ClassTag[T]].runtimeClass)))
288+
289+
def DirectorySetting(name: String, helpArg: String, descr: String, default: Directory): Setting[Directory] =
290+
publish(Setting(name, descr, default, helpArg))
281291
}
282292
}

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ class ReplDriver(settings: Array[String],
106106
protected[this] def resetToInitial(): Unit = {
107107
rootCtx = initialCtx
108108
val outDir: AbstractFile = {
109-
if (rootCtx.settings.d.isDefault(rootCtx))
109+
if (rootCtx.settings.outputDir.isDefault(rootCtx))
110110
new VirtualDirectory("(memory)", None)
111111
else
112-
new PlainDirectory(new Directory(new JFile(rootCtx.settings.d.value(rootCtx))))
112+
new PlainDirectory(rootCtx.settings.outputDir.value(rootCtx))
113113
}
114114
compiler = new ReplCompiler(outDir)
115115
rendering = new Rendering(compiler, classLoader)

compiler/test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class tests extends CompilerTest {
111111
// remove class files from stdlib and tests compilation
112112
Directory(defaultOutputDir + "scala").deleteRecursively()
113113
Directory(defaultOutputDir + "java").deleteRecursively()
114+
Directory(defaultOutputDir).createDirectory()
114115
}
115116

116117
@Test def pickle_pickleOK = compileFiles(testsDir + "pickling/", testPickling)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package dotty.tools.dotc
2+
3+
import org.junit.Test
4+
import org.junit.Assert._
5+
6+
class SettingsTests {
7+
8+
@Test def missingOutputDir: Unit = {
9+
val options = Array("-d", "not_here")
10+
val reporter = Main.process(options)
11+
assertEquals(1, reporter.errorCount)
12+
assertEquals("'not_here' does not exist or is not a directory", reporter.allErrors.head.message)
13+
}
14+
}

0 commit comments

Comments
 (0)